/* Query (js/pages/query.js): read-only SQL over a game's stats. It is an .st-page, so cards, the
   table box, errors and skeletons are css/stats.css's. The editor is a mono textarea; results scroll
   inside their own box (never the page); the tables and examples sit beside the editor, under it on
   a phone. */

.sq-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  align-items: start;
  gap: 14px;
}
.sq-main,
.sq-aside {
  display: grid;
  gap: 14px;
  min-width: 0;
}
.sq-aside {
  position: sticky;
  top: 16px;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

/* ---------------------------------------------------------------- the editor */
.sq-edit {
  gap: 10px;
  padding: 12px;
}
.sq-editor {
  min-height: 190px;
  padding: 12px 14px;
  font-size: var(--fs-code);
  line-height: 1.6;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
  background: var(--bg);
}
.sq-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}
.sq-rows {
  width: auto;
  height: 32px;
  padding-right: 28px;
  font-size: var(--fs-13);
}
.sq-hint {
  margin-left: auto;
}
.sq-run {
  min-width: 96px;
}
.sq-run .i {
  width: 14px;
  height: 14px;
}
.sq-kbd {
  margin-left: 2px;
  padding: 1px 5px;
  border-radius: var(--r-1);
  font-size: 11px;
  color: inherit;
  background: color-mix(in srgb, var(--accent-ink) 12%, transparent);
  box-shadow: none;
}
.sq-spin {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid color-mix(in srgb, var(--accent-ink) 30%, transparent);
  border-top-color: var(--accent-ink);
  animation: sq-spin 0.8s linear infinite;
}
@keyframes sq-spin {
  to {
    rotate: 360deg;
  }
}

/* ---------------------------------------------------------------- results */
.sq-result {
  min-height: 200px;
  gap: 10px;
}
.sq-res {
  display: grid;
  gap: 10px;
  min-width: 0;
}
.sq-res.is-stale,
.sq-err.is-stale {
  opacity: 0.55;
}
.sq-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 12px;
}
.sq-facts .t-small {
  font-variant-numeric: tabular-nums;
}
.sq-dot {
  margin: 0 7px;
  color: var(--ink-4);
}
.sq-cut {
  color: var(--warning-ink);
}
.sq-table-wrap {
  max-height: min(62dvh, 560px);
}
.sq-table-wrap:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 1px var(--focus), 0 0 0 3px var(--focus-soft);
}
.sq-table th {
  vertical-align: bottom;
}
.sq-table th > span {
  display: block;
  color: var(--ink-2);
}
.sq-type {
  display: block;
  margin-top: 1px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--ink-4);
}
.sq-table td {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-ligatures: none;
}
.sq-table .sq-null {
  color: var(--ink-4);
  font-style: italic;
}
.sq-err p {
  margin-top: 3px;
}
.sq-errmsg {
  margin: 8px 0 4px;
  padding: 8px 10px;
  max-height: 160px;
  overflow: auto;
  border-radius: var(--r-2);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--ink-3);
  background: var(--bg);
}

/* ---------------------------------------------------------------- recent queries */
.sq-hist {
  list-style: none;
  display: grid;
  margin: 0 -8px;
}
.sq-hist-b {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 12px;
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: var(--r-2);
  text-align: left;
  font-size: var(--fs-12);
  color: var(--ink-2);
}
.sq-hist-b:hover {
  background: var(--hover);
  color: var(--ink);
}
.sq-hist-b time {
  font-size: var(--fs-12);
}

/* ---------------------------------------------------------------- tables and examples */
.sq-ex {
  list-style: none;
  display: grid;
  gap: 2px;
  margin: 0 -8px;
}
.sq-ex-b {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 6px 8px;
  border-radius: var(--r-2);
  text-align: left;
  font-size: var(--fs-13);
  color: var(--ink-2);
}
.sq-ex-b .i {
  flex: none;
  color: var(--ink-4);
}
.sq-ex-b:hover {
  background: var(--hover);
  color: var(--ink);
}
.sq-ex-b:hover .i {
  color: var(--ink-2);
}
.sq-tables {
  gap: 4px;
}
.sq-t + .sq-t {
  box-shadow: inset 0 1px 0 var(--line);
}
.sq-t summary {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  min-height: 36px;
  padding: 9px 0;
  cursor: pointer;
  list-style: none;
}
.sq-t summary::-webkit-details-marker {
  display: none;
}
.sq-t summary::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  margin-right: 2px;
  border-right: 1.5px solid var(--ink-4);
  border-bottom: 1.5px solid var(--ink-4);
  rotate: -45deg;
  translate: 0 -1px;
  transition: rotate var(--t-fast) var(--ease);
}
.sq-t[open] summary::before {
  rotate: 45deg;
}
.sq-t-n {
  flex: 1;
  font-weight: 600;
  color: var(--ink);
}
.sq-t-d {
  margin-bottom: 8px;
  color: var(--ink-3);
}
.sq-cols {
  list-style: none;
  display: grid;
  gap: 1px;
  margin-bottom: 10px;
}
.sq-cols li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: baseline;
  gap: 0 10px;
  padding: 3px 0;
}
.sq-col {
  padding: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  text-align: left;
}
.sq-col:hover {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.sq-col-t {
  font-size: 11px;
  text-align: right;
}
.sq-col-d {
  grid-column: 1 / -1;
  color: var(--ink-4);
}

@media (prefers-reduced-motion: reduce) {
  .sq-spin {
    animation: none;
  }
}
@media (pointer: coarse) {
  /* 16 px: iOS doesn't zoom the page into the editor */
  .sq-editor {
    font-size: 16px;
  }
  .sq-col {
    min-height: 32px;
  }
}

/* ---------------------------------------------------------------- narrower */
@media (max-width: 1100px) {
  .sq-layout {
    grid-template-columns: minmax(0, 1fr) 280px;
  }
}
@media (max-width: 900px) {
  .sq-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .sq-aside {
    position: static;
    max-height: none;
    overflow: visible;
  }
}
@media (max-width: 680px) {
  .sq-edit {
    padding: 10px;
  }
  .sq-editor {
    min-height: 160px;
  }
  .sq-hint {
    flex-basis: 100%;
    margin-left: 0;
  }
}
