:root {
  color-scheme: dark;
  --ink: #edf2eb;
  --muted: #9caaa6;
  --panel: rgba(20, 34, 37, 0.91);
  --panel-edge: rgba(237, 242, 235, 0.14);
  --orange: #ff7651;
  --mint: #a9e3cf;
  --mono: "DM Mono", Consolas, monospace;
  --sans: "Space Grotesk", "Trebuchet MS", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: #b7d1d1; }
body { color: var(--ink); font-family: var(--sans); }
button, input, select { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.app-shell { position: relative; width: 100%; height: 100vh; height: 100dvh; min-height: 0; isolation: isolate; overflow: hidden; }
#scene { position: absolute; inset: 0; z-index: -2; width: 100%; height: 100%; display: block; }
.scene-vignette { position: absolute; inset: 0; z-index: -1; pointer-events: none; background: linear-gradient(180deg, rgba(13, 30, 34, .44) 0%, transparent 25%, transparent 60%, rgba(13, 30, 34, .36) 100%); }
.topbar { position: absolute; top: 0; left: 0; right: 0; height: 76px; padding: 0 42px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,.2); }
.wordmark { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.wordmark strong { display: block; font-size: 15px; line-height: 1.1; font-weight: 700; }
.wordmark small { display: block; margin-top: 5px; font: 9px var(--mono); letter-spacing: 1.4px; color: #d3e2dd; }
.brand-symbol { position: relative; display: flex; align-items: center; gap: 4px; width: 29px; height: 30px; transform: rotate(-22deg); }
.brand-symbol i { display: block; width: 3px; height: 26px; border-radius: 2px; background: var(--orange); }
.brand-symbol i + i { height: 20px; margin-top: 8px; background: var(--mint); }
.top-actions { display: flex; align-items: center; gap: 25px; }
.connection, .eyebrow, .panel-kicker, .field-label, .range-ends, .compact-field > span:first-child, .bottom-note, .coach-readout, .results-summary, .results-table th { font-family: var(--mono); letter-spacing: 1px; }
.connection { display: flex; align-items: center; gap: 8px; font-size: 9px; color: #e0e9e4; }
.connection i { width: 6px; height: 6px; border-radius: 50%; background: #a9e3cf; box-shadow: 0 0 12px #a9e3cf; }
.icon-button, .close-button { border: 0; background: transparent; cursor: pointer; }
.icon-button { min-height: 38px; display: inline-flex; gap: 10px; align-items: center; border: 1px solid rgba(255,255,255,.35); padding: 0 13px; font: 10px var(--mono); letter-spacing: .8px; transition: background .2s, border-color .2s; }
.guide-link { color: inherit; text-decoration: none; }
.icon-button:hover { background: rgba(255,255,255,.13); border-color: white; }
.icon-button > span:first-child { font-size: 17px; color: var(--mint); }
.guide-link > span:first-child { font-size: 10px; font-weight: 500; }

.race-hud { position: absolute; top: 104px; right: 42px; width: min(390px, 42vw); display: grid; grid-template-columns: repeat(3, 1fr); padding-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,.5); text-shadow: 0 2px 14px rgba(13,30,34,.4); }
.hud-cell { display: flex; flex-direction: column; gap: 7px; }
.hud-cell + .hud-cell { padding-left: 20px; border-left: 1px solid rgba(255,255,255,.3); }
.eyebrow { color: #e3ebe5; font-size: 9px; }
.hud-cell strong { font: 500 23px var(--mono); white-space: nowrap; }
.hud-cell strong small { font-size: 10px; color: #e3ebe5; }
.hud-progress { position: absolute; bottom: -2px; left: 0; width: 100%; height: 2px; background: rgba(255,255,255,.24); }
.hud-progress span { display: block; width: 0; height: 100%; background: var(--orange); transition: width .15s linear; }

.setup-panel, .finish-panel { position: absolute; left: 42px; top: 50%; width: min(350px, calc(100vw - 36px)); max-height: calc(100dvh - 120px); overflow-y: auto; transform: translateY(-50%); padding: 25px 26px 21px; border: 1px solid var(--panel-edge); background: var(--panel); box-shadow: 0 20px 70px rgba(13, 30, 34, .2); backdrop-filter: blur(14px); animation: panel-in .55s cubic-bezier(.2,.8,.2,1) both; }
.panel-kicker { display: flex; gap: 9px; align-items: center; color: var(--mint); font-size: 9px; }
.panel-kicker span:first-child { color: var(--orange); }
.setup-panel h1, .finish-panel h2, .results-head h2 { margin: 15px 0 7px; font-size: 33px; line-height: 1; letter-spacing: 0; font-weight: 600; }
.panel-copy { max-width: 260px; margin: 0 0 22px; color: #b9c5c0; font-size: 12px; line-height: 1.55; }
.field-label { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; font-size: 9px; color: #c4cfca; }
.field-label output { font-size: 10px; color: var(--mint); }
.range-input { display: block; width: 100%; height: 3px; margin: 12px 0 0; appearance: none; background: linear-gradient(90deg, var(--orange), #d8ede2); cursor: pointer; }
.range-input::-webkit-slider-thumb { width: 13px; height: 13px; appearance: none; border: 2px solid #fff; border-radius: 50%; background: var(--orange); box-shadow: 0 1px 5px #18282c; }
.range-input::-moz-range-thumb { width: 10px; height: 10px; border: 2px solid #fff; border-radius: 50%; background: var(--orange); box-shadow: 0 1px 5px #18282c; }
.range-ends { display: flex; justify-content: space-between; margin-top: 7px; font-size: 8px; color: #84938e; }
.select-input { width: 100%; height: 38px; padding: 0 11px; border: 1px solid rgba(237,242,235,.22); border-radius: 0; background: rgba(255,255,255,.06); color: var(--ink); font-size: 12px; }
.select-input option { background: #17292c; }
.motion-controls { margin-top: 15px; padding-top: 2px; border-top: 1px solid rgba(255,255,255,.1); }
.motion-controls .field-label { margin-top: 12px; }
.motion-actions { display: flex; gap: 8px; }
.motion-toggle, .motion-calibrate { min-height: 36px; padding: 0 10px; border: 1px solid rgba(237,242,235,.3); background: rgba(255,255,255,.06); color: var(--ink); cursor: pointer; font: 9px var(--mono); letter-spacing: .5px; }
.motion-toggle { flex: 1; }
.motion-toggle[aria-pressed="true"] { border-color: var(--mint); color: var(--mint); }
.motion-calibrate { border-color: rgba(255,118,81,.55); color: var(--orange); }
.motion-status { min-height: 2.8em; margin: 8px 0 0; color: #aab8b2; font-size: 10px; line-height: 1.4; }
.trainer-fields { display: none; margin-top: 10px; padding: 9px 10px; border-left: 2px solid var(--mint); background: rgba(255,255,255,.045); }
.trainer-fields.is-visible { display: block; animation: fade-in .25s ease both; }
.compact-field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; color: #c3cfca; font-size: 10px; }
.compact-field > span:first-child { font-size: 8px; color: #9cacA6; }
.compact-field input { width: 48px; margin-right: 4px; padding: 4px 3px; border: 0; border-bottom: 1px solid #72857f; border-radius: 0; outline: 0; background: transparent; color: var(--mint); text-align: right; font: 12px var(--mono); }
.interval-fields { display: none; grid-template-columns: 1fr 1fr; gap: 10px; border-top: 1px solid rgba(255,255,255,.1); }
.interval-fields.is-visible { display: grid; }
.best-note { display: none; margin: 7px 0 2px; color: #aab8b2; font-size: 10px; line-height: 1.4; }
.best-note.is-visible { display: block; }
.start-button { width: 100%; min-height: 47px; margin-top: 21px; padding: 0 15px; display: flex; align-items: center; justify-content: space-between; border: 0; background: var(--orange); color: #1b292b; cursor: pointer; font: 700 10px var(--mono); letter-spacing: 1.3px; transition: background .18s, transform .18s; }
.start-button:hover { background: #ff967a; transform: translateY(-1px); }
.start-button > span:last-child { font-size: 17px; }
.setup-footnote { margin: 13px 0 0; color: #9eada7; font-size: 9px; text-align: center; }
.keycap { display: inline-block; min-width: 16px; margin: 0 2px; padding: 2px 4px; border: 1px solid rgba(255,255,255,.2); color: #dbe5df; font: 9px var(--mono); }

.run-controls { position: absolute; left: 50%; bottom: 47px; display: flex; align-items: end; gap: 12px; transform: translateX(-50%); }
.push-button { display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.58); background: rgba(20,34,37,.62); backdrop-filter: blur(10px); cursor: pointer; touch-action: none; user-select: none; }
.push-button { width: 220px; height: 75px; gap: 5px; border-color: var(--orange); background: rgba(255,118,81,.94); color: #1b292b; font: 700 9px var(--mono); letter-spacing: 1px; transition: background .15s, transform .15s; }
.push-button:active, .push-button.is-active { background: #ffb095; transform: translateY(2px); }
.push-mark { font: 28px var(--sans); line-height: 1; }
.run-controls.is-locked { opacity: .48; filter: grayscale(.65); pointer-events: none; }
.run-controls.is-locked button { cursor: not-allowed; }
.rearview-frame { position: absolute; z-index: 2; bottom: clamp(88px, 14vh, 130px); left: 22px; width: min(270px, 30vw); aspect-ratio: 16 / 9; overflow: hidden; border: 2px solid rgba(237,242,235,.78); background: rgba(104,130,126,.28); box-shadow: 0 8px 26px rgba(13,30,34,.25); pointer-events: none; }
.rearview-frame > span { position: absolute; z-index: 2; top: 0; left: 0; padding: 5px 7px; background: rgba(20,34,37,.78); color: var(--mint); font: 8px var(--mono); letter-spacing: 1px; }
.bear-chase-hint { position: absolute; z-index: 2; top: 0; right: 0; padding: 5px 6px; background: rgba(112,38,27,.88); color: #fff1e9; font: 7px var(--mono); letter-spacing: .2px; }
.bear-chase-hint[hidden] { display: none; }
.bear-attack { position: absolute; z-index: 1; inset: 0; display: grid; align-content: center; justify-items: center; gap: 5px; overflow: hidden; background: rgba(66,5,8,.28); color: #fff1e9; font-family: var(--mono); text-align: center; text-shadow: 0 1px 5px #300; }
.bear-attack[hidden] { display: none; }
.bear-attack::before { position: absolute; inset: 0; background: radial-gradient(ellipse at 18% 82%, rgba(147,10,18,.94) 0 10%, transparent 11%), radial-gradient(circle at 34% 64%, rgba(178,18,24,.92) 0 5%, transparent 6%), radial-gradient(ellipse at 51% 92%, rgba(126,8,15,.9) 0 11%, transparent 12%), radial-gradient(circle at 73% 77%, rgba(168,14,22,.95) 0 7%, transparent 8%), radial-gradient(ellipse at 88% 57%, rgba(139,9,17,.85) 0 6%, transparent 7%), radial-gradient(circle at 61% 36%, rgba(175,14,21,.8) 0 3%, transparent 4%); content: ""; }
.bear-attack::after { position: absolute; right: 0; bottom: 0; left: 0; height: 34%; background: rgba(120,7,14,.62); clip-path: polygon(0 100%, 0 54%, 9% 67%, 16% 28%, 23% 68%, 31% 18%, 39% 66%, 48% 35%, 55% 78%, 64% 14%, 72% 67%, 83% 30%, 91% 72%, 100% 42%, 100% 100%); content: ""; }
.bear-attack strong, .bear-attack > span { position: relative; z-index: 1; }
.bear-attack strong { font-size: clamp(8px, 1.5vw, 12px); letter-spacing: .7px; }
.bear-attack > span { font-size: 8px; }
.bear-attack b { color: #ffb09d; font-size: 14px; }
.bear-escaped { position: absolute; z-index: 3; top: 50%; left: 50%; padding: 8px 10px; transform: translate(-50%, -50%); background: rgba(20,34,37,.82); color: var(--mint); font: 700 9px var(--mono); letter-spacing: .5px; text-align: center; white-space: nowrap; }
.bear-escaped[hidden] { display: none; }
.coach-readout { position: absolute; right: 42px; bottom: 50px; display: flex; align-items: center; gap: 9px; padding: 10px 12px; border: 1px solid rgba(255,255,255,.3); background: rgba(20,34,37,.6); backdrop-filter: blur(8px); font-size: 9px; }
.coach-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 12px var(--mint); }
.finish-panel { top: 50%; }
.finish-panel h2 { font-size: 35px; }
.finish-stats { display: grid; grid-template-columns: 1fr 1fr; margin-top: 24px; padding: 15px 0; border-top: 1px solid rgba(255,255,255,.16); border-bottom: 1px solid rgba(255,255,255,.16); }
.finish-stats div { display: grid; gap: 8px; }
.finish-stats div + div { padding-left: 15px; border-left: 1px solid rgba(255,255,255,.16); }
.finish-stats span { color: #aab8b2; font: 8px var(--mono); letter-spacing: 1px; }
.finish-stats strong { font: 14px var(--mono); }
.bottom-note { position: absolute; right: 42px; bottom: 18px; left: 42px; display: flex; justify-content: space-between; color: rgba(237,242,235,.82); font-size: 8px; }

.results-backdrop { position: absolute; inset: 0; z-index: 4; background: rgba(10,20,22,.35); }
.results-panel { position: absolute; z-index: 5; top: 0; right: 0; bottom: 0; width: min(500px, 100%); padding: 34px 32px; border-left: 1px solid var(--panel-edge); background: #17292c; box-shadow: -20px 0 60px rgba(10,20,22,.24); transform: translateX(102%); transition: transform .32s cubic-bezier(.2,.8,.2,1); }
.results-panel.is-open { transform: translateX(0); }
.help-backdrop { position: absolute; z-index: 6; inset: 0; background: rgba(10,20,22,.68); backdrop-filter: blur(5px); }
.help-panel { display: none; position: absolute; z-index: 7; top: 50%; left: 50%; width: min(720px, calc(100% - 32px)); max-height: calc(100dvh - 48px); overflow-y: auto; padding: 28px 32px 30px; border: 1px solid var(--panel-edge); background: #17292c; box-shadow: 0 24px 80px rgba(10,20,22,.45); transform: translate(-50%, -50%); }
.help-panel.is-open { display: block; }
.help-panel:focus { outline: none; }
.help-content { margin-top: 20px; color: #c4cfca; font-size: 13px; line-height: 1.6; }
.help-content section { padding: 15px 0; border-top: 1px solid rgba(255,255,255,.12); }
.help-content h3 { margin: 0 0 8px; color: var(--mint); font-size: 15px; font-weight: 600; }
.help-content p { margin: 7px 0; }
.help-content ul, .help-content ol { margin: 8px 0; padding-left: 22px; }
.help-content li { margin: 8px 0; }
.help-content strong { color: var(--ink); }
.help-content em { color: var(--mint); font-style: normal; }
.help-safety { margin: 16px 0 0; padding: 12px 14px; border-left: 2px solid var(--orange); background: rgba(255,255,255,.05); }
.icon-button:focus-visible, .close-button:focus-visible, .help-panel button:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
.results-head { display: flex; justify-content: space-between; align-items: flex-start; }
.results-head h2 { margin-top: 12px; font-size: 28px; }
.close-button { width: 38px; height: 38px; font-size: 28px; color: #becac4; }
.close-button:hover { color: var(--orange); }
.results-summary { display: flex; align-items: center; gap: 9px; margin: 22px 0 14px; padding: 12px 0; border-top: 1px solid rgba(255,255,255,.14); border-bottom: 1px solid rgba(255,255,255,.14); color: #9dada7; font-size: 8px; }
.results-summary strong { color: var(--mint); font-size: 17px; }
.results-summary button { margin-left: auto; padding: 6px 0 6px 10px; border: 0; background: transparent; color: var(--orange); cursor: pointer; font: 9px var(--mono); }
.results-table-wrap { max-height: calc(100% - 160px); overflow: auto; }
.results-table { width: 100%; border-collapse: collapse; }
table { width: 100%; border-collapse: collapse; }
.results-table th, th { position: sticky; top: 0; padding: 9px 5px; background: #17292c; color: #81928c; text-align: left; font-size: 8px; font-weight: 400; }
td { padding: 12px 5px; border-top: 1px solid rgba(255,255,255,.1); color: #e5ebe6; white-space: nowrap; font: 10px var(--mono); }
td:first-child { color: #aab8b2; font-size: 9px; }
.delete-result { border: 0; background: transparent; color: #96a7a0; cursor: pointer; font-size: 16px; }
.delete-result:hover { color: var(--orange); }
.empty-results { padding: 25px 0; color: #9eada7; font-size: 12px; }

@keyframes panel-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 760px) {
  .topbar { height: 62px; padding: 0 18px; }
  .top-actions { gap: 12px; }
  .connection { font-size: 8px; }
  .button-label { display: none; }
  .icon-button { width: 38px; padding: 0; justify-content: center; }
  .guide-link { width: 42px; }
  .race-hud { top: 78px; right: 18px; width: min(350px, calc(100vw - 36px)); }
  .hud-cell + .hud-cell { padding-left: 11px; }
  .hud-cell strong { font-size: 17px; }
  .setup-panel, .finish-panel { top: max(72px, env(safe-area-inset-top)); left: 14px; width: min(390px, calc(100vw - 28px)); max-height: calc(100dvh - 108px); padding: 18px 19px 16px; transform: none; }
  .setup-panel h1, .finish-panel h2 { margin-top: 10px; font-size: 27px; }
  .panel-copy { margin-bottom: 14px; }
  .field-label { margin-top: 12px; }
  .start-button { min-height: 42px; margin-top: 15px; }
  .run-controls { bottom: 29px; gap: 8px; }
  .push-button { width: min(180px, 45vw); height: 66px; }
  .rearview-frame { bottom: 94px; left: 12px; width: min(220px, 44vw); }
  .coach-readout { right: 14px; bottom: 100px; font-size: 8px; }
  .bottom-note { right: 16px; bottom: 9px; left: 16px; font-size: 7px; }
  .results-panel { padding: 26px 18px; }
  .help-panel { width: calc(100% - 20px); max-height: calc(100dvh - 20px); padding: 20px 18px; }
  .help-content { margin-top: 13px; font-size: 12px; }
  .help-content section { padding: 11px 0; }
  .help-content h3 { font-size: 14px; }
  td, th { padding-right: 3px; padding-left: 3px; }
}

@media (max-width: 500px) {
  .connection { display: none; }
  .top-actions { gap: 8px; }
}

@media (max-width: 370px) {
  .topbar { padding-right: 12px; padding-left: 12px; }
  .wordmark { gap: 8px; }
  .wordmark small { display: none; }
  .top-actions { gap: 5px; }
  .icon-button { width: 34px; min-height: 34px; }
  .guide-link { width: 38px; }
}

@media (max-height: 650px) and (min-width: 761px) {
  .setup-panel, .finish-panel { top: 82px; max-height: calc(100dvh - 136px); transform: none; }
  .run-controls { bottom: 25px; }
  .race-hud { top: 90px; }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 500px) {
  .setup-panel {
    top: max(82px, env(safe-area-inset-top));
    left: 14px;
    width: min(390px, calc(100vw - 28px));
    max-height: calc(100dvh - 92px);
    padding: 10px 14px 9px;
  }
  .setup-panel h1 { margin: 6px 0 4px; font-size: 22px; }
  .panel-copy, .setup-footnote { display: none; }
  .setup-panel .field-label { margin: 7px 0 5px; }
  .range-input { margin-top: 8px; }
  .range-ends { margin-top: 4px; }
  .select-input { height: 32px; }
  .motion-controls { margin-top: 7px; }
  .motion-controls .field-label { margin: 6px 0 5px; }
  .motion-toggle, .motion-calibrate { min-height: 32px; }
  .motion-status { min-height: 0; margin-top: 4px; font-size: 9px; line-height: 1.25; }
  .start-button { min-height: 38px; margin-top: 9px; }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 420px) {
  .setup-panel > .panel-kicker, .setup-panel > h1,
  .setup-panel .motion-status, .setup-panel .setup-footnote { display: none; }
  .setup-panel .field-label { margin: 5px 0 3px; }
  .trainer-fields { margin-top: 5px; padding: 5px 8px; }
  .compact-field { padding: 3px 0; }
  .interval-fields { gap: 6px; }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 360px) {
  .setup-panel {
    top: max(82px, env(safe-area-inset-top));
    max-height: calc(100dvh - 92px);
    padding: 8px 12px 7px;
  }
  .setup-panel > .panel-kicker, .setup-panel > h1 { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}