/* ════════════════════════════════════════════════════════════════════════
   Sudoku — The Daily Grid
   An "ink on paper" editorial/risograph aesthetic. Warm paper, near-black ink,
   two overprint accents, and a couple of distinctive grotesque typefaces.
   Custom-built from scratch — not a framework class in sight.
   ════════════════════════════════════════════════════════════════════════ */

:root {
  /* Paper & ink */
  --paper:    #efe6d4;
  --paper-2:  #f6efe1;
  --paper-3:  #faf5ea;
  --ink:      #1c1916;
  --ink-soft: #6b6357;
  --line:     rgba(28, 25, 22, 0.16);
  --line-2:   rgba(28, 25, 22, 0.28);

  /* Risograph overprint accents */
  --blue:      #2f49d8;
  --blue-wash: rgba(47, 73, 216, 0.12);
  --vermilion: #ef5130;
  --verm-wash: rgba(239, 81, 48, 0.14);
  --moss:      #3f6b3a;
  --moss-wash: rgba(63, 107, 58, 0.16);

  --display: "Bricolage Grotesque", Georgia, serif;
  --text:    "Hanken Grotesk", system-ui, sans-serif;

  --radius: 4px;
  --shadow: 6px 8px 0 rgba(28, 25, 22, 0.16);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--paper);
  color: var(--ink);
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* Respect the iPhone notch / home indicator when installed full-screen */
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Paper grain — a faint noise wash over the whole page for a printed feel */
.grain {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.5;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/%3E%3C/svg%3E");
}

.sheet {
  max-width: 1080px;
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2.5rem) clamp(1rem, 4vw, 2rem) 3rem;
}

/* ───────────────────────── Masthead ───────────────────────── */
.masthead { text-align: center; margin-bottom: clamp(1.25rem, 4vw, 2.5rem); }

.masthead-kicker {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 600;
}

.masthead-title {
  margin: 0.1em 0 0.05em;
  font-family: var(--display);
  font-weight: 800;
  font-size: clamp(3.4rem, 14vw, 7.5rem);
  line-height: 0.85;
  letter-spacing: -0.035em;
  /* The risograph "overprint" — two accents nudged out of register */
  text-shadow: 0.035em 0.028em 0 var(--vermilion),
               -0.026em -0.018em 0 var(--blue);
}

.masthead-date {
  margin: 0.2em 0 0;
  font-family: var(--display);
  font-style: italic;
  font-size: clamp(0.95rem, 2.4vw, 1.15rem);
  color: var(--ink-soft);
}

.masthead-rule {
  height: 0;
  margin: 1rem auto 0;
  max-width: 640px;
  border-top: 3px solid var(--ink);
  border-bottom: 1px solid var(--ink);
  padding-bottom: 4px;
}

/* ───────────────────────── Layout ───────────────────────── */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: start;
}

.board-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }

/* ───────────────────────── Heads-up display ───────────────────────── */
.hud {
  display: flex;
  gap: 0.6rem;
  width: min(92vw, 540px);
  margin-bottom: 1rem;
}

.hud-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 0.4rem;
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
}

.hud-label {
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.hud-value {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.hud.is-play .hud-difficulty .hud-value { color: var(--blue); }

/* ───────────────────────── The board ───────────────────────── */
.board-frame {
  position: relative;
  padding: 6px;
  background: var(--ink);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.board {
  --size: 9;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  aspect-ratio: 1 / 1;
  width: min(92vw, 528px);
  gap: 0;
  /* Must be OPAQUE: the semi-transparent cell tints (peer/selected/wrong)
     blend over this, and if it were see-through the dark frame behind would
     show through and turn every highlight near-black. Learnt that the hard way. */
  background: var(--paper-2);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  margin: 0;
  border: 1px solid var(--line);
  background: var(--paper-2);
  color: var(--blue);
  font-family: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: clamp(1rem, 5.4vw, 1.85rem);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s ease;
  overflow: hidden;
}

/* Thicker ink rules where the 3×3 boxes meet */
.cell.box-left  { border-left: 2.5px solid var(--ink); }
.cell.box-top   { border-top: 2.5px solid var(--ink); }

.cell .value { line-height: 1; pointer-events: none; }

/* Given clues: printed in solid ink and bold, so they read as "the question" */
.cell.given { color: var(--ink); font-weight: 800; background: var(--paper-3); }

/* Soft highlight of the selected cell's row, column and box */
.cell.peer { background: rgba(28, 25, 22, 0.055); }

/* Every cell sharing the selected number gets a quiet ring */
.cell.same { box-shadow: inset 0 0 0 2px rgba(47, 73, 216, 0.32); }

/* The selected cell itself */
.cell.selected {
  background: var(--blue-wash);
  box-shadow: inset 0 0 0 2.5px var(--blue);
}

/* A duff entry in play mode */
.cell.wrong { color: var(--vermilion); background: var(--verm-wash); }
.cell.selected.wrong { box-shadow: inset 0 0 0 2.5px var(--vermilion); }

/* Hint flash */
.cell.hinted { animation: pop 0.9s ease; }
@keyframes pop {
  0%   { background: var(--moss-wash); }
  100% { background: var(--paper-2); }
}

/* Visual-solver theatrics */
.cell.try       { animation: tryflash 0.4s ease; }
.cell.backtrack { animation: backflash 0.4s ease; }
@keyframes tryflash  { 0% { background: var(--moss-wash); } 100% { background: var(--paper-2); } }
@keyframes backflash { 0% { background: var(--verm-wash); } 100% { background: var(--paper-2); } }

/* Pencil notes: a little sub-grid of faint candidates */
.cell .notes {
  position: absolute;
  inset: 8%;
  display: grid;
  grid-template-columns: repeat(var(--sub, 3), 1fr);
  grid-template-rows: repeat(var(--sub, 3), 1fr);
  pointer-events: none;
}
.cell .note {
  display: grid;
  place-items: center;
  font-size: 0.5em;
  font-weight: 600;
  color: var(--ink-soft);
  line-height: 1;
}

/* Deal / busy overlay */
.deal-status {
  position: absolute;
  inset: 6px;
  display: none;
  place-items: center;
  text-align: center;
  padding: 1rem;
  font-family: var(--display);
  font-size: 1.2rem;
  color: var(--ink);
  background: rgba(239, 230, 212, 0.92);
  border-radius: 4px;
}
.deal-status.show { display: grid; }

/* ───────────────────────── Number pad ───────────────────────── */
.pad-row {
  display: flex;
  gap: 0.7rem;
  width: min(92vw, 540px);
  margin-top: 1rem;
  align-items: stretch;
}

.pad {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.pad-key {
  position: relative;
  aspect-ratio: 3 / 2;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 2px 3px 0 rgba(28, 25, 22, 0.18);
  font-family: var(--display);
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.1s ease;
}
.pad-key .pad-num { font-size: 1.7rem; line-height: 1; }
.pad-key .pad-left {
  position: absolute;
  top: 4px;
  right: 7px;
  font-family: var(--text);
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.pad-key:hover { background: var(--paper-3); }
.pad-key:active { transform: translate(2px, 3px); box-shadow: 0 0 0 rgba(0,0,0,0); }
.pad-key.done { opacity: 0.38; }

.pad-side { display: flex; flex-direction: column; gap: 0.5rem; width: 5.2rem; }
.pad-side .tool { flex: 1; }

/* ───────────────────────── Buttons (tools & difficulty) ───────────────────────── */
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.7rem 0.5rem;
  background: var(--paper-2);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 2px 3px 0 rgba(28, 25, 22, 0.18);
  color: var(--ink);
  font-family: var(--text);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.12s ease, color 0.12s ease;
}
.tool .tool-glyph { font-size: 1.1rem; line-height: 1; }
.tool:hover { background: var(--ink); color: var(--paper); }
.tool:active { transform: translate(2px, 3px); box-shadow: none; }

.tool-toggle.active {
  background: var(--blue);
  color: var(--paper-3);
  border-color: var(--blue);
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}
.tool.wide { flex-direction: row; gap: 0.5rem; }

/* ───────────────────────── Controls column ───────────────────────── */
.controls { display: flex; flex-direction: column; gap: 1.25rem; }

.panel {
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 1.1rem 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}

.panel-title {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.01em;
}

.panel-note {
  margin: 0 0 0.9rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.4;
}

.difficulty-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

.diff {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  padding: 0.85rem 0.9rem;
  background: var(--paper-3);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 2px 3px 0 rgba(28, 25, 22, 0.18);
  cursor: pointer;
  text-align: left;
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.12s ease, color 0.12s ease;
}
.diff-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.15rem;
}
.diff-sub { font-size: 0.72rem; color: var(--ink-soft); }
.diff:hover { background: var(--ink); color: var(--paper); }
.diff:hover .diff-sub { color: rgba(239, 230, 212, 0.7); }
.diff:active { transform: translate(2px, 3px); box-shadow: none; }

/* Accent the two ends of the difficulty range */
.diff[data-new-game="gentle"]:hover   { background: var(--moss); border-color: var(--moss); }
.diff[data-new-game="fiendish"]:hover  { background: var(--vermilion); border-color: var(--vermilion); }

/* ───────────────────────── Studio / settings ───────────────────────── */
.studio-panel summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.studio-panel summary::-webkit-details-marker { display: none; }
.studio-panel summary::before {
  content: "+";
  font-family: var(--display);
  font-size: 1.3rem;
  line-height: 1;
}
.studio-panel[open] summary::before { content: "–"; }
.studio-panel[open] summary { margin-bottom: 0.7rem; }

.field { margin-bottom: 0.85rem; }
.field label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.3rem;
}
.field-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.field-inline label { margin-bottom: 0; }

select, input[type="range"] {
  width: 100%;
  font-family: var(--text);
}
select {
  padding: 0.5rem 0.6rem;
  background: var(--paper-3);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.85rem;
}

/* Range slider, inked */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--line-2);
  border-radius: 2px;
  margin: 0.6rem 0;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--paper);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid var(--paper);
  cursor: pointer;
}

/* Checkbox styled as a little ink switch */
.switch {
  -webkit-appearance: none;
  appearance: none;
  width: 44px; height: 24px;
  background: var(--line-2);
  border-radius: 12px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s ease;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--paper-3);
  transition: transform 0.15s ease;
}
.switch:checked { background: var(--blue); }
.switch:checked::after { transform: translateX(20px); }

/* ───────────────────────── Colophon ───────────────────────── */
.colophon {
  margin-top: 2.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.72rem;
  color: var(--ink-soft);
}
.colophon a { color: var(--blue); text-decoration: none; }
.colophon a:hover { text-decoration: underline; }

/* ───────────────────────── Win overlay ───────────────────────── */
.win-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  place-items: center;
  padding: 1.5rem;
  background: rgba(239, 230, 212, 0.86);
  backdrop-filter: blur(3px);
}
.win-overlay.show { display: grid; animation: fade 0.3s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.win-card {
  position: relative;
  max-width: 380px;
  width: 100%;
  text-align: center;
  background: var(--paper-3);
  border: 2.5px solid var(--ink);
  border-radius: 8px;
  padding: 2.5rem 2rem 2rem;
  box-shadow: 10px 12px 0 rgba(28, 25, 22, 0.2);
}

.win-stamp {
  position: absolute;
  top: -1.1rem;
  right: 1.2rem;
  margin: 0;
  font-family: var(--display);
  font-weight: 800;
  font-size: 1.6rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--vermilion);
  border: 3px solid var(--vermilion);
  padding: 0.1rem 0.7rem;
  border-radius: 4px;
  transform: rotate(-8deg);
  background: var(--paper-3);
}

.win-title {
  margin: 0.5rem 0 1.4rem;
  font-family: var(--display);
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.02em;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 1.6rem;
  margin: 0 0 1.6rem;
}
.win-stats dt {
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}
.win-stats dd {
  margin: 0.2rem 0 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.4rem;
  font-variant-numeric: tabular-nums;
}

.win-actions { display: flex; gap: 0.7rem; justify-content: center; }
.win-actions .diff { align-items: center; text-align: center; }

/* ───────────────────────── Toasts ───────────────────────── */
.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(1.2rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  width: max-content;
  max-width: 90vw;
  pointer-events: none;
}
.toast {
  padding: 0.6rem 1.1rem;
  background: var(--ink);
  color: var(--paper-3);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--moss); }
.toast-danger  { background: var(--vermilion); }
.toast-warning { background: #b8860b; }
.toast-info    { background: var(--blue); }

/* ───────────────────────── Responsive ───────────────────────── */
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
  .controls { width: min(92vw, 540px); margin: 0 auto; }
  .masthead-title { text-shadow: 0.03em 0.024em 0 var(--vermilion), -0.022em -0.015em 0 var(--blue); }
}

@media (max-width: 420px) {
  .difficulty-grid { grid-template-columns: 1fr 1fr; }
  .hud-value { font-size: 1.15rem; }
  .pad-side { width: 4.4rem; }
}

/* Be kind to those who'd rather not have things flying about */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
