/* ---------- Design tokens ----------
   App chrome (dark, everything except the puzzle grid itself):
   --app-bg:        near-black warm charcoal
   --app-bg2:       slightly lighter panel
   --app-text:      warm off-white
   --app-text-soft: muted warm grey
   --app-border:    subtle hairline on dark
   --accent-blue:   score / leaderboard accent, tuned for dark bg

   Puzzle grid ("paper island" — stays literal paper regardless of app theme):
   --paper / --ink / --stamp-green / --pencil-red / --highlighter / --ledger-blue

   Display face: Bitter (slab serif, puzzle-magazine headline)
   Mono face:    IBM Plex Mono (filled letters — typewriter feel)
   Body face:    Inter
------------------------------------- */

:root {
  color-scheme: dark;
  --app-bg: #1C1A16;
  --app-bg2: #262319;
  --app-text: #EDEAE4;
  --app-text-soft: #A79F8E;
  --app-border: rgba(237, 234, 228, 0.14);
  --accent-blue: #7C9CEA;

  --paper: #EDEAE1;
  --ink: #1B1B1F;
  --ink-soft: #55545C;
  --stamp-green: #2F6F4F;
  --pencil-red: #B23A48;
  --highlighter: #F2C94C;
  --ledger-blue: #3556A3;

  --cell-size: 34px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color-scheme: dark;
  background: var(--app-bg);
  color: var(--app-text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 16px 32px;
}

/* ---------- Header ---------- */
.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--app-border);
}

.brand-eyebrow {
  display: block;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--app-text-soft);
  margin-bottom: 2px;
}

.brand h1 {
  font-family: 'Bitter', serif;
  font-weight: 900;
  font-size: 24px;
  margin: 0;
  line-height: 1.05;
  color: var(--app-text);
}

.score-pill {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 64px;
  padding: 6px 10px;
  border: 2px solid var(--app-text);
  border-radius: 3px;
  background: var(--ledger-blue);
  color: #fff;
  cursor: pointer;
  transform: rotate(-2deg);
}
.score-value { font-family: 'Bitter', serif; font-weight: 900; font-size: 20px; line-height: 1; }
.score-label { font-family: 'IBM Plex Mono', monospace; font-size: 9px; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.85; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}
.tab {
  flex: 1;
  padding: 9px 0;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: transparent;
  border: 2px solid var(--app-text);
  border-radius: 3px;
  color: var(--app-text);
  cursor: pointer;
}
.tab.active { background: var(--app-text); color: var(--app-bg); }

.view { display: none; }
.view.active { display: block; }

/* ---------- Zoom controls ---------- */
.zoom-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 8px;
}
.zoom-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--app-border);
  border-radius: 4px;
  background: var(--app-bg2);
  color: var(--app-text);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.zoom-btn:active { transform: translateY(1px); }
#zoom-level {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--app-text-soft);
  min-width: 36px;
  text-align: center;
}

/* ---------- Grid ("paper island") ---------- */
.grid-wrap {
  display: flex;
  justify-content: safe center;
  margin-bottom: 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.grid {
  display: grid;
  gap: 2px;
  background: var(--ink);
  border: 2px solid var(--ink);
  width: fit-content;
  flex-shrink: 0;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
  border-radius: 2px;
  overflow: hidden;
}
.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.cell.blocked { background: var(--ink); }
.cell input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: calc(var(--cell-size) * 0.47);
  text-transform: uppercase;
  color: var(--ink);
  padding: 0;
}
.cell input:focus { outline: none; background: rgba(242, 201, 76, 0.55); }
.cell.active-word input:not(:focus) { background: rgba(242, 201, 76, 0.22); }
.cell .num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: calc(var(--cell-size) * 0.235);
  color: var(--ink-soft);
  pointer-events: none;
}
.cell.correct input { color: var(--stamp-green); }
.cell.correct { position: relative; }
.cell.correct::after {
  content: "✓";
  position: absolute;
  bottom: -3px;
  right: -1px;
  font-size: 10px;
  color: var(--stamp-green);
  transform: rotate(-12deg);
}
.cell.incorrect input { color: var(--pencil-red); }
.cell.hinted:not(.correct) input { color: var(--ledger-blue); }
.cell.hinted:not(.correct) { background: rgba(53, 86, 163, 0.16); }
.cell input:disabled {
  opacity: 1;
  -webkit-text-fill-color: currentColor;
  cursor: default;
}

/* ---------- Clue bar ---------- */
.clue-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--app-bg2);
  border: 1.5px solid var(--app-border);
  border-radius: 4px;
  padding: 8px 10px;
  margin-bottom: 14px;
}
.clue-nav {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--app-text);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.clue-text { flex: 1; font-size: 14px; line-height: 1.3; color: var(--app-text); }

.action-row { margin-bottom: 12px; }
.hint-btn {
  width: 100%;
  padding: 10px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  background: transparent;
  color: var(--ledger-blue);
  border: 1.5px solid var(--ledger-blue);
  border-radius: 4px;
  cursor: pointer;
}
.hint-btn:active { transform: translateY(1px); }
.hint-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.hint-btn #hint-counter { font-weight: 700; }

.primary-btn {
  width: 100%;
  padding: 13px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--stamp-green);
  color: #fff;
  border: 2px solid var(--app-text);
  border-radius: 3px;
  cursor: pointer;
  margin-bottom: 18px;
}
.primary-btn:active { transform: translateY(1px); }

.secondary-btn {
  width: 100%;
  padding: 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 3px;
  cursor: pointer;
}
.secondary-btn:active { transform: translateY(1px); }

/* ---------- Clue list ---------- */
.clue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1.5px solid var(--app-border);
}
.clue-list li {
  display: flex;
  gap: 8px;
  padding: 9px 6px;
  font-size: 13.5px;
  color: var(--app-text);
  border-bottom: 1.5px solid var(--app-border);
  border-left: 3px solid transparent;
  cursor: pointer;
}
.clue-list li:active { background: var(--app-bg2); }
.clue-list li.active { background: var(--app-bg2); border-left-color: var(--highlighter); }
.clue-list .n {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  color: var(--app-text-soft);
  min-width: 18px;
}
.clue-list .dir {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9px;
  text-transform: uppercase;
  color: var(--accent-blue);
  align-self: center;
}

/* ---------- Nickname editor ---------- */
.nickname-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.nickname-input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  background: var(--app-bg2);
  border: 1.5px solid var(--app-border);
  border-radius: 4px;
  color: var(--app-text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
}
.nickname-input::placeholder { color: var(--app-text-soft); }
.nickname-input:focus { outline: none; border-color: var(--highlighter); }
.mini-btn {
  padding: 10px 14px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  background: var(--ledger-blue);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
}
.mini-btn:active { transform: translateY(1px); }

/* ---------- Puzzle list ---------- */
.puzzle-list { list-style: none; margin: 0; padding: 0; }
.puzzle-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 10px;
  border-bottom: 1.5px solid var(--app-border);
  border-left: 3px solid transparent;
  color: var(--app-text);
  cursor: pointer;
}
.puzzle-list-item:active { background: var(--app-bg2); }
.puzzle-list-item.active { background: var(--app-bg2); border-left-color: var(--highlighter); }
.puzzle-list-item .title { font-family: 'Bitter', serif; font-weight: 700; font-size: 15px; }
.puzzle-list-item .meta {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  color: var(--app-text-soft);
  white-space: nowrap;
}
.puzzle-list-item.locked { cursor: not-allowed; }
.puzzle-list-item.locked .title { color: var(--app-text-soft); }
.puzzle-list-item.locked .meta { font-size: 13px; }

/* ---------- Leaderboard ---------- */
.section-title {
  font-family: 'Bitter', serif;
  font-weight: 900;
  font-size: 19px;
  margin: 4px 0 14px;
  color: var(--app-text);
}
.leaderboard { list-style: none; margin: 0; padding: 0; }
.leaderboard li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 6px;
  border-bottom: 1.5px solid var(--app-border);
  border-left: 3px solid transparent;
  color: var(--app-text);
}
.leaderboard li.own {
  background: rgba(242, 201, 76, 0.10);
  border-left-color: var(--highlighter);
}
.leaderboard li.own .name { font-weight: 600; }
.leaderboard .rank {
  font-family: 'Bitter', serif;
  font-weight: 900;
  font-size: 15px;
  width: 24px;
  text-align: center;
  color: var(--app-text-soft);
}
.leaderboard li:nth-child(1) .rank { color: #E0BB4A; }
.leaderboard li:nth-child(2) .rank { color: #C7C9CD; }
.leaderboard li:nth-child(3) .rank { color: #C48A54; }
.leaderboard .name { flex: 1; font-size: 14px; }
.leaderboard .pts {
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  color: var(--accent-blue);
  font-size: 13px;
}

/* ---------- Congrats screen ---------- */
.congrats-card {
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  padding: 32px 22px 24px;
  text-align: center;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  margin-top: 24px;
}
.congrats-stamp {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  border: 3px solid var(--stamp-green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  color: var(--stamp-green);
  transform: rotate(-8deg);
}
.congrats-card h2 {
  font-family: 'Bitter', serif;
  font-weight: 900;
  font-size: 22px;
  margin: 0 0 6px;
}
.congrats-score {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 15px;
  margin: 0 0 4px;
}
.congrats-score b { color: var(--stamp-green); font-size: 20px; }
.congrats-hints {
  font-size: 13px;
  font-weight: 600;
  color: var(--ledger-blue);
  margin: 0 0 4px;
}
.congrats-rank {
  font-size: 13px;
  color: var(--ink-soft);
  margin: 0 0 22px;
}
.congrats-card .primary-btn,
.congrats-card .secondary-btn { margin-bottom: 10px; }
.congrats-card .primary-btn:last-child,
.congrats-card .secondary-btn:last-child { margin-bottom: 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: var(--ink);
  color: var(--paper);
  padding: 11px 18px;
  border-radius: 5px;
  font-size: 13.5px;
  font-family: 'Inter', sans-serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: 90%;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
