/* The Iron Maze: the play screen, the machine inspector and the cards (dialogs). */

/* ---------- play layout ---------- */
.play-screen {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--panel-w, 330px);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: 'top top' 'stage panel' 'bottom panel';
  background: radial-gradient(1100px 620px at 50% 38%, #12252c, var(--bg) 72%);
  padding-left: var(--safe-left); padding-right: var(--safe-right);
}
.play-screen[data-machine='closed'] { --panel-w: 0px; }
.play-screen[data-wing='foundry'] { --wing-glow: rgba(224, 176, 79, 0.1); }
.play-screen[data-wing='bellworks'] { --wing-glow: rgba(127, 218, 212, 0.1); }
.play-screen[data-wing='archive'] { --wing-glow: rgba(210, 189, 120, 0.1); }
.play-screen[data-wing='mint'] { --wing-glow: rgba(118, 208, 160, 0.1); }
.play-screen[data-wing='meridian'] { --wing-glow: rgba(111, 214, 226, 0.1); }
.play-screen[data-wing='counterweight'] { --wing-glow: rgba(224, 140, 82, 0.11); }
.play-screen[data-wing='pneumatic'] { --wing-glow: rgba(144, 191, 230, 0.1); }
.play-screen[data-wing='gallery'] { --wing-glow: rgba(240, 207, 126, 0.1); }
.play-screen[data-wing='orrery'] { --wing-glow: rgba(166, 160, 242, 0.11); }
.play-screen[data-wing='expert'] { --wing-glow: rgba(229, 123, 120, 0.11); }
.play-screen::before { content: ''; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(900px 520px at 50% 46%, var(--wing-glow, transparent), transparent 70%); }

.hud-top {
  grid-area: top; position: relative; z-index: 3; display: flex; align-items: center; gap: 12px;
  padding: max(8px, var(--safe-top)) 14px 8px 12px; background: linear-gradient(180deg, rgba(5, 9, 12, 0.92), rgba(5, 9, 12, 0.6)); border-bottom: 1px solid var(--line-soft);
}
.room-title { flex: 1 1 auto; min-width: 0; }
.room-title h1 { font: 700 clamp(1rem, 2.1vw, 1.45rem)/1.15 var(--display); letter-spacing: 0.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.readout { display: flex; gap: 6px; }
.stat { min-width: 54px; padding: 4px 10px 5px; text-align: center; border: 1px solid var(--line-soft); border-radius: 10px; background: rgba(9, 18, 23, 0.7); }
.stat dt { font: 700 0.75rem/1.2 var(--display); letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.stat dd { font: 700 1.05rem/1.2 var(--display); color: var(--text); }
#mark-value[data-state='done'], #seal-value[data-state='open'] { color: var(--brass-hi); }
#seal-value[data-state='lost'] { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(226, 85, 79, 0.8); }
#turn-value.over { color: #ffb36b; }
.key-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font: 700 0.78rem/1.3 var(--display); letter-spacing: 0.06em; text-transform: uppercase; background: rgba(214, 169, 74, 0.14); border: 1px solid var(--line); }
.key-chip[data-shape='bar'] { color: #8eeeff; border-color: rgba(142, 238, 255, 0.55); background: rgba(142, 238, 255, 0.1); }
.key-chip[data-shape='hook'] { color: #ffd483; border-color: rgba(255, 212, 131, 0.55); background: rgba(255, 212, 131, 0.1); }
.key-chip[data-shape='crown'] { color: #ff9ca4; border-color: rgba(255, 156, 164, 0.55); background: rgba(255, 156, 164, 0.1); }
.hud-actions { display: flex; gap: 8px; }

.stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; overflow: hidden; touch-action: none; }
.game-canvas { position: absolute; inset: 0; }
.game-canvas canvas { display: block; touch-action: none; }
.status-message {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: min(720px, calc(100% - 24px)); width: max-content;
  padding: 7px 16px; border-radius: 999px; text-align: center; font: 600 0.92rem/1.35 var(--body);
  background: rgba(7, 14, 18, 0.88); border: 1px solid var(--line); color: var(--text); pointer-events: none; z-index: 2;
}
.status-message.danger { border-color: rgba(226, 85, 79, 0.8); background: rgba(46, 16, 14, 0.92); color: #ffd9d4; }
.status-message.success { border-color: rgba(94, 220, 170, 0.7); color: #c8ffe8; }
.status-message.notice { border-color: rgba(255, 179, 107, 0.7); color: #ffe0c2; }
.status-message:empty { display: none; }
.aside {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 2; max-width: min(520px, calc(100% - 28px)); padding: 8px 16px; border-radius: 14px;
  font: italic 600 0.95rem/1.35 var(--body); text-align: center; color: #f6ecc7; background: rgba(40, 30, 12, 0.88); border: 1px solid var(--line);
  animation: aside-in 0.4s ease both; pointer-events: none;
}
.rotate-hint {
  position: absolute; left: 50%; top: 50%; transform: translateX(-50%); z-index: 2; width: max-content; max-width: calc(100% - 28px); padding: 6px 14px; border-radius: 999px;
  font: 600 0.8rem/1.3 var(--body); text-align: center; color: #cfe6ea; background: rgba(8, 20, 26, 0.9); border: 1px solid var(--line-soft); pointer-events: none;
}
.aside.leaving { opacity: 0; transition: opacity 0.6s; }
@keyframes aside-in { from { opacity: 0; transform: translate(-50%, -6px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- machine inspector ---------- */
.machine-panel {
  grid-area: panel; position: relative; z-index: 3; overflow: auto; overscroll-behavior: contain; width: var(--panel-w, 330px);
  padding: 12px 14px 20px; background: linear-gradient(180deg, rgba(8, 16, 20, 0.96), rgba(6, 12, 15, 0.96)); border-left: 1px solid var(--line-soft);
}
.play-screen[data-machine='closed'] .machine-panel { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.panel-head h2 { font: 700 1.05rem/1.2 var(--display); letter-spacing: 0.08em; color: var(--brass-hi); }
.panel-head .icon-button { display: none; }
.panel-section { padding: 12px 0; border-top: 1px solid var(--line-soft); }
.panel-section h3 { font: 700 0.78rem/1.2 var(--display); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text); margin-bottom: 6px; }
.panel-note { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }
.cycle-list { display: grid; gap: 10px; }
.cycle-card strong { display: block; font: 700 0.84rem/1.25 var(--body); margin-bottom: 4px; }
.cycle-card strong small { font-weight: 600; color: var(--muted); }
.cycle-track { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.cycle-frame { padding: 5px 0; text-align: center; font: 700 0.85rem/1.2 var(--display); border-radius: 8px; border: 1px solid var(--line-soft); background: rgba(14, 28, 34, 0.9); }
.cycle-frame.danger { background: rgba(120, 28, 24, 0.75); border-color: rgba(255, 138, 114, 0.85); color: #ffe3dd; }
.cycle-frame.latched { color: var(--muted); }
.hint-panel p { color: #f2ead2; }
.toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 42px; padding: 7px 12px; text-align: left; font: 700 0.9rem/1.2 var(--body); margin-bottom: 8px; }
.toggle > span:nth-child(2) { flex: 1; }
.toggle .icon { color: var(--brass-hi); }
.toggle-state { margin-left: auto; font: 700 0.72rem/1 var(--display); letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.toggle[aria-pressed='true'] { border-color: var(--brass); }
.toggle[aria-pressed='true'] .toggle-state { color: var(--ok); }
.freeze-list { display: grid; gap: 6px; }
.freeze-list button { min-height: 38px; padding: 6px 12px; text-align: left; font: 600 0.85rem/1.2 var(--body); }
.freeze-list button.selected { border-color: var(--teal); }

/* ---------- bottom controls ---------- */
.hud-bottom { grid-area: bottom; position: relative; z-index: 3; display: flex; align-items: center; justify-content: center; gap: 22px; padding: 6px 14px max(8px, var(--safe-bottom)); }
.keyboard-help { color: var(--muted); font-size: 0.8rem; max-width: 520px; }
.dpad { display: none; grid-template: 'a up b' 'left wait right' 'c down d' / 1fr 1fr 1fr; gap: 6px; }
.pad { width: 52px; height: 52px; padding: 0; display: inline-flex; align-items: center; justify-content: center; color: var(--brass-hi); border-radius: 12px; }
.pad .icon { width: 24px; height: 24px; }
.pad.up { grid-area: up; } .pad.down { grid-area: down; } .pad.left { grid-area: left; } .pad.right { grid-area: right; } .pad.wait { grid-area: wait; }
@media (pointer: coarse) { .dpad { display: grid; } .keyboard-help { display: none; } }
.play-screen[data-large='true'] .dpad { display: grid; }
.play-screen[data-large='true'] .pad { width: 64px; height: 64px; }

/* ---------- cards ---------- */
dialog.card {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: hidden; color: var(--text);
  border: 1px solid var(--line); border-radius: 18px; background: var(--panel-solid);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7), 0 0 0 1px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 233, 168, 0.1);
}
dialog.card[open] { display: flex; flex-direction: column; animation: card-in 0.26s ease both; }
dialog.card::backdrop { background: rgba(2, 6, 8, 0.72); backdrop-filter: blur(3px); }
@keyframes card-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
.card-banner { height: clamp(110px, 24vh, 200px); flex: none; background: var(--banner, linear-gradient(135deg, #1c2e35, #0a1317)) center var(--banner-y, 50%) / cover; border-bottom: 1px solid var(--line-soft); }
.card-body { padding: clamp(16px, 3vw, 26px); overflow: auto; display: grid; gap: 10px; align-content: start; }
.card-body h2 { font: 700 clamp(1.4rem, 3.4vw, 2rem)/1.1 var(--display); letter-spacing: 0.03em; }
.epigraph { font: italic 600 1rem/1.4 var(--body); color: var(--brass-hi); }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }
.card-actions.vertical { flex-direction: column; }
.card button { display: inline-flex; align-items: center; gap: 8px; justify-content: center; min-height: var(--tap); padding: 8px 18px; font: 700 0.95rem/1.2 var(--body); }
.card .card-actions.vertical button { justify-content: flex-start; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(76px, 1fr)); gap: 8px; margin: 4px 0; }
.stat-row div { padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: 10px; background: rgba(14, 26, 32, 0.8); text-align: center; }
.stat-row dt { font: 700 0.75rem/1.2 var(--display); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.stat-row dd { font: 700 1.25rem/1.2 var(--display); color: var(--brass-hi); }
.seal-mark { width: 74px; height: 74px; margin: 0 auto 2px; color: var(--muted); display: grid; place-items: center; border-radius: 50%; border: 2px solid var(--line); background: radial-gradient(circle, rgba(20, 34, 40, 0.9), rgba(8, 14, 18, 0.9)); }
.seal-mark .icon { width: 40px; height: 40px; }
.seal-mark.struck { color: #ffe9a8; border-color: var(--brass-hi); box-shadow: 0 0 28px rgba(255, 217, 120, 0.4); animation: seal-pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1) both; }
@keyframes seal-pop { from { transform: scale(0.4) rotate(-20deg); opacity: 0; } to { transform: none; opacity: 1; } }
.complete-card .eyebrow, .complete-card h2, .complete-card #complete-copy { text-align: center; }
.seal-reason { padding: 8px 12px; border-radius: 10px; background: rgba(60, 40, 14, 0.5); border: 1px solid var(--line); color: #f6dfae; font-size: 0.92rem; }
.daily-line { margin: 2px 0 4px; padding: 8px 14px; border: 1px solid rgba(201, 179, 109, 0.55); border-radius: 999px; background: rgba(70, 52, 20, 0.35); font: 700 0.86rem/1.3 var(--body); color: #f6ecc7; text-align: center; }
.maker-note { margin: 4px 0; padding: 12px 16px; border-left: 3px solid var(--brass); background: linear-gradient(90deg, rgba(70, 52, 20, 0.45), rgba(12, 18, 22, 0.5)); border-radius: 0 10px 10px 0; font: italic 600 0.98rem/1.5 var(--body); color: #f6ecc7; }
.maker-note::before { content: 'Found in the Maker\'s journal'; display: block; margin-bottom: 4px; font: 700 0.66rem/1.2 var(--display); font-style: normal; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.ending-card { width: min(640px, calc(100vw - 24px)); }
.ending-card #ending-pages p { margin-bottom: 10px; font-size: 1.04rem; }
.settings-grid { display: grid; gap: 8px; }
.slider { display: grid; gap: 4px; padding: 0 4px 4px; font: 700 0.82rem/1.2 var(--body); color: var(--muted); }
.slider input { width: 100%; accent-color: var(--brass); height: 28px; }
.confirm-card { width: min(440px, calc(100vw - 24px)); }

/* ---------- compact layouts ---------- */
@media (max-width: 900px) {
  .play-screen { grid-template-columns: minmax(0, 1fr); grid-template-areas: 'top' 'stage' 'bottom'; }
  .readout .stat-key, .readout .stat-mark { display: none; }
  .machine-panel {
    position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: min(64dvh, 520px); border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    padding-bottom: max(20px, var(--safe-bottom)); box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6); z-index: 8;
  }
  .play-screen[data-machine='closed'] .machine-panel { display: none; }
  .panel-head .icon-button { display: inline-flex; }
  .hud-top { gap: 8px; padding: max(6px, var(--safe-top)) 8px 6px 8px; }
  .icon-button { --tap: 40px; }
  .hud-actions { gap: 5px; }
}
@media (max-width: 560px) {
  .hud-top { flex-wrap: wrap; row-gap: 4px; }
  .room-title { order: 2; flex-basis: 100%; }
  .hud-actions { margin-left: auto; order: 1; }
  .readout { order: 1; }
  #btn-menu { order: 0; }
  .stat { min-width: 46px; padding: 3px 8px 4px; }
  .status-message { font-size: 0.82rem; padding: 5px 12px; bottom: 6px; }
  .pad { width: 56px; height: 56px; }
}
@media (max-width: 560px) and (orientation: portrait) {
  /* The board sits at the top of the stage here; the apprentice's aside goes under it, never over a tile. */
  .aside { top: calc(var(--board-bottom, 0px) + 58px); }
}
@media (max-height: 520px) and (orientation: landscape) {
  .play-screen { grid-template-areas: 'top top' 'stage panel' 'stage panel'; grid-template-rows: auto minmax(0, 1fr) 0; }
  .play-screen[data-machine='closed'] { grid-template-columns: minmax(0, 1fr) 0; }
  .hud-top { padding-top: max(4px, var(--safe-top)); padding-bottom: 4px; gap: 8px; }
  .room-title h1 { font-size: 0.95rem; }
  .icon-button { --tap: 36px; }
  .stat { padding: 2px 8px 3px; }
  .hud-bottom { position: absolute; right: calc(max(10px, var(--safe-right)) + var(--panel-w, 0px)); bottom: 8px; padding: 0; z-index: 4; }
  .pad { width: 46px; height: 46px; opacity: 0.88; }
  .machine-panel { position: relative; max-height: none; border-radius: 0; border-top: 0; border-left: 1px solid var(--line-soft); width: var(--panel-w, 300px); box-shadow: none; }
  .play-screen { --panel-w: 280px; }
  .play-screen[data-machine='closed'] { --panel-w: 0px; }
  .keyboard-help { display: none; }
  /* The board gets the stage minus a strip for the objective line, and minus a column for the touch pad: nothing sits on a tile. */
  .game-canvas { bottom: var(--status-strip, 40px); right: var(--pad-gutter, 0px); }
  .status-message { bottom: 3px; left: calc(50% - var(--pad-gutter, 0px) / 2); max-width: calc(100% - var(--pad-gutter, 0px) - 20px); font-size: 0.78rem; line-height: 1.25; padding: 3px 12px; }
  .aside { top: 4px; font-size: 0.82rem; padding: 5px 12px; }
  dialog.card { max-height: calc(100dvh - 10px); }
  .card-banner { height: 70px; }
}
@media (max-height: 520px) and (orientation: landscape) and (pointer: coarse) { .stage { --pad-gutter: 166px; } }
@media (max-height: 520px) and (orientation: landscape) { .play-screen[data-large='true'] .stage { --pad-gutter: 166px; } }
@media (prefers-reduced-motion: reduce) {
  dialog.card[open], .aside, .seal-mark.struck { animation: none; }
}

/* ---------- the free demo ---------- */
/* The site's demo bar sits fixed at the bottom left; the layout leaves it room. */
body[data-demo='true'] .hud-bottom { padding-bottom: 62px; align-items: flex-start; }
body[data-demo='true'] .rooms-screen, body[data-demo='true'] .journal-screen { padding-bottom: 96px; }
body[data-demo='true'] .title-copy { left: auto; right: max(var(--gutter), var(--safe-right)); }
.card a.button {
  display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 8px 20px; border-radius: 10px; text-decoration: none;
  font: 800 0.95rem/1.2 var(--body); border: 1px solid #f6e5ad; background: linear-gradient(180deg, #f1dc9c 0%, #cfa244 52%, #8e6420 100%); color: #1d1305;
}
.card a.button:hover { filter: brightness(1.08); }
.demo-end-card { width: min(600px, calc(100vw - 24px)); --banner-y: 8%; }
.feature-list { margin: 4px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.feature-list li { position: relative; padding: 6px 12px 6px 30px; border: 1px solid var(--line-soft); border-radius: 10px; background: rgba(14, 26, 32, 0.8); font-size: 0.95rem; }
.feature-list li::before { content: ''; position: absolute; left: 11px; top: 50%; width: 7px; height: 7px; margin-top: -4px; transform: rotate(45deg); background: var(--brass); }
@media (max-width: 760px) {
  body[data-demo='true'] .title-menu { bottom: 96px; }
  body[data-demo='true'] .title-copy { bottom: 62px; right: 50%; transform: translateX(50%); white-space: nowrap; }
}

/* ---------- very large screens: the interface grows with the board ---------- */
@media (min-width: 2200px) and (min-height: 1100px) {
  :root { --tap: 58px; --panel-w: 430px; }
  html { font-size: 21px; }
  .play-screen { --panel-w: 430px; }
  .play-screen[data-machine='closed'] { --panel-w: 0px; }
  .machine-panel { width: var(--panel-w); }
  .readout .stat { min-width: 72px; }
  .icon-button .icon { width: 28px; height: 28px; }
  .title-menu { width: 420px; }
}

/* ---------- short landscape screens: cards give up decoration, not content ---------- */
@media (max-height: 520px) and (orientation: landscape) {
  .seal-mark { display: none; }
  .card-body { padding: 12px 18px; gap: 6px; }
  .card-body h2 { font-size: 1.35rem; }
  .stat-row { margin: 0; }
  .stat-row dd { font-size: 1.05rem; }
  .maker-note { font-size: 0.85rem; padding: 8px 12px; }
  .card button, .card a.button { min-height: 38px; padding: 6px 14px; }
}

/* ---------- touch and text floors (standard rows I1 and I5) ----------
   Last in the cascade so that no viewport rule above can undercut them: on a coarse pointer every control is at least
   44 px, and no label anywhere is set below 0.75rem (the small labels above are set at 0.75rem). Kept by
   tests/the-iron-maze-touch-floors.test.mjs; measured in Chromium at 844x390 and 390x844 (docs/quality-pass/the-iron-maze.md). */
@media (pointer: coarse) {
  .card button, .card a.button, .menu-item, .menu-item.link { min-height: 44px; }
}
/* The very large screen rule above sets 58 px; below it the viewport rules shrink the icon buttons, so the floor goes here. */
@media (pointer: coarse) and (max-width: 2199px), (pointer: coarse) and (max-height: 1099px) {
  .icon-button { --tap: 44px; }
}
