:root {
  --bg: #ffffff;
  --panel: #f5f6f8;
  --ink: #16181d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --hit: #3aa757;
  --near: #d9a520;
  --miss: #c4c8cf;
  --key: #e2e5ea;
  --accent: #16181d;
  --accent-ink: #ffffff;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --panel: #171a21;
    --ink: #f3f4f6;
    --muted: #9aa1ad;
    --line: #262a33;
    --hit: #3aa757;
    --near: #c9a227;
    --miss: #3a3f4a;
    --key: #2a2f39;
    --accent: #f3f4f6;
    --accent-ink: #0f1115;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { -webkit-font-smoothing: antialiased; }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }
a { color: inherit; }
button { font: inherit; }

.top { border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top .wrap { display: flex; align-items: center; gap: 12px; height: 56px; }
.brand { font-weight: 800; letter-spacing: -0.02em; text-decoration: none; font-size: 18px; }
.brand span { color: var(--muted); font-weight: 600; }
.today { display: flex; gap: 6px; margin-left: auto; overflow-x: auto; }
.today a { text-decoration: none; font-size: 12px; font-weight: 700; padding: 6px 9px; border-radius: 999px; background: var(--panel); color: var(--muted); white-space: nowrap; }
.today a.on { background: var(--accent); color: var(--accent-ink); }
.today a.done::after { content: " ✓"; }
.icons { display: flex; gap: 6px; }
.icon { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: transparent; color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0; }
.btn svg { vertical-align: -5px; margin-right: 4px; }
.btn.ghost svg { margin-right: 4px; }

.head { padding: 26px 0 14px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
h1 { font-size: 28px; letter-spacing: -0.02em; margin: 6px 0 4px; }
.sub { margin: 0; color: var(--muted); }

.seg { display: inline-flex; margin-top: 14px; padding: 3px; background: var(--panel); border-radius: 999px; gap: 2px; }
.seg a { text-decoration: none; font-size: 13px; font-weight: 700; padding: 7px 16px; border-radius: 999px; color: var(--muted); }
.seg a.on { background: var(--accent); color: var(--accent-ink); }
.seg a.done::after { content: " ✓"; }

/* player mode */
.rows { display: grid; gap: 8px; }
.row { display: grid; grid-template-columns: 1.7fr repeat(7, 1fr); gap: 4px; }
.row.head { padding: 0; }
.row.head .cell { background: transparent; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; height: 16px; min-height: 0; }
.cell { background: var(--panel); border-radius: 8px; min-height: 46px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; padding: 4px 2px; text-align: center; line-height: 1.1; }
.cell small { font-weight: 500; color: var(--muted); font-size: 10px; margin-top: 2px; }
.cell.name { align-items: flex-start; text-align: left; padding-left: 10px; font-size: 13px; }
.cell.hit { background: var(--hit); color: #fff; }
.cell.hit small { color: rgba(255,255,255,0.8); }
.cell.near { background: var(--near); color: #1a1a1a; }
.cell.near small { color: rgba(0,0,0,0.6); }
.cell.miss { background: var(--miss); color: var(--ink); }
.row.empty .cell { background: transparent; border: 1px dashed var(--line); }
.row.flip .cell { animation: pop 0.25s ease; }
.grid .r.shake { animation: shake 0.4s ease; }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-6px); } 40%, 60% { transform: translateX(6px); } }
@keyframes pop { from { transform: scale(0.92); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

.controls { margin-top: 16px; position: relative; }
.search { display: flex; gap: 8px; }
.search input { flex: 1; font-size: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); outline: none; }
.search input:focus { border-color: var(--ink); }
.btn { background: var(--accent); color: var(--accent-ink); border: 0; padding: 12px 18px; border-radius: var(--radius); font-weight: 700; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn:disabled { opacity: 0.4; cursor: default; }
.suggest { position: absolute; left: 0; right: 0; top: 52px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; z-index: 4; box-shadow: 0 12px 30px rgba(0,0,0,0.15); max-height: 280px; overflow-y: auto; }
.suggest div { padding: 10px 14px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.suggest div:hover, .suggest div.sel { background: var(--panel); }
.suggest span { color: var(--muted); font-size: 13px; }
.hintline { margin-top: 10px; color: var(--muted); font-size: 13px; display: flex; justify-content: space-between; }

/* word mode */
.grid { display: grid; gap: 6px; justify-content: center; }
.grid .r { display: grid; gap: 6px; grid-auto-flow: column; }
.tile { width: 52px; height: 52px; border: 2px solid var(--line); border-radius: 8px; display: grid; place-items: center; font-size: 24px; font-weight: 800; text-transform: uppercase; }
.tile.filled { border-color: var(--muted); }
.tile.hit { background: var(--hit); border-color: var(--hit); color: #fff; }
.tile.near { background: var(--near); border-color: var(--near); color: #1a1a1a; }
.tile.miss { background: var(--miss); border-color: var(--miss); }
.kb { margin-top: 18px; display: grid; gap: 6px; }
.kb .kr { display: flex; gap: 5px; justify-content: center; }
.key { min-width: 30px; height: 50px; border: 0; border-radius: 6px; background: var(--key); color: var(--ink); font-weight: 700; cursor: pointer; padding: 0 8px; }
.key.wide { min-width: 58px; font-size: 12px; }
.key.hit { background: var(--hit); color: #fff; }
.key.near { background: var(--near); color: #1a1a1a; }
.key.miss { background: var(--miss); opacity: 0.6; }
.hint { margin-top: 12px; padding: 12px 14px; background: var(--panel); border-radius: var(--radius); color: var(--muted); font-size: 14px; }

/* result */
.result { margin-top: 20px; padding: 18px; border-radius: var(--radius); background: var(--panel); }
.result h2 { margin: 0 0 4px; font-size: 20px; }
.result .note { color: var(--muted); margin: 6px 0 12px; }
.result .answer { display: flex; align-items: center; gap: 12px; margin: 10px 0 14px; }
.result .answer img { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--bg); }
.result pre { background: var(--bg); padding: 10px 12px; border-radius: 8px; font-size: 14px; line-height: 1.35; margin: 0 0 12px; white-space: pre-wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.countdown { color: var(--muted); font-size: 13px; margin-top: 12px; }

.more { margin-top: 28px; }
.more h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 8px; }
.more .list { display: grid; gap: 6px; }
.more a { display: flex; justify-content: space-between; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; }
.more a span { color: var(--muted); font-size: 13px; }

.foot { color: var(--muted); font-size: 12px; padding: 30px 16px 40px; }

dialog { border: 0; border-radius: 16px; padding: 22px; max-width: 420px; width: calc(100% - 32px); background: var(--bg); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,0.5); }
dialog h2 { margin: 0 0 10px; }
dialog .btn { margin-top: 14px; width: 100%; }
.muted { color: var(--muted); }
.legend { display: flex; gap: 8px; align-items: center; margin: 6px 0; font-size: 14px; }
.legend i { width: 18px; height: 18px; border-radius: 4px; display: inline-block; }
.stat { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; gap: 8px; margin: 10px 0 14px; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.dist div { display: flex; align-items: center; gap: 8px; margin: 3px 0; font-size: 13px; }
.dist b { flex: 0 0 14px; }
.dist i { display: block; height: 18px; background: var(--miss); border-radius: 3px; min-width: 18px; text-align: right; padding-right: 5px; font-style: normal; font-size: 12px; line-height: 18px; }
.dist i.me { background: var(--hit); color: #fff; }
.teams { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-height: 50vh; overflow-y: auto; }
.teams button { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 4px; font-size: 12px; font-weight: 700; cursor: pointer; color: var(--ink); }

.toast { position: fixed; left: 50%; top: 70px; transform: translateX(-50%) translateY(-10px); background: var(--accent); color: var(--accent-ink); padding: 10px 16px; border-radius: 10px; font-weight: 700; opacity: 0; pointer-events: none; transition: 0.2s; z-index: 10; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 480px) {
  .today a span { display: none; }
  .today a { padding: 6px 8px; font-size: 14px; }
}
@media (max-width: 420px) {
  .cell { font-size: 11px; min-height: 42px; }
  .cell.name { font-size: 11px; padding-left: 6px; }
  .tile { width: 44px; height: 44px; font-size: 20px; }
  .key { min-width: 26px; padding: 0 5px; }
}
