:root {
  color-scheme: dark;
  --bg: #212121;
  --surface: #2c2c2c;
  --surface-2: #353535;
  --surface-3: #454545;
  --border: #656565;
  --border-soft: #343434;
  --text: #e8e8e8;
  --muted: #9a9a9a;
  --muted-2: #6f6f6f;
  --accent: #f2a81d;
  --accent-dark: #bd7a00;
  --accent-text: #212121;
  --danger: #ff7869;
  --success: #6fb980;
  --tile: 66px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

.topbar {
  min-height: 84px;
  border-bottom: 1px solid var(--border-soft);
  background: #1d1d1d;
  padding: max(10px, env(safe-area-inset-top)) 16px 9px;
}
.header-inner {
  position: relative;
  width: min(100%, 500px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text);
  text-decoration: none;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.15;
}
.brand-foot { font-size: 31px; filter: saturate(.9); transform: translateY(-1px); }
.icon-button {
  position: absolute;
  top: 50%;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  transform: translateY(-50%);
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:first-child { left: 0; }
.icon-button:last-child { right: 0; }
.icon-button:hover { color: var(--text); background: #282828; }
.icon-button svg { width: 23px; height: 23px; fill: currentColor; }
.subheader { margin: 2px 0 0; color: var(--muted); font-size: 14px; font-weight: 650; text-align: center; }

.game-stage { width: 100%; min-height: calc(100svh - 84px); padding: 18px 14px max(22px, env(safe-area-inset-bottom)); }
.game-shell { width: min(100%, 500px); min-height: calc(100svh - 124px); margin: 0 auto; display: flex; flex-direction: column; align-items: center; }
.puzzle-meta { font-family: var(--mono); font-size: 12px; color: var(--muted); letter-spacing: .35px; text-transform: uppercase; text-align: center; }
.puzzle-meta strong { color: var(--accent); }
.board-wrap { width: 100%; flex: 1; min-height: 268px; display: grid; place-items: center; padding: 18px 0 12px; }
.board { width: 100%; max-height: 345px; overflow-y: auto; display: flex; flex-direction: column; align-items: center; gap: 8px; scrollbar-width: none; }
.board::-webkit-scrollbar { display: none; }
.tile-row { display: grid; grid-template-columns: repeat(4, var(--tile)); gap: 8px; }
.tile {
  width: var(--tile);
  height: var(--tile);
  display: grid;
  place-items: center;
  border: 2px solid var(--border);
  color: var(--text);
  font-size: 32px;
  font-weight: 750;
  line-height: 1;
  text-transform: uppercase;
  transition: border-color .12s, background .16s, transform .12s;
}
.tile-row.start .tile { background: #252525; border-color: #727272; }
.tile-row.submitted .tile.changed { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tile-row.target .tile { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.tile-row.active .tile.filled { border-color: #999; transform: scale(1.02); }
.tile-row.enter { animation: fade-in .32s ease-out; }
.status { min-height: 26px; margin-bottom: 7px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; font-weight: 600; text-align: center; }
.status.error { color: var(--danger); }
.status.success { color: var(--success); }

.keyboard { width: 100%; display: flex; flex-direction: column; gap: 6px; margin-top: auto; }
.key-row { width: 100%; display: flex; justify-content: center; gap: 6px; }
.key-row.middle-row { padding: 0 5%; }
.key {
  height: 48px;
  flex: 1 1 0;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: #565656;
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
  user-select: none;
  transition: background .1s, transform .08s;
}
.key:hover { background: #676767; }
.key:active { transform: scale(.94); background: #717171; }
.key.wide { flex: 1.48; font-size: 12px; }
.utility-row { width: 100%; display: grid; grid-template-columns: 1.35fr 1fr; gap: 8px; margin-top: 12px; }
.utility-button { min-height: 40px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); font-size: 12px; font-weight: 650; cursor: pointer; }
.utility-button:hover { color: var(--text); background: #292929; }
.utility-button.primary { border-color: #d28e0b; background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 18px rgb(242 168 29 / .18); }
.utility-button.primary:hover { background: #ffb82e; }

.about, .faq { width: min(calc(100% - 32px), 650px); margin: 0 auto; }
.about { padding: 64px 0; border-top: 1px solid var(--border-soft); }
.about h1 { margin: 0 0 16px; font-size: clamp(32px, 7vw, 46px); letter-spacing: -1.6px; line-height: 1.05; }
.about p { margin: 0; color: var(--muted); font-size: 16px; line-height: 1.75; }
.about strong { color: var(--text); }
.faq { padding: 0 0 64px; }
.faq h2 { margin: 0 0 18px; font-size: clamp(24px, 5vw, 32px); letter-spacing: -1px; }
.faq details { border-top: 1px solid var(--border-soft); }
.faq details:last-child { border-bottom: 1px solid var(--border-soft); }
.faq summary { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px 0; color: var(--text); font-size: 15px; font-weight: 650; cursor: pointer; list-style: none; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--muted); font: 20px var(--mono); }
.faq details[open] summary::after { content: "−"; }
.faq details p { margin: 0; padding: 0 28px 18px 0; color: var(--muted); font-size: 14px; line-height: 1.7; }
.site-footer { padding: 0 16px 30px; color: #666; font-family: var(--mono); font-size: 11px; text-align: center; }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: 18px; background: rgb(0 0 0 / .72); backdrop-filter: blur(3px); }
.overlay[hidden] { display: none; }
.modal { position: relative; width: min(100%, 420px); max-height: calc(100svh - 36px); overflow-y: auto; padding: 24px; border: 1px solid #444; border-radius: 11px; background: var(--surface); box-shadow: 0 24px 80px rgb(0 0 0 / .46); animation: fade-in .18s ease-out; }
.modal h2 { margin: 0 30px 17px 0; font-size: 22px; letter-spacing: -.35px; }
.modal p { color: #ccc; font-size: 14px; line-height: 1.55; }
.modal-lead { color: var(--text) !important; }
.modal-close { position: absolute; top: 9px; right: 11px; width: 34px; height: 34px; border: 0; background: transparent; color: var(--text); font-size: 25px; line-height: 1; cursor: pointer; }
.example { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 17px 0; }
.example div { display: flex; gap: 4px; }
.example span { width: 34px; height: 34px; display: grid; place-items: center; border: 2px solid var(--border); font-weight: 750; }
.example .hit { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; }
.modal-primary, .modal-secondary { min-height: 44px; flex: 1; padding: 0 18px; border-radius: 6px; font-weight: 750; cursor: pointer; }
.modal-primary { border: 1px solid #d28e0b; background: var(--accent); color: var(--accent-text); }
.modal-secondary { border: 1px solid #505050; background: var(--surface-2); color: var(--text); }
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { padding: 14px 4px; border: 1px solid #444; border-radius: 8px; background: #292929; text-align: center; }
.stat strong { display: block; font: 700 23px var(--mono); }
.stat span { display: block; margin-top: 5px; color: var(--muted); font-size: 9px; font-weight: 700; letter-spacing: .55px; text-transform: uppercase; }
.result-kicker { margin: 0 0 7px !important; color: var(--accent) !important; font: 750 10px var(--mono) !important; letter-spacing: 1.4px; }
.result-score { margin: 3px 0 4px; color: var(--accent); font: 750 36px var(--mono); }
.result-sub { margin: 0 0 14px; color: var(--muted) !important; }
.result-path { padding: 12px; border-radius: 7px; background: #1b1b1b; color: #bbb; font: 12px/1.75 var(--mono); overflow-wrap: anywhere; }

@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes shake { 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
.tile-row.shake { animation: shake .22s ease-in-out; }

@media (max-width: 599px) {
  :root { --tile: clamp(58px, 17vw, 67px); }
  .topbar { min-height: 78px; }
  .brand { font-size: 28px; }
  .brand-foot { font-size: 28px; }
  .game-stage { min-height: calc(100svh - 78px); padding-top: 14px; }
  .game-shell { min-height: calc(100svh - 110px); }
  .board-wrap { min-height: 220px; padding: 13px 0 9px; }
  .board { max-height: 305px; }
  .key-row { gap: 5px; }
  .key { height: 50px; font-size: 13px; }
}

@media (max-height: 720px) {
  .topbar { min-height: 65px; padding-top: 6px; padding-bottom: 5px; }
  .brand { font-size: 25px; }
  .brand-foot { font-size: 25px; }
  .subheader { font-size: 12px; }
  .game-stage { min-height: calc(100svh - 65px); padding-top: 9px; padding-bottom: 10px; }
  .game-shell { min-height: calc(100svh - 84px); }
  .board-wrap { min-height: 180px; padding: 8px 0 5px; }
  .board { max-height: 240px; }
  .key { height: 43px; }
  .status { margin-bottom: 4px; }
  .utility-row { margin-top: 7px; }
}

@media (max-width: 370px) {
  .game-stage { padding-left: 9px; padding-right: 9px; }
  .key-row { gap: 4px; }
  .key { height: 46px; font-size: 12px; }
  .utility-button { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
