/* ============================================================
   Numzy — Editorial Redesign
   ============================================================ */

/* ── 1. Design tokens ────────────────────────────────────── */
:root {
  --bg:          #f4eee2;
  --surface:     #fffdf8;
  --ink:         #2a2620;
  --ink-soft:    #6c6353;
  --ink-mute:    #aaa091;
  --line:        rgba(42,38,32,0.14);
  --line-soft:   rgba(42,38,32,0.08);
  --accent:      #cf5a23;
  --accent-ink:  #fffdf8;
  --correct:     #4d7a55;
  --misplaced:   #c08a1c;

  --font-display: 'Spectral', Georgia, serif;
  --font-num:     'Spectral', Georgia, serif;
  --font-ui:      'Hanken Grotesk', system-ui, sans-serif;

  --r:      7px;
  --r-key:  9px;
  --r-card: 14px;
}

/* ── 2. Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* ── 3. Screen containers ─────────────────────────────────── */
.screen {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow: hidden;
  height: 100vh;   /* fallback for browsers without dvh support */
  height: 100dvh;  /* dynamic viewport height: excludes browser chrome (address bar, nav bar) */
}

/* ── 4. How-to screen ────────────────────────────────────── */
.how-to-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 26px 0;
}

.how-to-logo {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
}

.how-to-subhead {
  font-family: var(--font-ui);
  font-size: 15px;
  color: var(--ink-soft);
  margin-top: 12px;
  line-height: 1.5;
  max-width: 280px;
}

.rule-divider {
  height: 1px;
  background: var(--line);
  margin: 26px 0;
}

.rules-list {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.rule-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.rule-badge {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: var(--r);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}

.rule-title {
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  margin-bottom: 3px;
}

.rule-body {
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink-soft);
}

.how-to-legend {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 30px;
  margin-bottom: 24px;
}

.example-cell {
  width: 34px;
  height: 34px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 17px;
}

.example-correct  { border: 1.5px solid var(--correct);   color: var(--correct);   }
.example-misplaced{ border: 1.5px solid var(--misplaced); color: var(--misplaced); }

.legend-label {
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--ink-soft);
}

.how-to-cta {
  flex-shrink: 0;
  padding: 16px 26px 30px;
}

/* ── 5. Big button ───────────────────────────────────────── */
.big-btn {
  width: 100%;
  height: 54px;
  border-radius: var(--r-key);
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 16px;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: opacity 0.15s;
}
.big-btn:active { opacity: 0.82; }

/* ── 6. Header ───────────────────────────────────────────── */
#header {
  flex-shrink: 0;
  padding: 6px 22px 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 46px;
}

.wordmark {
  font-family: var(--font-display);
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: border-color 0.15s;
}
.icon-btn:hover { border-color: var(--ink-soft); }

/* ── 7. Digit-sum chip ───────────────────────────────────── */
#digit-sum-chip {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  margin: 16px 0 4px;
}

.chip {
  display: inline-flex;
  align-items: baseline;
  gap: 9px;
  padding: 8px 16px;
  border-radius: var(--r);
  background: var(--surface);
  border: 1px solid var(--line-soft);
}

.chip-label {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-mute);
  white-space: nowrap;
}

.chip-value {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

/* ── 8. Board ────────────────────────────────────────────── */
.board {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 18px 22px 0;
}

.board--compact { gap: 6px; padding-top: 10px; }

.board-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-cells {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

/* ─── Digit cells ─── */
.cell {
  width: 50px;
  height: 50px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-size: 25px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.12s;
}

.board--compact .cell { width: 44px; height: 44px; font-size: 22px; }

.cell--empty         { background: transparent; border: 1px solid var(--line-soft); }
.cell--filled        { background: var(--surface); border: 1px solid var(--line); color: var(--ink); }
.cell--active        { background: var(--surface); border: 1.5px solid var(--accent); }
.cell--pos-correct   { background: var(--surface); border: 1.5px solid var(--correct);   color: var(--correct);   }
.cell--pos-misplaced { background: var(--surface); border: 1.5px solid var(--misplaced); color: var(--misplaced); }
.cell--theory-green  { background: rgba(77,122,85,0.12);  border: 1.5px solid var(--correct);   color: var(--correct);   }
.cell--theory-amber  { background: rgba(192,138,28,0.12); border: 1.5px solid var(--misplaced); color: var(--misplaced); }
.cell--tappable { cursor: pointer; }
.cell--tappable:hover { opacity: 0.75; }

/* ─── Fill-in animation ─── */
@keyframes fillIn {
  from { transform: scale(0.8); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.cell--fill-anim { animation: fillIn 0.18s ease forwards; }

/* ─── Feedback badges ─── */
.feedback {
  width: 92px;
  flex-shrink: 0;
  display: flex;
  gap: 7px;
  align-items: center;
  padding-left: 4px;
}

.feedback-empty { visibility: hidden; }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateX(-6px); }
  to   { opacity: 1; transform: translateX(0); }
}
.feedback-new { animation: fadeSlideIn 0.25s ease 0.28s both; }

.fb-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.fb-badge {
  width: 30px;
  height: 30px;
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  font-family: var(--font-num);
  font-size: 15px;
  font-weight: 700;
  line-height: 1;
}

.fb-correct   .fb-badge { color: var(--correct);   border: 1px solid var(--correct);   }
.fb-misplaced .fb-badge { color: var(--misplaced); border: 1px solid var(--misplaced); }

.fb-label {
  font-family: var(--font-ui);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
}

/* ── 9. Message area ─────────────────────────────────────── */
.message-area {
  flex-shrink: 0;
  text-align: center;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  padding: 10px 22px;
  margin: 8px 22px 0;
  border-radius: var(--r);
  line-height: 1.4;
}
.message-success { background: rgba(77,122,85,0.10);  color: var(--correct);   }
.message-error   { background: rgba(207,90,35,0.10);  color: var(--accent);    }
.message-info    { background: rgba(192,138,28,0.10); color: var(--misplaced); }

/* ── 10. Keypad ──────────────────────────────────────────── */
.keypad {
  flex-shrink: 0;
  margin-top: auto;
  padding: 0 22px max(22px, env(safe-area-inset-bottom));
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.key {
  height: 50px;
  border-radius: var(--r-key);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.12s;
}
.key:active { opacity: 0.7; }
.key:disabled { opacity: 0.35; cursor: not-allowed; }

.key-delete {
  color: var(--ink-soft);
  font-size: 18px;
}

.key-guess {
  background: var(--accent);
  border-color: transparent;
  color: var(--accent-ink);
  font-family: var(--font-ui);
  font-size: 14px;
}
.key-guess:disabled { background: var(--accent); opacity: 0.35; }

/* ── 11. Result sheet ────────────────────────────────────── */
.result-sheet {
  flex-shrink: 0;
  margin-top: auto;
  background: var(--surface);
  border-top: 1px solid var(--line-soft);
  border-top-left-radius: var(--r-card);
  border-top-right-radius: var(--r-card);
  box-shadow: 0 -10px 30px rgba(0,0,0,0.05);
  padding: 18px 24px 20px;
}

.result-eyebrow {
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.result-eyebrow--win  { color: var(--correct);   }
.result-eyebrow--lose { color: var(--misplaced); }

.result-headline {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 700;
  color: var(--ink);
  margin-top: 4px;
  line-height: 1.2;
}

.result-answer {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.answer-cell {
  width: 42px;
  height: 44px;
  border-radius: var(--r);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
}

.metrics-row {
  display: flex;
  margin: 14px 0 16px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r);
  overflow: hidden;
}

.metric {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
}

.metric-border { border-left: 1px solid var(--line-soft); }

.metric-value {
  font-family: var(--font-num);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.metric-label {
  font-family: var(--font-ui);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-mute);
  margin-top: 3px;
}

.countdown-caption {
  text-align: center;
  font-family: var(--font-ui);
  font-size: 12.5px;
  color: var(--ink-mute);
  margin-top: 9px;
}

.countdown-time {
  color: var(--ink-soft);
  font-weight: 600;
}

/* ── 12. Share modal (bottom sheet) ─────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,18,15,0.32);
  display: none;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  z-index: 100;
}
.modal-overlay.show { display: flex; }

.share-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-top-left-radius: var(--r-card);
  border-top-right-radius: var(--r-card);
  box-shadow: 0 -14px 40px rgba(0,0,0,0.18);
  padding: 20px 24px 26px;
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
  margin: 0 auto 18px;
}

.share-title {
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  color: var(--ink);
}

.share-preview {
  margin-top: 16px;
  padding: 16px 18px;
  border-radius: var(--r);
  background: var(--bg);
  border: 1px solid var(--line-soft);
}

.share-caption {
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 10px;
}

.share-grid {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.share-row {
  display: flex;
  gap: 4px;
}

.share-swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.share-swatch--correct   { background: var(--correct); }
.share-swatch--misplaced { background: var(--misplaced); }
.share-swatch--empty     { background: transparent; border: 1px solid var(--line); }

.share-platforms {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 18px;
}

.platform-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  background: var(--surface);
  text-decoration: none;
  transition: border-color 0.15s;
}
.platform-btn:hover { border-color: var(--ink-mute); }

.platform-chip {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.platform-label {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14.5px;
  color: var(--ink);
}

.copy-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.copy-url-display {
  flex: 1;
  padding: 11px 14px;
  border-radius: var(--r);
  background: var(--bg);
  border: 1px solid var(--line-soft);
  font-family: var(--font-ui);
  font-size: 13px;
  color: var(--ink-soft);
  display: flex;
  align-items: center;
}

.copy-btn {
  padding: 0 20px;
  border-radius: var(--r);
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.copy-btn:active { opacity: 0.82; }

.copy-toast {
  margin-top: 8px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 700;
  color: var(--correct);
  text-align: center;
}

/* ── 13. Responsive ──────────────────────────────────────── */
@media (max-width: 359px) {
  .cell { width: 46px; height: 46px; font-size: 22px; }
  .board--compact .cell { width: 40px; height: 40px; font-size: 20px; }
  .feedback { width: 80px; }
  .fb-label { font-size: 7.5px; }
  .board { padding-left: 14px; padding-right: 14px; }
  .keypad { padding-left: 14px; padding-right: 14px; }
}

/* ── 14. Short-screen scaling ────────────────────────────── */
/* Triggered on phones where browser chrome (address/nav bars) leaves < 720px.
   Reduces cells 50→44px and keys 50→44px, dropping total layout height ~100px. */
@media (max-height: 720px) {
  .cell { width: 44px; height: 44px; font-size: 22px; }
  .board--compact .cell { width: 38px; height: 38px; font-size: 19px; }
  .board { gap: 6px; padding-top: 12px; }
  .row-cells { gap: 7px; }
  .board-row { gap: 7px; }
  .fb-badge { width: 26px; height: 26px; font-size: 13px; }
  .feedback { width: 80px; }
  #digit-sum-chip { margin: 8px 0 2px; }
  .key { height: 44px; }
  .keypad-grid { gap: 6px; }
  .keypad { padding-bottom: 16px; }
}

/* Further reduction for very small phones or landscape orientation.
   Reduces cells 44→40px and keys 44→40px. */
@media (max-height: 650px) {
  .cell { width: 40px; height: 40px; font-size: 20px; }
  .board--compact .cell { width: 34px; height: 34px; font-size: 17px; }
  .board { gap: 5px; padding-top: 8px; }
  .row-cells { gap: 6px; }
  .board-row { gap: 6px; }
  .fb-badge { width: 24px; height: 24px; font-size: 12px; }
  .feedback { width: 74px; }
  #digit-sum-chip { margin: 4px 0 0; }
  #header { padding-top: 2px; }
  .header-row { height: 40px; }
  .key { height: 40px; font-size: 18px; }
  .key-guess { font-size: 12px; }
  .keypad-grid { gap: 5px; }
  .keypad { padding-bottom: 12px; }
}
