:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #161a22;
  --muted: #697184;
  --line: #e1e4ea;
  --code-bg: #0f1117;
  --code-ink: #dfe5f0;
  --code-num: #4b5366;
  --bar: #2a3040;
  --accent: #10b981;
  --accent-ink: #ffffff;
  --win: #22c55e;
  --family: #eab308;
  --miss: #3f4656;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12;
    --card: #151922;
    --ink: #e8ecf3;
    --muted: #9099ab;
    --line: #262c39;
    --code-bg: #10131a;
    --accent: #38e0a8;
    --accent-ink: #0b0d12;
    --miss: #4a5163;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

button { font: inherit; cursor: pointer; }
a { color: var(--accent); }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}

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

.mark {
  background: var(--accent);
  color: var(--accent-ink);
  font: 800 14px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  border-radius: 7px;
  padding: 5px 6px;
}

.name { font: 700 22px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: -0.03em; }
.name b { color: var(--accent); }

.right { display: flex; gap: 4px; }

.icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-weight: 700;
}

main {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px 10px;
  flex: 1;
}

.day { margin: 0; color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.title { font-size: clamp(22px, 5.5vw, 28px); letter-spacing: -0.01em; margin: 4px 0 12px; }

.code {
  background: var(--code-bg);
  color: var(--code-ink);
  border-radius: 14px;
  padding: 12px 0;
  font: 13.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  overflow-x: auto;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.04) inset, 0 8px 30px rgb(0 0 0 / 0.18);
}

@media (max-width: 480px) {
  .code { font-size: 12px; }
  .num { width: 3.5ch; padding-right: 1.2ch; }
}

.row { display: flex; min-height: 1.6em; padding-right: 14px; white-space: pre; width: max-content; min-width: 100%; }

.num {
  flex: none;
  width: 4.5ch;
  padding-right: 1.5ch;
  text-align: right;
  color: var(--code-num);
  user-select: none;
}

.text { animation: none; }
.text.new { animation: reveal 600ms ease-out; }

@keyframes reveal {
  from { background: rgb(56 224 168 / 0.25); }
  to { background: transparent; }
}

.blur {
  display: inline-block;
  height: 0.7em;
  margin-top: 0.45em;
  border-radius: 4px;
  background: var(--bar);
}

.left { color: var(--muted); font-size: 14px; margin: 10px 2px; }

.guess { display: flex; gap: 8px; margin-top: 4px; }

.combo { position: relative; flex: 1; min-width: 0; }

.combo input {
  width: 100%;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 12px;
  font: 600 18px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: 13px 12px;
  outline: none;
}

.combo input:focus { border-color: var(--accent); }

.matches {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 5;
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 240px;
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.25);
}

.matches li { padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.matches li.active { background: var(--accent); color: var(--accent-ink); font-weight: 700; }

#guess-btn {
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  padding: 0 18px;
}

.ghost {
  border: 2px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  padding: 0 12px;
}

.guesses { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }

.guesses li {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 12px;
  padding: 8px 12px;
  animation: pop 220ms ease-out;
}

.guesses li.win { border-left-color: var(--win); }
.guesses li.family { border-left-color: var(--family); }
.guesses li.miss, .guesses li.skip { border-left-color: var(--miss); }
.guesses .badge { grid-row: span 2; font-size: 20px; }
.guesses .value { font-weight: 700; }
.guesses .hint { color: var(--muted); font-size: 14px; }

@keyframes pop {
  from { transform: scale(0.97); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result {
  margin-top: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}

.verdict { margin: 0; font-weight: 800; font-size: 19px; }
.answer { margin: 2px 0 6px; font: 800 30px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--accent); }
.source { margin: 0 0 14px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }

.share-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

#share {
  border: 0;
  border-radius: 12px;
  background: var(--win);
  color: white;
  font-weight: 800;
  padding: 11px 26px;
}

.next { color: var(--muted); font-size: 14px; }

footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
}

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  width: min(460px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 20px;
}

dialog::backdrop { background: rgb(0 0 0 / 0.5); }
dialog h2 { margin: 0 0 10px; }
dialog h3 { margin: 16px 0 8px; font-size: 15px; }
dialog p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 14px; }

.legend { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; }
.legend span { display: inline-block; width: 28px; }

details { margin: 0 0 12px; }
summary { cursor: pointer; font-weight: 700; font-size: 15px; }
.families { margin: 8px 0 0; font-size: 14px; }
.families dt { font-weight: 700; margin-top: 6px; }
.families dd { margin: 0; color: var(--muted); }

.close {
  width: 100%;
  margin-top: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
  padding: 11px;
}

.numbers { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.numbers b { display: block; font-size: 28px; }
.numbers span { font-size: 12px; color: var(--muted); }

.spread { display: grid; gap: 4px; }
.spread div { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.spread i { display: block; background: var(--miss); color: white; font-style: normal; text-align: right; padding: 0 6px; border-radius: 4px; min-width: 22px; }
.spread i.today { background: var(--win); }

.days { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; max-height: 50vh; overflow: auto; }
.days a {
  display: block;
  text-align: center;
  padding: 8px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
}
.days a.won { border-color: var(--win); }
.days a.lost { border-color: #e0483e; }
.days small { display: block; font-size: 16px; line-height: 1; }

.toast {
  position: fixed;
  left: 50%;
  top: 70px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 15px;
  z-index: 10;
}

[hidden] { display: none !important; }
