/* Wind-Up Toys: page-specific layout on top of house-style.css (which holds the tokens, top bar, opening, How dialog).
   Compare = two equal display cases side by side, creature tabs above, one shared control dock pinned under them.
   --chrome is everything on screen that is not a 3D view; the views take the height that is left, so every control stays visible. */
:root {
  --ray-a: #f6edd8; /* sunburst behind the creatures: light cream, two tones */
  --ray-b: #efe2c4;
  --ray-na: #17254a; /* navy sunburst for the Play slot */
  --ray-nb: #1e2f5c;
  --chrome: 470px;
}
html { overflow-x: clip; }
main {
  display: flex; flex-direction: column;
  padding-left: max(4.2%, env(safe-area-inset-left, 0px)); padding-right: max(4.2%, env(safe-area-inset-right, 0px));
}
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.opening { padding: 22px 0 18px; }
.intro { max-width: 520px; }
code { font: 0.92em var(--mono); color: var(--ink); }

/* ---------- View switch + creature tabs ---------- */
.subnav { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding-bottom: 14px; }
.view-switch { display: flex; flex: none; border: 1px solid var(--rule); }
.view-switch a {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px;
  font-size: 11px; letter-spacing: 0.13em; text-transform: uppercase; text-decoration: none; color: var(--muted);
}
.view-switch a + a { border-left: 1px solid var(--rule); }
.view-switch .num { font-size: 10px; font-variant-numeric: tabular-nums; }
.view-switch a:hover { color: var(--accent); }
.view-switch a[aria-current='true'] { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.tabs button {
  display: inline-flex; align-items: center; gap: 7px; min-height: 40px; padding: 0 13px;
  border: 1px solid var(--rule); font-size: 13px; line-height: 1; font-weight: 600; white-space: nowrap;
}
.tabs small { padding-top: 2px; font-size: 10px; font-weight: 400; color: var(--muted); }
.tabs button:hover { border-color: var(--accent); }
.tabs button[aria-pressed='true'] { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
body[data-view='play'] .tabs { display: none; }
.subnav a, .subnav button, .dock button, .concept { outline-offset: 2px; }

/* ---------- Compare ---------- */
.view-compare { display: flex; flex-direction: column; gap: 12px; }
.stages { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.build { min-width: 0; display: flex; flex-direction: column; border: 1px solid var(--rule); background: var(--panel); container-type: inline-size; }
.view {
  position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden;
  max-height: clamp(230px, calc(100dvh - var(--chrome)), 660px);
  touch-action: none; cursor: grab;
  background: repeating-conic-gradient(from 0deg at 50% 62%, var(--ray-a) 0 7.5deg, var(--ray-b) 7.5deg 15deg);
}
/* shell.js measures what is left of the window and sets --view-h; the max-height above is only the fallback before it runs */
.fit .view { aspect-ratio: auto; height: var(--view-h); max-height: none; }
.tight .opening, .tight .hint { display: none; }
.tight .subnav { padding-top: 14px; }
.view:active { cursor: grabbing; }
.view canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.note {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; text-align: center; font-size: 13px; color: #52628a; pointer-events: none;
}
.note.is-lost { z-index: 3; pointer-events: auto; background: var(--ray-a); color: #1c2747; }
.note-reload { margin-left: 6px; padding: 6px 10px; border: 1px solid #1c2747; font: inherit; font-weight: 600; color: inherit; background: none; cursor: pointer; }
/* Glass badge: which model built what is on screen, and what one build costs. */
.build-badge {
  position: absolute; left: 12px; bottom: 12px; z-index: 2; max-width: calc(100% - 24px);
  margin: 0; padding: 8px 12px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  border: 1px solid var(--glass-line); border-radius: 4px; background: var(--glass); backdrop-filter: blur(10px);
  font: 12px / 1.3 var(--mono); letter-spacing: 0.04em; color: var(--ink); pointer-events: none;
}
.build-badge b { margin-right: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.12em; color: var(--accent); }

.view-tip {
  position: absolute; right: 12px; bottom: 12px; z-index: 2; margin: 0; padding: 8px 12px;
  border: 1px solid var(--glass-line); border-radius: 4px; background: var(--glass); backdrop-filter: blur(10px);
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); pointer-events: none;
}
.view.can-fire { cursor: crosshair; }
/* Per-panel stats */
.build dl { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0; border-top: 1px solid var(--rule); }
.build dl div { min-width: 0; padding: 8px 12px 9px; border-left: 1px solid var(--rule); }
.build dl div:first-child { border-left: 0; }
.build dt { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.build dd { margin: 2px 0 0; font: 400 26px / 1 'Instrument Serif', serif; font-variant-numeric: tabular-nums; }

/* Concept thumbnail: sits over the seam between the two panels; click to enlarge. */
.concept {
  --cw: clamp(96px, 13vw, 160px);
  position: absolute; z-index: 4; left: calc(50% - var(--cw) / 2); top: 12px; width: var(--cw);
  display: flex; flex-direction: column; padding: 0; overflow: hidden;
  border: 1px solid var(--glass-line); border-radius: 4px; background: var(--glass); backdrop-filter: blur(10px);
  transition: width 0.15s, left 0.15s, top 0.15s, border-color 0.2s;
}
.concept:hover { border-color: var(--accent); }
.concept img { display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: cover; background: var(--panel); }
.concept span { padding: 4px 0 5px; font-size: 10px; letter-spacing: 0.13em; text-transform: uppercase; }
.concept[aria-pressed='true'] { --cw: min(360px, 78vw); }

.hint { margin: 0; font-size: 12px; line-height: 1.6; color: var(--muted); }
/* Glossary tips are placed against their paragraph, not the word, so they can never run off the side of the window. */
.hint, .intro > p:last-child { position: relative; }
.hint .term, .intro .term { position: static; }
.hint .term-tip { top: auto; bottom: calc(100% + 6px); }

/* Shared controls, pinned to the bottom of the window */
.dock {
  position: sticky; bottom: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 28px;
  padding: 10px 0 calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--rule); background: var(--bg);
}
.dock-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.dock b { margin-right: 4px; font-size: 10px; font-weight: 400; letter-spacing: 0.13em; text-transform: uppercase; color: var(--muted); }
.dock button {
  min-height: 36px; padding: 0 12px; border: 1px solid var(--rule); background: var(--panel);
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.dock button:hover { border-color: var(--accent); }
.dock button[aria-pressed='true'] { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }

/* ---------- Play ---------- */
.view-play { padding-bottom: 28px; }
.play-stage { aspect-ratio: var(--aspect, 16 / 9); display: grid; place-items: center; border: 1px solid var(--rule); background: repeating-conic-gradient(from 0deg at 50% 62%, var(--ray-na) 0 7.5deg, var(--ray-nb) 7.5deg 15deg); }
.play-stage.has-poster { background-size: cover; background-position: center; }
.play-stage iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #000; }
.play-stage .stage-top { z-index: 2; grid-template-columns: 1fr auto; grid-template-areas: '. tools'; }
.stage-wrap.playing .stage-badge { display: none; }
.play-empty { max-width: 560px; padding: 24px; text-align: center; }
.play-empty h2 { margin: 12px 0 12px; font: 400 clamp(30px, 4vw, 52px) / 1 'Instrument Serif', serif; letter-spacing: -0.02em; }
.play-empty p:last-child { margin: 0; font-size: 13px; line-height: 1.6; color: var(--muted); }
.rail-static { cursor: default; padding: 10px 0; }
.rail-static strong { margin-bottom: 4px; }
.rail-item kbd { min-width: 22px; height: 22px; margin-right: 3px; font-size: 11px; }
.how-pending { margin: 24px 0 0; padding: 14px 16px; border: 1px dashed var(--line-2); font-size: 14px; color: var(--muted); }

/* ---------- Game trailer: its own section under the main views ---------- */
.trailer { display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 20px 40px; align-items: start; padding: 44px 0 52px; border-top: 1px solid var(--rule); }
.trailer h2 { margin: 12px 0 14px; font: 400 clamp(32px, 3.6vw, 52px) / 1 'Instrument Serif', serif; letter-spacing: -0.02em; }
.trailer h2 em { font-style: normal; color: var(--accent); }
.trailer-head p:last-child { margin: 0; font-size: 14px; line-height: 1.6; color: var(--muted); }
.trailer video { display: block; width: 100%; aspect-ratio: 16 / 9; border: 1px solid var(--rule); background: #000; }
@media (max-width: 900px) { .trailer { grid-template-columns: minmax(0, 1fr); padding: 28px 0 36px; } }

/* ---------- Footer (the shared exploration runtime mounts its tools strip in [data-exploration-controls]) ---------- */
.site-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 22px 4.2% 28px;
  border-top: 1px solid var(--rule); font-size: 12px; color: var(--muted);
}
.site-foot .foot-id { margin-right: auto; }
.site-foot .foot-link { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
.site-foot .foot-link:hover { color: var(--accent); border-color: var(--accent); }
/* the footer draws the rule and background; the runtime's tool strip sits inside it without a second rule */
.site-foot [data-exploration-controls] { flex: 1 1 320px; display: flex; justify-content: flex-end; border-top: 0; background: none; }
:root { --exploration-footer-bg: var(--bg); --exploration-footer-ink: var(--ink); --exploration-footer-border: var(--rule); }

/* ---------- Responsive ---------- */
@media (max-width: 820px) and (min-height: 501px) {
  :root { --bar-h: 111px; } /* the two-row bar measures 111px with its border */
}
@media (max-width: 900px) {
  .build-badge { padding: 6px 9px; font-size: 10.5px; }
  .build-badge b { margin-right: 8px; }
}
@media (max-width: 1100px) {
  :root { --chrome: 450px; }
}
@media (max-height: 780px) and (min-width: 761px) {
  /* short desktop or tablet landscape: the bar already carries the title */
  .opening { display: none; }
  .subnav { padding-top: 14px; }
  :root { --chrome: 306px; }
}
@media (max-height: 780px) and (min-width: 761px) and (max-width: 1100px) {
  :root { --chrome: 356px; } /* the creature tabs wrap to a second row here */
}
@media (max-width: 820px) and (min-width: 761px) {
  /* tablet portrait: two-row bar, title only in the opening */
  .opening { padding: 14px 0 12px; }
  .intro { display: none; }
  :root { --chrome: 520px; }
}
@media (max-width: 760px) {
  /* narrow window: compact controls. The panels stay side by side unless the window is also tall (next block). */
  .opening, .hint { display: none; }
  .subnav { padding: 10px 0; gap: 6px; }
  .view-switch { width: 100%; }
  .view-switch a { flex: 1; justify-content: center; min-height: 36px; }
  .tabs { gap: 5px; }
  .tabs button { min-height: 32px; padding: 0 8px; font-size: 12px; }
  .tabs small { display: none; }
  .view-compare { gap: 10px; }
  .stages { gap: 8px; }
  .concept { --cw: 70px; top: 8px; }
  .view-tip { right: 8px; bottom: 8px; padding: 5px 8px; font-size: 9px; }
  .build-badge { left: 8px; bottom: 8px; padding: 5px 8px; font-size: 10px; }
  .build-badge b { margin-right: 6px; }
  .build dl div { padding: 4px 9px 5px; }
  .build dt { font-size: 9px; letter-spacing: 0.03em; }
  .build dd { font-size: 19px; }
  .concept[aria-pressed='true'] { --cw: min(300px, 78vw); }
  .concept span { font-size: 9px; padding: 2px 0 3px; }
  .dock { gap: 6px 14px; padding: 8px 0 calc(8px + env(safe-area-inset-bottom, 0px)); }
  .dock-row { gap: 5px; }
  .dock b { display: none; }
  .dock button { min-height: 32px; padding: 0 9px; font-size: 12px; }
  .play-empty { padding: 14px; }
  .play-empty h2 { font-size: 26px; margin: 8px 0; }
}
@media (max-width: 760px) and (max-aspect-ratio: 7/10) {
  /* phone portrait: the panels stack; each view gets half of what is left */
  .stages { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .view { max-height: clamp(150px, calc(50dvh - 252px), 420px); }
  .concept { --cw: 74px; left: auto; right: 10px; top: calc(50% - var(--cw) / 2 - 10px); }
  #s-kimi dl { padding-right: 88px; }
}
/* a narrow panel (two side by side in a small window): the four numbers go two by two, the badge keeps only the model name */
@container (max-width: 300px) {
  .build dl { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .build dl div:nth-child(3) { border-left: 0; }
  .build dl div:nth-child(n + 3) { border-top: 1px solid var(--rule); }
  .build-badge { font-size: 0; padding: 5px 8px; }
  .build-badge b { margin: 0; font-size: 9.5px; letter-spacing: 0.06em; }
}
@media (max-width: 400px) {
  .build dl { grid-template-columns: 1.5fr 1fr 1fr 1fr; }
  .build dl div { padding: 4px 6px 5px; }
  .build dt { font-size: 8.5px; letter-spacing: 0; }
  .build-badge { font-size: 9px; letter-spacing: 0; }
  .build-badge b { letter-spacing: 0.06em; }
}
@media (max-height: 520px) and (min-width: 560px) {
  /* phone landscape: one bar row, one tab row, two views, one dock row */
  .opening, .hint, .build dl, .dock b, .tabs small { display: none; }
  .subnav { flex-wrap: nowrap; padding: 6px 0; gap: 8px; }
  .view-switch { width: auto; }
  .view-switch a { min-height: 30px; padding: 0 9px; gap: 5px; letter-spacing: 0.08em; }
  /* a narrow landscape phone scrolls the row instead of losing the last toys; the 3px padding, taken back by the margin, keeps the 2px focus outline inside the scroll box */
  .tabs { flex-wrap: nowrap; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 3px; margin: -3px; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: none; }
  .tabs button { min-height: 30px; padding: 0 7px; font-size: 12px; }
  .view-compare { gap: 6px; }
  .stages { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .view { max-height: max(140px, calc(100dvh - var(--bar-h) - 98px)); }
  .build-badge { left: 8px; bottom: 8px; padding: 5px 8px; font-size: 10px; }
  .concept { --cw: 76px; left: calc(50% - var(--cw) / 2); right: auto; top: 8px; }
  .concept[aria-pressed='true'] { --cw: min(230px, 55dvh); }
  .dock { flex-wrap: nowrap; gap: 6px 12px; padding: 5px 0 calc(5px + env(safe-area-inset-bottom, 0px)); }
  .dock-row { flex-wrap: nowrap; gap: 4px; }
  .dock button { min-height: 30px; padding: 0 8px; }
  .view-play { padding-bottom: 8px; }
  .play-stage { aspect-ratio: auto; height: calc(100dvh - var(--bar-h) - 60px); min-height: 200px; }
  .view-play .stage-badge { display: none; }
}
