:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --border: #dedcd5;
  --accent: #2f7d5b;
  --accent-text: #ffffff;
  --shape: #1d1f23;
  --row: #ffffff;
  --hit: #2f7d5b;
  --bar: #9aa0a6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1f2226;
    --text: #eceae4;
    --muted: #9a9ea5;
    --border: #33373d;
    --accent: #4fb388;
    --accent-text: #0c1310;
    --shape: #eceae4;
    --row: #24282d;
    --hit: #4fb388;
    --bar: #5c6168;
    color-scheme: dark;
  }
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button { font: inherit; color: inherit; cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  font-weight: 800;
}
.topbar h1 span { color: var(--accent); }

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  font-weight: 700;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px 48px;
}

.day-label {
  margin: 0 0 8px;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.shape-card {
  margin: 0 0 16px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

#shape {
  display: block;
  width: 100%;
  max-height: 46vh;
}

#shape-path {
  fill: var(--shape);
  stroke: var(--shape);
  stroke-width: 1.2;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

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

.guesses li {
  display: grid;
  grid-template-columns: 1fr 84px 38px 62px;
  gap: 6px;
  min-height: 40px;
}

.guesses li > span {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  background: var(--row);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  white-space: nowrap;
}

.guesses li > span:first-child {
  justify-content: flex-start;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 600;
}

.guesses li.empty > span { background: transparent; }
.guesses li.empty { grid-template-columns: 1fr; }

.guesses li.hit > span {
  background: var(--hit);
  border-color: var(--hit);
  color: var(--accent-text);
}

.guesses li.new > span { animation: pop 0.35s ease-out both; }
.guesses li.new > span:nth-child(2) { animation-delay: 0.08s; }
.guesses li.new > span:nth-child(3) { animation-delay: 0.16s; }
.guesses li.new > span:nth-child(4) { animation-delay: 0.24s; }

@keyframes pop {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .guesses li.new > span { animation: none; }
}

.guess-form {
  display: flex;
  gap: 8px;
}

.combo {
  position: relative;
  flex: 1;
}

#guess-input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

#guess-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 4px);
  z-index: 5;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
}

.suggestions li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
}

.suggestions li[aria-selected="true"],
.suggestions li:hover {
  background: var(--accent);
  color: var(--accent-text);
}

.primary {
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}

.result {
  text-align: center;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.result-title { margin: 0; font-size: 1.15rem; font-weight: 700; }
.result-answer { margin: 4px 0 8px; font-size: 1.4rem; font-weight: 800; }
.result-links { display: flex; gap: 16px; justify-content: center; margin: 0 0 12px; }
.result-links a { color: var(--accent); font-weight: 600; }
.countdown { margin: 12px 0 0; color: var(--muted); }
.countdown strong { color: var(--text); font-variant-numeric: tabular-nums; }

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin-top: 0; }
dialog h3 { font-size: 0.95rem; margin: 16px 0 8px; }
dialog form { margin-top: 16px; text-align: right; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  text-align: center;
}
.stats-grid strong { display: block; font-size: 1.6rem; }
.stats-grid span { font-size: 0.75rem; color: var(--muted); }

.dist { display: grid; gap: 4px; }
.dist-row { display: grid; grid-template-columns: 16px 1fr; gap: 8px; align-items: center; font-size: 0.85rem; }
.dist-bar {
  min-width: 24px;
  padding: 1px 6px;
  text-align: right;
  background: var(--bar);
  color: #fff;
  border-radius: 3px;
}
.dist-bar.current { background: var(--accent); color: var(--accent-text); }

.toast {
  position: fixed;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  padding: 8px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: 8px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
