:root {
  color-scheme: dark;
  --background: #101210;
  --panel: #181c17;
  --line: #30362c;
  --muted: #a3ad9c;
  --text: #f0f3e9;
  --accent: #d6fa82;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 280px;
  min-height: 100svh;
  margin: 0;
  display: flex;
  flex-direction: column;
  color: var(--text);
  background: radial-gradient(ellipse at 74% 33%, #20291b 0%, var(--background) 61%) fixed;
}

button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.masthead, .game, .footer {
  width: min(100% - 64px, 1056px);
  margin-inline: auto;
}

.masthead {
  display: flex;
  align-items: center;
  min-height: 84px;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 13px;
  color: #e0e6d8;
  font: 600 .875rem var(--mono);
  letter-spacing: .055em;
}

.mark {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border: 1px solid #5c7044;
  border-radius: 5px;
  transform: rotate(-12deg);
}

.mark::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 14px #d6fa8240;
}

.game {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.24fr);
  align-content: center;
  align-items: center;
  gap: clamp(30px, 8vw, 125px);
  padding-block: clamp(36px, 7vh, 78px);
}

.intro { padding-bottom: 30px; }

h1 {
  margin: 0 0 24px;
  font-size: clamp(4rem, 8.2vw, 6.75rem);
  font-weight: 750;
  letter-spacing: .015em;
  line-height: 1.08;
}

.rules {
  max-width: 20em;
  margin: 0;
  color: #b7c2ae;
  font-size: 1rem;
  line-height: 1.8;
  text-wrap: pretty;
}

.scores {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 340px;
  margin: 32px 0 18px;
}

.score {
  position: relative;
  min-height: 90px;
  padding: 13px 15px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #191e17;
}

.score dt { color: var(--muted); font-size: .875rem; }

.score dd {
  margin: 6px 0 0;
  overflow-wrap: anywhere;
  font: 650 clamp(1.25rem, 3.5vw, 1.875rem)/1.15 var(--mono);
  letter-spacing: -.05em;
}

.score-best { background: #20291a; border-color: #3a4930; }
.score-best dd { color: var(--accent); }

.gain {
  position: absolute;
  inset: 12px 11px auto auto;
  color: var(--accent);
  font: .75rem var(--mono);
  opacity: 0;
  pointer-events: none;
}

.restart, .replay {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid #485240;
  border-radius: 9px;
  background: #1a2018;
  color: var(--text);
  font-size: .875rem;
  transition: background .15s, border-color .15s;
}

.restart:hover { background: #293324; border-color: #69795c; }

.play { width: 100%; max-width: 510px; justify-self: end; }

.game-panel {
  padding: clamp(12px, 2.3vw, 20px);
  border: 1px solid #3a4634;
  border-radius: 21px;
  background: var(--panel);
  box-shadow: 0 22px 65px #06090650;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 3px 14px;
}

.panel-header h2 { margin: 0; font-size: .875rem; font-weight: 650; }
.available { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: .875rem; }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.available[data-empty="true"] .status-dot { background: var(--muted); }

.board-wrap { position: relative; }

.board {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(5px, 1.15vw, 9px);
  isolation: isolate;
  overflow: clip;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: clamp(7px, 1.4vw, 12px);
  background: #111510;
  -webkit-tap-highlight-color: transparent;
}

.cell:focus-visible { z-index: 2; outline-offset: -3px; }

.tile {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--edge, #dde8af);
  border-radius: inherit;
  background: linear-gradient(145deg, var(--top, #eaf4c5), var(--base, #d3dda8));
  color: var(--ink, #26321a);
  font: 650 clamp(1.05rem, 4vw, 2.05rem)/1 var(--mono);
  letter-spacing: -.075em;
  pointer-events: none;
  transition: filter .12s, box-shadow .12s;
}

.tile::after {
  position: absolute;
  inset: 11% 11% auto auto;
  width: 5px;
  height: 5px;
  border: 1px solid currentColor;
  border-radius: 2px;
  opacity: .45;
  content: "";
}

.cell[data-tone="1"] { --top: #2f3c2c; --base: #293327; --edge: #485844; --ink: #d5dfce; }
.cell[data-tone="2"] { --top: #455c3b; --base: #394e30; --edge: #5c7650; --ink: #eef5df; }
.cell[data-tone="3"] { --top: #79935a; --base: #6b834f; --edge: #8ca575; --ink: #101a0c; }
.cell[data-tone="4"] { --top: #c4e686; --base: #aece70; --edge: #d4eeab; --ink: #1d2a12; }
.cell[data-tone="5"] { --top: #e1faab; --base: #c7ed86; --edge: #ecfec4; --ink: #1d2a12; }
.cell[data-tone="6"] { --top: #f4f9cb; --base: #dceca7; --edge: #f4fed0; --ink: #1d2a12; }
.cell[data-tone="7"] { --top: #f4eab8; --base: #e6d687; --edge: #fff2bc; --ink: #302711; }
.cell[data-tone="8"] { --top: #f6f8ee; --base: #d8e7c9; --edge: #fafff2; --ink: #1a2513; }
.cell.is-match .tile { filter: brightness(1.18); box-shadow: inset 0 0 0 2px #e5f8c5bc; }
.cell:active .tile { filter: brightness(1.28); }

.end-screen {
  z-index: 3;
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 12px;
  padding: 16px;
  border-radius: 12px;
  background: #101410ed;
  text-align: center;
}

.end-screen h3 { margin: 0; font-size: 1.75rem; }
.end-screen p { margin: 0 0 6px; color: #c5d0be; }
.replay { border-color: var(--accent); background: var(--accent); color: #151f0b; font-weight: 700; }
.replay:hover { background: #e6ffb6; }

.controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  margin: 14px 2px 0;
  color: var(--muted);
  font-size: .875rem;
}

kbd {
  display: inline-block;
  margin-inline: 2px;
  padding: 2px 5px;
  border: 1px solid #444d3e;
  border-radius: 4px;
  color: #d4deca;
  font: .75rem var(--mono);
}

.footer {
  padding: 19px 0 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .8125rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (hover: none) and (pointer: coarse) {
  .keyboard { display: none; }
}

@media (max-width: 880px) {
  .masthead, .game, .footer { width: min(100% - 36px, 510px); }
  .masthead { min-height: 58px; }
  .game { grid-template-columns: minmax(0, 1fr); gap: 16px; padding-block: 25px; align-content: start; }
  .intro { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; align-items: end; padding: 0; }
  h1 { grid-column: 1 / -1; margin: 0 0 2px; font-size: clamp(2.75rem, 10vw, 4.5rem); }
  .rules { grid-column: 1 / -1; max-width: 28em; line-height: 1.6; }
  .scores { width: 100%; max-width: 340px; gap: 7px; margin: 4px 0 0; }
  .score { min-height: 62px; padding: 8px 10px; border-radius: 10px; }
  .score dd { margin-top: 3px; }
  .gain { display: none; }
  .restart { align-self: end; padding-inline: 10px; }
  .game-panel { border-radius: 15px; }
  .panel-header { padding-bottom: 10px; }
  .controls { margin-top: 11px; }
  .footer { padding-block: 14px; }
}

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