:root {
  --bg: #101418;
  --card: #1a2028;
  --border: #2b3440;
  --text: #f1f4f7;
  --muted: #a3aebb;
  --accent: #3fd0c9;
  --accent-tint: #123533;
  --warn: #ffc857;
  --warn-bg: #2e2617;
  --purple-bg: #2a1f3d;
  --purple: #c9a8ff;
  --p1: #6ab0ff;
  --p2: #ff9f5a;
  --r-card: 20px;
  --r-btn: 14px;
  --r-pill: 999px;
  --tap: 44px;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 400 16px/1.4 Inter, system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.4; cursor: default; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
[hidden] { display: none !important; }

#main { max-width: 560px; margin: 0 auto; padding: var(--gutter) var(--gutter) calc(96px + env(safe-area-inset-bottom)); }
.screen { display: flex; flex-direction: column; gap: 12px; }
.screen-title { font-size: 24px; font-weight: 800; }
.section-title { font-size: 15px; font-weight: 600; color: var(--muted); margin-top: 8px; }

.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card); padding: 16px; }
.list { padding: 4px 0; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 16px; min-height: var(--tap); }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.pill { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: var(--r-pill); border: 1px solid var(--border); font-size: 13px; font-weight: 500; white-space: nowrap; }
.pill.ok { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }

/* Buttons */
.btn {
  min-height: 52px; padding: 0 18px; border-radius: var(--r-btn); border: 1px solid var(--border);
  background: var(--card); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; text-align: center;
}
.btn.small { min-height: var(--tap); padding: 0 12px; font-size: 14px; }
.btn.outline { background: transparent; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #062523; }
.btn.full { width: 100%; }
.btn.wide { flex: 2; }
.chip {
  min-height: 36px; padding: 0 12px; border-radius: var(--r-pill); border: 1px solid var(--border);
  background: transparent; font-size: 13px; font-weight: 500;
}
.chip.selected { border-color: var(--accent); color: var(--accent); background: var(--accent-tint); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-switch { display: flex; gap: 8px; margin: 8px 0 12px; }
.lang-switch .chip { display: inline-flex; align-items: center; text-decoration: none; color: var(--text); }
.lang-switch .chip.selected { color: var(--accent); }

/* Round bar */
.round-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.round-control { display: flex; align-items: center; gap: 10px; }
.round-btn { width: 52px; height: 52px; border-radius: var(--r-btn); border: 1px solid var(--border); background: var(--card); font-size: 26px; font-weight: 600; }
.round-btn.accent { background: var(--accent); border-color: var(--accent); color: #062523; }
.round-label { font-size: 22px; font-weight: 800; min-width: 104px; text-align: center; }
.room-meta { display: flex; flex-direction: column; align-items: flex-end; color: var(--text); font-size: 14px; }
.room-code { font-weight: 600; letter-spacing: 0.04em; }
.room-code.big { font-size: 32px; font-weight: 800; }

/* Timer banner */
#timer-banner:empty { display: none; }
#timer-banner { display: flex; flex-direction: column; gap: 8px; }
.timer { display: flex; align-items: center; gap: 12px; background: var(--purple-bg); color: var(--purple); border-radius: var(--r-card); padding: 12px 16px; }
.timer-icon { font-size: 20px; }
.timer-label { flex: 1; font-weight: 600; }
.timer-count { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.timer-count.low { color: var(--warn); }
.timer-count.over { color: #ff6b6b; }
.timer-cancel { width: var(--tap); height: var(--tap); border: 0; background: transparent; color: var(--purple); font-size: 18px; }

/* Task card */
.task { display: flex; flex-direction: column; gap: 14px; }
.open-steps { display: flex; flex-direction: column; gap: 12px; }
.task-summary { display: flex; flex-direction: column; gap: 2px; cursor: pointer; list-style: none; }
.task-summary::-webkit-details-marker { display: none; }
.task-summary::after { content: "▾"; position: absolute; right: 16px; top: 16px; color: var(--muted); transition: transform 0.15s; }
details.task { position: relative; display: block; }
details.task[open] > .task-summary { margin-bottom: 14px; }
details.task:not([open]) .task-summary::after { transform: rotate(-90deg); }
details.task:not([open]) .task-title { font-size: 20px; }
.task-loc { color: var(--muted); font-size: 13px; padding-right: 24px; }
.task-title { font-size: 26px; font-weight: 800; line-height: 1.15; padding-right: 24px; }
.step-body { display: flex; flex-direction: column; gap: 14px; }

/* Guide screenshots */
.gallery-wrap { display: flex; flex-direction: column; gap: 6px; }
.gallery { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px 4px; }
.gallery figure { margin: 0; flex: none; width: 72%; max-width: 300px; scroll-snap-align: start; display: flex; flex-direction: column; gap: 6px; }
.gallery img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; background: var(--bg); cursor: zoom-in; }
.gallery figcaption { font-size: 13px; color: var(--muted); line-height: 1.3; }
.lightbox {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / 0.92); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: var(--gutter); cursor: zoom-out;
}
.lightbox img { max-width: 100%; max-height: 80dvh; object-fit: contain; border-radius: 8px; }
.lightbox p { margin: 0; max-width: 560px; text-align: center; }
.tags { display: flex; gap: 8px; flex-wrap: wrap; }
.substeps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.substep { display: flex; gap: 12px; align-items: flex-start; width: 100%; min-height: var(--tap); padding: 8px 0; border: 0; background: none; text-align: left; }
.check { width: 24px; height: 24px; flex: none; border-radius: 50%; border: 2px solid var(--border); display: grid; place-items: center; font-size: 13px; font-weight: 800; }
.substep.done { color: var(--muted); }
.substep.done .check { background: var(--accent); border-color: var(--accent); color: #062523; }
.substep.current .check { border-color: var(--accent); box-shadow: inset 0 0 0 4px var(--card), inset 0 0 0 12px var(--accent); }
.substep.current { font-weight: 600; }
.value { display: flex; flex-direction: column; gap: 4px; width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-btn); padding: 12px 14px; color: var(--text); }
.value-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.value-big { font-size: 24px; font-weight: 800; letter-spacing: 0.03em; font-variant-numeric: tabular-nums; }
.value.unset { border-style: dashed; }
.value-set { color: var(--accent); font-weight: 600; }
.task-actions { display: flex; gap: 10px; }
.task-actions .btn { flex: 1; }
.task-actions .btn.wide { flex: 2; }
.tips summary { color: var(--muted); cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }
.tips ul { margin: 0; padding-left: 20px; color: var(--muted); }

.warning { background: var(--warn-bg); color: var(--warn); border: 1px solid #5a4a22; border-radius: var(--r-btn); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.warning p { margin: 0; }
.dispute-option { display: flex; gap: 10px; align-items: center; justify-content: space-between; color: var(--text); }
.dispute-option .muted { color: #c9b98a; }

/* Step list */
.phase { background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card); margin-bottom: 8px; }
.phase summary { display: flex; justify-content: space-between; align-items: center; padding: 0 16px; min-height: 52px; font-weight: 600; cursor: pointer; }
.step-row { border-top: 1px solid var(--border); }
.step-row[open] { background: rgb(255 255 255 / 0.02); }
.step-row > .step-body { padding: 4px 16px 16px; }
.step-summary { display: flex; align-items: center; gap: 12px; padding: 10px 16px; min-height: 52px; cursor: pointer; list-style: none; }
.step-summary::-webkit-details-marker { display: none; }
.step-row.done .step-text, .step-row.skipped .step-text, .step-row.locked .step-text { opacity: 0.55; }
.step-text { flex: 1; min-width: 0; }
.step-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--border); }
.status-dot.done { background: var(--accent); }
.status-dot.available { background: var(--warn); }
.status-dot.waiting { background: var(--purple); }

/* Tabs */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; justify-content: center;
  padding: 12px var(--gutter) calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%);
}
.tab { flex: 1; max-width: 160px; min-height: 48px; display: grid; place-items: center; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--card); color: var(--text); font-weight: 600; }
.tab.active { background: var(--accent); border-color: var(--accent); color: #062523; }

/* Match */
.match-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px; background: none; border: 0; border-top: 1px solid var(--border); text-align: left; }
.match-row:first-child { border-top: 0; }
.status-dot.todo { background: var(--border); }
.match-text { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.match-resolved { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.link { color: var(--accent); font-weight: 600; }

/* Sheet */
.sheet-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 0.55); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88dvh; overflow-y: auto; max-width: 560px; margin: 0 auto;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card) var(--r-card) 0 0;
  padding: 16px var(--gutter) calc(16px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px;
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.choice-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { min-height: 76px; border-radius: var(--r-btn); border: 1px solid var(--border); background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; padding: 8px; }
.choice.selected { border: 2px solid var(--accent); background: var(--accent-tint); }
.choice-word { font-weight: 800; font-size: 18px; }
.choice-code { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.pigpen-entry { display: flex; gap: 10px; min-height: 64px; align-items: center; flex-wrap: wrap; }
.pigpen-letter { display: flex; flex-direction: column; align-items: center; font-weight: 800; }
.keypad { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.key { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--border); background: var(--bg); display: grid; place-items: center; }
.key.wide { grid-column: span 2; font-size: 20px; }
.order-list { margin: 0; padding-left: 24px; display: flex; flex-direction: column; gap: 4px; font-weight: 600; }
.glyph-slot { display: flex; flex-direction: column; gap: 8px; }

/* Keys */
#keys { display: flex; flex-direction: column; gap: 12px; }
.key-card { display: flex; flex-direction: column; gap: 10px; }
.key-card.delivered { opacity: 0.6; }
.key-head { display: flex; align-items: center; gap: 10px; }
.key-swatch { width: 20px; height: 20px; border-radius: 6px; }
.key-name { flex: 1; font-weight: 800; font-size: 18px; }
.spots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.spot { display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: var(--r-btn); border: 1px solid var(--border); background: var(--bg); text-align: left; font-size: 12px; min-height: var(--tap); }
.spot img, .spot-img { width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; object-fit: cover; background: var(--card); display: grid; place-items: center; color: var(--muted); font-weight: 800; }
.spot img { cursor: zoom-in; }
.spot-label { flex: 1; }
.spot-btn { width: 100%; padding: 0 6px; font-size: 12px; }
.spot.found .spot-btn { border-color: var(--accent); color: var(--accent); }
.key-area { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.spot.found { border: 2px solid var(--accent); background: var(--accent-tint); }
.spot.cleared { opacity: 0.45; }
.spot.cleared .spot-label { text-decoration: line-through; }

/* Lobby */
.share { display: flex; flex-direction: column; gap: 6px; }
.share-link { word-break: break-all; color: var(--accent); font-size: 14px; }
.check-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 52px; padding: 8px 16px; background: none; border: 0; border-top: 1px solid var(--border); text-align: left; }
.check-row:first-child { border-top: 0; }
.check-label { flex: 1; }
.ticks { display: flex; gap: 6px; }
.tick { font-size: 12px; padding: 4px 8px; border-radius: var(--r-pill); border: 1px solid var(--border); color: var(--muted); }
.tick.on { border-color: var(--c); color: var(--c); font-weight: 600; }
.danger summary { color: var(--muted); min-height: var(--tap); display: flex; align-items: center; cursor: pointer; }
.form { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; }
.form input:not([type]) , .form input[name="code"] { min-height: 52px; padding: 0 14px; border-radius: var(--r-btn); border: 1px solid var(--border); background: var(--bg); font-size: 18px; }
.slots { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.slot { flex-direction: row !important; align-items: center; gap: 10px !important; min-height: var(--tap); }

/* Toast + connection pill */
#toast { position: fixed; top: 12px; left: var(--gutter); right: var(--gutter); z-index: 30; pointer-events: none; display: flex; justify-content: center; }
.toast {
  max-width: 520px; padding: 12px 16px; border-radius: var(--r-btn); background: var(--card); border: 1px solid var(--border);
  font-weight: 600; box-shadow: 0 8px 24px rgb(0 0 0 / 0.4); animation: toast 6s forwards;
}
.toast.alert { background: var(--warn-bg); color: var(--warn); border-color: #5a4a22; }
.toast.error { border-color: #ff6b6b; color: #ff9b9b; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 5%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; visibility: hidden; } }
.conn-pill {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 40; padding: 6px 14px; border-radius: var(--r-pill);
  background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 600; display: none;
}
.conn-pill.show { display: block; }

/* Cube notes + photos */
.note-form { display: flex; gap: 8px; }
.note-form input { flex: 1; min-width: 0; min-height: var(--tap); padding: 0 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); }
.glyph-photo { width: 100%; max-height: 220px; object-fit: contain; border-radius: 10px; background: var(--bg); }
.upload { cursor: pointer; }
.thumbs { display: flex; gap: 6px; margin-top: 4px; }
.thumbs img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }

/* Digits keypad */
.digits-entry { display: flex; gap: 8px; justify-content: center; }
.digit { width: 44px; height: 56px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); display: grid; place-items: center; font-size: 28px; font-weight: 800; }
.keypad.digits { grid-template-columns: repeat(3, 1fr); }
.keypad.digits .key { min-height: 56px; font-size: 22px; font-weight: 700; }
.keypad.digits .key.wide { grid-column: span 2; }

/* Map picker */
.map-card { display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.map-card .map-name { font-size: 22px; font-weight: 800; }
