:root {
  --bg: #ffffff;
  --panel: #f4f5f7;
  --field: #ffffff;
  --ink: #16181d;
  --ink-2: #5a606d;
  --line: #dcdfe5;
  --accent: #0b5cad;
  --accent-2: #7fb0e4;
  --ap: #2f8f5b;
  --bad: #c0362c;
  --good: #1f7a4a;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --panel: #1a1d23;
    --field: #22262d;
    --ink: #eceef2;
    --ink-2: #9ea4b0;
    --line: #2f343d;
    --accent: #5d9fe6;
    --accent-2: #2f5f93;
    --ap: #4cbf82;
    --bad: #ff7b70;
    --good: #5fcf94;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; }

/* The page scrolls; on a desktop the results stay in view beside the settings. */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "bar bar" "controls results";
  min-height: 100dvh;
  max-width: 1280px;
  margin: 0 auto;
}
.bar { grid-area: bar; display: flex; align-items: baseline; justify-content: space-between; padding: 14px 20px 10px; }
h1 { font-size: 1.35rem; margin: 0; }
.controls { grid-area: controls; padding: 0 12px 20px 20px; }
.results { grid-area: results; display: flex; flex-direction: column; position: sticky; top: 0; align-self: start; height: 100dvh; max-height: 100dvh; padding: 8px 20px 12px 12px; }

@media (max-width: 860px) {
  .app { display: block; height: auto; }
  .controls { padding: 0 16px 16px; }
  .results { position: static; height: auto; max-height: none; padding: 0 16px 16px; }
  .verdict { position: sticky; top: 0; z-index: 2; background: var(--bg); }
  .view { height: 300px; flex: none; }
}

.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 0; }

/* Segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel); border-radius: 8px; padding: 3px; margin-bottom: 10px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 7px 10px; border-radius: 6px; font-weight: 600; color: var(--ink-2); }
.seg input:checked + span { background: var(--field); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.seg.small { margin: 0; min-width: 170px; }
.seg.small span { padding: 5px 8px; }

/* Rows: label left, field right */
.rows { background: var(--panel); border-radius: 10px; padding: 2px 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 48px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row small { color: var(--ink-2); font-size: 0.75rem; margin-left: auto; }
.row small:empty { display: none; }
.row small button { padding: 0; }
[hidden] { display: none !important; }

.row input:not([type]), .row input[inputmode] {
  font: inherit; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right;
  color: var(--ink); background: var(--field); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 9px; width: 100%;
}
.num { max-width: 76px; }
.money, .pct { position: relative; display: block; }
.money { width: 170px; }
.pct { width: 96px; }
.money::before { content: "$"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--ink-2); font-weight: 600; }
.money input { padding-left: 22px !important; }
.pct::after { content: "%"; position: absolute; right: 9px; top: 50%; transform: translateY(-50%); color: var(--ink-2); font-weight: 600; }
.pct input { padding-right: 24px !important; }
input:focus-visible, summary:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.switch { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; cursor: pointer; margin: 0; flex: none; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

.advanced { margin-top: 10px; }
.advanced summary { cursor: pointer; font-weight: 600; padding: 10px 2px; color: var(--ink-2); }

/* Results */
.verdict { font-size: 1.6rem; font-weight: 700; padding: 6px 0 10px; }
.verdict.ok { color: var(--good); }
.verdict.short { color: var(--bad); }
.verdict small { display: block; font-size: 0.95rem; font-weight: 500; color: var(--ink-2); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin-bottom: 12px; }
.tile { background: var(--panel); border-radius: 10px; padding: 10px 12px; }
.tile b { display: block; font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.tile span { color: var(--ink-2); font-size: 0.8rem; }

.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: 8px 0; cursor: pointer; color: var(--ink-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--ink); }

.view { position: relative; flex: 1; min-height: 240px; margin-top: 8px; }
.chart { position: absolute; inset: 0; display: flex; flex-direction: column; }
.chart svg { flex: 1; width: 100%; min-height: 0; display: block; }
.chart text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.grid { stroke: var(--line); }
.marker { stroke: var(--ink-2); stroke-dasharray: 4 4; }
.runout { stroke: var(--bad); stroke-width: 1.5; }
.hover { stroke: var(--ink); stroke-width: 1; }
.a-super { fill: var(--accent-2); opacity: .9; }
.a-out { fill: var(--accent); opacity: .85; }
.b-ap { fill: var(--ap); }
.b-draw { fill: var(--accent); }
.b-short { fill: var(--bad); }

.legend { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; color: var(--ink-2); font-size: 0.8rem; padding-top: 4px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: -10px; }
.k-out, .k-draw { background: var(--accent); }
.k-super { background: var(--accent-2); }
.k-ap { background: var(--ap); }
.k-short { background: var(--bad); }

.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 6px; padding: 6px 8px; font-size: 0.8rem; line-height: 1.35; font-variant-numeric: tabular-nums; white-space: nowrap; transform: translate(-50%, -100%); }

.table-wrap { position: absolute; inset: 0; overflow: auto; }
table { border-collapse: collapse; width: 100%; font-size: 0.82rem; font-variant-numeric: tabular-nums; }
th, td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--bg); }
th:first-child, td:first-child { text-align: left; }
tr.short td { color: var(--bad); }

.fine { color: var(--ink-2); font-size: 0.75rem; margin: 8px 0 0; }

dialog { border: 0; border-radius: 12px; max-width: 520px; width: calc(100% - 32px); background: var(--bg); color: var(--ink); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 8px; font-size: 1.15rem; }
dialog li { margin-bottom: 6px; }
.btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 16px; cursor: pointer; font-weight: 600; }

/* Hover or tap a setting to see what it means. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10;
  background: var(--ink); color: var(--bg); border-radius: 8px; padding: 8px 10px;
  font-size: 0.85rem; font-weight: 400; line-height: 1.35; box-shadow: 0 4px 14px rgba(0,0,0,.2);
  pointer-events: none; opacity: 0; visibility: hidden; transition: opacity .12s;
}
[data-tip]:hover::after, [data-tip]:focus-within::after { opacity: 1; visibility: visible; transition-delay: .25s; }
