/* ATS Sights — hand-rolled stylesheet, no external dependencies.
   Light theme is the default: high ambient light on a course washes out
   dark UIs, so daylight readability wins. Dark mode follows the system. */

:root {
    --paper: #f2f5f0;
    --card: #ffffff;
    --ink: #16211a;
    --muted: #5e6c61;
    --line: #dce3da;
    --field: #1a5632;   /* ATS brand green — Field round */
    --hunter: #a83c28;  /* Hunter round */
    --animal: #8f6d10;  /* Animal round */
    --danger: #c22a20;
    --ok: #1a5632;
    --theme: var(--field);
    --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(22, 33, 26, .06), 0 4px 14px rgba(22, 33, 26, .05);
}
body[data-round="Hunter"] { --theme: var(--hunter); }
body[data-round="Animal"] { --theme: var(--animal); }

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #0f1512;
        --card: #1a231c;
        --ink: #e9efe9;
        --muted: #9aab9d;
        --line: #2b372e;
        --field: #4fae77;
        --hunter: #e0705a;
        --animal: #d5a53a;
        --danger: #e25848;
        --ok: #4fae77;
        --shadow: none;
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--sans);
    background: var(--paper);
    color: var(--ink);
    line-height: 1.45;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
:focus-visible { outline: 2px solid var(--theme); outline-offset: 2px; border-radius: 4px; }
:disabled { opacity: .45; cursor: not-allowed; }
code {
    font-family: var(--mono); font-size: .85em;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: 4px; padding: 0 .3em;
}

/* ---------- Top bar ---------- */
.topbar {
    display: flex; align-items: center; gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky; top: 0; z-index: 30;
}
.topbar-logo { background: #fff; border-radius: 8px; padding: 2px; border: 1px solid var(--line); }
.topbar-title { display: flex; flex-direction: column; line-height: 1.15; }
.wordmark {
    font-weight: 800; font-size: 1.05rem;
    letter-spacing: .09em; text-transform: uppercase;
}
.topbar-sub { font-size: .68rem; color: var(--muted); letter-spacing: .04em; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.topbar-right .iconbtn { width: 36px; height: 36px; border-radius: 99px; }
.offline-badge {
    font-size: .68rem; font-weight: 700;
    color: var(--animal); border: 1px solid currentColor;
    border-radius: 99px; padding: 2px 9px;
}

/* ---------- Layout ---------- */
#app { max-width: 880px; margin: 0 auto; padding: 14px 14px 8px; }
.view { display: flex; flex-direction: column; gap: 14px; }
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}
.card-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
}
.card-head h2 { font-size: 1.05rem; font-weight: 800; letter-spacing: .01em; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.eyebrow {
    display: block;
    font-size: .66rem; font-weight: 800;
    letter-spacing: .12em; text-transform: uppercase;
    color: var(--muted); margin-bottom: 4px;
}
.hint { font-size: .8rem; color: var(--muted); margin: 8px 0; }
.hint.warn { color: var(--animal); font-weight: 600; }

/* ---------- Fields ---------- */
.field { display: block; min-width: 0; }
.field.grow, .grow { flex: 1 1 0; }
select, input[type="text"], input[type="number"] {
    width: 100%;
    font: inherit; color: var(--ink);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px 10px;
    min-height: 42px;
}
select:focus, input:focus { outline: 2px solid var(--theme); outline-offset: -1px; }
.ctx-row, .manage-row { display: flex; gap: 10px; align-items: flex-end; }
.manage-row { margin-bottom: 10px; }
.manage-row:last-child { margin-bottom: 0; }
.settings-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 10px; }
.settings-row > * { flex: 1 1 150px; }
.settings-row > .field.wide { flex-basis: 100%; }
.settings-row.three { margin-top: 0; margin-bottom: 10px; }
.field.slope { flex: 0 0 88px; }

/* ---------- Segmented controls ---------- */
.seg { display: flex; gap: 6px; margin-top: 12px; }
.seg.small { margin-top: 0; }
.seg.wrap { flex-wrap: wrap; }
.seg button {
    flex: 1 1 0;
    padding: 9px 10px;
    font-weight: 700; font-size: .88rem;
    border: 1px solid var(--line);
    border-radius: 9px;
    color: var(--muted);
    background: var(--card);
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
}
.seg.small button { padding: 7px 12px; flex: 0 1 auto; }
.seg button.active { background: var(--theme); border-color: var(--theme); color: #fff; }
.seg.neutral button.active { background: var(--ink); border-color: var(--ink); color: var(--paper); }
/* round identity colors on inactive chips too — color supports, text identifies */
.seg button[data-val="Field"].active  { background: var(--field);  border-color: var(--field); }
.seg button[data-val="Hunter"].active { background: var(--hunter); border-color: var(--hunter); }
.seg button[data-val="Animal"].active { background: var(--animal); border-color: var(--animal); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font-weight: 800; letter-spacing: .02em;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 11px 16px;
    background: var(--card);
    color: var(--ink);
    transition: filter .15s, background .15s;
}
.btn.primary { background: var(--theme); border-color: var(--theme); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost:hover { background: var(--paper); }
.btn.small { padding: 7px 12px; font-size: .8rem; }
.btn.block { width: 100%; }
.danger-text { color: var(--danger); }
.iconbtn {
    flex: 0 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    width: 42px; height: 42px;
    border: 1px solid var(--line); border-radius: 9px;
    color: var(--muted); background: var(--card);
}
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn:hover { background: var(--paper); }
.iconbtn.danger { color: var(--danger); }
.iconbtn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.iconbtn.small { width: 34px; height: 34px; }

/* ---------- Shoot view ---------- */
.target-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.target-num {
    font-family: var(--mono); font-weight: 700;
    font-size: clamp(2.6rem, 12vw, 3.6rem);
    line-height: 1; letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}
.target-total { font-size: .38em; color: var(--muted); font-weight: 600; margin-left: 2px; }
.jumper { flex: 0 0 auto; width: 128px; }

/* Signature: the mark list reads like a sight tape — ruled tick edge,
   engraved mono numerals in the round color. */
.tape-list { margin-top: 14px; border-top: 1px solid var(--line); }
.tape-row {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 4px 10px 18px;
    border-bottom: 1px solid var(--line);
    background:
        repeating-linear-gradient(to bottom,
            var(--line) 0 1px, transparent 1px 7px)
        left top / 8px calc(100% - 1px) no-repeat;
}
.tape-row .dist { font-weight: 800; font-size: 1.15rem; }
.tape-row .dist small { color: var(--muted); font-weight: 600; font-size: .72em; margin-left: 2px; }
.tape-row .dist .sub { display: block; font-size: .66rem; font-weight: 700; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.tape-row .mark {
    font-family: var(--mono); font-weight: 700;
    font-size: clamp(1.9rem, 9vw, 2.7rem);
    color: var(--theme);
    font-variant-numeric: tabular-nums;
    letter-spacing: -.01em;
    line-height: 1.1;
}
.tape-row .mark.blank { color: var(--muted); }
.tape-row.manual .mark { color: var(--ink); }
.tape-row .flag {
    font-size: .62rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); border: 1px solid var(--line);
    padding: 1px 7px; border-radius: 99px; margin-left: 8px;
}
.tape-row .flag.est { color: var(--animal); border-color: var(--animal); }
.tape-empty { padding: 22px 4px; color: var(--muted); text-align: center; }

.pager { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; }
.pager-btn { min-height: 62px; font-size: 1.15rem; }

/* ---------- Course editor ---------- */
.editor-grid { display: grid; grid-template-columns: 1fr; gap: 10px; max-height: 62vh; overflow-y: auto; padding-right: 2px; }
@media (min-width: 720px) { .editor-grid { grid-template-columns: 1fr 1fr; } }
.target-block { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.target-block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.target-block-head .tnum { font-weight: 800; font-size: .92rem; }
.shot-row { display: grid; grid-template-columns: 1fr 1fr 34px; gap: 8px; margin-bottom: 8px; align-items: center; }
.shot-row:last-child { margin-bottom: 0; }
.shot-row input { min-height: 38px; padding: 7px 9px; }
.shot-row .mark-in { font-family: var(--mono); }
.shot-row .mark-in:placeholder-shown { color: var(--theme); }
.shot-row .mark-in::placeholder { color: var(--theme); opacity: .85; }
.shot-row .mark-in.manual { color: var(--ink); font-weight: 700; }

/* ---------- Bow view ---------- */
.advanced { margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 10px; }
.advanced summary { font-weight: 700; font-size: .85rem; color: var(--muted); cursor: pointer; }
.marks-list { margin-top: 10px; }
.mark-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 4px 9px 14px;
    border-bottom: 1px solid var(--line);
    background:
        repeating-linear-gradient(to bottom,
            var(--line) 0 1px, transparent 1px 7px)
        left top / 6px calc(100% - 1px) no-repeat;
}
.mark-item:first-child { border-top: 1px solid var(--line); }
.mark-item .d { font-weight: 800; min-width: 74px; }
.mark-item .d small { color: var(--muted); font-weight: 600; }
.mark-item .m { font-family: var(--mono); font-weight: 700; font-size: 1.25rem; color: var(--theme); font-variant-numeric: tabular-nums; }
.mark-item .resid { margin-left: auto; font-size: .72rem; font-family: var(--mono); color: var(--muted); }
.mark-item .resid.outlier { color: var(--danger); font-weight: 700; }
.mark-item .del { flex: 0 0 auto; }

.chart { margin-top: 12px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-label { fill: var(--muted); font-size: 10px; font-family: var(--sans); }
.chart .curve { stroke: var(--theme); stroke-width: 2; fill: none; }
.chart .pt { fill: var(--ink); stroke: var(--card); stroke-width: 1.5; }
.chart .pt.outlier { fill: var(--danger); }

.quick-out { text-align: center; padding: 14px 0 6px; }
.quick-mark {
    font-family: var(--mono); font-weight: 700;
    font-size: clamp(2.6rem, 13vw, 3.4rem);
    color: var(--theme); line-height: 1.05;
    font-variant-numeric: tabular-nums;
}

.tape-unit { text-transform: none; }

/* ---------- Tab bar ---------- */
.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.tab {
    flex: 1;
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    padding: 9px 0 7px;
    font-size: .68rem; font-weight: 700; letter-spacing: .04em;
    color: var(--muted);
    border-top: 2px solid transparent;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--theme); border-top-color: var(--theme); }

/* ---------- Toast ---------- */
#toast {
    position: fixed; top: 12px; left: 50%;
    transform: translate(-50%, -140%);
    z-index: 60;
    max-width: min(92vw, 420px);
    padding: 11px 18px;
    border-radius: 10px;
    background: var(--ink); color: var(--paper);
    font-weight: 700; font-size: .88rem; text-align: center;
    transition: transform .25s ease, opacity .25s ease;
    opacity: 0;
    pointer-events: none;
}
#toast.show { transform: translate(-50%, 0); opacity: 1; }
#toast.ok { background: var(--ok); color: #fff; }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- Tape overlay & print ---------- */
#tapeOverlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(10, 16, 12, .55);
    overflow: auto;
    display: flex; flex-direction: column; align-items: center;
}
.overlay-bar {
    position: sticky; top: 0; z-index: 2;
    width: 100%;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    background: var(--card);
    border-bottom: 1px solid var(--line);
    padding: 10px 14px;
}
.overlay-note { font-size: .72rem; color: var(--muted); text-align: center; }
.tape-sheet {
    background: #fff; color: #000;
    margin: 18px 0 40px;
    padding: 8mm;
    box-shadow: 0 8px 32px rgba(0, 0, 0, .4);
}
.sheet-head { font: 700 3.4mm/1.4 var(--sans); color: #000; }
.sheet-sub { font: 400 2.6mm/1.5 var(--sans); color: #333; margin-bottom: 4mm; }
.calib { position: relative; width: 50mm; height: 4mm; border-left: .3mm solid #000; border-right: .3mm solid #000; border-bottom: .3mm solid #000; margin: 2mm 0 5mm; }
.calib span { position: absolute; left: 52mm; top: 0; white-space: nowrap; font: 400 2.6mm/1.4 var(--sans); color: #333; }
.tapes { display: flex; gap: 9mm; }
.tape-col { position: relative; width: 15mm; border: .35mm solid #000; border-radius: 1mm; background: #fff; }
.tick { position: absolute; right: 0; width: 7mm; border-top: .25mm solid #000; }
.tick.minor { width: 3.5mm; border-top-width: .2mm; }
.tick .lbl {
    position: absolute; right: 7.6mm; top: -1.7mm;
    font: 700 3mm/1 var(--mono); color: #000;
}
.tick.extra { border-top-color: #999; }
.tick.extra .lbl { color: #999; font-style: italic; }
.sheet-foot { margin-top: 5mm; font: 400 2.6mm/1.5 var(--sans); color: #333; max-width: 120mm; }

/* ---------- Help overlay ---------- */
#helpOverlay {
    position: fixed; inset: 0; z-index: 50;
    background: rgba(10, 16, 12, .55);
    overflow: auto;
    display: flex; flex-direction: column; align-items: center;
}
.overlay-title { font-weight: 800; letter-spacing: .02em; }
.help-sheet {
    background: var(--card);
    border-radius: var(--radius);
    max-width: 560px; width: calc(100% - 28px);
    margin: 18px 0 40px;
    padding: 20px 18px;
    display: flex; flex-direction: column; gap: 18px;
}
.help-step { display: flex; gap: 12px; align-items: flex-start; }
.help-num {
    flex: 0 0 auto;
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 99px;
    background: var(--theme); color: #fff;
    font-family: var(--mono); font-weight: 700; font-size: .85rem;
}
.help-step h3 { font-size: .95rem; font-weight: 800; margin-bottom: 3px; }
.help-step h3 em { color: var(--theme); font-style: normal; }
.help-step p { font-size: .85rem; color: var(--muted); }
.help-step p strong { color: var(--ink); }

@page { size: auto; margin: 6mm; }
@media print {
    body > :not(#tapeOverlay) { display: none !important; }
    body { padding: 0; background: #fff; }
    #tapeOverlay { position: static !important; background: none; overflow: visible; display: block; }
    .overlay-bar { display: none !important; }
    .tape-sheet { margin: 0; padding: 0; box-shadow: none; }
}

/* ---------- Motion ---------- */
@media (prefers-reduced-motion: no-preference) {
    .target-card.slide-next #shotList { animation: slideL .18s ease; }
    .target-card.slide-prev #shotList { animation: slideR .18s ease; }
    @keyframes slideL { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; transform: none; } }
    @keyframes slideR { from { opacity: 0; transform: translateX(-14px); } to { opacity: 1; transform: none; } }
}
