/* Dialed web app. Mirrors the iPhone app's look: grouped cards, orange accent, light/dark, red night mode. */

:root {
  --accent: #ff8f2e;
  --accent-soft: rgba(255, 143, 46, 0.16);
  --warn: #f08a00;
  --danger: #e5484d;
  --bg: #f2f2f7;
  --card: #ffffff;
  --fill: rgba(118, 118, 128, 0.12);
  --text: #000000;
  --muted: rgba(60, 60, 67, 0.62);
  --faint: rgba(60, 60, 67, 0.32);
  --separator: rgba(60, 60, 67, 0.22);
  --bar: rgba(249, 249, 249, 0.82);
  --on-accent: #ffffff;
  --appbar-h: 52px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --bg: #000000; --card: #1c1c1e; --fill: rgba(118, 118, 128, 0.24); --text: #ffffff;
    --muted: rgba(235, 235, 245, 0.6); --faint: rgba(235, 235, 245, 0.3); --separator: rgba(84, 84, 88, 0.6);
    --bar: rgba(22, 22, 24, 0.82);
  }
}
/* Appearance setting: Light or Dark overrides the system. */
:root.light { color-scheme: light; }
:root.dark {
    --bg: #000000; --card: #1c1c1e; --fill: rgba(118, 118, 128, 0.24); --text: #ffffff;
    --muted: rgba(235, 235, 245, 0.6); --faint: rgba(235, 235, 245, 0.3); --separator: rgba(84, 84, 88, 0.6);
    --bar: rgba(22, 22, 24, 0.82);
  color-scheme: dark;
}
/* Night mode: dark theme, then everything multiplied by dim red (see .night-filter). */
:root.night {
  --bg: #000000; --card: #141414; --fill: rgba(118, 118, 128, 0.28); --text: #ffffff;
  --muted: rgba(235, 235, 245, 0.62); --faint: rgba(235, 235, 245, 0.32); --separator: rgba(84, 84, 88, 0.7);
  --bar: rgba(10, 10, 10, 0.9); --on-accent: #000000;
  color-scheme: dark;
}
.night-filter { display: none; }
:root.night .night-filter {
  display: block; position: fixed; inset: 0; z-index: 10000; pointer-events: none;
  background: #d90000; mix-blend-mode: multiply;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
}
body.sheet-open { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
hr { border: 0; border-top: 1px solid var(--separator); margin: 0; }
h1, h2, h3, p { margin: 0; }

.icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
.icon svg { width: 100%; height: 100%; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.strong { font-weight: 600; }
.mono, .num, .big-num, .stat-value, .dope td { font-variant-numeric: tabular-nums; }
.warn-text { color: var(--warn); }
.accent-text { color: var(--accent); }

/* MARK: App bar, title, tab bar */

#appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  padding-top: var(--safe-top); background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
body.scrolled #appbar { border-bottom-color: var(--separator); }
.appbar-inner { max-width: 600px; margin: 0 auto; height: var(--appbar-h); display: flex; align-items: center; justify-content: flex-end; padding: 0 16px; position: relative; }
.small-title { position: absolute; left: 50%; transform: translateX(-50%); font-weight: 600; opacity: 0; transition: opacity 0.15s; }
body.scrolled .small-title { opacity: 1; }
.toolbar { display: flex; gap: 8px; }
.toolbar-btn {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 14px;
  border: 0; border-radius: 20px; background: var(--fill); color: var(--accent); font-weight: 500;
}
.toolbar-btn.round-btn { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%; }
.toolbar-btn .icon { width: 22px; height: 22px; }
.toolbar-btn:disabled { opacity: 0.4; }

.page { max-width: 600px; margin: 0 auto; padding: calc(var(--appbar-h) + var(--safe-top) + 4px) 16px calc(96px + var(--safe-bottom)); }
.large-title { font-size: 34px; font-weight: 700; letter-spacing: 0.01em; margin: 0 4px 12px; }

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  padding: 6px 8px calc(6px + var(--safe-bottom)); background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--separator);
}
.tab {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0 4px; color: var(--text); text-decoration: none; font-size: 11px; font-weight: 500; border-radius: 14px;
}
.tab .icon { width: 26px; height: 26px; }
.tab .tab-rifles { width: 44px; }
.tab.on { color: var(--accent); background: var(--fill); }

/* MARK: Sticky answer bar */

#sticky {
  position: fixed; left: 0; right: 0; z-index: 19; top: calc(var(--appbar-h) + var(--safe-top));
  padding: 6px 16px; pointer-events: none; opacity: 0; transform: translateY(-8px); transition: opacity 0.18s, transform 0.18s;
}
#sticky.show { opacity: 1; transform: none; pointer-events: auto; }
.sticky-bar {
  max-width: 568px; margin: 0 auto; width: 100%; display: flex; align-items: baseline; gap: 14px; padding: 10px 16px;
  border: 1px solid var(--separator); border-radius: 14px; background: var(--bar);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); text-align: left;
}
.sticky-part { display: inline-flex; align-items: baseline; gap: 4px; }
.sticky-part b { font-size: 21px; font-variant-numeric: tabular-nums; }
.sticky-bar .dir { font-size: 12px; font-weight: 700; color: var(--accent); }
.sticky-bar .unit { font-size: 12px; color: var(--muted); }
.spacer { flex: 1; }

/* MARK: Cards and rows */

.card { background: var(--card); border-radius: 18px; padding: 14px 16px; margin-bottom: 14px; }
.card.flush { padding: 4px 0; }
.card.list { padding: 0 16px; }
.card-title {
  display: flex; align-items: center; gap: 8px; margin-bottom: 10px;
  font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.card-title .icon { width: 18px; height: 18px; }
.section-title { font-size: 13px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 16px 6px; }
.footnote { font-size: 13px; color: var(--muted); margin: 6px 16px 14px; line-height: 1.35; }
.card .footnote { margin: 8px 0 2px; }
.hint { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big-icon { width: 48px; height: 48px; margin-bottom: 12px; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 46px; padding: 4px 0; }
.row.tight { min-height: 32px; }
.row.strong { font-weight: 600; }
.row-label { flex: 1 1 auto; min-width: 0; }
.row-label.strong { font-weight: 500; font-size: 15px; }
.row-value { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-end; flex: 0 1 auto; min-width: 0; text-align: right; }
.unit { color: var(--muted); }
.num, .text {
  width: 88px; border: 0; background: transparent; text-align: right; padding: 8px 0; outline-offset: 4px; border-radius: 6px;
}
.num.narrow { width: 52px; }
.text { width: 60%; max-width: 260px; }
.num:focus, .text:focus { background: var(--fill); outline: none; padding: 8px 6px; }
.num::placeholder, .text::placeholder { color: var(--faint); }

select {
  border: 0; background: transparent; color: var(--muted); text-align: right; text-align-last: right;
  padding: 8px 0; max-width: 62%; appearance: none; -webkit-appearance: none;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
select.wide-select { max-width: 70%; }
.overlay-select { position: absolute; inset: 0; opacity: 0; width: 100%; max-width: none; cursor: pointer; }

.segmented { display: inline-flex; background: var(--fill); border-radius: 9px; padding: 2px; gap: 2px; }
.segmented button { border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; font-size: 15px; white-space: nowrap; }
.segmented button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18); font-weight: 600; }
.row > .segmented:only-child { flex: 1; }
.row > .segmented:only-child button { flex: 1; }

.switch {
  appearance: none; -webkit-appearance: none; width: 51px; height: 31px; border-radius: 16px; background: var(--fill);
  position: relative; flex: none; transition: background 0.2s; margin: 0; cursor: pointer;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch:checked { background: #34c759; }
:root.night .switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

.stepper { display: inline-flex; background: var(--fill); border-radius: 9px; }
.stepper button { border: 0; background: transparent; width: 46px; height: 34px; display: grid; place-items: center; }
.stepper button + button { border-left: 1px solid var(--separator); }
.stepper .icon { width: 18px; height: 18px; }

.chip-btn { border: 0; background: var(--fill); color: var(--accent); width: 40px; height: 32px; border-radius: 16px; display: inline-grid; place-items: center; }
.chip-btn .icon { width: 18px; height: 18px; }

.pill { border: 0; background: var(--fill); padding: 9px 16px; border-radius: 20px; font-size: 15px; }
.pill.accent { color: var(--accent); }
.button-row { display: flex; justify-content: space-between; gap: 10px; margin-top: 10px; }
.button-stack { display: flex; flex-direction: column; align-items: center; gap: 6px; margin: 18px 0 8px; }

.primary {
  border: 0; background: var(--accent); color: var(--on-accent); font-weight: 600; padding: 14px 18px; border-radius: 14px;
}
.primary.wide { width: 100%; margin: 6px 0 10px; }
.primary:disabled { opacity: 0.4; }
.link { border: 0; background: transparent; color: var(--accent); padding: 8px 0; display: inline-flex; align-items: center; gap: 6px; }
.link.small { font-size: 15px; }
.link.strong { font-weight: 600; }
.link.danger { color: var(--danger); }

.warning { display: flex; gap: 6px; align-items: flex-start; font-size: 13px; color: var(--warn); margin-top: 10px; }
.warning .icon { width: 16px; height: 16px; margin-top: 1px; }

.tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 10px; font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); vertical-align: 1px; }

/* MARK: Solve */

.rifle-header { position: relative; display: flex; align-items: center; gap: 12px; padding: 16px; cursor: pointer; }
.rifle-header-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rifle-name { font-size: 20px; font-weight: 600; }
.rifle-sub { font-size: 15px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.range-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.round { width: 56px; height: 56px; border-radius: 50%; border: 0; background: var(--fill); color: var(--accent); display: grid; place-items: center; flex: none; }
.round .icon { width: 24px; height: 24px; }
.range-value { display: flex; align-items: baseline; justify-content: center; gap: 4px; min-width: 0; }
.num.big {
  width: 4.2ch; font: 700 48px/1.1 ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif; text-align: center; padding: 2px 0;
}
.num.big:focus { padding: 2px 4px; }
.num.big.mid { font-size: 34px; width: 3ch; text-align: left; }
.big-unit { font-size: 20px; }
.range-row + hr { margin: 10px 0 2px; }

.axes { width: 100%; display: grid; grid-template-columns: 1fr 1px 1fr; gap: 12px; border: 0; background: transparent; padding: 2px 0 12px; text-align: left; }
.vrule { background: var(--separator); }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.eyebrow.plain { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 400; }
.axis-value { display: flex; align-items: baseline; gap: 6px; margin: 2px 0; }
.axis-value .dir { font-size: 17px; font-weight: 600; color: var(--accent); }
.big-num { font: 700 40px/1.1 ui-rounded, "SF Pro Rounded", -apple-system, system-ui, sans-serif; }
.axis-action { font-size: 15px; font-weight: 500; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding-top: 12px; text-align: center; }
.stat-value { font-size: 20px; font-weight: 600; }
.stat-label { font-size: 11px; color: var(--muted); }

.reticle-wrap { max-width: 340px; margin: 0 auto 8px; }
.reticle-wrap.small { max-width: 240px; margin-top: 12px; }
.reticle { width: 100%; height: auto; display: block; font-family: -apple-system, system-ui, sans-serif; }

.wind-row { display: flex; align-items: center; gap: 14px; }
.wind-dial { position: relative; width: 170px; height: 170px; flex: none; }
.wind-dial svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.wind-dial .hour {
  position: absolute; width: 32px; height: 32px; transform: translate(-50%, -50%); border: 0; border-radius: 50%;
  background: transparent; font-size: 14px; font-variant-numeric: tabular-nums; padding: 0;
}
.wind-dial .hour.on { background: var(--accent); color: var(--on-accent); font-weight: 700; }
.wind-speed { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; flex: 1; min-width: 0; }

/* MARK: Lists, search, chips */

.list-row {
  width: 100%; display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 10px 0;
  border: 0; background: transparent; text-align: left; color: inherit;
}
.list-row.accent-text { color: var(--accent); }
.list-row .icon { width: 22px; height: 22px; }
.list-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-title { font-weight: 600; }
.list-sub { color: var(--muted); font-size: 15px; }
.list-meta { color: var(--faint); font-size: 13px; }
.list-right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.check-badge { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; flex: none; }
.check-badge .icon { width: 16px; height: 16px; }
.file-pick { position: relative; cursor: pointer; }
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.search { display: flex; align-items: center; gap: 8px; background: var(--fill); border-radius: 12px; padding: 0 12px; margin-bottom: 12px; }
.search input { flex: 1; border: 0; background: transparent; padding: 11px 0; outline: none; min-width: 0; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -16px 4px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 0; border-radius: 18px; padding: 8px 15px; background: var(--card); font-size: 15px; }
.chip.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }

.disclosure { width: 100%; display: flex; justify-content: space-between; align-items: center; border: 0; background: transparent; padding: 10px 0; text-align: left; }
.rot90 { transform: rotate(90deg); }
.icon.rot90 { transition: transform 0.2s; }
.prose p + p { margin-top: 10px; }
.prose { font-size: 15px; line-height: 1.4; }

/* MARK: Dope table */

.dope { width: 100%; border-collapse: collapse; font-size: 15px; }
.dope th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: right; padding: 10px 16px 6px 4px; }
.dope td { text-align: right; padding: 9px 16px 9px 4px; border-top: 1px solid var(--separator); }
.dope th:first-child, .dope td:first-child { text-align: left; padding-left: 16px; }

/* MARK: Sheets */

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.35); display: flex; align-items: flex-end; justify-content: center;
  animation: fade 0.18s ease-out;
}
.sheet {
  width: 100%; max-width: 600px; max-height: calc(100% - var(--safe-top) - 24px); display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0; animation: rise 0.22s ease-out; overflow: hidden;
}
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 16px; max-height: 88vh; } }
.sheet-header { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--separator); }
.sheet-header h2 { font-size: 17px; font-weight: 600; text-align: center; max-width: 60vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-header .link { justify-self: end; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(24px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.sheet-backdrop.closing { animation: fade 0.18s ease-in reverse forwards; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(40px); opacity: 0.6; } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* Small phones (iPhone mini / SE): tighten the big numbers. */
@media (max-width: 380px) {
  .num.big { font-size: 42px; }
  .big-num { font-size: 34px; }
  .stat-value { font-size: 17px; }
  .round { width: 50px; height: 50px; }
  .page { padding-left: 12px; padding-right: 12px; }
}
