:root {
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    --bg: #e9eef5;
    --surface: #ffffff;
    --ink: #002147;
    --muted: #4a5f7a;
    --line: #c8d3e2;
    --curve: #002147;
    --fill: rgba(0,33,71,0.10);
    --bolt: #f2b705;
    --hit: #2e8b57;
    --focus: #1f4e8c;
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #001a38; --surface: #002147; --ink: #eaf0f8; --muted: #9db1cc;
      --line: #1c3d6b; --curve: #f2b705; --fill: rgba(242,183,5,0.12);
      --bolt: #f2b705; --hit: #4fb57a; --focus: #f2b705;
    }
  }
  :root[data-theme="dark"] {
    --bg: #001a38; --surface: #002147; --ink: #eaf0f8; --muted: #9db1cc;
      --line: #1c3d6b; --curve: #f2b705; --fill: rgba(242,183,5,0.12);
      --bolt: #f2b705; --hit: #4fb57a; --focus: #f2b705;
  }
  html { scroll-padding-top: env(safe-area-inset-top, 0px); }
  * { box-sizing: inherit; }
  body {
    margin: 0; background: var(--bg); color: var(--ink);
    font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
    font-size: 16px; line-height: 1.5;
    font-feature-settings: "tnum" 1;
  }
  main { max-width: 34rem; margin: 0 auto; padding: 1rem 1rem 3rem; }
  .topbar { border-bottom: 1px solid var(--line); background: var(--bg); }
  .topbar-inner { max-width: 60rem; margin: 0 auto; padding: .55rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
  .icons { display: flex; gap: .25rem; }
  .icon-btn { width: 2.4rem; height: 2.4rem; border: 0; background: none; color: var(--ink); border-radius: 50%; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
  .icon-btn svg { width: 1.45rem; height: 1.45rem; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .icon-btn:hover { background: var(--fill); }
  .icon-btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .meta { text-align: center; color: var(--muted); font-size: .85rem; margin: .5rem 0 .75rem; letter-spacing: .04em; text-transform: uppercase; }
  h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; margin: 0; display: flex; align-items: center; gap: .1rem; }
  h1 .bolt { width: 1.1em; height: 1.1em; display: inline-block; margin: 0 -.05em 0 -.02em; filter: drop-shadow(0 0 4px rgba(242,183,5,.55)); }
  h1 .le { color: var(--bolt); }
  button { font: inherit; }
  .chart-wrap { background: var(--surface); border: 2px solid var(--curve); border-top-width: 6px; padding: .75rem .5rem .35rem; }
  .chart-wrap svg { width: 100%; height: auto; display: block; }
  .chart-cap { color: var(--curve); font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin: .4rem .5rem .1rem; text-align: center; }
  .chart-cap .sun { color: var(--bolt); }
  #chartSvg { touch-action: pan-y; }
  .curve-anim { stroke-dasharray: 2000; stroke-dashoffset: 2000; animation: draw 1.1s ease-out forwards; }
  @keyframes draw { to { stroke-dashoffset: 0; } }
  @media (prefers-reduced-motion: reduce) { .curve-anim { animation: none; stroke-dashoffset: 0; } }

  .hints { margin: 1rem 0 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
  .hints button { border: 1px solid var(--line); background: transparent; border-radius: 0; padding: .25rem .75rem; font-size: .85rem; color: var(--muted); cursor: default; }
  .hints button.ready { color: var(--ink); border-color: var(--bolt); background: rgba(242,183,5,0.12); cursor: pointer; }
  .hints button.ready:hover { background: rgba(242,183,5,0.25); }
  .hints button.shown { color: var(--ink); border-color: var(--ink); cursor: default; }
  .hints button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

  .guess-area { margin-top: 1rem; position: relative; }
  .guess-area input {
    width: 100%; font: inherit; font-size: 1.05rem; padding: .7rem .9rem;
    border: 2px solid var(--line); border-radius: 0; background: var(--surface); color: var(--ink); text-align: center;
  }
  .guess-area input:focus { outline: 2px solid var(--focus); outline-offset: 1px; border-color: transparent; }
  .sugg { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface);
    border: 2px solid var(--line); border-top: 0; overflow: hidden; z-index: 5; display: none; }
  .sugg button { display: block; width: 100%; text-align: left; padding: .55rem .9rem; border: 0; background: none; color: var(--ink); cursor: pointer; }
  .sugg button:hover, .sugg button:focus { background: var(--fill); outline: none; }

  .rows { margin-top: .5rem; display: grid; gap: .35rem; }
  .row {
    display: grid; grid-template-columns: 1.4rem 1fr auto auto; align-items: center; gap: .6rem;
    background: var(--surface); border: 2px solid var(--line); padding: .5rem .8rem; min-height: 3rem;
    position: relative; overflow: hidden;
  }
  .row .bar { position: absolute; left: 0; top: 0; bottom: 0; background: var(--fill); z-index: 0; }
  .row > * { position: relative; z-index: 1; }
  .row .n { color: var(--muted); font-size: .85rem; }
  .row .name { font-weight: 600; }
  .row .dist { color: var(--muted); font-size: .9rem; white-space: nowrap; }
  .row .dir { font-size: 1.1rem; width: 1.6rem; text-align: center; }
  .row.hit { border-color: var(--hit); background: var(--hit); color: #fff; }
  .row.hit .n, .row.hit .dist { color: rgba(255,255,255,.85); }
  .row.hit .bar { background: rgba(46,139,87,0.15); }
  .row.hit .dir { color: #fff; }
  .row.empty { background: transparent; }
  .row.empty .n { opacity: 0; }

  .result { margin-top: 1.1rem; background: var(--surface); border: 2px solid var(--line); padding: 1rem; }
  .result h2 { font-size: 1.15rem; margin: 0 0 .35rem; }
  .result p { margin: .35rem 0; }
  .why { color: var(--muted); }
  .actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
  .btn { border: 1.5px solid var(--ink); background: var(--ink); color: var(--bg); border-radius: 999px; padding: .5rem 1rem; cursor: pointer; font-weight: 600; }
  .btn.quiet { background: transparent; color: var(--ink); }
  .btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
    background: var(--ink); color: var(--bg); padding: .5rem .9rem; border-radius: 999px; font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; }
  .toast.show { opacity: 1; }
  footer { margin-top: 3rem; color: var(--muted); font-size: .75rem; line-height: 1.5; text-align: center; }
  footer a { color: inherit; }
  /* modals */
  dialog { border: 0; padding: 0; background: transparent; max-width: min(92vw, 30rem); width: 100%; }
  dialog::backdrop { background: rgba(0,0,0,.45); }
  .modal { background: var(--surface); color: var(--ink); padding: 1.5rem 1.5rem 1.25rem; border: 2px solid var(--line); position: relative; }
  .modal h2 { margin: 0 0 .75rem; font-size: 1.05rem; letter-spacing: .06em; text-transform: uppercase; text-align: center; }
  .modal p { margin: .5rem 0; font-size: .95rem; }
  .modal .close { position: absolute; top: .6rem; right: .6rem; }
  .statgrid { display: flex; justify-content: center; gap: 1.25rem; margin: .25rem 0 1rem; text-align: center; }
  .statgrid b { display: block; font-size: 1.6rem; font-weight: 500; }
  .statgrid span { font-size: .7rem; color: var(--muted); }
  .dist { display: grid; gap: .3rem; margin-top: .5rem; }
  .dist .drow { display: grid; grid-template-columns: 1rem 1fr; gap: .5rem; align-items: center; font-size: .85rem; }
  .dist .dbar { background: var(--muted); color: #fff; padding: .1rem .4rem; min-width: 1.2rem; text-align: right; font-weight: 600; box-sizing: border-box; }
  .dist .dbar.me { background: var(--hit); }
  .setting { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 0; border-bottom: 1px solid var(--line); }
  .setting:last-child { border-bottom: 0; }
  .setting small { display: block; color: var(--muted); font-size: .8rem; }
  .setting select { font: inherit; padding: .3rem .5rem; background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
  .switch { width: 2.6rem; height: 1.4rem; border-radius: 999px; border: 0; background: var(--line); position: relative; cursor: pointer; flex: none; }
  .switch::after { content: ""; position: absolute; top: .15rem; left: .15rem; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: #fff; transition: left .15s; }
  .switch[aria-checked="true"] { background: var(--hit); }
  .switch[aria-checked="true"]::after { left: 1.35rem; }
