/* ── VARIABLES ─────────────────────────────────────────────── */
:root {
  --bg:          #0d1117;
  --bg2:         #161b22;
  --bg3:         #1c2128;
  --bg4:         #21262d;
  --border:      #30363d;
  --gold:        #e6b04d;
  --gold-dim:    #b8893a;
  --gold-glow:   rgba(230,176,77,0.15);
  --text:        #e6edf3;
  --text2:       #8b949e;
  --text3:       #484f58;
  --green:       #3fb950;
  --amber:       #d29922;
  --red:         #f85149;
  --red-dim:     rgba(248,81,73,0.12);
  --debug-blue:  #79c0ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── RESET ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

/* ── SCREENS ────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(52px + var(--safe-bottom)); /* debug panel */
}
.screen.active { display: flex; }

.screen-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px 24px;
  text-align: center;
  min-height: 100%;
}

/* ── TYPOGRAPHY ─────────────────────────────────────────────── */
.logo { font-size: 72px; line-height: 1; }

h1 {
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--gold);
  text-transform: uppercase;
}

h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--gold);
}

h3 {
  font-size: 19px;
  font-weight: 700;
  color: var(--text);
}

.tagline {
  font-size: 11px;
  letter-spacing: 5px;
  color: var(--text3);
  text-transform: uppercase;
  margin-top: -12px;
}

/* ── BLOCKS ─────────────────────────────────────────────────── */
.info-block {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
  max-width: 380px;
  text-align: left;
}
.info-block p { color: var(--text2); font-size: 14px; line-height: 1.65; }

.warning-block {
  display: flex;
  gap: 10px;
  background: rgba(210,153,34,0.1);
  border: 1px solid rgba(210,153,34,0.25);
  border-radius: 10px;
  padding: 14px 18px;
  max-width: 380px;
  text-align: left;
}
.warn-icon { font-size: 18px; flex-shrink: 0; color: var(--amber); padding-top: 1px; }
.warning-block p { color: var(--amber); font-size: 14px; line-height: 1.6; }

.resume-block {
  background: var(--gold-glow);
  border: 1px solid rgba(230,176,77,0.3);
  border-radius: 10px;
  padding: 12px 18px;
  max-width: 380px;
  font-size: 14px;
  color: var(--gold);
}

.error-block {
  background: var(--red-dim);
  border: 1px solid rgba(248,81,73,0.3);
  border-radius: 10px;
  padding: 14px 18px;
  max-width: 380px;
  color: var(--red);
  font-size: 14px;
  text-align: left;
}

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: opacity .12s, transform .08s;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
  max-width: 380px;
}
.btn:active { transform: scale(0.96); opacity: .8; }

.btn-primary { background: var(--gold); color: #0d1117; }
.btn-large   { padding: 17px 24px; font-size: 17px; }
.btn-small   { padding: 10px 18px; font-size: 14px; max-width: 200px; }
.btn-ghost   {
  background: transparent;
  color: var(--text2);
  border: 1px solid var(--border);
  padding: 13px 24px;
  font-size: 15px;
}
.btn-control {
  flex: 1;
  padding: 14px 12px;
  font-size: 15px;
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-danger {
  padding: 14px 18px;
  font-size: 14px;
  background: var(--red-dim);
  color: var(--red);
  border: 1px solid rgba(248,81,73,0.25);
  flex-shrink: 0;
}

/* ── CALIBRATION ────────────────────────────────────────────── */
.calib-stats {
  display: flex;
  gap: 10px;
  max-width: 380px;
  width: 100%;
}
.calib-card {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}
.calib-label {
  display: block;
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 4px;
}
.calib-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

/* ── GAME SCREEN ────────────────────────────────────────────── */
#screen-game {
  padding-bottom: 0;
  overflow: hidden;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.case-eyebrow {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: 2px;
  text-transform: uppercase;
}
.case-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--gold);
  margin-top: 1px;
}

.sensor-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text2);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 5px 10px;
}
.sensor-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text3);
  flex-shrink: 0;
}
.sensor-dot.active  { background: var(--green); box-shadow: 0 0 5px var(--green); }
.sensor-dot.paused  { background: var(--amber); }
.sensor-dot.error   { background: var(--red); }

.game-main {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 20px calc(52px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Steps hero */
.steps-hero { text-align: center; padding: 16px 0 8px; }
.step-count {
  font-size: 88px;
  font-weight: 800;
  color: var(--gold);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -3px;
}
.steps-unit {
  font-size: 14px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 4px;
  margin-top: 4px;
}

/* Card */
.card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.card-row { margin-bottom: 10px; }
.card-eyebrow {
  display: block;
  font-size: 10px;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: 3px;
}
.current-chapter-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
}
.next-label {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 8px;
}
.progress-track {
  height: 5px;
  background: var(--bg2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 3px;
  transition: width .4s ease;
}

/* Controls */
.controls-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

/* Status bar */
.status-bar {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text3);
  padding: 4px 0;
}

/* ── OVERLAYS ───────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(13,17,23,.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }

.overlay-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px 22px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.overlay-icon { font-size: 52px; }
.overlay-card p { color: var(--text2); font-size: 15px; line-height: 1.6; }
.unlock-title-text { font-size: 18px; font-weight: 700; color: var(--gold) !important; }
.safety-text { color: var(--amber) !important; font-size: 14px !important; }

/* Modal */
.modal-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 20px;
  max-width: 440px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--bg4);
  border: 1px solid var(--border);
  color: var(--text2);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-eyebrow {
  font-size: 10px;
  color: var(--text3);
  letter-spacing: 2.5px;
  text-transform: uppercase;
}
.modal-list-title {
  font-size: 22px;
  color: var(--gold);
  padding-right: 36px;
}
.modal-body {
  color: var(--text2);
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-line;
  user-select: text;
  -webkit-user-select: text;
}

/* Question block */
.question-block {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.question-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
}
.answer-textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  resize: vertical;
  min-height: 72px;
  user-select: text;
  -webkit-user-select: text;
}
.answer-textarea:focus { outline: none; border-color: var(--gold-dim); }
.saved-answer {
  font-size: 13px;
  color: var(--green);
  padding: 6px 0;
}

/* Chapters list */
#chapters-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.chapter-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 15px;
}
.chapter-item.unlocked {
  cursor: pointer;
  border-color: rgba(230,176,77,0.25);
}
.chapter-item.unlocked:active { background: var(--bg4); }
.chapter-status-icon { font-size: 20px; flex-shrink: 0; }
.chapter-item-title { font-size: 15px; font-weight: 600; color: var(--text); }
.chapter-item.locked .chapter-item-title { color: var(--text3); }
.chapter-item-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }

/* ── DEBUG PANEL ────────────────────────────────────────────── */
#debug-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(13,17,23,.97);
  border-top: 1px solid var(--border);
  z-index: 100;
  font-family: 'Courier New', 'SF Mono', monospace;
  font-size: 11px;
  padding-bottom: var(--safe-bottom);
}
#debug-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 16px;
  cursor: pointer;
  color: var(--text3);
  letter-spacing: 1.5px;
}
#debug-toggle:active { background: rgba(255,255,255,.04); }
.debug-label-text { font-size: 11px; }

#debug-body {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border);
  max-height: 42vh;
  overflow-y: auto;
}
#debug-body.hidden { display: none; }

.debug-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 20px;
  margin-bottom: 12px;
}
.dr { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid rgba(48,54,61,.4); }
.dk { color: var(--text3); }
.dv { color: var(--debug-blue); font-weight: bold; }

.debug-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.dbtn {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 11px;
  font-family: monospace;
  cursor: pointer;
}
.dbtn:active { background: var(--bg4); }

/* ── PAUSED STATE ───────────────────────────────────────────── */
body.is-paused .step-count { opacity: .45; }
body.is-paused #btn-pause { color: var(--gold); border-color: var(--gold-dim); }

/* ── UTILITIES ──────────────────────────────────────────────── */
.hidden { display: none !important; }
