/* Underground Tactical Range Calc. Dark by default; "Sun" theme for bright daylight. */
:root {
  --bg: #111315; --surface: #1b1f23; --raised: #2a3037; --line: #3a424b;
  --text: #ffffff; --muted: #a9b0b8;
  --pink: #d11f55; --pink-hi: #e5275f; --teal: #2caeaa; --gold: #fab040;
  --danger-bg: #d11f55; --danger-text: #ffffff;
  --head: "Bahnschrift Condensed", "Bahnschrift SemiBold Condensed", "Avenir Next Condensed", "Roboto Condensed",
          "Arial Narrow", "sans-serif-condensed", "Helvetica Neue", Arial, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --tap: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
:root[data-theme="sun"] {
  --bg: #ffffff; --surface: #f3f4f6; --raised: #e2e5e9; --line: #111315;
  --text: #000000; --muted: #2f353c;
  --teal: #0d6461; --gold: #7a4b00;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font: 17px/1.45 var(--body);
  padding-bottom: calc(72px + var(--safe-b));
  -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none;
}
h1, h2, .brand b, .btn, .tab, .stat b, .big2 b, .entry, .keypad button, .seg button, .chip {
  font-family: var(--head); font-stretch: condensed;
}
h1 { font-size: 30px; font-weight: 800; text-transform: uppercase; letter-spacing: .02em; margin: 6px 0 12px; line-height: 1.05; }
h2 { font-size: 18px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--teal);
     margin: 22px 0 8px; border-bottom: 2px solid var(--raised); padding-bottom: 4px; }
a { color: var(--teal); }

/* Header */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px; background: var(--bg); border-bottom: 3px solid var(--pink); }
.top img { width: 40px; height: 40px; }
.brand { display: flex; flex-direction: column; line-height: 1; }
.brand b { font-size: 24px; font-weight: 800; text-transform: uppercase; letter-spacing: .03em; }
.brand span { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--muted); margin-top: 3px; }
.motto { margin-left: auto; text-align: right; font-size: 11px; white-space: nowrap; line-height: 1.25; color: var(--gold); text-transform: uppercase; letter-spacing: .04em; }

main { max-width: 640px; margin: 0 auto; padding: 8px 16px 24px; }
.screen[hidden] { display: none; }

/* Fields */
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; text-transform: uppercase;
       letter-spacing: .05em; color: var(--muted); min-width: 0; }
.fld > span { display: block; }
input, select {
  width: 100%; min-height: var(--tap); font: 600 22px var(--body); color: var(--text); background: var(--surface);
  border: 2px solid var(--line); border-radius: 6px; padding: 8px 12px; text-transform: none; letter-spacing: 0;
}
select { font-size: 18px; appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
input:focus, select:focus { outline: 3px solid var(--teal); outline-offset: 1px; border-color: var(--teal); }
input::placeholder { color: var(--muted); opacity: .7; font-weight: 400; font-size: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-bottom: 10px; align-items: end; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 10px; align-items: end; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 18px;
  border: 0; border-radius: 6px; background: var(--pink); color: #fff; font-size: 19px; font-weight: 800;
  text-transform: uppercase; letter-spacing: .06em; cursor: pointer; text-decoration: none; touch-action: manipulation; }
.btn:active { background: var(--pink-hi); transform: translateY(1px); }
.btn.alt { background: var(--teal); color: #000; }
:root[data-theme="sun"] .btn.alt { color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border: 2px solid var(--line); }
.btn.danger { background: transparent; color: var(--pink); border: 2px solid var(--pink); }
.btn.sm { min-height: 48px; padding: 0 12px; font-size: 16px; }
.btn.file { position: relative; overflow: hidden; }
.btn.file input { position: absolute; inset: 0; opacity: 0; min-height: 0; cursor: pointer; }
.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0; }
.stack { display: grid; gap: 10px; }

.seg { display: flex; border: 2px solid var(--line); border-radius: 6px; overflow: hidden; min-height: var(--tap); }
.seg button { flex: 1; border: 0; background: var(--surface); color: var(--text); font-size: 19px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .05em; min-height: calc(var(--tap) - 4px); cursor: pointer; }
.seg button + button { border-left: 2px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--teal); color: #000; }
:root[data-theme="sun"] .seg button[aria-pressed="true"] { background: #111315; color: #fff; }
.seg.wide button { font-size: 17px; }

/* Chrono */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.chip { flex: none; min-height: 48px; padding: 0 14px; border-radius: 24px; border: 2px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 18px; font-weight: 700; cursor: pointer; white-space: nowrap; }
.chip small { font-size: 13px; color: var(--muted); margin-left: 6px; }
.chip[aria-selected="true"] { border-color: var(--teal); background: var(--raised); box-shadow: inset 0 -4px 0 var(--teal); }
.chip.over { border-color: var(--pink); color: var(--pink); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 10px; }
.stat { background: var(--surface); border: 1px solid var(--raised); border-radius: 6px; padding: 6px 8px; min-width: 0; }
.stat span { display: block; font-size: 12px; font-weight: 700; letter-spacing: .1em; color: var(--muted); }
.stat b { display: block; font-size: 30px; font-weight: 800; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat.key b { color: var(--gold); }
.entry { min-height: 64px; display: flex; align-items: center; justify-content: flex-end; padding: 0 16px;
  background: #000; border: 2px solid var(--teal); border-radius: 6px; font-size: 44px; font-weight: 800;
  font-variant-numeric: tabular-nums; color: #fff; }
:root[data-theme="sun"] .entry { background: #fff; color: #000; border-color: #000; }
.entry .ph { font-size: 20px; color: var(--muted); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.keypad button { min-height: 60px; font-size: 30px; font-weight: 800; border: 0; border-radius: 6px; background: var(--raised);
  color: var(--text); cursor: pointer; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.keypad button:active { background: var(--teal); color: #000; }
.keypad .ghost { background: transparent; border: 2px solid var(--line); font-size: 20px; text-transform: uppercase; }
.keypad .add { grid-column: span 2; background: var(--pink); color: #fff; font-size: 24px; }
.keypad .add:active { background: var(--pink-hi); color: #fff; }
.shots { display: flex; flex-wrap: wrap; gap: 6px; }
.shot { min-height: 44px; min-width: 64px; padding: 0 10px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: 600 17px var(--body); font-variant-numeric: tabular-nums; cursor: pointer; }
.shot i { font-style: normal; font-size: 12px; color: var(--muted); margin-right: 4px; }
.shot.hi { border-color: var(--gold); } .shot.lo { border-color: var(--teal); }
.stop { background: var(--danger-bg); color: var(--danger-text); border-radius: 6px; padding: 12px 14px; margin: 4px 0 10px;
  font-weight: 700; font-size: 17px; line-height: 1.3; animation: pulse 1.2s ease-in-out infinite alternate; }
.stop b { display: block; font-family: var(--head); font-size: 30px; letter-spacing: .08em; line-height: 1; }
@keyframes pulse { from { box-shadow: 0 0 0 0 rgba(209,31,85,.0); } to { box-shadow: 0 0 0 6px rgba(209,31,85,.35); } }
@media (prefers-reduced-motion: reduce) { .stop { animation: none; } }

/* Tables */
.tbl-wrap { overflow-x: auto; margin: 6px -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { font: 700 12px var(--body); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: right; padding: 6px 6px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { text-align: right; padding: 9px 6px; border-bottom: 1px solid var(--raised); font-size: 17px; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
td.em { font-weight: 800; color: var(--gold); font-size: 19px; }
tr.over td { color: var(--pink); font-weight: 700; }
tr.sub td { color: var(--muted); }
tr.zero td { background: var(--surface); }
.chart { width: 100%; height: auto; display: block; margin: 8px 0; background: var(--surface); border-radius: 6px; }
.chart text { fill: var(--muted); font: 600 11px var(--body); }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .ln { stroke: var(--teal); stroke-width: 2.5; fill: none; }
.chart .pt { fill: var(--teal); }
.chart .pt.over { fill: var(--pink); }
.chart .err { stroke: var(--teal); stroke-width: 1.5; opacity: .6; }
.chart .max { stroke: var(--pink); stroke-width: 2; stroke-dasharray: 5 4; }
.chart .maxt { fill: var(--pink); font-weight: 800; }

/* Results */
.big2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 6px; }
.big2 > div { background: var(--surface); border: 2px solid var(--raised); border-radius: 8px; padding: 10px 12px; min-width: 0; }
.big2 span { display: block; font-size: 13px; font-weight: 700; letter-spacing: .1em; color: var(--muted); text-transform: uppercase; }
.big2 b { display: block; font-size: 46px; font-weight: 800; line-height: 1.05; color: var(--gold); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.big2 small { display: block; font-size: 14px; color: var(--muted); }
.big2 .full { grid-column: span 2; }
.atm { font-size: 14px; color: var(--muted); margin: 4px 0 6px; }
.atm b { color: var(--text); }
.err-msg { color: var(--gold); font-weight: 600; margin: 12px 0; }
.legend { font-size: 13px; color: var(--muted); margin: 4px 0 0; }

/* Profiles */
.profile-bar { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.profile-bar select { min-height: 48px; font-size: 17px; }

/* Round counter */
.add-gun { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.add-gun input { font-size: 19px; }
.gun { background: var(--surface); border: 2px solid var(--raised); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.gun-head { display: flex; align-items: baseline; gap: 8px; }
.gun-head h3 { margin: 0; font: 800 22px var(--head); font-stretch: condensed; text-transform: uppercase; letter-spacing: .03em; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.gun-head button { background: none; border: 0; color: var(--muted); font-size: 15px; text-decoration: underline; min-height: 44px; padding: 0 6px; cursor: pointer; }
.gun-count { display: grid; grid-template-columns: 72px 1fr 72px; gap: 8px; align-items: center; margin: 8px 0; }
.gun-count b { text-align: center; font: 800 52px var(--head); font-stretch: condensed; color: var(--gold); font-variant-numeric: tabular-nums; line-height: 1; }
.gun-count button, .quick button { min-height: 60px; border: 0; border-radius: 6px; background: var(--raised); color: var(--text);
  font: 800 30px var(--head); cursor: pointer; touch-action: manipulation; }
.gun-count button:active, .quick button:active { background: var(--teal); color: #000; }
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quick button { font-size: 22px; background: var(--pink); color: #fff; }
.gun .meta { font-size: 13px; color: var(--muted); margin-top: 8px; }

/* More */
.tile { display: block; text-decoration: none; color: var(--text); background: var(--surface); border: 2px solid var(--raised);
  border-left: 6px solid var(--pink); border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; min-height: 72px; }
.tile b { display: block; font: 800 22px var(--head); font-stretch: condensed; text-transform: uppercase; letter-spacing: .03em; }
.tile span { color: var(--muted); font-size: 15px; }
.tile.teal { border-left-color: var(--teal); } .tile.gold { border-left-color: var(--gold); }
.back { display: inline-flex; align-items: center; min-height: 44px; font-weight: 700; text-decoration: none; font-size: 17px; }
.lead { font: 700 20px var(--head); font-stretch: condensed; text-transform: uppercase; letter-spacing: .04em; color: var(--gold); }
.center { text-align: center; }
.logo { display: block; margin: 0 auto; width: 220px; height: auto; }
:root[data-theme="sun"] .logo { background: #111315; border-radius: 12px; padding: 10px; }
.safety { border: 2px solid var(--pink); border-radius: 8px; padding: 12px 14px; margin: 14px 0; }
.safety b { font: 800 20px var(--head); text-transform: uppercase; letter-spacing: .06em; color: var(--pink); }
.safety p { margin: 6px 0 0; }
.note { font-size: 14px; color: var(--muted); border-left: 3px solid var(--gold); padding-left: 10px; margin: 14px 0; }
.hint { font-size: 14px; color: var(--muted); margin: 6px 0; }

/* Bottom tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--bg); border-top: 2px solid var(--raised); padding-bottom: var(--safe-b); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 64px;
  color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab svg circle[r="1"], .tab svg circle[r="1.4"], .tab svg circle[r="1.6"] { fill: currentColor; }
.tab[aria-current="page"] { color: var(--text); box-shadow: inset 0 3px 0 var(--pink); }
.tab[aria-current="page"] svg { stroke: var(--pink); }

.toast { position: fixed; left: 16px; right: 16px; bottom: calc(80px + var(--safe-b)); z-index: 7; background: var(--teal); color: #000;
  font-weight: 700; padding: 14px 16px; border-radius: 8px; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast button { margin-left: 10px; }

@media (max-width: 359px) {
  .motto { display: none; }
  .stat b { font-size: 26px; }
  .big2 b { font-size: 38px; }
}
@media (min-width: 700px) {
  .tabs { max-width: 640px; margin: 0 auto; }
}
