/* ============================================================
   ATLAS — design tokens
   Palette: near-black stage with a single "flash green" accent
   reserved for live/ready states, and gold reserved ONLY for
   personal-best celebration — the one bold moment in the app.
   ============================================================ */
:root {
  --bg: #0B0C0E;
  --bg-elevated: #131518;
  --surface: #1A1C20;
  --surface-2: #202226;
  --border: #2A2D33;
  --text: #F2F3F5;
  --text-secondary: #9A9EA6;
  --text-tertiary: #5B5F66;

  --accent: #2BD576;        /* ready-to-go green */
  --accent-dim: rgba(43, 213, 118, 0.14);
  --hold: #FF5C5C;          /* holding / not-ready red */
  --hold-dim: rgba(255, 92, 92, 0.14);
  --gold: #F5C24D;          /* reserved for PB celebration only */
  --gold-dim: rgba(245, 194, 77, 0.14);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 11px;

  --font-display: 'Sora', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
h1, h2, h3 { font-family: var(--font-display); margin: 0; }
button { font-family: inherit; border: none; background: none; color: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 18px 0;
  animation: fadeIn .18s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 10px;
}
.topbar h1 { font-size: 22px; font-weight: 700; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font-display);
}
.chip-ghost { color: var(--text-secondary); }

/* ---------- Timer screen ---------- */
.scramble-bar {
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  text-align: center;
  padding: 10px 6px;
  min-height: 44px;
  letter-spacing: 0.3px;
}

.timer-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: var(--radius-lg);
  transition: background .12s ease;
  margin: 4px 0;
}
.timer-stage.holding { background: var(--hold-dim); }
.timer-stage.ready { background: var(--accent-dim); }
.timer-stage.running { background: transparent; }

.timer-display {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15vw;
  line-height: 1;
  letter-spacing: -1px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  transition: color .1s ease, transform .18s cubic-bezier(.2,.8,.2,1);
}
.timer-stage.holding .timer-display { color: var(--hold); }
.timer-stage.ready .timer-display { color: var(--accent); }
.timer-display.pb-pulse { color: var(--gold); transform: scale(1.08); }

.timer-hint {
  font-size: 13px;
  color: var(--text-tertiary);
  font-weight: 500;
  letter-spacing: 0.2px;
}

.mini-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 0 14px;
}
.mini-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 10px 4px;
}
.mini-label { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.6px; }
.mini-value { font-family: var(--font-mono); font-size: 15px; font-weight: 600; }

.last-solve-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding-bottom: 14px;
}
.pill {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 11px 4px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: var(--text-secondary);
}
.pill-primary { background: var(--accent-dim); color: var(--accent); }

/* ---------- Scroll content screens ---------- */
.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 18px;
  -webkit-overflow-scrolling: touch;
}
.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
}
.card h3 { font-size: 13px; color: var(--text-secondary); font-weight: 600; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 10px; }
.stat-block { text-align: center; }
.stat-block .val { font-family: var(--font-mono); font-size: 20px; font-weight: 700; }
.stat-block .lbl { font-size: 11px; color: var(--text-tertiary); margin-top: 2px; }

.insight-row {
  display: flex;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.insight-row:last-child { border-bottom: none; }
.insight-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex: 0 0 auto; }
.insight-text { font-size: 14px; line-height: 1.4; color: var(--text); }
.insight-text small { display: block; color: var(--text-tertiary); font-size: 11px; margin-top: 2px; }

.milestone-track { display: flex; flex-direction: column; gap: 0; }
.milestone {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  position: relative;
}
.milestone .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface-2);
  border: 2px solid var(--border);
  flex: 0 0 auto;
}
.milestone.hit .dot { background: var(--gold); border-color: var(--gold); }
.milestone .label { font-weight: 600; font-size: 14px; flex: 1; }
.milestone .date { font-size: 12px; color: var(--text-tertiary); font-family: var(--font-mono); }
.milestone.locked .label, .milestone.locked .date { color: var(--text-tertiary); }

.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .l-left { font-size: 14px; font-weight: 500; }
.list-row .l-right { font-family: var(--font-mono); font-size: 14px; color: var(--text-secondary); }

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.setting-row:last-child { border-bottom: none; }
.setting-row .desc { color: var(--text-tertiary); font-size: 12px; margin-top: 2px; }

.switch {
  width: 46px; height: 28px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  position: relative; flex: 0 0 auto;
}
.switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 22px; height: 22px; border-radius: 50%; background: var(--text-secondary);
  transition: transform .15s ease, background .15s ease;
}
.switch.on { background: var(--accent-dim); border-color: var(--accent); }
.switch.on::after { transform: translateX(18px); background: var(--accent); }

.btn-secondary {
  width: 100%;
  padding: 13px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 14px;
  margin-top: 8px;
  color: var(--text);
}
.btn-danger { color: var(--hold); }

/* ---------- Tab bar ---------- */
.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 6px 6px calc(6px + var(--safe-bottom));
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--text-tertiary);
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--radius-sm);
}
.tab.active { color: var(--accent); }

/* ---------- Celebration / toast ---------- */
.celebration-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 40;
}
.confetti-piece {
  position: absolute;
  top: -10px;
  width: 7px; height: 12px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(112vh) rotate(540deg); opacity: 0.9; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(78px + var(--safe-bottom));
  transform: translateX(-50%) translateY(10px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-tertiary);
}
.empty-state .glyph { font-size: 34px; margin-bottom: 10px; }
.empty-state .title { font-family: var(--font-display); color: var(--text-secondary); font-weight: 600; font-size: 15px; margin-bottom: 4px; }

/* ---------- Action sheet (session/cube pickers, comment, manual entry) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 60; display: flex; align-items: flex-end;
  opacity: 0; transition: opacity .15s ease;
}
.sheet-backdrop.show { opacity: 1; }
.sheet {
  width: 100%;
  background: var(--bg-elevated);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform .2s cubic-bezier(.2,.8,.2,1);
  max-height: 70vh;
  overflow-y: auto;
}
.sheet-backdrop.show .sheet { transform: translateY(0); }
.sheet h3 { font-size: 15px; margin-bottom: 12px; }
.sheet-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 4px; border-bottom: 1px solid var(--border); font-size: 15px; font-weight: 500;
}
.sheet-row:last-child { border-bottom: none; }
.sheet-input {
  width: 100%; background: var(--surface); border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px 14px; font-size: 15px; font-family: inherit;
  margin-bottom: 10px;
}
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-btn {
  flex: 1; padding: 13px; border-radius: var(--radius-sm); font-weight: 600; text-align: center; font-size: 14px;
  background: var(--surface);
}
.sheet-btn.primary { background: var(--accent-dim); color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
