/* Sudoku Maestro - Readingg Games
   Portrait-first layout. All colors resolve from shared tokens. */

[hidden] {
  display: none !important;
}

:root {
  --sd-shell: 480px;
  --sd-board-max: 460px;
  --sd-frame: #3b4562;
  --sd-line: rgba(255, 255, 255, 0.065);
  --sd-line-strong: #4a5474;
  --sd-cell: #141826;
  --sd-alt: rgba(120, 150, 255, 0.045);
  --sd-given: #eef2ff;
  --sd-user: #9db2ff;
  --sd-peer: rgba(76, 109, 240, 0.12);
  --sd-same: rgba(253, 57, 161, 0.16);
  --sd-selected: rgba(76, 109, 240, 0.3);
  --sd-hover: rgba(255, 255, 255, 0.04);
  --sd-wrong-bg: rgba(248, 113, 113, 0.16);
  --sd-danger: #ff9d9d;
  --sd-success: #6ee7b7;
  --sd-accent-text: #ff8fc4;
  --sd-focus: #fcce90;
  --sd-glow-1: rgba(76, 109, 240, 0.45);
  --sd-glow-2: rgba(253, 57, 161, 0.3);
  --sd-board-shadow: 0 22px 48px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  --sd-key-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

[data-theme="light"] {
  --sd-frame: #a9b4ce;
  --sd-line: rgba(21, 24, 33, 0.1);
  --sd-line-strong: #7d8aab;
  --sd-cell: #ffffff;
  --sd-alt: rgba(76, 109, 240, 0.05);
  --sd-given: #12151f;
  --sd-user: #2b49c9;
  --sd-peer: rgba(76, 109, 240, 0.12);
  --sd-same: rgba(253, 57, 161, 0.13);
  --sd-selected: rgba(76, 109, 240, 0.24);
  --sd-hover: rgba(76, 109, 240, 0.07);
  --sd-wrong-bg: rgba(179, 38, 30, 0.11);
  --sd-danger: #b3261e;
  --sd-success: #0b6b4a;
  --sd-accent-text: #b5177c;
  --sd-focus: #8a4b00;
  --sd-glow-1: rgba(76, 109, 240, 0.3);
  --sd-glow-2: rgba(253, 57, 161, 0.18);
  --sd-board-shadow: 0 18px 40px rgba(21, 24, 33, 0.14), inset 0 1px 0 #ffffff;
  --sd-key-shadow: inset 0 1px 0 #ffffff;
}

.sudoku {
  gap: 10px;
  background:
    radial-gradient(90% 42% at 50% -8%, rgba(76, 109, 240, 0.17), transparent 70%),
    radial-gradient(60% 30% at 100% 26%, rgba(253, 57, 161, 0.08), transparent 72%);
  background-repeat: no-repeat;
}

[data-theme="light"] .sudoku {
  background:
    radial-gradient(90% 42% at 50% -8%, rgba(76, 109, 240, 0.12), transparent 70%),
    radial-gradient(60% 30% at 100% 26%, rgba(253, 57, 161, 0.07), transparent 72%);
  background-repeat: no-repeat;
}

.sudoku-header,
.sudoku-levels,
.sudoku-hud,
.sudoku-board-wrap,
.sudoku-pad,
.sudoku-status {
  width: 100%;
  max-width: var(--sd-shell);
  margin-inline: auto;
}

/* Header ------------------------------------------------------------------ */

.sudoku-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 52px;
}

.sudoku-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.sudoku-mark {
  flex: none;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 13px;
  background: linear-gradient(145deg, #5b76ff 0%, #8a4dff 52%, #fd39a1 100%);
  color: #ffffff;
  box-shadow: 0 8px 22px rgba(76, 109, 240, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.sudoku-mark svg {
  width: 24px;
  height: 24px;
}

.sudoku-brand-text {
  min-width: 0;
}

.sudoku-eyebrow {
  margin: 0 0 2px;
  color: var(--rg-muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.16em;
  line-height: 1.2;
  text-transform: uppercase;
  white-space: nowrap;
}

.sudoku .rg-title {
  font-size: 19px;
  line-height: 1.1;
  white-space: nowrap;
}

.sudoku-new {
  flex: none;
  min-height: 48px;
  padding: 0 12px;
  gap: 6px;
  border-radius: 13px;
  font-size: 12.5px;
  letter-spacing: -0.01em;
}

.sudoku-new svg {
  flex: none;
}

/* Difficulty -------------------------------------------------------------- */

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

.level-chip {
  width: 100%;
  min-height: 48px;
  gap: 6px;
  border-radius: 13px;
  font-size: 13px;
}

.level-chip[aria-pressed="true"] {
  border-color: transparent;
  background: linear-gradient(135deg, #3f5ee0, #7a3fd0);
  box-shadow: 0 6px 18px rgba(76, 109, 240, 0.32);
}

.level-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
}

.level-dot--easy {
  background: #34d399;
}

.level-dot--medium {
  background: #fcce90;
}

.level-dot--hard {
  background: #fd39a1;
}

/* HUD --------------------------------------------------------------------- */

.sudoku-hud {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: center;
  gap: 6px;
  min-height: 48px;
  padding: 7px 12px;
  border: 1px solid var(--rg-border);
  border-radius: 14px;
  background: var(--rg-surface);
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-width: 0;
}

.hud-label {
  color: var(--rg-muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.hud-item strong {
  font-size: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

#errorCount.is-alert {
  color: var(--sd-danger);
}

.hud-divider {
  width: 1px;
  height: 22px;
  background: var(--rg-border);
}

/* Board ------------------------------------------------------------------- */

.sudoku-board-wrap {
  position: relative;
  display: flex;
  justify-content: center;
  isolation: isolate;
}

.sudoku-board-wrap::before {
  content: "";
  position: absolute;
  inset: 8% 6%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, var(--sd-glow-1), transparent 68%);
  filter: blur(26px);
  opacity: 0.5;
  pointer-events: none;
}

.sudoku-board {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  width: min(100%, var(--sd-board-max), calc(100vh - 344px - var(--rg-safe-top) - var(--rg-safe-bottom)));
  width: min(100%, var(--sd-board-max), calc(100dvh - 344px - var(--rg-safe-top) - var(--rg-safe-bottom)));
  min-width: 252px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border: 2px solid var(--sd-frame);
  border-radius: 16px;
  overflow: hidden;
  background: var(--sd-cell);
  box-shadow: var(--sd-board-shadow);
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-right: 1px solid var(--sd-line);
  border-bottom: 1px solid var(--sd-line);
  border-radius: 0;
  background: transparent;
  color: var(--sd-given);
  font-size: clamp(15px, 4.7vw, 24px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.12s ease, color 0.12s ease;
}

.cell.box-alt {
  background: var(--sd-alt);
}

.cell.box-right {
  border-right: 2px solid var(--sd-line-strong);
}

.cell.box-bottom {
  border-bottom: 2px solid var(--sd-line-strong);
}

.cell.col-end {
  border-right: 0;
}

.cell.row-end {
  border-bottom: 0;
}

.cell.is-peer {
  background: var(--sd-peer);
}

.cell.is-same {
  background: var(--sd-same);
}

.cell.is-selected {
  z-index: 1;
  background: var(--sd-selected);
  box-shadow: inset 0 0 0 2px var(--rg-primary);
}

.cell.is-given {
  color: var(--sd-given);
  font-weight: 800;
}

.cell.is-user {
  color: var(--sd-user);
  font-weight: 600;
}

.cell.is-wrong {
  color: var(--sd-danger);
  background: var(--sd-wrong-bg);
}

.cell.is-wrong.is-selected {
  box-shadow: inset 0 0 0 2px var(--sd-danger);
}

.cell.is-selected .cell-value {
  font-weight: 700;
}

.cell:focus-visible {
  z-index: 2;
  outline: 2px solid var(--sd-focus);
  outline-offset: -2px;
}

.cell-value {
  display: block;
  padding-bottom: 1px;
  will-change: transform;
}

/* Numpad ------------------------------------------------------------------ */

.sudoku-pad {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  max-width: var(--sd-board-max);
}

.pad-key {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0;
  border: 1px solid var(--rg-border);
  border-radius: 14px;
  background: linear-gradient(180deg, var(--rg-surface-2), var(--rg-surface));
  color: var(--rg-text);
  box-shadow: var(--sd-key-shadow);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s ease, border-color 0.14s ease, background-color 0.14s ease;
}

.pad-key .key-num {
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.pad-key .key-count {
  position: absolute;
  top: 5px;
  right: 7px;
  color: var(--rg-muted);
  font-size: 9px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  opacity: 0.85;
}

.pad-key.is-active {
  border-color: var(--rg-accent);
  background: var(--sd-same);
  color: var(--sd-accent-text);
  box-shadow: inset 0 0 0 1px var(--rg-accent), 0 0 16px rgba(253, 57, 161, 0.22);
}

.pad-key.is-complete {
  border-color: var(--rg-border);
  opacity: 0.55;
}

.pad-key.is-complete .key-count {
  color: var(--sd-danger);
  opacity: 1;
}

.pad-key:active {
  transform: scale(0.96);
}

.pad-key:focus-visible {
  outline: 2px solid var(--sd-focus);
  outline-offset: 2px;
}

.pad-key--erase {
  gap: 2px;
  flex-direction: column;
  color: var(--sd-danger);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.pad-key--erase svg {
  width: 19px;
  height: 19px;
}

/* Status ------------------------------------------------------------------ */

.sudoku-status {
  min-height: 16px;
  margin: 0;
  color: var(--rg-muted);
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
}

.sudoku-status.is-error {
  color: var(--sd-danger);
}

.sudoku-status.is-ok {
  color: var(--sd-success);
}

/* Transient feedback ------------------------------------------------------ */

@keyframes sd-pop {
  0% {
    transform: scale(0.55);
    opacity: 0.35;
  }
  60% {
    transform: scale(1.08);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

@keyframes sd-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(3px);
  }
}

@keyframes sd-bump {
  0%,
  100% {
    transform: translateX(0);
  }
  30% {
    transform: translateX(-2px);
  }
  70% {
    transform: translateX(2px);
  }
}

.cell-value.is-pop {
  animation: sd-pop 0.22s ease-out;
}

.cell-value.is-shake {
  animation: sd-shake 0.24s ease-in-out;
}

.cell.is-blocked {
  animation: sd-bump 0.2s ease-in-out;
}

/* Victory overlay --------------------------------------------------------- */

.sudoku-win .rg-modal {
  width: min(100%, 340px);
}

.win-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 26%, #7c9bff, var(--rg-primary) 58%, #3f5ee0);
  color: #ffffff;
  box-shadow: 0 0 0 8px rgba(76, 109, 240, 0.12), 0 14px 30px rgba(76, 109, 240, 0.4);
}

.win-mark svg {
  width: 30px;
  height: 30px;
}

.sudoku-win .rg-modal h2 {
  font-size: 21px;
}

.win-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 18px;
  padding: 10px 0;
  border-top: 1px solid var(--rg-border);
  border-bottom: 1px solid var(--rg-border);
}

.win-stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.win-stats span {
  color: var(--rg-muted);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.win-stats strong {
  font-size: 15px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.sudoku-win:not([hidden]) .rg-modal {
  animation: sd-win-in 0.28s cubic-bezier(0.2, 0.8, 0.3, 1);
}

@keyframes sd-win-in {
  0% {
    transform: translateY(12px) scale(0.97);
    opacity: 0;
  }
  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Pointer refinements ----------------------------------------------------- */

@media (hover: hover) and (pointer: fine) {
  .cell:hover {
    background: var(--sd-hover);
  }

  .cell.is-peer:hover {
    background: color-mix(in srgb, var(--sd-peer) 60%, var(--sd-hover));
  }

  .cell.is-selected:hover {
    background: var(--sd-selected);
  }

  .pad-key:not(.is-complete):hover {
    border-color: var(--rg-primary);
  }

  .rg-btn:hover {
    border-color: var(--rg-primary);
  }

  .sudoku-new:hover {
    background: var(--rg-surface-2);
  }

  .level-chip[aria-pressed="false"]:hover {
    border-color: var(--rg-primary);
    color: var(--rg-text);
  }
}

/* Global focus ring ------------------------------------------------------- */

.sudoku-new:focus-visible,
.level-chip:focus-visible {
  outline: 2px solid var(--sd-focus);
  outline-offset: 2px;
}

.sudoku-win .rg-btn:focus-visible {
  outline: 2px solid var(--sd-focus);
  outline-offset: 2px;
}

/* Small phones ------------------------------------------------------------ */

@media (max-width: 379px) {
  .sudoku {
    gap: 8px;
  }

  .sudoku-eyebrow {
    display: none;
  }

  .sudoku-mark {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }

  .sudoku-mark svg {
    width: 21px;
    height: 21px;
  }

  .sudoku .rg-title {
    font-size: 16.5px;
  }

  .sudoku-new {
    padding: 0 10px;
    font-size: 11.5px;
  }

  .sudoku-new svg {
    width: 13px;
    height: 13px;
  }

  .level-chip {
    font-size: 12px;
  }

  .hud-label {
    font-size: 8px;
    letter-spacing: 0.1em;
  }

  .hud-item strong {
    font-size: 15px;
  }
}

@media (max-height: 680px) {
  .sudoku {
    gap: 8px;
  }

  .sudoku-eyebrow {
    display: none;
  }

  .sudoku-header {
    min-height: 48px;
  }

  .sudoku-mark {
    width: 38px;
    height: 38px;
  }

  .sudoku-mark svg {
    width: 21px;
    height: 21px;
  }

  .sudoku-hud {
    padding: 5px 10px;
  }

  .sudoku-status {
    min-height: 14px;
    font-size: 11px;
  }
}
