/* Kludgeworks UI — technical drawing on parchment, framed in brass. Textures (--tex-*) are generated
   procedurally into canvases at load by js/ui/textures.js; no image files are used. */
:root {
  --brass: #C9A227; --brass-hi: #E6C766; --brass-dark: #8A6E1F; --brass-deep: #5E4A12;
  --copper: #B4703A; --copper-dark: #7A4423;
  --walnut: #5C3D24; --walnut-dark: #2E1F13; --walnut-mid: #452c19;
  --iron: #3A3A3D; --iron-dark: #1A1A1C;
  --verdigris: #4E8A78; --amber: #FFB347; --parchment: #E8DCC0; --parchment-dark: #d7c7a3;
  --ink: #2B241B; --ink-soft: #5a4b38; --signal: #B3402F;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", "URW Palladio L", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tex-parchment: none; --tex-walnut: none; --tex-brass: none; --tex-iron: none;
  --ease-mech: cubic-bezier(.2, 1.35, .4, 1);
  --topbar: 64px; --chest: 252px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0e0a07; overflow: hidden; overscroll-behavior: none; font-family: var(--serif); color: var(--parchment); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
/* inset rather than 100vw/100vh: on phones 100vh includes the browser's toolbars, which stretched the image
   and put taps in the wrong place */
canvas#gl, canvas#ink { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#gl { touch-action: none; } /* pinch and drag belong to the workshop, not the page */
#ui, #gate, .modal-wrap, #settings, #works, #notebook { touch-action: manipulation; } /* no double-tap zoom */
canvas#ink { pointer-events: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--amber); outline-offset: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hidden, [hidden] { display: none !important; }

/* ------------------------------------------------------------------ brass plate buttons */
.plate {
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .5em;
  min-height: 40px; padding: 0 18px; border: 1px solid var(--brass-deep); border-radius: 4px; cursor: pointer;
  font-family: var(--serif); font-weight: 700; font-size: 15px; letter-spacing: .06em; text-transform: uppercase;
  color: #241c10; text-shadow: 0 1px 0 rgba(255, 240, 200, .5);
  background: var(--tex-brass), linear-gradient(180deg, #ecd27a 0%, #d2ae3c 22%, #b8931f 55%, #94751a 100%);
  background-blend-mode: overlay, normal; background-size: cover;
  box-shadow: inset 0 1px 0 rgba(255, 245, 210, .75), inset 0 -2px 0 rgba(60, 40, 5, .45), 0 3px 0 #4a3a0e, 0 5px 10px rgba(0, 0, 0, .55);
  transition: transform .08s ease, box-shadow .08s ease, filter .2s ease;
  user-select: none;
}
.plate::before, .plate::after { /* rivets */
  content: ""; position: absolute; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3c4 0%, #c9a227 35%, #5e4a12 80%);
  box-shadow: 0 1px 1px rgba(0, 0, 0, .5);
}
.plate::before { left: 6px; } .plate::after { right: 6px; }
.plate:hover { filter: brightness(1.08); box-shadow: inset 0 1px 0 rgba(255, 245, 210, .75), inset 0 -2px 0 rgba(60, 40, 5, .45), 0 3px 0 #4a3a0e, 0 5px 10px rgba(0, 0, 0, .55), 0 0 18px rgba(255, 179, 71, .45); }
.plate:active, .plate.pressed { transform: translateY(3px); box-shadow: inset 0 1px 0 rgba(255, 245, 210, .5), inset 0 2px 6px rgba(60, 40, 5, .5), 0 0 0 #4a3a0e, 0 2px 4px rgba(0, 0, 0, .5); }
.plate:disabled { filter: grayscale(.7) brightness(.7); cursor: not-allowed; }
.plate.small { min-height: 32px; padding: 0 12px; font-size: 12.5px; }
.plate.small::before { left: 4px; } .plate.small::after { right: 4px; }
.plate.icon { padding: 0 10px; min-width: 40px; }
.plate.icon::before, .plate.icon::after { display: none; }
.plate.big { min-height: 52px; padding: 0 28px; font-size: 19px; }
.plate.copper { background: var(--tex-brass), linear-gradient(180deg, #e0a071 0%, #c37f47 30%, #a2622f 60%, #7a4423 100%); border-color: #4d2a14; box-shadow: inset 0 1px 0 rgba(255, 220, 190, .6), inset 0 -2px 0 rgba(60, 25, 5, .45), 0 3px 0 #3d200d, 0 5px 10px rgba(0, 0, 0, .55); }
.plate.iron { color: var(--parchment); text-shadow: 0 -1px 0 rgba(0, 0, 0, .6); background: var(--tex-iron), linear-gradient(180deg, #5a5a5f 0%, #3f3f44 45%, #2a2a2e 100%); border-color: #121214; box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 3px 0 #0d0d0f, 0 5px 10px rgba(0, 0, 0, .55); }
.plate.run { min-width: 150px; }
.plate.run.running { background: var(--tex-brass), linear-gradient(180deg, #d67a66 0%, #b3402f 45%, #7d2a1f 100%); color: #fbe9d8; text-shadow: 0 -1px 0 rgba(0,0,0,.5); border-color: #4a1510; }
.plate svg { width: 18px; height: 18px; flex: none; }

/* ------------------------------------------------------------------ lever switch (toggle) */
.lever { display: inline-flex; align-items: flex-end; gap: 8px; cursor: pointer; background: none; border: 0; padding: 20px 6px 4px; color: var(--parchment); font-family: var(--serif); font-size: 13px; letter-spacing: .04em; }
/* a narrow slotted base; the lever pivots at its centre and throws nearly its full width */
.lever .track { position: relative; flex: none; width: 30px; height: 16px; border-radius: 8px; background: linear-gradient(180deg, #19120b, #3a2a1a); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .7), 0 1px 0 rgba(255, 220, 160, .15); border: 1px solid #120c07; }
.lever .arm { position: absolute; left: 50%; bottom: 50%; width: 6px; height: 24px; margin-left: -3px; border-radius: 3px; background: linear-gradient(90deg, #8a6e1f, #f2d98a, #8a6e1f); transform-origin: 50% 100%; transform: rotate(-32deg); transition: transform .28s var(--ease-mech); }
.lever .arm::after { content: ""; position: absolute; top: -8px; left: 50%; width: 15px; height: 15px; margin-left: -7.5px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffe9b0, #b3402f 45%, #5a1c12 90%); box-shadow: 0 1px 3px rgba(0, 0, 0, .6); }
.lever .pivot { position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; margin: -5.5px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #fff3c4, #c9a227 40%, #5e4a12); box-shadow: 0 1px 1px rgba(0, 0, 0, .5); }
.lever[aria-checked="true"] .arm { transform: rotate(32deg); }
.lever[aria-checked="true"] .arm::after { background: radial-gradient(circle at 35% 30%, #fffbe6, #ffb347 45%, #a8611a 90%); box-shadow: 0 0 10px rgba(255, 179, 71, .9); }

/* ------------------------------------------------------------------ parchment panels framed in brass */
.parchment {
  position: relative; color: var(--ink);
  background: var(--tex-parchment), var(--parchment); background-size: 512px 512px;
  border: 3px solid var(--brass-dark); border-radius: 3px;
  box-shadow: inset 0 0 0 1px #f4ead2, inset 0 0 26px rgba(120, 90, 40, .35), 0 0 0 1px #3a2c0a, 0 12px 30px rgba(0, 0, 0, .6);
}
.parchment .corner { position: absolute; width: 26px; height: 26px; pointer-events: none;
  background: radial-gradient(circle at 9px 9px, #fff3c4 0, #c9a227 2px, #5e4a12 4.5px, transparent 5px), linear-gradient(135deg, #e6c766, #8a6e1f); clip-path: polygon(0 0, 100% 0, 100% 22%, 22% 22%, 22% 100%, 0 100%); }
.parchment .corner.tl { left: -4px; top: -4px; }
.parchment .corner.tr { right: -4px; top: -4px; transform: scaleX(-1); }
.parchment .corner.bl { left: -4px; bottom: -4px; transform: scaleY(-1); }
.parchment .corner.br { right: -4px; bottom: -4px; transform: scale(-1, -1); }
.parchment h1, .parchment h2, .parchment h3 { font-family: var(--serif); color: var(--ink); margin: 0; }
.parchment p { line-height: 1.5; }
.parchment .rule { height: 0; border-top: 1px solid rgba(43, 36, 27, .45); border-bottom: 1px solid rgba(255, 255, 255, .35); margin: 10px 0; }
.ink-label { font-family: var(--serif); font-style: italic; color: var(--ink-soft); font-size: 12px; letter-spacing: .03em; }

/* ------------------------------------------------------------------ top bar (walnut rail) */
#topbar { position: fixed; left: 0; right: 0; top: 0; height: var(--topbar); display: flex; align-items: center; gap: 12px; padding: 0 14px;
  background: var(--tex-walnut), linear-gradient(180deg, #4a3020, #2e1f13); background-size: 512px 256px, auto;
  border-bottom: 3px solid var(--brass-dark); box-shadow: 0 1px 0 #e6c766 inset, 0 6px 18px rgba(0, 0, 0, .6); z-index: 5; }
#topbar .title-plate { display: flex; flex-direction: column; min-width: 0; padding: 4px 14px; border-radius: 3px; background: linear-gradient(180deg, rgba(0,0,0,.35), rgba(0,0,0,.15)); border: 1px solid rgba(201,162,39,.35); }
#topbar .title-plate .num { font-family: var(--sans); font-size: 11px; letter-spacing: .18em; color: var(--brass-hi); text-transform: uppercase; }
#topbar .title-plate .name { font-size: 20px; font-weight: 700; color: var(--parchment); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar .goal { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 14px; color: var(--ink); font-size: 15px;
  background: var(--tex-parchment), var(--parchment); background-size: 512px; border: 1px solid var(--brass-dark); border-radius: 2px; box-shadow: inset 0 0 12px rgba(120, 90, 40, .35); }
#topbar .goal .goal-list { display: flex; flex-direction: column; min-width: 0; }
#topbar .goal .g { display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#topbar .goal .tick { width: 16px; height: 16px; border: 1.5px solid var(--ink); border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 11px; }
#topbar .goal .g.done .tick { background: var(--verdigris); border-color: #2a5245; color: #fff; }
#topbar .goal .g.done span { text-decoration: line-through; text-decoration-color: rgba(43,36,27,.5); }
#topbar .spacer { flex: 1; }
#topbar .group { display: flex; align-items: center; gap: 8px; }
#topbar .speed { display: flex; border-radius: 4px; overflow: hidden; box-shadow: 0 3px 0 #4a3a0e, 0 5px 10px rgba(0,0,0,.5); }
#topbar .speed .plate { border-radius: 0; min-width: 44px; padding: 0 8px; box-shadow: inset 0 1px 0 rgba(255,245,210,.7), inset 0 -2px 0 rgba(60,40,5,.45); }
#topbar .speed .plate::before, #topbar .speed .plate::after { display: none; }
#topbar .speed .plate[aria-pressed="true"] { background: linear-gradient(180deg, #7a5d14, #a88620 50%, #c9a227); box-shadow: inset 0 3px 6px rgba(40, 25, 0, .7); transform: translateY(2px); }

/* ------------------------------------------------------------------ tool chest */
#chest { position: fixed; left: 0; top: var(--topbar); bottom: 0; width: var(--chest); padding: 12px 10px 16px; overflow-y: auto; overflow-x: hidden;
  background: var(--tex-walnut), linear-gradient(90deg, #3d2817, #2a1b10); background-size: 512px 256px, auto;
  border-right: 3px solid var(--brass-dark); box-shadow: 6px 0 18px rgba(0, 0, 0, .55), inset -1px 0 0 #e6c766; z-index: 4; scrollbar-width: thin; scrollbar-color: #8a6e1f #2e1f13; }
#chest h2 { margin: 2px 4px 10px; font-size: 13px; letter-spacing: .22em; text-transform: uppercase; color: var(--brass-hi); text-align: center; font-weight: 700; }
#chest h2::before, #chest h2::after { content: "✦"; color: var(--brass-dark); margin: 0 8px; font-size: 10px; }
.drawer { margin-bottom: 10px; border-radius: 3px; background: linear-gradient(180deg, #5c3d24, #3f2816); border: 1px solid #1f140b; box-shadow: inset 0 1px 0 rgba(255, 220, 170, .18), 0 3px 6px rgba(0, 0, 0, .5); }
.drawer > button.pull { width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 10px; background: none; border: 0; cursor: pointer; color: var(--parchment); font-family: var(--serif); font-size: 14.5px; letter-spacing: .04em; text-align: left; }
.drawer > button.pull .handle { width: 34px; height: 10px; border-radius: 5px; flex: none; background: linear-gradient(180deg, #f2d98a, #c9a227 45%, #5e4a12); box-shadow: 0 2px 2px rgba(0, 0, 0, .6), inset 0 1px 0 #fff6d0; }
.drawer > button.pull .count { margin-left: auto; font-family: var(--sans); font-size: 11px; color: var(--brass-hi); }
.drawer .tray { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .32s var(--ease-mech); }
.drawer.open .tray { grid-template-rows: 1fr; }
.drawer .tray > div { overflow: hidden; }
.drawer .tray .cards { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; padding: 4px 8px 10px; }
.part-card { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px 6px; cursor: grab; border-radius: 3px; min-height: 92px;
  background: var(--tex-parchment), var(--parchment); background-size: 400px; color: var(--ink); border: 1px solid #8a6e1f; box-shadow: inset 0 0 10px rgba(120, 90, 40, .35), 0 2px 3px rgba(0, 0, 0, .5); user-select: none; touch-action: none; }
.part-card:hover { box-shadow: inset 0 0 10px rgba(120, 90, 40, .35), 0 0 0 2px var(--amber), 0 2px 3px rgba(0, 0, 0, .5); }
.part-card[aria-disabled="true"] { opacity: .45; cursor: not-allowed; filter: sepia(.4); }
.part-card.armed { box-shadow: inset 0 0 10px rgba(120, 90, 40, .35), 0 0 0 3px var(--amber), 0 0 16px rgba(255, 179, 71, .7); }
.part-card svg { width: 58px; height: 42px; }
.part-card .nm { font-size: 12px; line-height: 1.15; text-align: center; font-weight: 700; }
.part-card .badge { position: absolute; top: 3px; right: 3px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; font-family: var(--sans); font-size: 11px; font-weight: 700; display: grid; place-items: center;
  background: radial-gradient(circle at 35% 30%, #fff3c4, #c9a227 45%, #6e5716); color: #241c10; box-shadow: 0 1px 2px rgba(0, 0, 0, .5); }
.part-card .badge.zero { background: radial-gradient(circle at 35% 30%, #e8b0a8, #b3402f 50%, #5a1c12); color: #fff; }
.chest-foot { margin-top: 8px; padding: 10px 8px; border-top: 1px dashed rgba(201, 162, 39, .35); font-size: 12.5px; color: #d7c7a3; line-height: 1.5; }
.chest-foot kbd, .keys kbd { font-family: var(--mono); font-size: 11px; padding: 1px 5px; border-radius: 3px; background: #1a120b; border: 1px solid #6b5220; color: var(--brass-hi); }

/* ------------------------------------------------------------------ gauges */
#gauges { position: fixed; right: 14px; bottom: 14px; display: flex; gap: 10px; z-index: 3; pointer-events: none; }
.gauge { width: 112px; text-align: center; font-family: var(--sans); }
.gauge svg { width: 112px; height: 112px; display: block; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .6)); }
.gauge .cap { margin-top: 6px; font-family: var(--serif); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; color: var(--brass-hi); text-shadow: 0 1px 2px #000; }

/* ------------------------------------------------------------------ inspector energy panel */
#energy { position: fixed; right: 14px; top: calc(var(--topbar) + 14px); width: 250px; padding: 12px 14px 12px; z-index: 3; font-size: 13px; }
#energy h3 { font-size: 13px; letter-spacing: .16em; text-transform: uppercase; margin-bottom: 6px; }
#energy .row { display: grid; grid-template-columns: 78px 1fr 58px; align-items: center; gap: 6px; margin: 5px 0; }
#energy .bar { height: 12px; border: 1px solid var(--ink); background: rgba(255,255,255,.35); position: relative; overflow: hidden; }
#energy .bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: repeating-linear-gradient(135deg, var(--c) 0 4px, color-mix(in srgb, var(--c) 70%, #000) 4px 6px); transition: width .12s linear; }
#energy .val { font-family: var(--sans); font-size: 11.5px; text-align: right; font-variant-numeric: tabular-nums; }
#energy .legend { margin-top: 8px; font-size: 11.5px; color: var(--ink-soft); line-height: 1.35; }

/* ------------------------------------------------------------------ properties card (selected part) */
#props { position: fixed; width: 250px; padding: 12px 14px 12px; z-index: 6; font-size: 13.5px; }
#props h3 { font-size: 17px; margin-bottom: 2px; }
#props .blurb { font-style: italic; color: var(--ink-soft); font-size: 12.5px; margin: 4px 0 8px; line-height: 1.35; }
#props .param { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 6px 0; }
#props .param .opts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
#props .opt { font-family: var(--sans); font-size: 12px; padding: 4px 8px; border-radius: 3px; border: 1px solid #8a6e1f; background: #efe4c8; color: var(--ink); cursor: pointer; }
#props .opt[aria-pressed="true"] { background: #2b241b; color: var(--parchment); border-color: #2b241b; }
#props .actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
#props .actions .plate { flex: 1; }

/* ------------------------------------------------------------------ concept card & toasts */
#concept { position: fixed; right: 16px; top: calc(var(--topbar) + 16px); width: 360px; max-height: calc(100vh - var(--topbar) - 170px); overflow: auto; padding: 16px 18px 14px; z-index: 7;
  transform: translateX(420px) rotate(2deg); transition: transform .55s var(--ease-mech); }
#concept.show { transform: translateX(0) rotate(0); }
#concept .kicker { font-family: var(--sans); font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--copper-dark); font-weight: 700; }
#concept h2 { font-size: 24px; margin: 2px 0 6px; }
#concept .happened { font-style: italic; margin: 0 0 8px; color: var(--ink-soft); }
#concept .diagram { color: var(--ink); background: rgba(255, 255, 255, .25); border: 1px solid rgba(43, 36, 27, .3); padding: 4px; margin: 6px 0; }
#concept .diagram svg { width: 100%; height: auto; display: block; }
#concept .formula { font-family: var(--serif); font-size: 21px; text-align: center; margin: 8px 0 2px; }
#concept .fkey { font-size: 11.5px; text-align: center; color: var(--ink-soft); font-family: var(--sans); }
#concept .rw { font-size: 13px; margin: 8px 0 0; }
#concept .close { position: absolute; right: 8px; top: 6px; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--ink); }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 30px); opacity: 0; padding: 10px 18px; z-index: 9; font-size: 15px; transition: transform .35s var(--ease-mech), opacity .3s; pointer-events: none; }
.toast.show { transform: translate(-50%, 0); opacity: 1; }

/* ------------------------------------------------------------------ modals */
.modal-wrap { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: radial-gradient(ellipse at center, rgba(10, 6, 3, .35), rgba(10, 6, 3, .75)); animation: fadeIn .25s ease; }
.modal { width: min(560px, 92vw); max-height: 88vh; overflow: auto; padding: 22px 26px 20px; animation: dropIn .5s var(--ease-mech); }
.modal h2 { font-size: 30px; text-align: center; }
.modal .sub { text-align: center; font-style: italic; color: var(--ink-soft); margin-top: 4px; }
.modal .btns { display: flex; justify-content: center; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes dropIn { from { transform: translateY(-60px) rotate(-1.5deg); opacity: 0; } }
.medals { display: flex; justify-content: center; gap: 22px; margin: 18px 0 8px; }
.medal { width: 132px; text-align: center; }
.medal .disc { width: 84px; height: 84px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; position: relative;
  background: radial-gradient(circle at 35% 30%, #d8d0bd, #9d9482 55%, #5e584c); box-shadow: inset 0 2px 3px rgba(255,255,255,.5), inset 0 -3px 5px rgba(0,0,0,.35), 0 3px 6px rgba(0,0,0,.35); filter: grayscale(1) opacity(.45); }
.medal .disc svg { width: 44px; height: 44px; }
.medal.won .disc { filter: none; background: radial-gradient(circle at 35% 30%, #fff3c4, #e0bd4d 35%, #a8861f 70%, #5e4a12); animation: medalIn .7s var(--ease-mech) both; }
.medal.won.new .disc::after { content: "NEW"; position: absolute; bottom: -6px; right: -6px; font-family: var(--sans); font-size: 10px; font-weight: 800; padding: 2px 5px; border-radius: 3px; background: var(--signal); color: #fff; }
.medal .nm { font-weight: 700; letter-spacing: .08em; text-transform: uppercase; font-size: 13px; }
.medal .req { font-size: 11.5px; color: var(--ink-soft); line-height: 1.3; margin-top: 2px; }
@keyframes medalIn { from { transform: rotateY(180deg) scale(.4); } }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; text-align: center; font-family: var(--sans); }
.stats b { display: block; font-size: 22px; font-family: var(--serif); }
.stats span { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-soft); }

/* ------------------------------------------------------------------ replay bar */
#replay { position: fixed; left: calc(var(--chest) + 20px); right: 400px; bottom: 18px; display: flex; gap: 10px; align-items: center; padding: 8px 14px; z-index: 6; }
#replay input[type=range] { flex: 1; accent-color: var(--copper); }
#replay .t { font-family: var(--sans); font-size: 13px; min-width: 64px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ------------------------------------------------------------------ title / menus */
#gate { position: fixed; inset: 0; display: grid; place-items: center; background: #070503; z-index: 30; cursor: pointer; transition: opacity .8s ease; }
#gate.fade { opacity: 0; pointer-events: none; }
#gate .inner { text-align: center; }
#gate .match { display: inline-flex; flex-direction: column; align-items: center; gap: 18px; background: none; border: 0; color: #e0d0ab; font-family: var(--serif); font-size: 30px; letter-spacing: .12em; cursor: pointer; }
#gate .match .flame { width: 32px; height: 50px; border-radius: 50% 50% 45% 45% / 60% 60% 40% 40%; background: radial-gradient(circle at 50% 70%, #fff4d0, #ffb347 40%, #b3402f 75%, transparent 76%); box-shadow: 0 0 54px 18px rgba(255, 179, 71, .35); animation: flick 1.6s infinite ease-in-out; }
#gate .hint { margin-top: 16px; font-size: 13px; color: #9a8466; letter-spacing: .08em; font-family: var(--sans); }
@keyframes flick { 0%, 100% { transform: scale(1) rotate(-2deg); } 45% { transform: scale(1.06, .95) rotate(2deg); } 70% { transform: scale(.96, 1.05); } }

#menu { position: fixed; right: max(5vw, 40px); top: 50%; transform: translateY(-40%); display: flex; flex-direction: column; gap: 14px; z-index: 5; }
#menu .plate { min-width: 280px; justify-content: flex-start; font-size: 17px; min-height: 50px; padding-left: 26px; opacity: 0; transform: translateX(40px); }
#menu.show .plate { opacity: 1; transform: none; transition: opacity .4s ease, transform .5s var(--ease-mech), filter .2s, box-shadow .15s; }
#menu.show .plate:nth-child(2) { transition-delay: .07s, .07s, 0s, 0s; }
#menu.show .plate:nth-child(3) { transition-delay: .14s, .14s, 0s, 0s; }
#menu.show .plate:nth-child(4) { transition-delay: .21s, .21s, 0s, 0s; }
#menu.show .plate:nth-child(5) { transition-delay: .28s, .28s, 0s, 0s; }
#menu .plate small { margin-left: auto; font-family: var(--sans); font-size: 11px; font-weight: 600; letter-spacing: .08em; opacity: .7; padding-right: 8px; }
#menu .plate:active { transform: translateY(3px); }
#credit { position: fixed; left: 18px; bottom: 14px; font-size: 12px; color: #8a7556; letter-spacing: .08em; z-index: 5; font-family: var(--sans); }
#version { position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%); font-size: 12px; color: #6f5d45; letter-spacing: .08em; z-index: 5; font-family: var(--sans); white-space: nowrap; }
.legal-links { position: fixed; right: 18px; bottom: 14px; display: flex; gap: 8px; font-size: 12px; color: #8a7556; letter-spacing: .08em; z-index: 5; font-family: var(--sans); }
.legal-links a { color: #a88d62; text-decoration: none; }
.legal-links a:hover, .legal-links a:focus-visible { color: var(--brass-hi); text-decoration: underline; }
#gate .legal-links { z-index: 31; right: auto; left: 50%; bottom: 22px; transform: translateX(-50%); }

/* level select */
#works { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; padding: 22px max(3vw, 24px) 18px; background: radial-gradient(ellipse at 50% 30%, rgba(20, 12, 6, .35), rgba(8, 5, 3, .88)); }
#works header { display: flex; align-items: center; gap: 16px; }
#works header h1 { font-size: 34px; margin: 0; color: var(--parchment); letter-spacing: .06em; text-shadow: 0 2px 8px #000; }
#works header .medals-total { margin-left: auto; font-family: var(--sans); font-size: 14px; color: var(--brass-hi); display: flex; align-items: center; gap: 8px; }
.tabs { display: flex; gap: 6px; margin: 16px 0 0; flex-wrap: wrap; }
.tab { position: relative; padding: 9px 16px 10px; border: 1px solid #5e4a12; border-bottom: 0; border-radius: 6px 6px 0 0; cursor: pointer; font-family: var(--serif); font-size: 15px; color: #d7c7a3;
  background: linear-gradient(180deg, #4a3020, #2e1f13); }
.tab small { display: block; font-family: var(--sans); font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; color: #a58a52; }
.tab[aria-selected="true"] { background: var(--tex-parchment), var(--parchment); background-size: 512px; color: var(--ink); z-index: 1; }
.tab[aria-selected="true"] small { color: var(--copper-dark); }
.tab.locked { opacity: .55; }
.board { flex: 1; min-height: 0; overflow: auto; padding: 22px 24px 26px; border-radius: 0 4px 4px 4px; }
.board .world-intro { display: flex; align-items: baseline; gap: 14px; margin-bottom: 14px; }
.board .world-intro h2 { font-size: 26px; }
.board .world-intro p { margin: 0; color: var(--ink-soft); font-style: italic; }
.dials { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 22px 14px; }
.dial { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 0; cursor: pointer; color: var(--ink); padding: 6px 2px; border-radius: 6px; }
.dial:hover:not(:disabled) svg { filter: drop-shadow(0 0 10px rgba(255, 179, 71, .8)) drop-shadow(0 4px 6px rgba(0,0,0,.5)); }
.dial svg { width: 122px; height: 122px; filter: drop-shadow(0 4px 6px rgba(0,0,0,.45)); transition: filter .2s; }
.dial .lt { font-size: 13.5px; font-weight: 700; text-align: center; line-height: 1.2; max-width: 150px; }
.dial .lm { font-family: var(--sans); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-soft); }
.dial:disabled { cursor: not-allowed; opacity: .5; }
.soon { padding: 30px; text-align: center; color: var(--ink-soft); font-style: italic; font-size: 17px; line-height: 1.6; }

/* notebook */
#notebook { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; padding: 22px max(3vw, 24px) 18px; background: radial-gradient(ellipse at 50% 30%, rgba(20, 12, 6, .35), rgba(8, 5, 3, .9)); }
#notebook header { display: flex; align-items: center; gap: 16px; }
#notebook header h1 { font-size: 34px; margin: 0; color: var(--parchment); text-shadow: 0 2px 8px #000; }
#notebook header .count { margin-left: auto; font-family: var(--sans); color: var(--brass-hi); font-size: 14px; }
.book { flex: 1; min-height: 0; overflow: auto; margin-top: 16px; padding: 20px 24px; }
.book h2.wsec { font-size: 20px; margin: 18px 0 10px; padding-bottom: 4px; border-bottom: 1px solid rgba(43, 36, 27, .35); }
.book h2.wsec:first-child { margin-top: 0; }
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.ncard { position: relative; padding: 12px 14px 12px; border: 1px solid rgba(43, 36, 27, .4); background: rgba(255, 252, 240, .35); border-radius: 2px; color: var(--ink); }
.ncard h3 { font-size: 18px; margin: 0 0 4px; }
.ncard .diagram { color: var(--ink); margin: 6px 0; }
.ncard .diagram svg { width: 100%; height: auto; display: block; max-height: 150px; }
.ncard .formula { font-size: 18px; text-align: center; margin: 4px 0; }
.ncard p { font-size: 13.5px; margin: 6px 0; line-height: 1.45; }
.ncard .try { font-size: 12.5px; font-style: italic; color: var(--ink-soft); }
.ncard .terms { font-size: 12.5px; margin: 6px 0; }
.ncard .terms dt { font-weight: 700; display: inline; } .ncard .terms dd { display: inline; margin: 0; } .ncard .terms dd::after { content: ""; display: block; margin-bottom: 3px; }
.ncard.locked { display: grid; place-items: center; min-height: 140px; color: rgba(43, 36, 27, .45); font-style: italic; text-align: center; background: repeating-linear-gradient(135deg, rgba(43,36,27,.04) 0 8px, transparent 8px 16px); }
.ncard.locked .q { font-size: 34px; font-family: var(--serif); }

/* settings */
#settings { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(8, 5, 3, .7); }
#settings .panel { width: min(640px, 94vw); max-height: 90vh; overflow: auto; padding: 22px 28px 20px; }
#settings h2 { font-size: 28px; text-align: center; margin-bottom: 10px; }
#settings .sect { margin: 14px 0 6px; font-family: var(--sans); font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--copper-dark); font-weight: 700; }
#settings .row { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px dotted rgba(43,36,27,.25); color: var(--ink); }
#settings .row label { font-size: 15px; } #settings .row small { display: block; font-size: 12px; color: var(--ink-soft); font-style: italic; }
#settings input[type=range] { width: 200px; accent-color: var(--copper); }
#settings .lever { color: var(--ink); }
#settings .lever .track { background: linear-gradient(180deg, #3a2a1a, #5c3d24); }
#settings .btns { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* intro card */
#intro { position: fixed; left: calc(var(--chest) + (100vw - var(--chest)) / 2 - 220px); top: calc(var(--topbar) + 26vh); width: 440px; padding: 16px 20px 14px; z-index: 8; }
#intro .kicker { font-family: var(--sans); font-size: 10.5px; letter-spacing: .2em; text-transform: uppercase; color: var(--copper-dark); font-weight: 700; }
#intro h2 { font-size: 26px; margin: 2px 0 6px; }
#intro p { margin: 6px 0; font-size: 15px; }
#intro .par { font-family: var(--sans); font-size: 12px; color: var(--ink-soft); margin-top: 8px; }
#intro .keys { font-size: 12.5px; color: var(--ink-soft); margin-top: 8px; line-height: 1.7; }
#intro .keys kbd { background: #2b241b; color: var(--parchment); border-color: #2b241b; }
#intro .touch-help { font-size: 13.5px; margin-top: 8px; padding: 6px 10px; border-left: 3px solid var(--brass); background: rgba(255, 252, 240, .45); line-height: 1.45; }

/* failure banner */
#banner { position: fixed; left: 50%; top: calc(var(--topbar) + 18px); transform: translate(-50%, -20px); opacity: 0; padding: 10px 22px; z-index: 8; text-align: center; transition: all .4s var(--ease-mech); display: flex; align-items: center; gap: 14px; }
#banner.show { transform: translate(-50%, 0); opacity: 1; }
#banner .msg { font-size: 17px; font-style: italic; }

/* no WebGL */
#nogl { position: fixed; inset: 0; display: grid; place-items: center; background: #0e0a07; z-index: 50; }
#nogl .parchment { max-width: 520px; padding: 26px 30px; }
#gllost { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(8, 5, 3, .88); z-index: 60; }
#gllost .parchment { max-width: 460px; padding: 26px 30px; text-align: center; }
#gllost .plate { margin-top: 8px; }
/* landscape only on phones and tablets: a card asks to turn the device while it's held upright */
#rotate { display: none; position: fixed; inset: 0; z-index: 100; place-items: center; padding: 24px; background: #0e0a07; }
#rotate .parchment { max-width: 340px; padding: 24px 24px 20px; text-align: center; }
#rotate h2 { font-size: 22px; margin: 14px 0 8px; }
#rotate p { margin: 0; font-size: 15px; }
#rotate .turn { width: 44px; height: 72px; margin: 0 auto; border: 3px solid var(--brass-dark); border-radius: 8px; position: relative; animation: turn 2.4s var(--ease-mech) infinite; }
#rotate .turn span { position: absolute; left: 50%; bottom: 5px; width: 10px; height: 3px; margin-left: -5px; border-radius: 2px; background: var(--brass-dark); }
@keyframes turn { 0%, 25% { transform: rotate(0); } 55%, 100% { transform: rotate(-90deg); } }
@media (orientation: portrait) and (pointer: coarse) { #rotate { display: grid; } }
#loading { position: fixed; inset: 0; display: grid; place-items: center; z-index: 40; background: #070503; color: #6b5220; letter-spacing: .4em; font-size: 13px; text-transform: uppercase; }

/* high-contrast mode */
body.hc { --parchment: #fffaf0; --ink: #000; --ink-soft: #222; }
body.hc .parchment { background: #fffaf0; border-color: #000; }
body.hc .plate { background: #f0c93a; color: #000; text-shadow: none; border: 2px solid #000; }
body.hc .part-card { background: #fffaf0; border: 2px solid #000; }
body.hc #topbar, body.hc #chest { background: #1a1a1a; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
body.reduced *, body.reduced *::before, body.reduced *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
@media (max-width: 900px) { :root { --chest: 200px; } .part-card .nm { font-size: 11px; } #topbar .goal { font-size: 13px; } }

.world-concepts { margin-top: 30px; padding-top: 14px; border-top: 1px solid rgba(43, 36, 27, .3); }
.world-concepts h3 { font-size: 15px; letter-spacing: .14em; text-transform: uppercase; color: var(--copper-dark); margin-bottom: 10px; font-family: var(--sans); }
.world-concepts .tags { display: flex; flex-wrap: wrap; gap: 8px; }
.world-concepts .tag { font-size: 13.5px; padding: 5px 11px; border: 1px solid rgba(43, 36, 27, .45); border-radius: 14px; color: var(--ink); background: rgba(255, 252, 240, .4); }
.world-concepts .tag.found { background: #2b241b; color: var(--parchment); border-color: #2b241b; }
.world-concepts .tag.found::before { content: "✓ "; color: var(--brass-hi); }
.world-concepts p { margin: 10px 0 0; font-size: 13px; color: var(--ink-soft); font-style: italic; }

/* narrower desktop windows: keep the goal readable */
@media (max-width: 1280px) {
  #topbar { gap: 8px; padding: 0 10px; }
  #topbar .lever > span:last-child { display: none; }
  #topbar .title-plate .name { font-size: 17px; }
  .plate.run { min-width: 112px; }
  .plate.big { padding: 0 16px; font-size: 17px; }
}
@media (max-width: 1100px) {
  #topbar .title-plate { display: none; }
  #topbar .speed .plate { min-width: 36px; }
}

/* ------------------------------------------------------------------ phones in landscape (short screens) */
@media (max-height: 500px) {
  :root { --topbar: 46px; --chest: 116px; }
  /* top bar */
  #topbar { gap: 5px; padding: 0 6px; }
  #topbar .plate { min-height: 34px; }
  #topbar .plate.icon { width: 34px; min-width: 34px; padding: 0 6px; }
  #topbar .goal { padding: 3px 8px; font-size: 12px; gap: 6px; }
  #topbar .goal .plate.icon { width: 28px; min-width: 28px; min-height: 28px; }
  #topbar .speed .plate { min-width: 30px; min-height: 30px; padding: 0 4px; font-size: 13px; }
  #topbar .lever { padding: 16px 2px 2px; }
  .plate.run { min-width: 84px; }
  .plate.big { min-height: 36px; padding: 0 10px; font-size: 15px; }
  /* tool chest: one column of smaller cards, no key help */
  #chest { padding: 6px 6px 10px; }
  #chest h2 { font-size: 10px; letter-spacing: .12em; margin: 0 0 6px; }
  #chest h2::before, #chest h2::after { display: none; }
  .drawer { margin-bottom: 6px; }
  .drawer > button.pull { padding: 7px 6px; gap: 6px; font-size: 12px; }
  .drawer > button.pull .handle { width: 18px; }
  .drawer .tray .cards { grid-template-columns: 1fr; gap: 5px; padding: 2px 5px 7px; }
  .part-card { min-height: 64px; padding: 5px 3px 4px; }
  .part-card svg { width: 46px; height: 32px; }
  .part-card .nm { font-size: 10.5px; }
  .chest-foot { display: none; }
  /* gauges */
  #gauges { right: 6px; bottom: 4px; gap: 4px; }
  .gauge, .gauge svg { width: 64px; }
  .gauge svg { height: 64px; }
  .gauge .cap { margin-top: 2px; font-size: 9px; letter-spacing: .08em; }
  #gauges.idle { display: none; }
  .drawer > button.pull .handle { display: none; }
  /* panels and cards */
  #energy { width: 200px; top: calc(var(--topbar) + 6px); right: 6px; padding: 8px 10px; font-size: 11px; }
  #energy .row { grid-template-columns: 64px 1fr 44px; margin: 3px 0; }
  #energy .legend { display: none; }
  #props { padding: 8px 10px; font-size: 12.5px; }
  #props h3 { font-size: 15px; }
  #props .blurb { display: none; }
  #props .opt { padding: 6px 9px; }
  #concept { width: min(300px, 44vw); right: 6px; top: calc(var(--topbar) + 6px); max-height: calc(100% - var(--topbar) - 12px); padding: 10px 12px; }
  #concept h2 { font-size: 19px; } #concept .formula { font-size: 17px; }
  #intro { left: calc(var(--chest) + (100vw - var(--chest)) / 2 - min(220px, 36vw)); width: min(440px, 72vw); top: calc(var(--topbar) + 8px); max-height: calc(100% - var(--topbar) - 16px); overflow: auto; padding: 10px 14px; }
  #intro h2 { font-size: 20px; } #intro p { font-size: 13.5px; } #intro .keys { display: none; }
  #banner { top: calc(var(--topbar) + 8px); padding: 6px 12px; } #banner .msg { font-size: 14px; }
  #replay { left: calc(var(--chest) + 8px); right: 220px; bottom: 6px; padding: 5px 10px; }
  .toast { bottom: 12px; font-size: 13.5px; padding: 8px 14px; max-width: 80vw; }
  /* dialogs */
  .modal { max-height: 94vh; padding: 12px 16px; }
  .modal h2 { font-size: 22px; }
  .medals { margin: 8px 0 4px; gap: 10px; } .medal { width: 96px; } .medal .disc { width: 56px; height: 56px; } .medal .disc svg { width: 30px; height: 30px; }
  .modal .btns { margin-top: 10px; }
  #settings .panel { max-height: 94vh; padding: 12px 18px; }
  #settings h2 { font-size: 22px; }
  /* title and menus */
  #menu { gap: 7px; transform: translateY(-50%); }
  #menu .plate { min-height: 38px; min-width: 230px; font-size: 14.5px; padding-left: 16px; }
  #credit, #version, .legal-links { bottom: 6px; font-size: 10.5px; }
  #credit { left: 10px; } .legal-links { right: 10px; }
  #credit .long { display: none; }
  #works, #notebook { padding: 10px 14px 8px; }
  #works header h1, #notebook header h1 { font-size: 22px; }
  .tabs { margin-top: 8px; } .tab { padding: 6px 10px 7px; font-size: 13px; }
  .board, .book { padding: 12px 14px; }
  .dials { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px 8px; }
  .dial svg { width: 84px; height: 84px; }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
  #gate .match { font-size: 24px; gap: 12px; }
}
