:root {
  --bg: #f6f3ec;
  --card: #fffdf8;
  --ink: #1f1d18;
  --muted: #6d675b;
  --line: #e3ddd0;
  --a: #13857b;
  --b: #e4573d;
  --a-fill: rgba(19, 133, 123, .45);
  --b-fill: rgba(228, 87, 61, .5);
  --stage: #fbf9f4;
  --grid: rgba(31, 29, 24, .05);
  --ground: #b9b1a1;
  --good: #2f9e5b;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --card: #1d2024;
    --ink: #ecebe6;
    --muted: #a19d93;
    --line: #2e3238;
    --a: #3cc2b3;
    --b: #ff7a5e;
    --a-fill: rgba(60, 194, 179, .42);
    --b-fill: rgba(255, 122, 94, .48);
    --stage: #1a1d21;
    --grid: rgba(255, 255, 255, .04);
    --ground: #4b5058;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.top {
  max-width: 860px; width: 100%; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 6px;
}
.logo {
  color: var(--ink); text-decoration: none; font-weight: 800; font-size: 1.25rem; letter-spacing: -.01em;
  display: inline-flex; align-items: center;
}
.logo em { font-style: normal; font-weight: 500; color: var(--muted); margin: 0 .3em; }
.logo .dot { width: 18px; height: 18px; border-radius: 50%; display: inline-block; }
.logo .dot.a { background: var(--a); opacity: .85; }
.logo .dot.b { background: var(--b); opacity: .85; width: 12px; height: 12px; margin: 0 10px 0 -6px; align-self: flex-end; margin-bottom: 4px; }
.lang { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang button { border: 0; background: transparent; padding: 4px 10px; font-size: .85rem; font-weight: 600; color: var(--muted); }
.lang button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

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

#menu { padding-bottom: 12px; }
.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; margin: 28px 0 26px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.08; letter-spacing: -.02em; margin: 0 0 14px; }
.intro { font-size: 1.15rem; margin: 0; max-width: 34em; color: var(--muted); }
.hero-art { position: relative; width: 190px; height: 170px; }
.hero-art span { position: absolute; border-radius: 50%; }
.hero-art .big { width: 150px; height: 150px; left: 0; top: 0; background: var(--a-fill); border: 2px solid var(--a); }
.hero-art .small { width: 78px; height: 78px; right: 0; bottom: 0; background: var(--b-fill); border: 2px solid var(--b); }
.hero-art .q { right: 26px; bottom: 18px; font-size: 2.2rem; font-weight: 800; color: var(--b); }
.diff-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 16px; }
.diff-label { font-weight: 700; }
.diff { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; background: var(--card); }
.diff button { border: 0; background: transparent; padding: 8px 20px; font-weight: 700; color: var(--muted); }
.diff button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }
.diff-note { color: var(--muted); font-size: .92rem; }
.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.mode {
  text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  padding: 24px 22px 20px; display: flex; flex-direction: column; gap: 4px; min-height: 210px;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.mode:hover, .mode:focus-visible { transform: translateY(-3px); border-color: var(--a); outline: none; box-shadow: 0 8px 22px rgba(0,0,0,.08); }
.mode svg { width: 64px; height: 64px; fill: var(--a); stroke: var(--b); margin-bottom: 10px; }
.mode strong { font-size: 1.45rem; }
.mode small { color: var(--muted); font-size: .98rem; }
.steps { list-style: none; padding: 0; margin: 30px 0 8px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; color: var(--muted); font-size: .95rem; }
.steps b { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: var(--line); color: var(--ink); }
.mode .best { font-style: normal; font-size: .9rem; color: var(--a); font-weight: 700; min-height: 1.2em; margin-top: auto; padding-top: 10px; }

.hud { display: flex; align-items: center; gap: 10px; margin-top: 6px; color: var(--muted); font-weight: 600; font-size: .9rem; }
.hud #quit { margin-left: auto; }
#extreme { background: var(--b); color: #fff; border-radius: 999px; padding: 1px 10px; font-size: .8rem; }
.ghost { background: transparent; border: 0; color: var(--muted); font-size: 1.1rem; padding: 4px 8px; border-radius: 8px; }
.ghost:hover { background: var(--line); }

h2 { font-size: 1.3rem; margin: 6px 0 8px; line-height: 1.3; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-bottom: 8px; font-size: .95rem; }
.legend small { color: var(--muted); }
.chip { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chip.a { background: var(--a); }
.chip.b { background: var(--b); }

#stage {
  position: relative; width: 100%; height: min(58vh, 480px); min-height: 260px;
  background-color: var(--stage);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px), linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 32px 32px;
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
}
#stage.space { background: radial-gradient(ellipse at 30% 20%, #1b2340 0%, #0a0d18 70%); border-color: #1d2333; }
#stage.space::before {
  content: ""; position: absolute; inset: 0; opacity: .7; pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 12% 18%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 72% 34%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 38% 76%, #cfe0ff 50%, transparent 51%), radial-gradient(1.5px 1.5px at 88% 82%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 55% 12%, #ffe9c4 50%, transparent 51%), radial-gradient(1px 1px at 22% 58%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 93% 8%, #fff 50%, transparent 51%), radial-gradient(1px 1px at 5% 92%, #fff 50%, transparent 51%);
}
#svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
#svg.dragging { cursor: grabbing; }
#svg .a { fill: var(--a-fill); stroke: var(--a); }
#svg .b { fill: var(--b-fill); stroke: var(--b); }
#svg .shape { stroke-width: 1.2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
#svg .ghost-shape { vector-effect: non-scaling-stroke; fill: none; stroke: var(--b); stroke-width: 1.6; stroke-dasharray: 5 4; }
#svg .ground { stroke: var(--ground); stroke-width: 1.5; }
#svg .marker { fill: none; stroke-width: 2; }
#svg .marker.a { stroke: var(--a); }
#svg .marker.b { stroke: var(--b); }
#svg .body-b { opacity: .72; }
#svg .ring-b { fill: none; stroke: var(--b); stroke-width: 2; }
#svg .ring-a { fill: none; stroke: var(--a); stroke-width: 1.5; opacity: .9; }
#handle {
  position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%;
  background: var(--card); border: 3px solid var(--b); box-shadow: 0 2px 6px rgba(0,0,0,.25);
  cursor: nesw-resize; touch-action: none;
}
#handle::after { content: "⤡"; position: absolute; inset: 0; display: grid; place-items: center; font-size: 15px; color: var(--b); font-weight: 700; }

.controls { display: flex; align-items: center; gap: 10px; margin: 12px 0 4px; }
.round-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--card);
  font-size: 1.5rem; line-height: 1; font-weight: 600;
}
.round-btn:active { transform: scale(.94); }
#slider { flex: 1; accent-color: var(--b); height: 32px; }
.guess { text-align: center; font-weight: 600; margin: 4px 0 8px; min-height: 1.5em; }

.result { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 6px 0 10px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; margin-top: 10px; }
.card { border-top: 1px solid var(--line); padding-top: 8px; font-size: .92rem; }
.card .sub { color: var(--muted); }
.card p { margin: 4px 0; }
.card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0 0; }
.card dt { color: var(--muted); }
.card dd { margin: 0; }
.result .line { display: flex; flex-wrap: wrap; gap: 4px 16px; align-items: baseline; }
.result .acc { font-size: 1.6rem; font-weight: 800; }
.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--good); width: 0; transition: width .6s ease; }

.actions { display: flex; gap: 10px; justify-content: center; margin: 10px 0 24px; flex-wrap: wrap; }
.primary, .secondary {
  border-radius: 999px; padding: 12px 28px; font-weight: 700; font-size: 1.05rem; border: 0; min-width: 160px;
}
.primary { background: var(--ink); color: var(--bg); }
.primary:hover { opacity: .9; }
.secondary { background: transparent; border: 1px solid var(--line); }

#summary { text-align: center; }
.score { margin: 10px 0 0; }
.score span { font-size: 3.4rem; font-weight: 800; display: block; line-height: 1.1; }
.score small { color: var(--muted); }
.rating { font-size: 1.15rem; font-weight: 600; margin: 8px 0; }
.newbest { color: var(--good); font-weight: 700; }
.rounds { list-style: none; padding: 0; margin: 18px auto; max-width: 520px; text-align: left; }
.rounds li { display: grid; grid-template-columns: 1fr 70px 44px; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: .93rem; }
.rounds .bar { margin: 0; }
.rounds b { text-align: right; }

footer { text-align: center; padding: 8px 16px 18px; }
.copy { margin: 6px 0 0; color: var(--muted); font-size: .8rem; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: .9rem; }

dialog {
  max-width: 640px; width: calc(100% - 32px); max-height: 85vh; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); padding: 18px 20px;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .close { position: sticky; top: 0; float: right; }
dialog h3 { margin: 4px 0 8px; }
dialog h4 { margin: 18px 0 4px; }
dialog p, dialog li { font-size: .92rem; }
dialog ul { padding-left: 18px; }
dialog a { color: var(--a); }

@media (max-width: 620px) {
  .hero { grid-template-columns: 1fr; margin-top: 16px; }
  .hero-art { display: none; }
  .mode { min-height: 0; }
}
@media (max-width: 520px) {
  .logo { font-size: 1.05rem; }
  h2 { font-size: 1.1rem; }
  #stage { height: 52vh; }
  .primary, .secondary { min-width: 0; flex: 1; }
}
