/* ===== Sudoku game ===== */
:root {
  --board-max: 560px;
  --panel-max: 340px;
  --layout-gap: 32px;
}

.sudoku {
  --cell-line: #CDBFA6;
  --box-line: var(--wood-dark);
  --user-digit: var(--felt);
  padding-block: 8px 24px;
}

/* ----- Page header ----- */
.game-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  max-width: calc(var(--board-max) + 2 * var(--gutter));
  padding-top: 8px;
}

/* Repeats the game's columns so the level switch is as wide as the panel. */
@media (min-width: 900px) {
  .game-header {
    display: grid;
    grid-template-columns: minmax(0, var(--board-max)) minmax(280px, var(--panel-max));
    justify-content: center;
    column-gap: var(--layout-gap);
    max-width: calc(var(--board-max) + var(--layout-gap) + var(--panel-max) + 2 * var(--gutter));
  }

  .daily-date {
    justify-self: end;
  }
}

/* Smaller than the site h1 so the title and the switch fit on one line. */
.game-header h1 {
  margin: 0;
  font-size: clamp(2rem, 1.5rem + 1.6vw, 2.375rem);
}

.daily-date {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--accent-dark);
}

/* ----- Level switch ----- */
.levels {
  flex: 1 1 100%;
}

.levels ul {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--wall-deep);
  border-radius: 12px;
}

.levels a {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 4px;
  border-radius: 9px;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

@media (min-width: 600px) {
  .levels {
    flex: none;
  }

  .levels ul {
    display: flex;
  }

  .levels a {
    padding: 0 16px;
  }
}

@media (min-width: 900px) {
  .levels ul {
    display: grid;
  }

  .levels a {
    padding: 0 4px;
  }
}

.levels a:hover {
  background: var(--paper);
  color: var(--text);
}

.levels a[aria-current="page"] {
  background: var(--accent);
  color: #FFFFFF;
}

.streak {
  max-width: var(--board-max);
  margin: 0 auto 14px;
  padding: 10px 16px;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 12px;
  font-weight: 700;
  text-align: center;
}

@media (min-width: 900px) {
  .streak {
    max-width: calc(var(--board-max) + var(--layout-gap) + var(--panel-max));
  }
}

/* ----- Layout ----- */
.sudoku__layout {
  display: grid;
  gap: 20px;
  justify-content: center;
  grid-template-columns: minmax(0, var(--board-max));
}

@media (min-width: 900px) {
  .sudoku__layout {
    grid-template-columns: minmax(0, var(--board-max)) minmax(280px, var(--panel-max));
    gap: var(--layout-gap);
    align-items: start;
  }

  .sudoku__panel {
    padding-top: 54px;
  }
}

.statusbar {
  display: flex;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 10px;
}

.statusbar__puzzle {
  flex: 1 1 auto;
  font-weight: 700;
  color: var(--text-muted);
}

.statusbar__timer {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ----- Board ----- */
.board-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: 100%;
  height: 100%;
  background: var(--paper);
  border: 3px solid var(--box-line);
  border-radius: 6px;
  overflow: hidden;
  container-type: inline-size;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.board__row {
  display: contents;
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  border-right: 1px solid var(--cell-line);
  border-bottom: 1px solid var(--cell-line);
  font-size: 1.5rem;
  font-size: clamp(1.1rem, 7.2cqi, 2.4rem);
  line-height: 1;
  cursor: pointer;
}

.board__row > .cell:nth-child(3n) {
  border-right: 3px solid var(--box-line);
}

.board__row > .cell:last-child {
  border-right: 0;
}

.board__row:nth-child(3n) > .cell {
  border-bottom: 3px solid var(--box-line);
}

.board__row:last-child > .cell {
  border-bottom: 0;
}

.cell:focus {
  outline: none;
}

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

.cell__value {
  color: var(--user-digit);
}

.cell.is-given .cell__value {
  color: var(--text);
  font-weight: 700;
}

.cell.is-hint::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  border-style: solid;
  border-width: 0 8px 8px 0;
  border-color: transparent var(--wood) transparent transparent;
}

.cell__notes {
  position: absolute;
  inset: 1px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  align-items: center;
  justify-items: center;
  font-size: clamp(0.56rem, 2.6cqi, 0.95rem);
  font-weight: 700;
  line-height: 1;
  color: var(--text-muted);
  pointer-events: none;
}

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

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

.cell.is-selected {
  background: var(--highlight-strong);
}

.cell.is-conflict:not(.is-selected) {
  background: var(--error-bg);
}

.cell.is-conflict .cell__value {
  color: var(--error);
  text-decoration: underline wavy;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.15em;
}

.board.is-hidden .cell > * {
  visibility: hidden;
}

.board.is-hidden .cell {
  background: var(--paper);
}

/* ----- Overlays: loader and pause ----- */
.board-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  background: rgb(255 253 248 / 0.94);
  border-radius: 6px;
  text-align: center;
}

.board-overlay--loading {
  animation: overlay-in 0.25s 0.1s both;
}

.board-overlay__text {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
}

.loader {
  display: grid;
  grid-template-columns: repeat(3, 18px);
  gap: 5px;
}

.loader span {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  background: var(--wood);
  animation: loader-pulse 1.8s ease-in-out infinite;
}

.loader span:nth-child(2),
.loader span:nth-child(4) {
  animation-delay: 0.2s;
}

.loader span:nth-child(3),
.loader span:nth-child(5),
.loader span:nth-child(7) {
  animation-delay: 0.4s;
}

.loader span:nth-child(6),
.loader span:nth-child(8) {
  animation-delay: 0.6s;
}

.loader span:nth-child(9) {
  animation-delay: 0.8s;
}

@keyframes loader-pulse {
  0%, 100% { opacity: 0.25; transform: scale(0.85); }
  50% { opacity: 1; transform: scale(1); }
}

@keyframes overlay-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .loader span {
    animation-duration: 3.6s;
  }
}

.sudoku:not(.is-ready) .board-overlay--loading {
  animation: none;
}

/* ----- Keypad and tools ----- */
.controls {
  display: grid;
  gap: 12px;
}

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

@media (min-width: 440px) and (max-width: 899px) {
  .keypad {
    grid-template-columns: repeat(9, minmax(0, 1fr));
    gap: 6px;
  }
}

@media (min-width: 900px) {
  .keypad {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 44px;
  min-height: 58px;
  padding: 4px 0;
  background: var(--paper);
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

@media (min-width: 900px) {
  .key {
    min-height: 68px;
  }
}

.key:hover:not(:disabled) {
  border-color: var(--wood);
  background: #FFF8EA;
}

.key:active:not(:disabled) {
  background: var(--highlight);
}

.key__digit {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.key__count {
  font-size: 0.8rem;
  line-height: 1;
  color: var(--text-muted);
}

.key:disabled {
  opacity: 0.35;
  cursor: default;
}

.is-notes-mode .key {
  border-style: dashed;
  border-color: var(--felt);
}

.is-notes-mode .key__digit {
  color: var(--felt);
  font-size: 1.35rem;
}

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

@media (min-width: 900px) {
  .tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 64px;
  padding: 6px 2px;
  background: var(--wall-deep);
  border: 2px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.15;
  cursor: pointer;
  touch-action: manipulation;
}

.tool svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tool:hover:not(:disabled) {
  border-color: var(--wood);
}

.tool:disabled {
  opacity: 0.45;
  cursor: default;
}

.tool[aria-pressed="true"] {
  background: var(--felt);
  color: var(--text-on-dark);
}

.tool__state {
  font-weight: 400;
}

@media (min-width: 900px) {
  .tool {
    flex-direction: row;
    gap: 8px;
    min-height: 52px;
  }
}

/* ----- Game actions and settings ----- */
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.game-actions .btn {
  flex: 1 1 auto;
}

.game-message {
  min-height: 1.6em;
  margin: 10px 0 4px;
  font-weight: 700;
  color: var(--felt);
}

.settings {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 20px;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  cursor: pointer;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.switch__track {
  position: relative;
  flex: none;
  width: 46px;
  height: 26px;
  border-radius: 13px;
  background: var(--line-strong);
  transition: background-color 0.15s;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #FFFFFF;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  transition: transform 0.15s;
}

.switch input:checked + .switch__track {
  background: var(--felt);
}

.switch input:checked + .switch__track::after {
  transform: translateX(20px);
}

.switch input:focus-visible + .switch__track {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.noscript {
  margin: 16px auto 0;
  max-width: 560px;
  padding: 12px 16px;
  background: var(--error-bg);
  border-radius: var(--radius);
}

/* ----- Win panel ----- */
.win {
  padding: 20px;
  background: var(--paper);
  border: 3px solid var(--felt);
  border-radius: 14px;
  box-shadow: var(--shadow-soft);
}

.win:focus {
  outline: none;
}

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

.win__title {
  margin: 0 0 8px;
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--felt);
}

.win__text,
.win__streak,
.win__countdown {
  margin: 0 0 8px;
  font-size: 1.15rem;
}

.win__streak,
.win__countdown {
  font-weight: 700;
}

.win__streak:empty {
  display: none;
}

.win__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.win__actions .btn {
  flex: 1 1 auto;
}

/* ----- Printing: only the clean grid with its caption ----- */
.print-sheet {
  display: none;
}

@media print {
  @page {
    margin: 14mm;
  }

  body {
    display: block;
    min-height: 0;
    background: #FFFFFF;
  }

  .skip-link,
  .site-header,
  .site-footer,
  main > :not(.sudoku),
  .sudoku > :not(.print-sheet) {
    display: none !important;
  }

  .sudoku {
    padding: 0;
  }

  .print-sheet {
    display: block;
    color: #000000;
  }

  .print-sheet__title {
    margin: 0 0 8mm;
    font-size: 16pt;
    font-weight: 700;
    text-align: center;
  }

  .print-grid {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    border: 2.5pt solid #000000;
  }

  .print-grid td {
    height: 19.5mm;
    border: 0.75pt solid #555555;
    font-size: 24pt;
    font-weight: 700;
    text-align: center;
    vertical-align: middle;
  }

  .print-grid td:nth-child(3n):not(:last-child) {
    border-right: 2.5pt solid #000000;
  }

  .print-grid tr:nth-child(3n):not(:last-child) td {
    border-bottom: 2.5pt solid #000000;
  }

  .print-sheet__footer {
    margin: 6mm 0 0;
    font-size: 10pt;
    text-align: center;
    color: #444444;
  }
}
