:root {
  --page: #1b1c21;
  --surface: #24252c;
  --surface-raised: #2c2d35;
  --ink: #f1f1f4;
  --muted: rgba(241, 241, 244, 0.6);
  --blue: #4da3ff;
  --blue-soft: #8cc4ff;
  --amber: #f2b45c;
  --error: #ff6b6b;
  --thin-line: rgba(255, 255, 255, 0.07);
  --box-line: rgba(255, 255, 255, 0.3);
  --header-height: 58px;
  --footer-height: 24px;
  --viewport-height: 100vh;
}

@supports (height: 100svh) {
  :root {
    --viewport-height: 100svh;
  }
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 50% 20%, #23252e, var(--page) 70%) no-repeat, var(--page);
  background-size: 100% var(--viewport-height), auto;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--header-height);
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.18);
  user-select: none;
}

.header-start {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.home-link {
  position: relative;
  display: flex;
  align-items: center;
  padding-right: 14px;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  transition: opacity 0.15s;
}

.home-link:hover {
  opacity: 0.8;
}

.home-link-mark {
  display: block;
  width: 30px;
  height: 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--blue);
  color: #0f1a29;
}

h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 6px;
  margin: 0;
}

.stat {
  min-width: 70px;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
}

.stat-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.6;
}

.stat-value {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.mode-picker {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
}

.mode-option {
  position: relative;
  cursor: pointer;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option span {
  display: block;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 650;
  opacity: 0.7;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.mode-option:hover span {
  opacity: 1;
}

.mode-option input:checked + span {
  background: var(--ink);
  color: #1d1d27;
  opacity: 1;
}

.mode-option input:focus-visible + span {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.new-game-button {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: #0c1726;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.15s, transform 0.1s;
}

.new-game-button:hover {
  background: #6cb4ff;
}

.new-game-button:active {
  transform: scale(0.96);
}

kbd {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
}

.ghost-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  opacity: 0.85;
}

.ghost-button:hover,
.ghost-button[aria-expanded="true"] {
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

.settings {
  position: relative;
}

.settings-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 20;
  display: grid;
  gap: 4px;
  width: 250px;
  padding: 8px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  background: var(--surface-raised);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.settings-panel[hidden] {
  display: none;
}

.setting {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}

.setting:hover {
  background: rgba(255, 255, 255, 0.06);
}

.setting input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--blue);
}

#table {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--viewport-height) - var(--header-height) - var(--footer-height));
  padding: 20px 16px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.play-area {
  --board-size: min(600px, calc(var(--viewport-height) - var(--header-height) - var(--footer-height) - 90px), calc(100vw - 360px));
  display: flex;
  align-items: center;
  gap: 32px;
}

.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  grid-template-rows: repeat(9, 1fr);
  width: var(--board-size);
  height: var(--board-size);
  overflow: hidden;
  border: 2px solid var(--box-line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  touch-action: manipulation;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  border-right: 1px solid var(--thin-line);
  border-bottom: 1px solid var(--thin-line);
  cursor: pointer;
  transition: background 0.12s;
}

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

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

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

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

.cell.is-peer {
  background: rgba(77, 163, 255, 0.07);
}

.cell.is-same-digit {
  background: rgba(77, 163, 255, 0.22);
}

.cell.is-conflict {
  background: rgba(255, 107, 107, 0.16);
}

.cell.is-selected {
  background: rgba(77, 163, 255, 0.36);
  box-shadow: inset 0 0 0 2px var(--blue);
}

.cell.is-hint-flash {
  animation: hint-flash 0.9s ease-out;
}

.cell-value {
  grid-area: 1 / 1;
  color: var(--blue-soft);
  font-size: calc(var(--board-size) / 9 * 0.56);
  font-weight: 600;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.cell.is-given .cell-value {
  color: var(--ink);
  font-weight: 750;
}

.cell.is-hinted .cell-value {
  color: var(--amber);
}

.cell.is-wrong .cell-value {
  color: var(--error);
}

.cell-notes {
  display: grid;
  grid-area: 1 / 1;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 100%;
  height: 100%;
  padding: 2px;
}

.note {
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: calc(var(--board-size) / 9 * 0.24);
  font-weight: 600;
  line-height: 1;
}

.note.is-match {
  border-radius: 4px;
  background: var(--blue);
  color: #0c1726;
}

.board.is-finished .cell {
  cursor: default;
}

@keyframes hint-flash {
  from {
    background: rgba(242, 180, 92, 0.55);
  }
}

.status {
  min-height: 1.3em;
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  opacity: 0.65;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 288px;
}

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

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px 8px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  opacity: 0.85;
  transition: background 0.15s, opacity 0.15s;
}

.tool:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.07);
  opacity: 1;
}

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

.tool-label {
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.tool-state {
  display: inline-block;
  padding: 0 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  font-size: 10px;
}

.tool[aria-pressed="true"] {
  color: var(--blue-soft);
  opacity: 1;
}

.tool[aria-pressed="true"] .tool-state {
  background: var(--blue);
  color: #0c1726;
}

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

.pad-key {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1.15;
  border: 0;
  border-radius: 14px;
  background: var(--surface-raised);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: background 0.12s, transform 0.08s, opacity 0.15s;
}

.pad-key:hover {
  background: #353640;
}

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

.pad-digit {
  color: var(--blue-soft);
  font-size: 30px;
  font-weight: 650;
  line-height: 1;
}

.number-pad.is-notes .pad-digit {
  color: var(--muted);
  font-size: 22px;
}

.pad-remaining {
  min-height: 1em;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  opacity: 0.5;
}

.pad-key.is-complete {
  opacity: 0.3;
}

.rules-note {
  margin: 0;
  font-size: 12px;
  text-align: center;
  opacity: 0.5;
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 11, 14, 0.6);
  backdrop-filter: blur(3px);
  animation: fade-in 0.25s ease-out;
}

.result-overlay[hidden] {
  display: none;
}

.result-card {
  width: min(360px, 100%);
  padding: 26px 24px 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: var(--surface-raised);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: card-rise 0.35s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.result-card h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 0 14px;
}

.result-stat {
  min-width: 70px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.result-stat dd {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.result-note {
  margin: 0 0 14px;
  color: var(--amber);
  font-size: 14px;
  font-weight: 600;
}

.result-actions {
  display: grid;
  gap: 8px;
}

.action {
  height: 42px;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 15px;
  font-weight: 700;
}

.action:hover {
  background: rgba(255, 255, 255, 0.13);
}

.action.primary {
  background: var(--blue);
  color: #0c1726;
}

.action.primary:hover {
  background: #6cb4ff;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes card-rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 10px;
  opacity: 0.7;
}

.site-footer a {
  color: inherit;
}

@media (max-width: 1100px) {
  header {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .button-label {
    display: none;
  }

  .new-game-button {
    width: 38px;
    justify-content: center;
    padding: 0;
  }
}

@media (max-width: 860px) {
  :root {
    --header-height: 104px;
  }

  .play-area {
    --board-size: min(560px, calc(100vw - 24px), calc(var(--viewport-height) - var(--header-height) - var(--footer-height) - 210px));
    flex-direction: column;
    gap: 12px;
  }

  .board-column {
    gap: 6px;
  }

  .side-panel {
    width: var(--board-size);
    min-width: min(100%, 340px);
    gap: 8px;
  }

  .tools {
    gap: 2px;
  }

  .tool {
    flex-direction: row;
    justify-content: center;
    gap: 6px;
    padding: 8px 2px;
  }

  .number-pad {
    grid-template-columns: repeat(9, 1fr);
    gap: 4px;
  }

  .pad-key {
    aspect-ratio: auto;
    height: 56px;
    border-radius: 10px;
  }

  .pad-digit {
    font-size: 24px;
  }

  .number-pad.is-notes .pad-digit {
    font-size: 18px;
  }

  .rules-note {
    display: none;
  }
}

@media (max-width: 640px) {
  header {
    padding: 8px 12px;
    gap: 8px;
  }

  .header-start {
    gap: 10px;
  }

  .home-link {
    padding-right: 10px;
  }

  .brand-mark {
    display: none;
  }

  h1 {
    font-size: 17px;
  }

  .stat {
    min-width: 58px;
    padding: 4px 8px;
  }

  .stat-value {
    font-size: 14px;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  .mode-option span {
    padding: 6px 7px;
    font-size: 12px;
  }

  #table {
    padding: 10px 8px 14px;
  }

  .play-area {
    --board-size: min(calc(100vw - 16px), calc(var(--viewport-height) - var(--header-height) - var(--footer-height) - 190px));
  }

  .tool {
    flex-direction: column;
    gap: 2px;
    padding: 6px 2px;
  }

  .tool svg {
    width: 20px;
    height: 20px;
  }

  .pad-key {
    height: 60px;
  }

  .site-footer {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell,
  .cell.is-hint-flash,
  .result-overlay,
  .result-card {
    animation: none;
    transition: none;
  }
}

.guide {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 20px 64px;
  color: rgba(241, 241, 244, 0.84);
  font-size: 16px;
  line-height: 1.65;
  user-select: text;
}

.guide h2 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 24px;
}

.guide h3 {
  margin: 22px 0 6px;
  color: var(--ink);
  font-size: 17px;
}

.guide p,
.guide li {
  margin: 0 0 10px;
}

.guide ul,
.guide ol {
  padding-left: 22px;
}

.guide kbd {
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  background: transparent;
  font: inherit;
  font-size: 13px;
}

.guide h2:not(:first-child) {
  margin-top: 40px;
}

.guide a,
.more-games a {
  color: var(--blue-soft);
}

.more-games {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 64px;
  user-select: text;
}

.more-games h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.more-games ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.noscript-note {
  margin: 0;
  padding: 12px 20px;
  background: var(--blue);
  color: #0c1726;
  text-align: center;
}

@media (max-width: 640px) {
  .site-footer {
    flex-wrap: wrap;
    row-gap: 2px;
    column-gap: 12px;
  }

  .site-footer > [aria-hidden="true"] {
    display: none;
  }
}
