    :root {
      --bg: #000000;
      --surface: #141414;
      --surface2: #1c1c1c;
      --surface3: #242424;
      --border: #3a3a3a;
      --text: #f2f2f2;
      --dim: #a6a6a6;
      --ghost: #8a8a8a;
      --teal: #2ccbc2;
      --tealbg: #182e30;
      --tealf: #2ccbc2;
      --amber: #dcb565;
      --amberbg: #2a2417;
      --gold: #e3c98a;
      --pink: #d9a3c9;
      --pinkbg: #241722;
      --plum: #b26b9a;
      --plumf: #8f4a7a;
      --plumb: #241722;
      --rust: #c96a4d;
      --rustf: #a94e35;
      --rustb: #2a1b17;
      --orange: #e8997f;
      --slate: #9aa0d4;
      --slatebg: #242424;
      --shadow: 0 10px 40px #000000aa;
      --ramp: var(--plum);
      --rampb: var(--plumb);
      --sg-pink: #f472b6;
      --sg-teal: #2dd4bf;
      --sg-border: rgba(255, 255, 255, 0.12);
      --sg-surface2: #18181b;
      --sg-card: #121214;
      --sg-gold: #ffe08e;
      --text-dim: #888888;
    }

    * { box-sizing: border-box; }
    html, body { margin: 0; padding: 0; height: 100%; width: 100%; background: var(--bg); color: var(--text); }
    body {
      font: 14.5px/1.45 "Segoe UI Variable Text", "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
      font-feature-settings: "tnum";
      -webkit-font-smoothing: antialiased;
      overflow-x: hidden;
      display: flex;
      flex-direction: column;
    }

    h1, h2, h3, h4 {
      font-family: "Segoe UI Variable Display", "Segoe UI", Roboto, sans-serif;
      margin: 0;
      letter-spacing: -0.01em;
    }
    button, input, select, textarea { font: inherit; color: inherit; }

    /* Spirit Guide Brand Line */
    .gline {
      height: 3px;
      background: linear-gradient(90deg, #b9768f, #c97c72, #d4966a, #d9b37a);
      flex: none;
      width: 100%;
    }

    .brand-title {
      font-weight: 800;
      letter-spacing: 0.12em;
      font-size: 1.15rem;
      text-transform: uppercase;
      color: #f2f2f2;
      white-space: nowrap;
      display: flex;
      align-items: baseline;
      gap: 6px;
    }
    .brand-sub {
      font-size: 0.72rem;
      color: var(--teal);
      letter-spacing: 0.08em;
      font-weight: 700;
      text-transform: uppercase;
      background: var(--tealbg);
      border: 1px solid var(--teal);
      padding: 1px 7px;
      transform: translateY(-2px);
      align-self: center;
      border-radius: 99px;
    }

    .dim { color: var(--dim); }
    .sp { flex: 1; }
    .row { display: flex; align-items: center; gap: 10px; }
    .col { display: flex; flex-direction: column; gap: 10px; }
    .ey {
      font-size: 0.72rem;
      font-weight: 800;
      letter-spacing: 0.09em;
      text-transform: uppercase;
      color: var(--dim);
    }

    /* Spirit Guide Modules */
    .mod {
      --ac: var(--slate);
      border: 1px solid var(--border);
      border-radius: 12px;
      background: var(--surface);
      overflow: hidden;
      display: flex;
      flex-direction: column;
      min-height: 0;
    }
    .mod.gold { --ac: var(--gold); }
    .mod.pink { --ac: var(--pink); }
    .mod.teal { --ac: var(--teal); }
    .mod.slate { --ac: var(--slate); }
    .mod.orange { --ac: var(--orange); }
    .mod.plum { --ac: var(--plum); }

    .mh {
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 9px 16px;
      margin: -1px -1px 0;
      background: color-mix(in srgb, var(--ac) 14%, var(--surface2));
      border: 3px solid var(--ac);
      border-bottom: 0;
      border-radius: 12px 12px 0 0;
      min-height: 44px;
      flex: none;
    }
    .mh h3 { font-size: 0.95rem; font-weight: 700; color: var(--text); }
    .mh .ct { font-size: 0.78rem; color: var(--dim); font-weight: 600; }
    .mb { padding: 16px; min-height: 0; }
    .mb.flush { padding: 0; }
    .mb.scroll { overflow-y: auto; }

    /* Spirit Guide Button Styles */
    .btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: 7px;
      min-height: 36px;
      padding: 0 14px;
      border-radius: 9px;
      border: 1.5px solid var(--ghost);
      background: transparent;
      font-weight: 600;
      font-size: 0.88rem;
      cursor: pointer;
      transition: background 0.15s, border-color 0.15s, transform 0.05s;
      white-space: nowrap;
      user-select: none;
    }
    .btn:hover { background: var(--surface3); }
    .btn:active { transform: translateY(1px); }
    .btn.sm { min-height: 30px; padding: 0 10px; font-size: 0.82rem; border-radius: 7px; }
    .btn.lg { min-height: 44px; padding: 0 20px; font-size: 0.98rem; border-radius: 10px; }
    .btn.teal { color: var(--teal); background: var(--tealbg); border-color: var(--teal); }
    .btn.teal:hover { background: color-mix(in srgb, var(--teal) 22%, var(--tealbg)); }
    .btn.gold { color: var(--amber); background: var(--amberbg); border-color: var(--amber); }
    .btn.gold:hover { background: color-mix(in srgb, var(--amber) 22%, var(--amberbg)); }
    .btn.pink { color: var(--pink); background: var(--pinkbg); border-color: var(--pink); }
    .btn.pink:hover { background: color-mix(in srgb, var(--pink) 22%, var(--pinkbg)); }
    .btn.slate { color: var(--slate); background: var(--slatebg); border-color: var(--slate); }
    .btn.grad {
      background: linear-gradient(90deg, #b9768f, #c97c72, #d4966a, #d9b37a);
      border-color: transparent;
      color: #1a0f0d;
      font-weight: 800;
    }
    .btn.grad:hover { filter: brightness(1.08); }
    .btn.icon { width: 36px; padding: 0; min-height: 36px; }
    .btn.sm.icon { width: 28px; min-height: 28px; padding: 0; }

    /* Segment / Toggle Bars */
    .seg {
      display: inline-flex;
      border: 1.5px solid var(--ghost);
      border-radius: 99px;
      padding: 2px;
      gap: 2px;
      background: var(--surface2);
    }
    .seg b {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 4px 12px;
      border-radius: 99px;
      font-weight: 600;
      font-size: 0.82rem;
      color: var(--dim);
      cursor: pointer;
      transition: 0.15s;
      user-select: none;
    }
    .seg b:hover { color: var(--text); }
    .seg b.on { background: var(--text); color: var(--bg); font-weight: 700; }

    .vt {
      display: inline-flex;
      padding: 2px;
      border-radius: 99px;
      background: #141414;
      border: 1.5px solid #3a3a3a;
    }
    .vt b {
      display: flex;
      align-items: center;
      gap: 6px;
      padding: 4px 12px;
      border-radius: 99px;
      font-weight: 700;
      font-size: 0.82rem;
      color: #a6a6a6;
      cursor: pointer;
      transition: 0.15s;
    }
    .vt b:hover { color: #fff; }
    .vt b.on {
      background: #182e30;
      color: var(--teal);
      box-shadow: inset 0 0 0 1.5px var(--teal);
    }

    .chip {
      display: inline-flex;
      align-items: center;
      gap: 5px;
      border-radius: 99px;
      padding: 2px 10px;
      font-size: 0.74rem;
      font-weight: 700;
      border: 1px solid var(--ghost);
      background: var(--surface2);
      white-space: nowrap;
      line-height: 1.5;
    }
    .chip.teal { color: var(--teal); border-color: var(--teal); background: var(--tealbg); }
    .chip.amber { color: var(--amber); border-color: var(--amber); background: var(--amberbg); }
    .chip.pink { color: var(--pink); border-color: var(--pink); background: var(--pinkbg); }
    .chip.plain { border-color: var(--border); color: var(--dim); background: transparent; }

    .dot {
      width: 9px;
      height: 9px;
      border-radius: 50%;
      background: var(--teal);
      box-shadow: 0 0 0 3px color-mix(in srgb, var(--teal) 28%, transparent);
      flex: none;
    }
    .dot.pulse { animation: dotpulse 1.8s infinite; }
    @keyframes dotpulse {
      0%, 100% { opacity: 1; transform: scale(1); }
      50% { opacity: 0.35; transform: scale(1.15); }
    }

    /* Header & Sub-Bar */
    .hd {
      display: flex;
      align-items: center;
      gap: 20px;
      height: 56px;
      padding: 0 20px;
      background: #000;
      color: #f2f2f2;
      flex: none;
    }
    .hd nav { display: flex; gap: 4px; margin-left: 10px; }
    .hd nav a {
      color: var(--dim);
      font-weight: 600;
      font-size: 0.88rem;
      padding: 17px 12px 15px;
      border-bottom: 3px solid transparent;
      transition: 0.15s;
      text-decoration: none;
      cursor: pointer;
    }
    .hd nav a:hover { color: #fff; }
    .hd nav a.on { color: #fff; border-bottom-color: #d4966a; }

    .strip {
      background: #000;
      color: #f2f2f2;
      flex: none;
    }
    .strip .in- {
      display: flex;
      align-items: center;
      gap: 16px;
      padding: 10px 20px;
      font-weight: 700;
      font-size: 0.9rem;
    }
    .strip .tr {
      flex: 1;
      height: 14px;
      border-radius: 99px;
      background: #101010;
      border: 1.5px solid #3a3a3a;
      overflow: hidden;
    }
    .strip .tr i {
      display: block;
      height: 100%;
      background: color-mix(in srgb, var(--ramp) 55%, #000);
      border-right: 2px solid var(--ramp);
      transition: width 0.3s ease;
    }

    /* Default Portrait Layout: 2x2 Grid */
    .metric-grid {
      display: grid !important;
      grid-template-columns: 1fr 1fr !important;
      gap: 10px;
      width: 100%;
    }

    /* Landscape Orientation Layout: 1 Row, 4 Columns */
    @media screen and (orientation: landscape) {
    .metric-grid {
      grid-template-columns: repeat(4, 1fr) !important;
      }
    }
    .tile {
      border: 1px solid var(--border);
      border-radius: 11px;
      padding: 10px 14px;
      background: var(--surface);
    }
    .tile b {
      display: block;
      font-size: 1.55rem;
      font-weight: 800;
      line-height: 1.15;
    }
    .tile span {
      font-size: 0.72rem;
      font-weight: 700;
      color: var(--dim);
      letter-spacing: 0.06em;
      text-transform: uppercase;
    }

    /* Gantt & Split Visualization */
    .track-row {
      display: flex;
      flex-direction: column;
      gap: 6px;
      padding: 12px 14px;
      border-radius: 10px;
      background: var(--surface2);
      border: 1px solid var(--border);
      margin-bottom: 8px;
    }
    .track-meta {
      display: flex;
      justify-content: space-between;
      font-size: 0.82rem;
      font-weight: 700;
    }
    .pbar {
      height: 12px;
      border-radius: 99px;
      background: #000;
      border: 1.5px solid var(--border);
      overflow: hidden;
    }
    .pbar i {
      display: block;
      height: 100%;
      border-radius: 99px;
      transition: width 0.25s linear;
    }

    /* Phone runner screen (plain responsive container, no device frame) */
    .phone-screen {
      width: 100%;
      min-width: 0;
      overflow-x: hidden;
      background: #000;
      color: #f2f2f2;
      display: flex;
      flex-direction: column;
    }

    /* Next Card Highlight */
    .next-card {
      border: 2px solid var(--ramp);
      border-radius: 14px;
      background: color-mix(in srgb, var(--ramp) 10%, var(--surface2));
      padding: 14px 16px;
      margin-bottom: 12px;
    }
    .next-card .nl {
      font-size: 0.72rem;
      font-weight: 800;
      letter-spacing: 0.1em;
      text-transform: uppercase;
      color: var(--ramp);
    }
    .next-card .na {
      font-size: 1.35rem;
      font-weight: 800;
      margin-top: 2px;
    }
    .next-card .ne {
      display: flex;
      align-items: baseline;
      gap: 10px;
      margin: 4px 0 8px;
    }
    .next-card .ne b { font-size: 2rem; }

    /* Single unified app container: mobile vertical stack by default */
    #app-container { display: flex; flex-direction: column; gap: 12px; padding: 12px; width: 100%; }

    /* Sliders and fields */
    .in-range {
      width: 100%;
      accent-color: var(--teal);
      height: 4px;
      border-radius: 99px;
      background: var(--surface3);
    }

    .ic {
      width: 1.15em;
      height: 1.15em;
      flex: none;
      vertical-align: -0.15em;
    }

    @media (max-width: 900px) {
      .hd { padding: 0 12px; gap: 10px; }
      .hd nav { display: none; }
    }

    /* --- LANDSCAPE / DESKTOP: side-by-side layout --- */
    @media screen and (orientation: landscape), (min-width: 768px) {
    }

    /* --- OPT-IN FULL SCREEN LOCK (landscape cockpit) --- */
    /* Normal layout: wrappers/panels that only matter in the lock stay inert. */
    .mode-center { display: contents; }
    .stat-panel, .pr-short, .fab-lock { display: none; }
    #lock-drawer { display: flex; flex-direction: column; }
    #drawer-scrim { position: fixed; inset: 0; z-index: 900; background: color-mix(in srgb, var(--bg) 55%, transparent); }
    .stat-row {
      display: flex; align-items: center; justify-content: space-between; gap: 8px;
      padding: 8px 10px; border-radius: 8px; font-size: 0.72rem; font-weight: 700;
      background: var(--sg-card); border: 1px solid var(--sg-border);
    }
    .stat-row .sr-k { color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
    .stat-row .sr-v { color: var(--sc, var(--teal)); font-size: 1rem; white-space: nowrap; }

    body.training-lock {
      --lock-rail: 160px; --lock-right: 190px; --lock-btn: 48px; --lock-safe: 68px;
    }
    body.training-lock, html.training-lock {
      margin: 0; padding: 0; height: 100dvh !important; overflow: hidden !important; overscroll-behavior: none;
    }
    body.training-lock header.hd, body.training-lock > .gline { display: none !important; }
    body.training-lock .lock-hide { display: none !important; }

    /* Frame: strip on top, tiles left, arena fills the rest (no scrolling anywhere) */
    body.training-lock #app-container {
      flex: 1 1 0; min-height: 0; overflow: hidden;
      display: grid; grid-template-columns: var(--lock-rail) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
      gap: 6px; padding: 6px 8px;
    }
    body.training-lock .metric-grid {
      grid-column: 1; height: 100%; min-height: 0; gap: 6px;
      grid-template-columns: 1fr !important; grid-template-rows: repeat(4, minmax(0, 1fr));
    }
    body.training-lock .tile {
      padding: 4px 10px; min-height: 0; overflow: hidden;
      display: flex; flex-direction: column; justify-content: center;
    }
    body.training-lock .tile b { font-size: 1.45rem; line-height: 1.1; }

    body.training-lock #arena-module { grid-column: 2; min-height: 0 !important; height: 100%; }
    body.training-lock #arena-module > .mh { display: none; }
    body.training-lock #arena-module > .mb { padding: 0; gap: 0; overflow: hidden !important; justify-content: flex-start !important; }
    body.training-lock #box-ghost, body.training-lock #box-zone,
    body.training-lock #box-boss, body.training-lock #box-ascent { flex: 1 1 0; min-height: 0; }

    /* Ghost Pacer: track center + compact standings right */
    body.training-lock #panel-ghost { position: relative; flex: 1; min-height: 0; }
    body.training-lock .ghost-hd { display: contents; }
    body.training-lock #ghost-lead-text {
      position: absolute; top: 8px; left: 10px; z-index: 2; font-size: 0.8rem;
      padding: 2px 8px; border-radius: 99px; background: color-mix(in srgb, var(--bg) 70%, transparent);
    }
    body.training-lock .ghost-row { flex: 1; min-height: 0 !important; gap: 6px !important; }
    body.training-lock .ghost-trackwrap { flex: 1 1 0 !important; min-width: 0; padding: 4px !important; }
    body.training-lock #track-svg { width: 100%; height: 100% !important; max-height: none !important; }
    body.training-lock #leaderboard-tower {
      flex: 0 0 var(--lock-right) !important; justify-content: flex-start !important; padding-bottom: var(--lock-safe);
    }
    body.training-lock #podium-list { gap: 4px !important; }
    body.training-lock .podium-row { padding: 5px 8px !important; font-size: 0.78rem !important; }
    body.training-lock .pr-name { display: none !important; }
    body.training-lock .pr-short { display: inline; white-space: nowrap; }
    body.training-lock .podium-row > div:last-child { flex-direction: column; align-items: flex-end; gap: 0 !important; }
    body.training-lock .pr-gap { order: -1; font-size: 0.95rem; line-height: 1.15; }
    body.training-lock .pr-rpm { font-size: 0.6rem; line-height: 1.1; color: var(--dim) !important; }

    /* Zone Lock / Boss Rush / Endless Ascent: big visual center + stat rows right */
    body.training-lock #box-zone, body.training-lock #box-boss, body.training-lock #box-ascent {
      flex-direction: row !important; gap: 6px !important; align-items: stretch;
    }
    body.training-lock .mode-center { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; gap: 6px; }
    body.training-lock .mode-center .next-card { margin: 0; padding: 8px 12px; flex: none; }
    body.training-lock .mode-center .track-row { flex: 1; min-height: 0; margin: 0; justify-content: center; gap: 10px; }
    body.training-lock .mode-center .pbar { height: 36px; }
    body.training-lock .track-meta { font-size: 0.95rem; }
    body.training-lock .stat-panel {
      display: flex; flex-direction: column; gap: 4px; flex: 0 0 var(--lock-right); min-width: 0;
      padding-bottom: var(--lock-safe);
    }

    /* Floating buttons: pause/resume, drawer, full screen (bottom-right) */
    .fab-fullscreen {
      position: fixed; bottom: 20px; right: 20px;
      width: 56px; height: 56px; border-radius: 50%;
      background: var(--teal); color: #000;
      display: flex; align-items: center; justify-content: center;
      font-size: 1.5rem; box-shadow: 0 4px 12px rgba(45, 212, 191, 0.4);
      border: none; cursor: pointer; z-index: 1000;
    }
    body.training-lock .fab-lock, body.training-lock .fab-fullscreen {
      display: flex; position: fixed; bottom: 10px; width: var(--lock-btn); height: var(--lock-btn);
      border-radius: 50%; align-items: center; justify-content: center; z-index: 1000; cursor: pointer;
      font-size: 1.3rem; padding: 0;
    }
    body.training-lock .fab-fullscreen { right: 10px; }
    body.training-lock #btn-lock-drawer { right: 66px; }
    body.training-lock #btn-lock-toggle { right: 122px; }
    body.training-lock .fab-lock { background: var(--teal); color: var(--bg); border: none; }
    body.training-lock #btn-lock-toggle.running { background: var(--gold); }
    body.training-lock #btn-lock-drawer { background: var(--surface2); color: var(--gold); border: 1px solid var(--border); }
    body.training-lock #btn-lock-drawer[aria-expanded="true"] { border-color: var(--gold); }

    /* Overlay drawer: fixed, so opening it never reflows the frame */
    #lock-drawer {
      position: fixed; z-index: 950; left: calc(var(--lock-rail, 160px) + 16px); top: 48px; bottom: 6px;
      width: min(460px, calc(100vw - var(--lock-rail, 160px) - 16px - 178px));
      overflow-y: auto; gap: 4px; padding: 4px;
      background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
    }
    #lock-drawer .mod { flex: none !important; min-height: auto !important; }
    #lock-drawer .mh { display: none; }
    #lock-drawer .mb { padding: 4px 8px; }
    #lock-drawer #mod-program > .mb { gap: 6px; }
    #lock-drawer #panel-cal > .mb { gap: 4px; }
    #lock-drawer #panel-cal .col { gap: 0 !important; }
    #lock-drawer #panel-cal .mb > .row { padding-top: 0 !important; }
    #lock-drawer #row-audio { margin-top: 0 !important; padding: 0 4px !important; border-top: 0 !important; }

/* --- View switching (nav tabs) --- */
[hidden] { display: none !important; }
body[data-view="splits"] .v-ses,
body[data-view="history"] .v-ses { display: none; }
body[data-view="hardware"] .v-ses:not(#panel-cal) { display: none; }
.hist-row, .split-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px;
  padding: 8px 10px; border-radius: 8px; font-size: 0.82rem; font-weight: 700;
  background: var(--sg-card); border: 1px solid var(--sg-border);
}
.hist-row .hr-mode { color: var(--gold); }
.hist-row .hr-date, .hist-row .hr-stats { color: var(--text-dim); font-weight: 600; }
