:root {
  color-scheme: light;
  --app-bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #111827;
  --muted: #667085;
  --line: #d7dde7;
  --line-strong: #8d99aa;
  --heavy: #172033;
  --accent: #175cd3;
  --accent-soft: #e7f0ff;
  --base: #d8ebff;
  --support: #ffe7ad;
  --elimination: #ffd4d4;
  --result: #cdeed7;
  --selected: #172033;
  --error: #d92d20;
  --shadow: 0 18px 48px rgb(17 24 39 / 12%);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgb(216 235 255 / 55%), transparent 34rem),
    linear-gradient(180deg, #f8fafc, var(--app-bg));
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.icon-sprite {
  display: none;
}

.app-menu {
  position: fixed;
  top: 28px;
  left: 28px;
  z-index: 20;
}

.app-menu details {
  position: relative;
}

.app-menu summary {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  box-shadow: 0 8px 22px rgb(17 24 39 / 8%);
}

.app-menu summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  top: 48px;
  left: 0;
  display: grid;
  width: 190px;
  gap: 8px;
  padding: 10px;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  background: rgb(255 255 255 / 96%);
  box-shadow: 0 18px 48px rgb(17 24 39 / 16%);
}

.menu-panel .icon-text-button {
  justify-content: start;
}

.view[hidden] {
  display: none;
}

[hidden] {
  display: none !important;
}

.start-view,
.reference-view {
  min-height: 100vh;
}

.start-view {
  padding: 32px;
}

.reference-view {
  padding: 82px 32px 32px;
}

.start-panel,
.reference-shell {
  max-width: 960px;
  margin: 0 auto;
}

.start-panel {
  display: grid;
  align-content: center;
  min-height: calc(100vh - 64px);
}

.start-panel h1,
.reference-shell h1,
.practice-controls h1 {
  margin: 0 0 18px;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.start-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 220px));
  gap: 10px;
}

.app {
  display: grid;
  grid-template-columns: minmax(320px, 650px) 316px;
  gap: 24px;
  align-items: start;
  max-width: 1060px;
  margin: 0 auto;
  padding: 82px 28px 28px;
}

.board-panel {
  width: 100%;
}

.board-wrap {
  position: relative;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  position: relative;
  aspect-ratio: 1;
  border: 3px solid var(--heavy);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.board.paused .cell {
  filter: blur(18px);
  opacity: 0.34;
  pointer-events: none;
}

.board.paused::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  border: 1px solid rgb(141 153 170 / 42%);
  background:
    linear-gradient(to right, rgb(141 153 170 / 18%) 1px, transparent 1px) 0 0 / calc(100% / 9) 100%,
    linear-gradient(to bottom, rgb(141 153 170 / 18%) 1px, transparent 1px) 0 0 / 100% calc(100% / 9),
    rgb(248 250 252 / 78%);
  backdrop-filter: blur(10px);
}

.resume-game {
  position: absolute;
  inset: auto 50% 50% auto;
  z-index: 8;
  min-width: 170px;
  transform: translate(50%, 50%);
  box-shadow: 0 18px 42px rgb(17 24 39 / 22%);
}

.resume-game[hidden] {
  display: none;
}

.board.generating .cell {
  opacity: 0.32;
}

.board.generating::before,
.board.generating::after {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.board.generating::before {
  content: "";
  background: linear-gradient(120deg, rgb(216 235 255 / 88%), rgb(255 231 173 / 82%), rgb(205 238 215 / 86%));
  background-size: 220% 220%;
  animation: board-generating 3.2s ease-in-out infinite;
}

.board.generating::after {
  content: "Generating board";
  display: grid;
  place-items: center;
  color: var(--heavy);
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0;
}

@keyframes board-generating {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  background: var(--surface);
  user-select: none;
}

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

.cell:nth-child(n + 19):nth-child(-n + 27),
.cell:nth-child(n + 46):nth-child(-n + 54) {
  border-bottom: 3px solid var(--line-strong);
}

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

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

.cell:first-child {
  border-top-left-radius: 7px;
}

.cell:nth-child(9) {
  border-top-right-radius: 7px;
}

.cell:nth-child(73) {
  border-bottom-left-radius: 7px;
}

.cell:last-child {
  border-bottom-right-radius: 7px;
}

.cell.selected {
  outline: 3px solid var(--selected);
  outline-offset: -4px;
  z-index: 3;
}

.cell.same-number:not(.base):not(.support):not(.elimination):not(.result) {
  background: var(--accent-soft);
}

.cell.same-note:not(.base):not(.support):not(.elimination):not(.result) {
  background: #f4f7fb;
}

.cell.error,
.cell.mistake {
  background: #fff1ef;
}

.cell.error .given,
.cell.error .entry,
.cell.mistake .entry {
  color: var(--error);
}

.cell.base {
  background: var(--base);
}

.cell.support {
  background: var(--support);
}

.cell.elimination {
  background: var(--elimination);
}

.cell.result {
  background: var(--result);
}

.given,
.entry {
  font-size: clamp(28px, 7vw, 54px);
  line-height: 1;
}

.given {
  color: #182230;
  font-weight: 750;
}

.entry {
  color: #101828;
  font-weight: 500;
}

.notes {
  position: absolute;
  inset: 5px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  color: #697586;
  font-size: clamp(9px, 1.7vw, 15px);
  line-height: 1;
  text-align: center;
}

.note {
  display: grid;
  place-items: center;
  border-radius: 999px;
}

.note.same-number {
  background: #d8ebff;
  color: #084c8d;
  box-shadow: 0 0 0 1px #7bb7f0 inset;
  font-weight: 800;
}

.note.base {
  background: #b9dcff;
  color: #084c8d;
  box-shadow: 0 0 0 1px #6aaee8 inset;
  font-weight: 800;
}

.note.support {
  background: #ffd27a;
  color: #7a4d00;
  box-shadow: 0 0 0 1px #d59a20 inset;
  font-weight: 800;
}

.note.elimination {
  background: #ff9b9b;
  color: #7a0000;
  box-shadow: 0 0 0 1px #df4b4b inset;
  font-weight: 900;
  text-decoration: line-through;
}

.note.result {
  background: #99dda9;
  color: #12542a;
  box-shadow: 0 0 0 1px #4faa66 inset;
  font-weight: 800;
}

.controls {
  display: grid;
  gap: 12px;
  align-self: start;
  padding: 14px;
  border: 1px solid rgb(203 213 225 / 80%);
  border-radius: 10px;
  background: rgb(255 255 255 / 72%);
  box-shadow: 0 12px 30px rgb(17 24 39 / 8%);
}

.timer-row,
.pattern-buttons,
.coach-buttons,
.history-buttons,
.rule-range {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.timer-row {
  grid-template-columns: 1fr 1fr 48px;
}

.game-timer {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: var(--surface);
  font-variant-numeric: tabular-nums;
  font-weight: 850;
}

button,
select {
  min-height: 42px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
}

button {
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}

button:not(:disabled):hover,
select:not(:disabled):hover {
  border-color: #98a2b3;
  background: #f8fafc;
}

button:focus-visible,
select:focus-visible,
.cell:focus-visible {
  outline: 3px solid rgb(23 92 211 / 34%);
  outline-offset: 2px;
}

.primary-button,
button.active {
  border-color: var(--heavy);
  background: var(--heavy);
  color: white;
}

.primary-button:not(:disabled):hover,
button.active:not(:disabled):hover {
  border-color: #101828;
  background: #101828;
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentcolor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-text-button {
  grid-auto-flow: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.icon-button {
  min-height: 0;
  padding: 0;
  font-weight: 700;
}

.pause-button {
  min-height: 42px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.text-link {
  display: inline-grid;
  width: fit-content;
  min-height: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 700;
}

.detail-button {
  width: 100%;
}

.mode-switch[aria-pressed="true"] {
  border-color: var(--heavy);
  background: var(--heavy);
  color: white;
}

.mode-switch[aria-pressed="true"]:not(:disabled):hover {
  border-color: #101828;
  background: #101828;
  color: white;
}

.entry-pad {
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 8px;
}

.entry-tools {
  display: grid;
  grid-template-rows: repeat(3, 1fr);
  gap: 6px;
}

.placeholder {
  visibility: hidden;
}

button:disabled {
  color: #98a2b3;
  background: #eef2f6;
  cursor: default;
}

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

.numpad button {
  font-size: 17px;
  font-weight: 700;
}

.numpad button.complete {
  color: #98a2b3;
  background: #eef2f6;
}

.patterns {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid #d0d5dd;
  border-radius: 10px;
  background: #f1f5f9;
  color: #667085;
}

.patterns.enabled {
  background: var(--surface);
  color: var(--ink);
}

.patterns:not(.enabled) select,
.patterns:not(.enabled) .pattern-buttons button,
.patterns:not(.enabled) #pattern-title,
.patterns:not(.enabled) #pattern-text {
  opacity: 0.58;
}

.pattern-list {
  display: grid;
  gap: 22px;
}

.pattern-group {
  display: grid;
  gap: 10px;
}

.pattern-group h2 {
  margin: 0;
  font-size: 20px;
}

.pattern-card {
  display: grid;
  gap: 4px;
  min-height: auto;
  padding: 12px;
  text-align: left;
}

.pattern-card-title {
  font-weight: 700;
}

.pattern-card-meta,
.pattern-meta {
  color: var(--muted);
}

.pattern-detail {
  display: grid;
  gap: 12px;
  max-width: 720px;
}

.pattern-detail h1 {
  margin: 0;
}

.pattern-detail p {
  margin: 0;
  line-height: 1.5;
}

.example-panel {
  display: grid;
  gap: 12px;
  margin-top: 24px;
  max-width: 650px;
}

.example-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.example-header h2 {
  margin: 0;
}

.game-status {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.game-status.solved {
  display: inline-grid;
  min-height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #dcfae6;
  color: #087443;
}

.game-status.error {
  color: var(--error);
}

.coach-text {
  min-height: 44px;
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.coach-text p {
  margin: 0 0 10px;
}

.coach-text p:last-child {
  margin-bottom: 0;
}

#pattern-title {
  margin: 12px 0 4px;
  font-weight: 700;
}

#pattern-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.help-dialog {
  max-width: 520px;
  border: 0;
  border-radius: 10px;
  box-shadow: 0 24px 60px rgb(16 24 40 / 24%);
}

.help-dialog::backdrop {
  background: rgb(16 24 40 / 36%);
}

.help-dialog form {
  display: grid;
  gap: 14px;
}

.help-dialog p,
.help-dialog h3,
.help-header h2 {
  margin: 0;
}

.shortcut-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.shortcut-list div {
  display: grid;
  grid-template-columns: minmax(130px, 0.65fr) 1fr;
  gap: 12px;
  align-items: baseline;
}

.shortcut-list dt {
  font-weight: 750;
}

.shortcut-list dd {
  margin: 0;
  color: var(--muted);
}

.help-header {
  display: grid;
  grid-template-columns: 1fr 40px;
  gap: 12px;
  align-items: center;
}

@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 64px 14px 14px;
  }

  .start-view,
  .reference-view {
    padding: 64px 14px 14px;
  }

  .start-actions {
    grid-template-columns: 1fr 1fr;
  }

  .controls {
    gap: 10px;
    max-width: none;
    padding: 12px;
  }
  .app-menu {
    top: 14px;
    left: 14px;
  }

  .entry-pad {
    grid-template-columns: 1fr 48px;
  }

  .example-header {
    grid-template-columns: 1fr;
  }
}
