:root {
  --cream: #F5F0E8;
  --paper: #FBF8F2;
  --ink: #1A1A18;
  --warm: #3D3B38;
  --muted: #77736B;
  --line: #E2DCCF;
  --terracotta: #C45D34;
  --amber: #E07A3D;
  --sage: #7D8C6E;
  --ok: #3F7A4E;
  --bad: #B33A2B;
  --display: 'Instrument Serif', Georgia, serif;
  --body: 'Instrument Sans', 'Helvetica Neue', sans-serif;
  --mono: 'Space Mono', ui-monospace, monospace;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- header / footer ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.wordmark { font-family: var(--display); font-size: 30px; line-height: 1; letter-spacing: -0.5px; }
.divider { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.section { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--warm); }
.secure { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; color: var(--ok); text-transform: uppercase; letter-spacing: 1px; }

.foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 10px;
  padding: 22px 16px 30px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
}
.foot .dot { width: 3px; height: 3px; border-radius: 50%; background: var(--muted); }

/* ---------- progress ---------- */
.progress { width: min(720px, calc(100% - 32px)); margin: 26px auto 0; }
.progress-meta { display: flex; justify-content: space-between; gap: 12px; font-family: var(--mono); font-size: 11px; color: var(--warm); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; }
.progress-track { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--terracotta); border-radius: 99px; transition: width .8s cubic-bezier(.2,.8,.2,1); }

/* ---------- stage + card ---------- */
.stage { flex: 1; width: min(720px, calc(100% - 32px)); margin: 18px auto 0; }
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 36px 30px;
  box-shadow: 0 1px 0 #fff inset, 0 18px 40px -28px rgba(26,26,24,.35);
  animation: rise .45s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.kicker { font-family: var(--mono); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: var(--terracotta); margin: 0 0 10px; }
.card h1, .card h2 { font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1.05; margin: 0 0 12px; letter-spacing: -0.5px; }
.card h2 { font-size: 34px; }
.card .sub { color: var(--warm); margin: 0 0 22px; max-width: 56ch; }
.card .body { display: flex; flex-direction: column; gap: 16px; }
.card .actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 26px; }
.small { font-size: 13px; color: var(--muted); }
.mono { font-family: var(--mono); }

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 13px 26px;
  background: var(--ink);
  color: var(--cream);
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s, background .2s;
}
.btn:hover { background: var(--terracotta); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .35; cursor: not-allowed; background: var(--ink); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--ink); }
.btn.ghost:hover { background: var(--ink); color: var(--cream); }
.btn.big { font-size: 18px; padding: 16px 34px; }
.linkish { background: none; border: 0; color: var(--warm); text-decoration: underline; cursor: pointer; padding: 0; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--warm); }
.field input, .field textarea, .field select {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px 14px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--terracotta); box-shadow: 0 0 0 3px rgba(196,93,52,.15); }
.field textarea { min-height: 96px; resize: vertical; }

.notice { border-radius: 10px; padding: 12px 14px; font-size: 14px; border: 1px solid; }
.notice.bad { background: #FBEDEA; border-color: #EBC2BB; color: var(--bad); }
.notice.ok { background: #EAF3EC; border-color: #BFD9C5; color: var(--ok); }
.notice.info { background: #F3EEE4; border-color: var(--line); color: var(--warm); }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-7px); } 40%, 80% { transform: translateX(7px); } }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; }
.pill.ok { background: #EAF3EC; color: var(--ok); }
.pill.warn { background: #FCEFE3; color: var(--terracotta); }

.kv { display: grid; grid-template-columns: 170px 1fr; border-top: 1px solid var(--line); }
.kv > div { padding: 12px 0; border-bottom: 1px solid var(--line); }
.kv > div:nth-child(odd) { font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding-top: 14px; }

.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--terracotta); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.working { display: flex; align-items: center; gap: 12px; color: var(--warm); font-size: 15px; padding: 8px 0; }

/* ---------- robot checkbox ---------- */
.robot-arena { position: relative; height: 280px; border: 1px dashed var(--line); border-radius: 12px; background: repeating-linear-gradient(45deg, #fff, #fff 12px, #FBF8F2 12px, #FBF8F2 24px); overflow: hidden; touch-action: none; }
.robot-box { position: absolute; display: flex; align-items: center; gap: 12px; padding: 14px 18px; background: #fff; border: 1px solid #d6d1c6; border-radius: 6px; box-shadow: 0 2px 6px rgba(0,0,0,.08); transition: left .18s ease-out, top .18s ease-out; user-select: none; cursor: pointer; white-space: nowrap; }
.robot-box .tick { width: 26px; height: 26px; border: 2px solid #c1bcb1; border-radius: 3px; background: #fff; display: grid; place-items: center; }
.robot-box.checked .tick { border-color: var(--ok); }
.robot-box.checked .tick::after { content: ''; width: 8px; height: 15px; border: solid var(--ok); border-width: 0 3px 3px 0; transform: rotate(45deg) translate(-1px, -2px); }
.robot-box small { display: block; font-size: 9px; color: var(--muted); font-family: var(--mono); }

/* ---------- image grid ---------- */
.grid-head { background: var(--terracotta); color: #fff; padding: 16px 18px; border-radius: 8px 8px 0 0; }
.grid-head strong { display: block; font-size: 24px; font-family: var(--display); font-weight: 400; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; background: #fff; padding: 4px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 8px 8px; }
.tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; background: #f1ece2; cursor: pointer; overflow: hidden; transition: transform .15s; }
.tile svg { width: 100%; height: 100%; display: block; }
.tile.sel { transform: scale(.86); }
.tile.sel::after { content: ''; position: absolute; top: 6px; left: 6px; width: 24px; height: 24px; border-radius: 50%; background: #2F6FDB; box-shadow: 0 0 0 2px #fff; }

/* ---------- keypad ---------- */
.keypad-display { font-family: var(--mono); font-size: 26px; letter-spacing: 6px; padding: 14px 18px; background: #fff; border: 1px solid var(--line); border-radius: 10px; min-height: 62px; }
.keypad { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.keypad button { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-family: var(--mono); font-size: 18px; font-weight: 700; cursor: pointer; transition: background .1s; }
.keypad button:hover { background: var(--cream); }
.keypad button.wide { grid-column: span 2; aspect-ratio: auto; font-size: 13px; }
.keypad.flipped { transform: rotate(180deg); }

/* ---------- meters ---------- */
.word-big { font-family: var(--display); font-size: 64px; line-height: 1; text-align: center; padding: 18px 0 6px; }
.wave { width: 100%; height: 90px; display: block; background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.heard { text-align: center; font-size: 20px; }
.heard q { font-family: var(--display); font-size: 34px; display: block; margin-top: 4px; }
.yesno { display: flex; justify-content: center; gap: 12px; }

.db-meter { position: relative; height: 54px; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.db-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--sage), var(--amber) 70%, var(--bad)); transition: width .06s linear; }
.db-target { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--ink); transition: left .5s cubic-bezier(.2,.8,.2,1); }
.db-target::after { content: attr(data-label); position: absolute; top: 4px; left: 6px; font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.db-read { font-family: var(--mono); font-size: 44px; text-align: center; }
.db-read small { font-size: 16px; color: var(--muted); }
.yell { text-align: center; font-family: var(--display); font-size: 30px; min-height: 40px; color: var(--terracotta); }

.tuner { position: relative; height: 120px; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.tuner .zone { position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%); background: #EAF3EC; }
.tuner .needle { position: absolute; bottom: 0; left: 50%; width: 4px; height: 100%; background: var(--terracotta); transform-origin: bottom center; transition: left .08s; }
.tuner .ticks { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; padding: 0 10px 6px; font-family: var(--mono); font-size: 10px; color: var(--muted); }
.tuner .note { position: absolute; top: 10px; left: 0; right: 0; text-align: center; font-family: var(--display); font-size: 38px; }
.hold-bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.hold-bar > div { height: 100%; width: 0; background: var(--ok); }

/* ---------- drawing ---------- */
.canvas-wrap { position: relative; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; touch-action: none; }
.canvas-wrap canvas { display: block; width: 100%; height: auto; cursor: crosshair; }
.scanline { position: absolute; left: 0; right: 0; height: 3px; background: var(--terracotta); box-shadow: 0 0 18px 6px rgba(196,93,52,.35); animation: scan 1.1s ease-in-out infinite alternate; }
@keyframes scan { from { top: 0; } to { top: calc(100% - 3px); } }
.palette { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; }
.swatch.on { box-shadow: 0 0 0 2px var(--ink); }
.ai-out { font-family: var(--mono); font-size: 13px; background: var(--ink); color: #DCD6C8; border-radius: 10px; padding: 14px 16px; min-height: 48px; white-space: pre-wrap; }

/* ---------- slider ---------- */
.slider-scroll { overflow-x: auto; padding-bottom: 8px; }
.slider-track { position: relative; height: 64px; border-radius: 99px; background: #fff; border: 1px solid var(--line); transition: width .6s cubic-bezier(.2,.8,.2,1); }
.slider-track .label { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 13px; color: var(--muted); letter-spacing: 1px; pointer-events: none; }
.slider-handle { position: absolute; top: 4px; left: 4px; width: 56px; height: 54px; border-radius: 99px; background: var(--ink); color: var(--cream); display: grid; place-items: center; cursor: grab; touch-action: none; font-size: 22px; }
.slider-handle.back { transition: left .5s cubic-bezier(.5,1.8,.4,1); }

/* ---------- password ---------- */
.pw-rules { display: flex; flex-direction: column; gap: 8px; }
.rule { border-radius: 10px; padding: 10px 14px; font-size: 14px; border: 1px solid; animation: rise .3s; }
.rule.ok { background: #EAF3EC; border-color: #BFD9C5; color: var(--ok); }
.rule.bad { background: #FBEDEA; border-color: #EBC2BB; color: var(--bad); }
.rule b { font-family: var(--mono); font-size: 11px; display: block; text-transform: uppercase; letter-spacing: 1px; opacity: .7; }
.pw-len { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }

/* ---------- terms ---------- */
.terms { height: 340px; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 18px 22px; font-size: 13px; line-height: 1.6; color: var(--warm); }
.terms h4 { font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 4px; color: var(--ink); }
.terms p { margin: 0 0 8px; }

/* ---------- maze ---------- */
.maze-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.timer { font-family: var(--mono); font-size: 30px; font-weight: 700; }
.timer.low { color: var(--bad); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .35; } }
.maze-wrap { position: relative; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.maze-wrap canvas { display: block; width: 100%; height: auto; }
.maze-banner { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: var(--bad); color: #fff; font-family: var(--mono); font-size: 12px; padding: 6px 12px; border-radius: 99px; white-space: nowrap; }
.dpad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); gap: 6px; justify-content: center; }
.dpad button { border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 20px; cursor: pointer; }
.dpad .up { grid-column: 2; }
.dpad .left { grid-column: 1; grid-row: 2; }
.dpad .down { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }

/* ---------- hold ---------- */
.hold-wrap { display: grid; place-items: center; padding: 20px 0 10px; transition: transform .3s; }
.hold-btn { position: relative; width: 180px; height: 180px; border-radius: 50%; border: 0; background: var(--ink); color: var(--cream); font-size: 18px; font-weight: 700; cursor: pointer; user-select: none; touch-action: none; }
.hold-btn svg { position: absolute; inset: -10px; width: 200px; height: 200px; transform: rotate(-90deg); pointer-events: none; }
.hold-btn span { position: relative; }
.hold-count { font-family: var(--mono); font-size: 14px; color: var(--warm); text-align: center; }

/* ---------- queue ---------- */
.queue-num { font-family: var(--display); font-size: 120px; line-height: 1; text-align: center; }
.queue-line { text-align: center; color: var(--warm); }

/* ---------- final ---------- */
.amount { font-family: var(--display); font-size: 72px; line-height: 1; }
.proc-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 15px; }
.proc-list li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.proc-list li.on { color: var(--ink); }
.proc-list li.done { color: var(--ok); }
.proc-list li .mark { width: 18px; text-align: center; font-family: var(--mono); }
.pct { font-family: var(--mono); font-size: 54px; text-align: center; }
.board { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fff; }
.board-row { display: grid; grid-template-columns: 44px 1fr auto auto; gap: 12px; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.board-row:last-child { border-bottom: 0; }
.board-row.you { background: #FCEFE3; font-weight: 700; }
.board-row .r { font-family: var(--mono); color: var(--muted); }
.board-row .t { font-family: var(--mono); }

/* ---------- modal / toast ---------- */
.modal-root:empty { display: none; }
.modal-back { position: fixed; inset: 0; background: rgba(26,26,24,.55); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.modal { background: var(--paper); border-radius: var(--radius); padding: 28px 30px; width: min(440px, 100%); box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); animation: pop .25s cubic-bezier(.2,1.4,.4,1); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.modal h3 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0 0 8px; }
.modal p { margin: 0 0 18px; color: var(--warm); }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.modal.error h3 { color: var(--bad); }
.toast-root { position: fixed; top: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; width: min(460px, calc(100% - 32px)); }
.toast { background: var(--ink); color: var(--cream); border-radius: 10px; padding: 12px 16px; font-size: 14px; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); animation: drop .3s cubic-bezier(.2,1.4,.4,1); }
@keyframes drop { from { transform: translateY(-14px); opacity: 0; } }

/* ---------- chat ---------- */
.chat { position: fixed; right: 18px; bottom: 18px; z-index: 40; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.chat-toggle { display: flex; align-items: center; gap: 8px; border: 0; border-radius: 999px; padding: 12px 18px; background: var(--ink); color: var(--cream); font-weight: 600; cursor: pointer; box-shadow: 0 10px 30px -10px rgba(0,0,0,.5); }
.chat-dot { width: 8px; height: 8px; border-radius: 50%; background: #5BD47C; box-shadow: 0 0 0 3px rgba(91,212,124,.25); }
.chat-panel { width: min(340px, calc(100vw - 36px)); height: 440px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 60px -20px rgba(0,0,0,.45); }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--ink); color: var(--cream); }
.chat-head small { display: block; font-size: 11px; opacity: .7; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--amber); color: var(--ink); display: grid; place-items: center; font-family: var(--display); font-size: 20px; }
.chat-close { margin-left: auto; background: none; border: 0; color: var(--cream); font-size: 24px; cursor: pointer; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 12px; font-size: 14px; line-height: 1.4; }
.msg.me { align-self: flex-end; background: var(--ink); color: var(--cream); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: none; color: var(--muted); font-size: 12px; font-family: var(--mono); }
.chat-form { display: flex; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; border: 0; padding: 12px; background: #fff; outline: none; }
.chat-form button { border: 0; background: var(--terracotta); color: #fff; padding: 0 16px; font-weight: 600; cursor: pointer; }

/* ---------- marquee ---------- */
.marquee { overflow: hidden; background: var(--ink); color: var(--amber); font-family: var(--mono); font-size: 12px; white-space: nowrap; padding: 6px 0; margin-top: 18px; }
.marquee-inner { display: inline-block; padding-left: 100%; animation: marquee 28s linear infinite; }
@keyframes marquee { to { transform: translateX(-100%); } }

/* ---------- the portal slowly loses it ---------- */
body[data-weird="1"] .card { transform: rotate(-.25deg); }
body[data-weird="2"] .card h2, body[data-weird="3"] .card h2 { font-family: 'Comic Neue', var(--display); font-weight: 700; }
body[data-weird="2"], body[data-weird="3"] {
  background-color: var(--cream);
  background-image:
    linear-gradient(rgba(224,122,61,.08) 2px, transparent 2px),
    linear-gradient(90deg, rgba(224,122,61,.08) 2px, transparent 2px);
  background-size: 34px 34px;
}
body[data-weird="2"] .card { transform: rotate(.35deg); }
body[data-weird="3"] .card { transform: rotate(-.6deg); }
body[data-weird="3"] .progress-fill { background: linear-gradient(90deg, #C45D34, #E0B13D, #7D8C6E, #3D7BC4, #C45D34); background-size: 200% 100%; animation: rainbow 2s linear infinite; }
@keyframes rainbow { to { background-position: 200% 0; } }
body[data-weird="3"] .wordmark { animation: wob 3s ease-in-out infinite; display: inline-block; }
@keyframes wob { 50% { transform: rotate(-4deg) scale(1.05); } }

@media (max-width: 600px) {
  .top { padding: 14px 16px; }
  .secure { display: none; }
  .card { padding: 24px 18px; }
  .card h1 { font-size: 32px; }
  .card h2 { font-size: 28px; }
  .kv { grid-template-columns: 1fr; }
  .kv > div:nth-child(odd) { padding-bottom: 0; border-bottom: 0; }
  .keypad { grid-template-columns: repeat(6, 1fr); }
  .word-big { font-size: 44px; }
  .queue-num { font-size: 84px; }
  .amount { font-size: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  .marquee-inner { animation-duration: 60s; }
}
