/* ---------------------------------------------
   Tokens
   Dark theme is the default (:root). The light
   theme overrides everything under [data-theme="light"].
--------------------------------------------- */
:root {
  --bg: #14161f;
  --bg-line: #1f2230;
  --ink: #e9e4d6;
  --ink-soft: #9d9788;
  --navy: #93a8e0;
  --navy-soft: #b7c5ec;
  --rust: #ff7a54;
  --card: #1b1e2b;
  --card-border: #333a52;
  --shadow: 0 10px 34px rgba(0, 0, 0, 0.5);

  --cell-bg: #232838;
  --given-bg: #3a3220;
  --given-ink: #f1ecd9;
  --player-ink: #a7bdf2;
  --note-ink: #767c93;
  --board-line: #0d0e15;

  --hl-peer: #24405f;      /* row / column / box highlight — cool blue, distinct from given cells' warm tone */
  --hl-same-bg: #1f4a3c;   /* same-number highlight — green, distinct from peer and given */
  --hl-same-ring: #5cc99a;
  --hl-selected: #6e4a1f;  /* selected cell — warm amber, dark-mode tuned */
  --error-ink: #ff7a7a;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Inter", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Courier New", monospace;
}

[data-theme="light"] {
  --bg: #efe7d4;
  --bg-line: #ddd0ac;
  --ink: #232324;
  --ink-soft: #55524a;
  --navy: #2b3a67;
  --navy-soft: #4a5a8f;
  --rust: #c1440e;
  --card: #f7f2e4;
  --card-border: #d8cba4;
  --shadow: 0 10px 30px rgba(35, 35, 36, 0.12);

  --cell-bg: #f7f2e4;
  --given-bg: #ece2c8;
  --given-ink: #232324;
  --player-ink: #2b3a67;
  --note-ink: #8a8574;
  --board-line: #232324;

  --hl-peer: #dbe4f5;
  --hl-same-bg: #d8efe1;
  --hl-same-ring: #2f8f63;
  --hl-selected: #f7d9a8;
  --error-ink: #c1440e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background:
    linear-gradient(var(--bg-line) 1px, transparent 1px) 0 0 / 100% 28px,
    linear-gradient(90deg, var(--bg-line) 1px, transparent 1px) 0 0 / 28px 100%,
    var(--bg);
  background-blend-mode: multiply, multiply, normal;
  transition: background-color 0.2s ease, color 0.2s ease;
}

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

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ---------------------------------------------
   Masthead
--------------------------------------------- */
.masthead {
  padding: 20px 0 18px;
  text-align: center;
  border-bottom: 2px solid var(--ink);
}

.masthead-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--card);
  border: 1.5px solid var(--card-border);
  color: var(--ink);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.icon-btn:hover { border-color: var(--navy-soft); }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 6px;
}

.title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(48px, 9vw, 76px);
  margin: 0;
  color: var(--navy);
  letter-spacing: -0.01em;
}

.subtitle {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--ink-soft);
  margin: 8px 0 0;
}

/* ---------------------------------------------
   Sheet / perforation signature
--------------------------------------------- */
.sheet {
  position: relative;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-top: none;
  box-shadow: var(--shadow);
  padding: 0 28px 40px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.perforation {
  height: 18px;
  margin: 0 -28px;
  background-image: radial-gradient(circle at 14px 9px, var(--bg) 6px, transparent 6.5px);
  background-size: 28px 18px;
  background-position: 14px 0;
  border-bottom: 1px dashed var(--card-border);
}

/* ---------------------------------------------
   Difficulty stamps
--------------------------------------------- */
.controls-top {
  padding: 26px 0 8px;
}

.stamp-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
}

.stamp {
  font-family: var(--font-display);
  cursor: pointer;
  background: transparent;
  border: 2.5px solid var(--navy);
  color: var(--navy);
  border-radius: 6px;
  padding: 10px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transform: rotate(var(--tilt, 0deg));
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.stamp:nth-child(1) { --tilt: -1.5deg; }
.stamp:nth-child(2) { --tilt: 0.5deg; }
.stamp:nth-child(3) { --tilt: -0.8deg; }

.stamp:hover {
  transform: rotate(0deg) scale(1.03);
}

.stamp:focus-visible {
  outline: 3px solid var(--rust);
  outline-offset: 2px;
}

.stamp-label {
  font-weight: 600;
  font-size: 20px;
  letter-spacing: 0.02em;
}

.stamp-sub {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--ink-soft);
}

.stamp.active {
  background: var(--navy);
  color: var(--card);
  transform: rotate(0deg);
}
.stamp.active .stamp-sub { color: var(--card); opacity: 0.75; }

/* ---------------------------------------------
   Game area layout
--------------------------------------------- */
.game-area {
  display: flex;
  gap: 36px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
  padding-top: 12px;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.board-meta {
  display: flex;
  gap: 22px;
}

.meta-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-family: var(--font-mono);
}

.meta-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ink-soft);
}

.meta-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
}

#lives {
  letter-spacing: 0.12em;
  color: var(--navy);
}
#lives.low { color: var(--rust); }

/* ---------------------------------------------
   Board
--------------------------------------------- */
.board-wrap {
  position: relative;
}

.board {
  --cell: min(52px, 10vw);
  display: grid;
  grid-template-columns: repeat(9, var(--cell));
  grid-template-rows: repeat(9, var(--cell));
  background: var(--board-line);
  border: 3px solid var(--board-line);
  border-radius: 4px;
  gap: 1px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.cell {
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-family: var(--font-mono);
  font-size: calc(var(--cell) * 0.44);
  font-weight: 500;
  color: var(--player-ink);
  cursor: pointer;
  user-select: none;
  transition: background-color 0.1s ease;
}

.cell.given {
  color: var(--given-ink);
  font-weight: 700;
  background: var(--given-bg);
}

/* Row / column / box highlight for the selected cell — kept visually
   distinct (cool blue) from the warm tone used for given/clue cells. */
.cell.peer {
  background: var(--hl-peer);
}

/* Cells sharing the same number as the selection — a second, clearly
   different hue (green) plus a ring so it never blends with .peer. */
.cell.same-value {
  background: var(--hl-same-bg);
  box-shadow: inset 0 0 0 2px var(--hl-same-ring);
}

.cell.selected {
  background: var(--hl-selected);
}

.cell.error {
  color: var(--error-ink);
}

.cell.error::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 2px solid var(--error-ink);
  border-radius: 3px;
  pointer-events: none;
}

.cell.hinted {
  animation: hintFlash 0.9s ease;
}
@keyframes hintFlash {
  0% { background: var(--hl-selected); }
  100% { background: inherit; }
}

/* thicker box borders every 3 cells */
.cell[data-col="2"], .cell[data-col="5"] { border-right: 2px solid var(--board-line); }
.cell[data-col="3"], .cell[data-col="6"] { border-left: 2px solid var(--board-line); }
.cell[data-row="2"], .cell[data-row="5"] { border-bottom: 2px solid var(--board-line); }
.cell[data-row="3"], .cell[data-row="6"] { border-top: 2px solid var(--board-line); }

.notes-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  pointer-events: none;
}
.notes-grid span {
  font-family: var(--font-mono);
  font-size: calc(var(--cell) * 0.19);
  color: var(--note-ink);
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  color: var(--navy-soft);
  font-size: 14px;
  border-radius: 4px;
  transition: opacity 0.2s ease;
  text-align: center;
  padding: 12px;
}
.board-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ---------------------------------------------
   Number pad
--------------------------------------------- */
.pad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-width: 420px;
}

.pad-num {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  padding: 12px 0;
  background: var(--cell-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 6px;
  color: var(--navy);
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease;
}
.pad-num:hover { background: var(--hl-peer); }
.pad-num:active { transform: scale(0.95); }
.pad-erase { color: var(--rust); font-size: 22px; }

/* ---------------------------------------------
   Side column / tools
--------------------------------------------- */
.side-column {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: 280px;
  max-width: 100%;
}

.tool-card {
  background: var(--bg);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 18px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.tool-title {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 12px;
  color: var(--navy);
}

.tool-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--cell-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 6px;
  padding: 11px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.tool-btn:last-child { margin-bottom: 0; }
.tool-btn:hover { background: var(--hl-peer); border-color: var(--navy-soft); }
.tool-btn-icon { font-size: 15px; }

.tool-btn-primary {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--card);
}
.tool-btn-primary:hover { background: var(--navy-soft); }

.tool-state {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.tool-btn.active .tool-state { color: var(--rust); font-weight: 700; }
.tool-btn.active { border-color: var(--rust); }

.tool-btn:disabled,
.tool-btn.depleted {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg);
}
.tool-btn:disabled:hover,
.tool-btn.depleted:hover {
  background: var(--bg);
  border-color: var(--card-border);
}

.rules {
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ink-soft);
}
.rules li { margin-bottom: 8px; }
.rules li:last-child { margin-bottom: 0; }

/* ---------------------------------------------
   Account / login panel
--------------------------------------------- */
.account-hint {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
  margin: 0 0 12px;
}

.account-user {
  font-size: 14px;
  margin: 0 0 12px;
}

.hidden { display: none !important; }

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

.stat-box {
  background: var(--cell-bg);
  border: 1px solid var(--card-border);
  border-radius: 6px;
  padding: 8px 4px;
  text-align: center;
}
.stat-box-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 9px;
  text-transform: uppercase;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
}
.stat-box-value {
  display: block;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  color: var(--navy);
  margin-top: 2px;
}

.history-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
  max-height: 140px;
  overflow-y: auto;
}
.history-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--card-border);
}
.history-list li:last-child { border-bottom: none; }
.history-empty {
  font-size: 12px;
  color: var(--ink-soft);
  font-style: italic;
}

.tool-subtitle {
  font-family: var(--font-display);
  font-size: 13px;
  margin: 4px 0 8px;
  color: var(--ink-soft);
}

.profile-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

/* ---------------------------------------------
   Classifica
--------------------------------------------- */
.leaderboard-group { margin-bottom: 14px; }
.leaderboard-group:last-child { margin-bottom: 0; }

.leaderboard-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-soft);
}
.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--card-border);
}
.leaderboard-list li:last-child { border-bottom: none; }

/* ---------------------------------------------
   Footer
--------------------------------------------- */
.colophon {
  text-align: center;
  padding: 22px 0 0;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-soft);
}

/* ---------------------------------------------
   Win / game-over modal
--------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-backdrop.visible {
  display: flex;
}

.modal-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 32px;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow);
}

.modal-eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--rust);
  margin: 0 0 6px;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 32px;
  margin: 0 0 12px;
  color: var(--navy);
}

.modal-body {
  font-size: 14px;
  color: var(--ink-soft);
  line-height: 1.6;
  margin: 0 0 20px;
}

/* ---------------------------------------------
   Responsive
--------------------------------------------- */
@media (max-width: 640px) {
  .sheet { padding: 0 14px 28px; }
  .perforation { margin: 0 -14px; }
  .stamp { padding: 8px 14px; }
  .stamp-label { font-size: 17px; }
  .side-column { width: 100%; }
  .board { --cell: min(38px, 9.6vw); }
}
