/* Sudoku - mobile first stylesheet */

/* ---------- theme ---------- */
:root {
  color-scheme: light dark;
  --bg: #efeded;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --line: #cbd5e1;
  --line-strong: #475569;
  --accent: #00933b;
  --accent-ink: #ffffff;
  --accent-soft: #d3ffd7;
  --given: #0f172a;
  --user: #08692f;
  --hint: #0f766e;
  --error: #dc2626;
  --error-soft: #fee2e2;
  --selected: #00933b; /* dark fill so the white digit clears 4.5:1 */
  --selected-ink: #ffffff; /* digit + notes colour inside the selected cell */
  --peer: #dff1e9;
  --same: #cbe9d1;
  --overlay: rgba(15, 23, 42, 0.45);
  --overlay-solid: rgba(238, 242, 247, 0.97);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 14px;
  /* credit strip stays dark grey in both colour schemes */
  --strip-bg: #33383d;
  --strip-ink: #ffffff;
  --strip-accent: #7ee2a8;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #111c2e;
    --surface-2: #16233a;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #24324a;
    --line-strong: #64748b;
    --accent: #3b82f6;
    --accent-ink: #f8fafc;
    --accent-soft: #1e3a5f;
    --given: #f8fafc;
    --user: #7dd3fc;
    --hint: #2dd4bf;
    --error: #f87171;
    --error-soft: #3f1d1d;
    --selected: #1d4ed8;
    --selected-ink: #ffffff;
    --peer: #182741;
    --same: #16324f;
    --overlay: rgba(2, 6, 23, 0.6);
    --overlay-solid: rgba(11, 18, 32, 0.97);
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

/* ---------- reset / base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- layout ---------- */
.app {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 12px 16px;
  display: flex;
  flex: 1 0 auto;
  flex-direction: column;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar__title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.levels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 4px;
  font-size: 14px;
  font-weight: 600;
  min-height: 44px;
}

.chip.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  box-shadow: var(--shadow);
}

.stat__label {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat__value {
  font-size: 17px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- board ---------- */
.board-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  aspect-ratio: 1 / 1;
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  overflow: hidden;
  container-type: inline-size;
  box-shadow: var(--shadow);
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  color: var(--user);
  font-size: clamp(15px, 4.6vw, 26px);
  font-weight: 700;
  line-height: 1;
  transition: background-color 0.12s ease;
}

/* Container units keep the digits in scale with the board itself. */
@supports (font-size: 1cqw) {
  .cell {
    font-size: clamp(15px, 5.4cqw, 26px);
  }
}

/* thin grid lines, thick 3x3 separators */
.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-child(n + 73) {
  border-bottom: 0;
}

.cell:nth-child(9n + 3),
.cell:nth-child(9n + 6) {
  border-right: 2px solid var(--line-strong);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 2px solid var(--line-strong);
}

/* cell states (later rules win) */
.cell.is-peer {
  background: var(--peer);
}

.cell.is-same {
  background: var(--same);
  border-radius: 6px;
}

.cell.is-given {
  color: var(--given);
  font-weight: 700;
}

.cell.is-hinted {
  color: var(--hint);
}

.cell.is-error {
  color: var(--error);
  background: var(--error-soft);
}

.cell.is-selected {
  background: var(--selected);
  box-shadow: inset 0 0 0 5px var(--accent);
  border-radius: 6px;
  color: var(--selected-ink);
}

/* a wrong digit keeps a legible red treatment while the cell is selected */
.cell.is-selected.is-error {
  background: var(--error-soft);
  color: var(--error);
}

/* pencil marks follow the selected cell ink instead of the muted grey */
.cell.is-selected .cell__notes {
  color: var(--selected-ink);
}

.cell__value {
  position: relative;
  z-index: 1;
}

/* pencil notes: 3x3 mini grid inside the cell */
.cell__notes {
  position: absolute;
  inset: 6%;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  font-size: clamp(7px, 1.6vw, 10px);
  font-weight: 600;
  line-height: 1;
  color: var(--muted);
  pointer-events: none;
}

@supports (font-size: 1cqw) {
  .cell__notes {
    font-size: clamp(7px, 1.9cqw, 11px);
  }
}

.cell__note {
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
}

.cell__note.is-on {
  visibility: visible;
}

/* ---------- overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--overlay);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

.overlay[hidden] {
  display: none;
}

.overlay.is-solid {
  background: var(--overlay-solid);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.overlay__card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: min(100%, 300px);
  padding: 20px 18px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.overlay__title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
}

.overlay__text {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.fallback {
  margin: 12px 0 0;
  color: var(--muted);
  text-align: center;
}

/* ---------- controls ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.action {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  min-height: 50px;
  padding: 8px 2px;
  font-size: 12px;
  font-weight: 700;
}

.action:disabled {
  opacity: 0.4;
  cursor: default;
}

.action.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.pad__key {
  position: relative;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--user);
  border-radius: 12px;
  min-height: 54px;
  padding: 6px 0;
  font-size: 22px;
  font-weight: 700;
}

.pad__key.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.pad__key.is-exhausted {
  color: var(--muted);
  opacity: 0.45;
}

.pad__count {
  position: absolute;
  right: 8px;
  bottom: 6px;
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
}

/* ---------- powered by strip ---------- */
.powered {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--strip-bg);
  color: var(--strip-ink);
}

.powered__logo {
  display: block;
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  /* the mark is wide (369x215) - contain instead of stretching it */
  object-fit: contain;
}

.powered__note {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.powered__link {
  color: var(--strip-ink);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.powered__link:hover,
.powered__link:focus-visible {
  color: var(--strip-accent);
}

/* ---------- wider screens ---------- */
@media (min-width: 560px) {
  .pad {
    grid-template-columns: repeat(9, 1fr);
  }

  .pad__key {
    min-height: 50px;
  }

  .cell__notes {
    inset: 8%;
  }
}

@media (min-width: 900px) {
  .app {
    padding-top: 24px;
  }

  .topbar__title {
    font-size: 28px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}


