:root {
  --bg: #f6f3ee; --ink: #26231f; --muted: #6b655d; --card: #fffdf9; --line: #d9d3ca; --accent: #26231f;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1d1b19; --ink: #f1ece4; --muted: #a59d92; --card: #2a2724; --line: #423d38; --accent: #f1ece4; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; min-height: 100dvh; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); overscroll-behavior: none; }

.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 4px; max-width: 560px; width: 100%; margin: 0 auto; }
.title { text-align: center; }
h1 { margin: 0; font-size: 1.5rem; letter-spacing: 0.04em; }
.sub { font-size: 0.85rem; color: var(--muted); min-height: 1.1em; }

main { flex: 1; display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 560px; margin: 0 auto; padding: 0 12px 12px; }
.bar { display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 4px 0 8px; }
.legend svg { height: 30px; width: 131px; display: block; }
.timer { font-variant-numeric: tabular-nums; font-size: 1.1rem; color: var(--muted); }

.board-wrap { width: 100%; display: flex; justify-content: center; align-items: center; flex: 1; min-height: 0; }
#board { width: 100%; max-height: calc(100dvh - 250px); touch-action: none; user-select: none; -webkit-user-select: none; outline: none; border-radius: 16px; }
#board:focus-visible { box-shadow: 0 0 0 3px var(--accent); }
#board .off { stroke: #0002; stroke-width: 2; }
#board .on { stroke: #0002; stroke-width: 2; opacity: 0.55; }
#board .nextring { stroke: var(--ink); stroke-width: 4; stroke-dasharray: 10 8; }
.trail-under { fill: none; stroke: #fff; stroke-width: 26; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85; }
.trail { fill: none; stroke: #26231f; stroke-width: 14; stroke-linecap: round; stroke-linejoin: round; }
.trail.won { stroke: #1b7a4b; }
.head { fill: #fff; stroke: #26231f; stroke-width: 6; }
.mark-start { fill: none; stroke: #26231f; stroke-width: 7; }
.mark-halo { fill: none; stroke: #fff; stroke-width: 13; opacity: 0.85; }
svg .arrow { stroke: var(--muted); }
.mark-end { fill: none; stroke: #26231f; stroke-width: 7; }
.mark-end2 { fill: none; stroke: #26231f; stroke-width: 3; }
.shake { animation: shake 0.28s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }
@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }

.controls { display: flex; gap: 10px; margin-top: 10px; }
button, .button {
  font: inherit; font-size: 1rem; padding: 10px 18px; border-radius: 999px; border: 2px solid var(--line);
  background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; min-height: 44px;
}
button:hover, .button:hover { border-color: var(--ink); }
button:focus-visible, .button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
button.icon { width: 44px; height: 44px; padding: 0; font-size: 1.2rem; font-weight: 700; }
button.link { border: none; background: none; color: var(--muted); text-decoration: underline; }
button.wide { width: 100%; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 8px 16px;
  border-radius: 999px; opacity: 0; transition: opacity 0.2s; pointer-events: none; font-size: 0.95rem; white-space: nowrap; }
.toast.show { opacity: 1; }

dialog { border: none; border-radius: 20px; background: var(--card); color: var(--ink); padding: 22px 22px 12px; width: min(92vw, 400px); box-shadow: 0 10px 40px #0004; }
dialog::backdrop { background: #0006; }
dialog h2 { margin: 0 0 12px; }
dialog h3 { margin: 18px 0 8px; font-size: 1rem; color: var(--muted); }
dialog form { text-align: center; margin-top: 10px; }
.rules { padding-left: 1.3em; line-height: 1.6; margin: 0 0 10px; }
.inline-legend svg.inline { height: 1.3em; width: 5.7em; vertical-align: -0.3em; }
.inline-ico { height: 1.2em; width: 1.2em; vertical-align: -0.25em; }
.inline-ico .mark-start, .inline-ico .mark-end, .inline-ico .mark-end2 { stroke: var(--ink); }
.tip { text-align: center; font-size: 0.95rem; color: var(--muted); margin: 4px 0; }
.tip a, dialog p a { color: var(--ink); }
.tip a { display: inline-block; padding: 12px 4px; }
.foot { text-align: center; padding: 0 0 6px; }
.foot button.link { min-height: 44px; font-size: 0.85rem; }
.small { font-size: 0.85rem; color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin: 10px 0; }
#win-share { background: var(--bg); border-radius: 12px; padding: 10px; font-size: 1rem; line-height: 1.25; text-align: center; white-space: pre; overflow-x: auto; margin: 8px 0; }
.archive { display: grid; grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)); gap: 6px; max-height: 30vh; overflow-y: auto; }
.archive.empty { display: block; font-size: 0.95rem; color: var(--muted); }
.archive button { padding: 6px 0; min-height: 44px; font-size: 0.9rem; }
