:root {
  --bg: #f2eee4;
  --bg-2: #e7e0d2;
  --surface: #fffcf5;
  --ink: #161310;
  --muted: #6b645b;
  --line: #dcd4c4;
  --line-strong: #1c1916;
  --accent: #0d5c54;
  --accent-ink: #073833;
  --accent-soft: #d5efe9;
  --select: #cfeae3;
  --peer: #f6f3eb;
  --same: #dceee9;
  --user: #0d5c54;
  --error: #b4232c;
  --error-soft: #f8d7d6;
  --given: #161310;
  --note: #7a7369;
  --ok: #2c7a4a;
  --shadow: 0 1px 0 rgba(22, 19, 16, 0.06), 0 24px 48px rgba(40, 32, 18, 0.08);
  --radius: 16px;
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font: "Outfit", "Segoe UI", system-ui, sans-serif;
  --board: min(94vw, 564px);
}

html[data-theme="dark"] {
  --bg: #141210;
  --bg-2: #1c1916;
  --surface: #221f1b;
  --ink: #f4eee6;
  --muted: #b3a99c;
  --line: #3a342d;
  --line-strong: #f0e7d8;
  --accent: #5fd0c0;
  --accent-ink: #d7f3ee;
  --accent-soft: #1c3d38;
  --select: #1f4f48;
  --peer: #24322f;
  --same: #2c5e56;
  --user: #7ee0d1;
  --error: #f07167;
  --error-soft: #4a2422;
  --given: #f4eee6;
  --note: #b3a99c;
  --ok: #8ad0a0;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

html[data-theme="dark"] body {
  background: var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px 96px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--ink) 10%, transparent);
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.04em;
  line-height: 1;
}

.brand-name em {
  font-style: italic;
  color: var(--accent);
  font-weight: 500;
}

.nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.nav-btn,
.icon-btn,
.tool,
.pad-btn,
.primary,
.ghost,
.diff-card,
.toggle {
  border: 0;
  background: transparent;
  color: inherit;
}

.nav-btn,
.ghost {
  padding: 8px 12px;
  border-radius: 999px;
  color: var(--muted);
}

a.nav-btn,
a.ghost,
a.primary {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.nav-btn.is-on {
  color: var(--ink);
  background: var(--accent-soft);
}

.nav-btn:hover,
.ghost:hover {
  background: rgba(26, 23, 20, 0.06);
  color: var(--ink);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.icon-btn:hover,
.icon-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.primary {
  background: var(--ink);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 560;
}

.primary:hover {
  transform: translateY(-1px);
}

html[data-theme="dark"] .primary {
  background: var(--accent);
  color: #082824;
}

.ad-unit {
  display: none;
  margin: 0;
}

.ad-unit.is-live {
  display: block;
}

.ad-top.is-live {
  margin: 8px 0 40px;
}

.ad-bottom.is-live {
  margin: 48px 0 28px;
}

.side .ad-unit.is-live {
  margin: 8px 0 28px;
}

.ad-kicker {
  display: block;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
  text-align: center;
}

.ad-unit.ad-box .ad-kicker {
  text-align: left;
}

.ad-frame {
  margin: 0 auto;
  background: color-mix(in srgb, var(--surface) 78%, var(--bg-2));
  border: 1px solid var(--line);
  overflow: hidden;
}

.ad-leaderboard .ad-frame {
  width: min(728px, 100%);
  min-height: 90px;
}

.ad-box .ad-frame {
  width: min(300px, 100%);
  min-height: 250px;
}

.ad-mobile {
  display: none;
}

.ad-unit.is-live .ad-frame {
  background: transparent;
  border-color: transparent;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 56px;
  align-items: start;
  margin-top: 12px;
}

.play {
  padding-right: 12px;
}

.play-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  max-width: var(--board);
}

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

.diff-btn {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 2px;
  background: none;
  border: 0;
  color: inherit;
}

.diff-kicker {
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.diff-name {
  font-family: var(--font-display);
  font-size: 22px;
  font-style: italic;
}

.mistakes,
.timer {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 15px;
}

.mistakes strong,
.timer strong {
  color: var(--ink);
  font-weight: 600;
}

.mistakes.is-hot strong {
  color: var(--error);
}

.board-wrap {
  position: relative;
  width: var(--board);
}

.board {
  width: var(--board);
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--line-strong);
  border-radius: 6px;
  box-shadow: var(--shadow);
  user-select: none;
}

.box {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: #c9c1b3;
}

html[data-theme="dark"] .box {
  background: var(--line);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  background: var(--surface);
  cursor: pointer;
  min-width: 0;
  min-height: 0;
  border: 0;
  padding: 0;
  border-radius: 0;
  color: inherit;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
}

.cell:hover {
  background: color-mix(in srgb, var(--select) 35%, var(--surface));
}

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

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

.cell.is-selected {
  background: var(--select);
  box-shadow: inset 0 0 0 2.5px var(--accent);
  z-index: 1;
}

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

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

.value {
  font-size: clamp(20px, 5.8vw, 34px);
  font-weight: 650;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  color: var(--given);
}

.cell.is-user .value {
  color: var(--user);
  font-weight: 500;
  animation: ink-in 0.16s ease;
}

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

.notes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 88%;
  height: 88%;
  pointer-events: none;
}

.notes span {
  display: grid;
  place-items: center;
  font-size: clamp(9px, 1.8vw, 13px);
  color: transparent;
  line-height: 1;
  font-weight: 600;
}

.notes span.on {
  color: var(--note);
}

.dock {
  width: var(--board);
  margin-top: 18px;
}

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

.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 8px 4px 10px;
  border-radius: 12px;
  background: transparent;
  border: 0;
  color: var(--ink);
}

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

.tool small {
  color: var(--muted);
  font-size: 12px;
}

.tool:hover,
.tool[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.tool[aria-pressed="true"] small {
  color: var(--accent-ink);
}

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

.pad-btn {
  aspect-ratio: 0.82;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
  touch-action: manipulation;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.pad-btn .n {
  font-size: clamp(18px, 3.4vw, 26px);
  font-weight: 600;
  color: var(--user);
  line-height: 1;
}

.pad-btn .left {
  font-size: 11px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pad-btn:hover,
.pad-btn.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.pad-btn.is-done {
  opacity: 0.38;
}

.hint-toast {
  min-height: 52px;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 14px;
  display: none;
}

.hint-toast.show {
  display: block;
}

.hint-toast b {
  display: block;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-top: 8px;
  max-width: 260px;
}

.play-new {
  width: 100%;
  text-align: center;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 16px;
  letter-spacing: 0.01em;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.rail-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.rail-daily {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 0;
  background: none;
  border: 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-align: left;
  width: 100%;
  border-radius: 0;
}

.rail-daily span {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.rail-daily strong {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  font-weight: 500;
}

.rail-links {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rail-links a {
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  width: fit-content;
  padding-bottom: 1px;
}

.rail-links a:hover {
  border-color: var(--accent);
  color: var(--accent-ink);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.card h2,
.modal h2 {
  font-family: var(--font-display);
  font-size: 28px;
  margin: 0 0 8px;
  letter-spacing: -0.03em;
}

.card p,
.lede {
  margin: 0;
  color: var(--muted);
}

.side .primary {
  width: 100%;
  text-align: center;
  padding: 14px 16px;
  border-radius: 14px;
  font-size: 16px;
}

.daily-date {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px;
  margin: 8px 0 14px;
}

.stat-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.stat {
  background: color-mix(in srgb, var(--bg) 70%, var(--surface));
  border-radius: 12px;
  padding: 10px 12px;
}

.stat span {
  display: block;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat strong {
  font-size: 22px;
  font-family: var(--font-display);
}

.keys {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.6;
}

.keys kbd {
  font-family: var(--font);
  font-size: 11px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 1px 6px;
  background: var(--bg);
}

.how {
  margin-top: 88px;
  max-width: 720px;
}

.how h2 {
  font-family: var(--font-display);
  font-size: 36px;
  margin: 0 0 10px;
}

.how h3 {
  font-family: var(--font-display);
  font-size: 22px;
  margin: 28px 0 8px;
}

.how p,
.how li {
  color: color-mix(in srgb, var(--ink) 78%, var(--muted));
}

.how ul {
  padding-left: 18px;
}

.overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, #1a1714 42%, transparent);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.overlay.show {
  display: flex;
}

.modal {
  width: min(560px, 100%);
  background: var(--surface);
  color: var(--ink);
  border-radius: 24px;
  padding: 24px;
  box-shadow: var(--shadow);
  max-height: min(86vh, 760px);
  overflow: auto;
}

.modal.wide {
  width: min(680px, 100%);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.diff-grid {
  display: grid;
  gap: 8px;
  margin: 16px 0 8px;
}

.diff-card {
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  background: var(--surface);
}

.diff-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.diff-card b {
  font-family: var(--font-display);
  font-size: 20px;
}

.diff-card span {
  color: var(--muted);
  font-size: 14px;
}

.diff-card em {
  font-style: normal;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-size: 12px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.win-time {
  font-family: var(--font-display);
  font-size: 64px;
  line-height: 0.9;
  letter-spacing: -0.04em;
  margin: 8px 0 6px;
}

.board-wrap.is-paused .board {
  filter: blur(9px);
  pointer-events: none;
}

.pause-cover {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  z-index: 2;
}

.board-wrap.is-paused .pause-cover {
  display: grid;
}

.pause-cover .primary {
  padding: 16px 28px;
  font-size: 18px;
}

.loading-copy {
  text-align: center;
}

.loading-copy .pulse {
  width: 48px;
  height: 48px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}

.toggle-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 4px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  width: 100%;
}

.toggle span {
  color: var(--ink);
}

.toggle small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.switch {
  width: 42px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex: none;
}

.switch::after {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform 0.16s ease;
}

.toggle[aria-pressed="true"] .switch {
  background: var(--accent);
}

.toggle[aria-pressed="true"] .switch::after {
  transform: translateX(16px);
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  margin-top: 12px;
}

.stats-table th,
.stats-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.stats-table th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.warn {
  background: color-mix(in srgb, var(--error-soft) 70%, var(--surface));
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  margin-top: 8px;
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes hint-flash {
  0%,
  100% {
    background: var(--select);
  }
  40% {
    background: #f4e27c;
  }
}

@keyframes ink-in {
  from {
    transform: scale(0.82);
    opacity: 0.35;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 36px;
  }

  .play {
    padding-right: 0;
  }

  .side {
    padding-top: 8px;
    max-width: var(--board);
    margin-left: auto;
    margin-right: auto;
  }

  .play-meta,
  .dock,
  .board-wrap {
    margin-left: auto;
    margin-right: auto;
  }
}

@media (max-width: 640px) {
  .ad-top {
    display: none !important;
  }

  .ad-unit.is-live.ad-mobile {
    display: block;
    max-width: var(--board);
    margin: 40px auto 8px;
  }

  .side .ad-unit.ad-box {
    display: none !important;
  }

  .app {
    padding: 0 12px 40px;
  }

  .brand-name {
    font-size: 24px;
  }

  .nav-btn {
    padding: 8px 8px;
    font-size: 14px;
  }

  .dock {
    position: sticky;
    bottom: 0;
    z-index: 5;
    padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--bg) 80%, transparent);
  }

  .pad-btn {
    aspect-ratio: 0.7;
    border-radius: 12px;
  }

  .diff-card {
    grid-template-columns: 72px 1fr;
  }

  .diff-card em {
    display: none;
  }

  .win-time {
    font-size: 52px;
  }
}

.site-foot {
  margin-top: 72px;
  padding-top: 24px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.site-foot a {
  color: inherit;
}

.page-hero {
  max-width: 720px;
  margin: 28px 0 22px;
}

.page-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(36px, 6vw, 56px);
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin: 0 0 10px;
}

.page-hero p {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg button,
.field {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 8px 14px;
  color: inherit;
}

.seg button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

html[data-theme="dark"] .seg button[aria-pressed="true"] {
  background: var(--accent);
  color: #082824;
  border-color: var(--accent);
}

.field {
  border-radius: 12px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 18px 28px;
  align-items: end;
  margin: 8px 0 28px;
}

.control label {
  display: block;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.control-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
