/* Schema Architect layout + animation. Tokens, the shell, the lobe and the capsules come from shared/theme.css. */
.shell { overflow-x: clip; } /* clip: confetti must not widen the page */
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.brief p { margin: 0; font-size: 17px; max-width: 54ch; }
.level-title:focus { outline: none; }
#concept { scroll-margin-top: 16px; }

#verdict { isolation: isolate; scroll-margin: 16px; }
#verdict .fails { margin: 0 0 8px; padding-left: 18px; display: grid; gap: 6px; font-size: 14px; line-height: 1.5; }
#verdict .fails b { display: block; }
#verdict .bad { font-weight: 700; }

/* ---- the wide table: a lake holding its columns as capsules, grouped by label (Keys / Descriptions / Numbers), never by colour ---- */
.tools { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.tools:focus { outline: none; }
#tray { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-height: 34px; }
#tray .lbl { width: 100%; font: 800 19px/1 var(--display); letter-spacing: -.02em; }
.grp { position: relative; flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding-left: 112px; } /* one row per kind, its label in the margin */
.grp > small, .toggle legend { font: 600 14px/1.2 var(--font); color: var(--muted); }
.grp > small { position: absolute; left: 0; top: 8px; }
.chip.col { font: 600 13px/1.2 var(--mono); min-height: 32px; cursor: grab; transition: background-color .2s, color .2s; }
.chip.col:hover { background: var(--panel-2); }
.chip.col.sel { background: var(--ink); color: var(--water); }
.chip.lock { font: 600 13px/1.2 var(--mono); border-style: dashed; }
.chip .type { font-size: 11px; font-weight: 400; color: var(--muted); border-left: 1px solid var(--line); padding-left: 6px; }
.chip.col.sel .type { color: var(--water); border-color: currentColor; }
.chip.fresh { animation: pop var(--t) var(--bounce) both; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }
.dest {
  font: 700 14px/1.3 var(--font); color: var(--ink); cursor: pointer;
  background: transparent; border: 2px solid var(--ink); border-radius: 20px; padding: 7px 14px;
  transition: background-color .2s, color .2s;
}
.dest:hover:enabled { background: var(--ink); color: var(--water); }
.dest:disabled { font-weight: 500; color: var(--muted); border: 1.5px dashed var(--muted); cursor: default; }
#wide { min-width: 0; }
#wide > summary, #peekPanel > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; width: max-content; max-width: 100%; }
#wide > summary { font-size: 15px; font-weight: 700; flex-wrap: wrap; }
#wide > summary small { font-size: 14px; font-weight: 400; }
#wide[open] > summary, #peekPanel[open] > summary { margin-bottom: 10px; }
#wide > summary::-webkit-details-marker, #peekPanel > summary::-webkit-details-marker { display: none; }
#wide > summary::before, #peekPanel > summary::before { /* drawn chevron, as on the concept */
  content: ''; flex: none; width: 16px; height: 16px; background: currentColor; mask: var(--i-down) center / contain no-repeat;
  transform: rotate(-90deg); transition: transform var(--t) var(--bounce);
}
#wide[open] > summary::before, #peekPanel[open] > summary::before { transform: none; }

/* ---- the model, on the lobe: the fact is the interchange (ink header), every keyed table a cream panel on its own path.
   A path is dotted until the fact holds that table's key, solid after. game.js draws the paths, their ends and the rows. ---- */
#board { container-type: inline-size; }
.model-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px 24px; margin-bottom: 14px; }
.model-head h2, #qPanel h2, #peekPanel h2 { margin: 0; }
h2 small { font: 400 14px/1.3 var(--font); letter-spacing: 0; margin-left: 6px; }
.meter { display: grid; grid-template-columns: auto auto; gap: 4px 12px; align-items: baseline; font-size: 14px; min-width: 230px; }
.meter b, .meter small { font-family: var(--mono); }
.meter small { font-size: 12px; color: var(--muted); text-align: right; }
.meter .bar { grid-column: 1 / -1; grid-row: 2; height: 10px; border-radius: var(--pill); background: var(--water); border: 2px solid var(--ink); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--ink); transition: width var(--t); }
.legend { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.legend b { font-family: var(--mono); color: var(--ink); }

#star { position: relative; }
#links { position: absolute; inset: 0; z-index: 1; width: 100%; height: 100%; pointer-events: none; overflow: visible; } /* over the cards: the ends sit on their edges */
.link { fill: none; stroke: var(--ink); stroke-width: 3; stroke-dasharray: 1 8; stroke-linecap: round; stroke-linejoin: round; }
.link.on { stroke-width: 4; stroke-dasharray: none; }
.ring { fill: var(--water); stroke: var(--ink); stroke-width: 3; }
.ring-dot, .row-dot { fill: var(--ink); }
.row-dot { stroke: var(--water); stroke-width: 2; offset-rotate: 0deg; animation: walk var(--t) cubic-bezier(.3, 0, .2, 1) both; } /* a row walking out to the table the question needs */
@keyframes walk { from { offset-distance: 0%; } 80% { opacity: 1; } to { offset-distance: 100%; opacity: 0; } }

#cards { position: relative; display: grid; grid-template-columns: 1fr 1.15fr 1fr; gap: 24px 56px; align-items: center; }
.tbl { grid-column: var(--col); grid-row: var(--row); min-width: 0; background: var(--water); border: 2px solid var(--ink); border-radius: var(--radius-card); }
.tbl.fact { grid-column: 2; grid-row: 1 / span 2; }
#cards.solo { grid-template-columns: 1.1fr 1fr; gap: 24px 88px; }
#cards.solo .fact { grid-column: 1; }
#cards.solo .dim { grid-column: 2; }
.tbl.target { outline: 2px dashed var(--ink); outline-offset: 3px; } /* where the selected column can go */
.tbl.landed, .tbl.scan { outline: 3px solid var(--ink); outline-offset: 3px; } /* just received a column (game.js clears it) / being read by the running question */
.tbl.scan { animation: land var(--t) var(--bounce) both; }
.tbl.dim.scan { animation-delay: .3s; } /* the rows arrive, then the table takes them */
@keyframes land { 45% { transform: scale(1.035); } }
.tbl header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; padding: 10px 14px 9px; border-bottom: 1px solid var(--line); border-radius: 16px 16px 0 0; }
.tbl header b { font: 700 15px var(--mono); }
.tbl header small { color: var(--muted); font-size: 14px; }
.tbl .rows { margin-left: auto; font: 12px var(--mono); color: var(--muted); }
.tbl.fact header { background: var(--ink); color: var(--water); border-bottom: 0; } /* the interchange: told apart by its ink header, not a hue */
.tbl.fact header small, .tbl.fact .rows { color: var(--water); }
.cols { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px; min-height: 48px; align-content: flex-start; }
.cols em { color: var(--muted); font-size: 14px; }
.tbl .dest { display: block; width: calc(100% - 28px); margin: 0 14px 14px; }
.toggle { margin: 12px 14px 0; padding: 0; border: 0; min-width: 0; display: grid; gap: 4px; font-size: 15px; } /* a plain group, not a card in a card */
.toggle legend { padding: 0; margin-bottom: 2px; }
.toggle label { display: flex; align-items: center; gap: 8px; min-height: 26px; cursor: pointer; }
.toggle input { margin: 0; width: 18px; height: 18px; flex: none; }
@container (max-width: 640px) { /* a narrow build column: the fact on top, the others below, paths down a gutter at the left */
  #cards, #cards.solo { grid-template-columns: 1fr; gap: 22px; padding-left: 44px; }
  #cards .tbl, #cards.solo .tbl { grid-column: 1; grid-row: auto; }
  .link.on { stroke-width: 3; } /* three tracks share the gutter */
}

/* ---- toolbar, between the wide table and the model so Run is in the first view: the target, then Reset and the one Run capsule ---- */
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.actions .target-chip { margin: 0 auto 0 0; }
.run-why { margin: 0; font-size: 14px; font-weight: 600; color: var(--amber); max-width: 26ch; }
.run-why:empty { display: none; }
.run-why::before { content: '! ' / ''; font-weight: 700; } /* a warning by sign as well as colour */

/* ---- questions: one per row, its status at the right; the peek shares their lake ---- */
.tables { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; } /* minmax: a wide peek table scrolls instead of widening the lake */
#questions { list-style: none; margin: 10px 0 0; padding: 0; display: grid; }
.q { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 12px 8px; border-top: 1px solid var(--line); border-radius: 0; }
.q > div { min-width: 0; }
.q .mark { width: 30px; height: 30px; border-radius: 50%; display: grid; place-content: center; font-weight: 700; background: var(--water); border: 2px solid var(--ink); }
.q code { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.q::after { content: 'Waiting' / ''; font: 600 14px/30px var(--font); color: var(--muted); white-space: nowrap; }
.q.running { background: var(--panel-2); }
.q.running::after { content: 'Checking' / ''; color: var(--ink); }
.q.running .mark { background: var(--accent); }
.q.ok::after { content: 'Correct' / ''; color: var(--good); }
.q.ok .mark { background: var(--ink); color: var(--water); animation: pop var(--t) var(--bounce) both; }
.q.fail::after { content: 'Wrong' / ''; color: var(--bad); }
.q.fail .mark { background: var(--coral); }
.q p { margin: 8px 0 0; font-size: 15px; line-height: 1.45; }
.q .reason { color: var(--bad); }
.q .answer { display: flex; flex-wrap: wrap; gap: 4px; }
.q .answer .chip { font: 400 12px/1.2 var(--mono); min-height: 24px; padding: 2px 9px; }
.q .answer b { font-weight: 700; }
.q table.data { margin-top: 8px; font-size: 12px; }
#peekPanel { border-top: 2px solid var(--ink); padding-top: 12px; }
#peekPanel > summary { min-height: 32px; }
#peekPanel > summary h2 { font-size: 19px; }
#tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
#tabs button { font: 600 12px var(--mono); color: var(--ink); cursor: pointer; background: transparent; border: 1.5px solid var(--ink); border-radius: var(--pill); padding: 4px 12px; min-height: 32px; }
#tabs button[aria-pressed="true"] { background: var(--ink); color: var(--water); }

/* tables */
.scroll { overflow-x: auto; scrollbar-width: thin; }
/* visible cue that a table continues sideways (class set in game.js when it overflows) */
.scroll.more::before { content: 'scroll sideways for more'; position: sticky; left: 0; display: block; width: max-content; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
table.data { width: 100%; white-space: nowrap; }
table.data td.num { text-align: right; }
table.data th small { display: block; font-weight: 400; font-size: 11px; color: var(--muted); }
td.ok::before { content: ''; display: inline-block; width: .9em; height: .9em; margin-right: 5px; vertical-align: -.1em; background: currentColor; mask: var(--i-tick) center / contain no-repeat; }
#peek[data-table] tbody tr:hover { background: var(--panel-2); }

/* placement targets for the selected column: last in the build column, so it sticks to the bottom of the viewport */
#dock { position: sticky; bottom: 8px; z-index: 5; display: grid; gap: 6px; margin-top: -16px; } /* empty on desktop: take back the column's gap */
/* placement confirmation: always in the tree so the live region speaks; only phones show it */
#placed { margin: 0; position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
#placeBar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; font-weight: 600; }
#placeBar[hidden] { display: none; }
@media (min-width: 641px) { #placeBar { display: none; } } /* phone-only: on wider screens each card's own "Place here" button is in view */
#placeBar .dest { min-height: 44px; min-width: 44px; font: 600 13px var(--mono); }
#placeBar b { font-family: var(--mono); }
.confetti { position: absolute; left: 50%; top: 70px; pointer-events: none; z-index: -1; } /* behind the result text (#verdict isolates) */
.confetti i { position: absolute; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); animation: burst 1s ease-out both; }
.confetti i:nth-child(3n) { background: var(--accent); }
@keyframes burst { to { transform: translate(var(--dx), var(--dy)) rotate(540deg); opacity: 0; } }

@media (max-width: 640px) {
  .q { column-gap: 8px; }
  .grp { padding-left: 0; }
  .grp > small { position: static; flex: 1 1 100%; }
  .meter { flex: 1 1 100%; }
  /* touch targets */
  .chip.col, .dest, #tabs button, .toggle label { min-height: 44px; min-width: 44px; }
  .cols .chip.col { padding: 8px 12px; }
  .actions .btn.run { margin-left: auto; }
  .actions .target-chip { display: block; }
  .run-why { max-width: none; flex: 1 1 100%; }
  #peekPanel > summary, #wide > summary { min-height: 44px; width: auto; }
  #dock { margin-top: 0; }
  #placed:not(:empty) { position: static; width: auto; height: auto; clip-path: none; padding: 10px 16px; font: 600 13px var(--mono);
    background: var(--water); border: 2px solid var(--ink); border-radius: var(--radius-card); }
}
@media (prefers-reduced-motion: reduce) {
  .row-dot, .confetti { display: none; } /* end state only: the table being read is outlined, nothing travels */
}
