:root {
  --page: #f6e8d5;
  --surface: #fff8ee;
  --surface-strong: #ffffff;
  --ink: #243447;
  --muted: #6d5c4f;
  --border: #b9855a;
  --button: #795235;
  --button-text: #fff8ee;
  --accent: #2f7f6f;
  --accent-soft: #d8efe9;
  --error: #c8453d;
  --fixed: #1f2933;
  --editable: #455a64;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Open Sans", "Segoe UI", Arial, sans-serif;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--button);
  color: var(--button-text);
  min-height: 44px;
  min-width: 44px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
}

button:disabled {
  cursor: not-allowed;
  opacity: .4;
}

.game-shell {
  min-height: 100vh;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 8px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto auto;
  gap: 6px;
}

.top-info {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 2px 8px;
}

.score,
.mistakes {
  font-size: 18px;
}

.score,
.timer,
.combo {
  font-weight: 800;
}

.timer-wrap {
  text-align: center;
}

.timer-caption {
  color: var(--muted);
  font-size: 11px;
}

.timer {
  font-size: 22px;
}

.mistakes {
  text-align: right;
}

.status {
  grid-column: 1 / -1;
  min-height: 21px;
  color: var(--muted);
  font-size: 14px;
}

.top-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.board-area {
  min-height: 0;
  display: grid;
  place-items: start center;
  position: relative;
}

.board {
  width: min(100%, calc(100vh - 285px), 620px);
  min-width: 300px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  background: var(--surface-strong);
  border: 2px solid var(--ink);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 14px 26px rgba(36, 52, 71, .14);
}

.cell {
  appearance: none;
  border-radius: 0;
  border-right: 1px solid #d6cabd;
  border-bottom: 1px solid #d6cabd;
  background: #fff;
  color: var(--editable);
  min-width: 0;
  min-height: 0;
  padding: 0;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  font-size: clamp(19px, 6.4vw, 24px);
  font-weight: 800;
}

.cell > * {
  position: relative;
  z-index: 1;
}

.cell-value {
  display: grid;
  place-items: center;
}

.cell:nth-child(3n) {
  border-right-width: 2px;
  border-right-color: var(--ink);
}

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom-width: 2px;
  border-bottom-color: var(--ink);
}

.cell:nth-child(9n) {
  border-right: 0;
}

.cell:nth-child(n + 73) {
  border-bottom: 0;
}

.cell.fixed {
  color: var(--fixed);
  background: #f8f4ee;
}

.cell.selected {
  background: var(--accent-soft);
  outline: 3px solid var(--accent);
  outline-offset: -3px;
  z-index: 2;
}

.cell.related {
  background: #f4efe7;
}

.cell.value-related {
  background: #f8dfb8;
}

.cell.same-value {
  background: #e5a13b;
  color: #6b3d05;
  font-size: clamp(21px, 7vw, 27px);
}

.cell.error {
  color: var(--error);
  background: #fde5e1;
}

.cell.hinted {
  color: #9a6700;
}

.cell.hinted::after {
  content: "";
  position: absolute;
  width: min(74%, 44px);
  height: min(74%, 44px);
  border: 2px solid #d97706;
  border-radius: 999px;
  background: rgba(255, 240, 186, .86);
  z-index: 0;
}

.notes {
  width: 100%;
  height: 100%;
  padding: 2px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  color: #7a6a5f;
  font-size: clamp(7px, 1.8vmin, 12px);
  font-weight: 700;
  line-height: 1;
}

.note {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.keypad {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 6px;
}

.keypad button {
  padding: 8px 2px;
  font-size: 20px;
}

.keypad button[hidden] {
  display: none;
}

.bottom-actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  align-items: center;
  justify-items: center;
}

.icon-action {
  width: 72px;
  height: 72px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
  display: grid;
  place-items: center;
}

.icon-action.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 3px var(--accent);
}

.pencil,
.eraser {
  position: relative;
  width: 46px;
  height: 46px;
  display: block;
}

.pencil::before {
  content: "";
  position: absolute;
  left: 18px;
  top: 2px;
  width: 12px;
  height: 42px;
  border-radius: 4px;
  background: linear-gradient(#f0c35a 0 70%, #39424e 70% 82%, #f4d7b5 82%);
  transform: rotate(42deg);
  box-shadow: 0 0 0 2px rgba(36, 52, 71, .18);
}

.eraser::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 16px;
  width: 34px;
  height: 18px;
  border-radius: 5px;
  background: linear-gradient(90deg, #f07f9f 0 55%, #f3d7b7 55%);
  transform: rotate(-18deg);
  box-shadow: 0 0 0 2px rgba(36, 52, 71, .2);
}

.combo {
  min-height: 24px;
  text-align: center;
  font-size: 16px;
}

.paused-overlay,
.game-over {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(246, 232, 213, .94);
  z-index: 5;
}

.paused-overlay[hidden],
.game-over[hidden] {
  display: none;
}

.paused-card,
.game-over-card {
  width: min(88%, 320px);
  padding: 20px 18px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
  box-shadow: 0 14px 26px rgba(36, 52, 71, .12);
}

.paused-card h1,
.game-over-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.paused-card p,
.game-over-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 15px;
}

@media (max-width: 460px) {
  .game-shell {
    padding: 8px 6px;
  }

  .score,
  .mistakes {
    font-size: 16px;
  }

  .timer {
    font-size: 20px;
  }

  .board {
    width: min(100%, calc(100vh - 275px));
    min-width: 0;
  }
}
