/* --- existing styling, carried over from fpv_rates.html ------------------ */

:root {
  color-scheme: light;
  --bg: #f7f6f2;
  --panel: #ffffff;
  --ink: #1c1c1a;
  --ink-2: #5f5e58;
  --ink-3: #8b8a82;
  --line: #dedcd3;
  --bf: #2a63b8;
  --ac: #16805c;
  --grid: rgba(139, 138, 130, 0.25);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #161614;
    --panel: #1f1f1c;
    --ink: #ecebe4;
    --ink-2: #b3b2a8;
    --ink-3: #7d7c74;
    --line: #34342f;
    --bf: #5b93e0;
    --ac: #3fb98d;
    --grid: rgba(125, 124, 116, 0.25);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1.6;
}
main { max-width: 860px; margin: 0 auto; padding: 2.5rem 1.25rem 4rem; }
header { border-bottom: 1px solid var(--line); padding-bottom: 1.25rem; margin-bottom: 2rem; }
h1 { font-size: 1.7rem; font-weight: 400; margin: 0 0 0.35rem; letter-spacing: 0.01em; }
.sub { color: var(--ink-2); font-size: 0.95rem; margin: 0; font-style: italic; }
.mono { font-family: 'SF Mono', 'Cascadia Code', Consolas, monospace; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
         padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.panel h2 { font-size: 0.8rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
            margin: 0 0 0.9rem; font-family: 'SF Mono', Consolas, monospace; color: var(--ink-2); }

.row { display: flex; align-items: center; gap: 0.7rem; margin-bottom: 0.7rem; }
.row:last-child { margin-bottom: 0; }
.row label { font-size: 0.85rem; color: var(--ink-2); width: 6.2rem; flex-shrink: 0; }
.row .num {
  width: 4.8rem; flex-shrink: 0; text-align: right;
  font-size: 0.85rem; font-variant-numeric: tabular-nums;
  background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 0.2rem 0.3rem;
}
.row .num:focus-visible { outline: none; border-color: var(--ink-3); box-shadow: 0 0 0 3px var(--grid); }

input[type="range"] { flex: 1; appearance: none; -webkit-appearance: none; height: 3px;
                      border-radius: 2px; background: var(--line); outline: none; }
input[type="range"]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%;
  background: var(--ink); border: 2px solid var(--bg); cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--ink); border: 2px solid var(--bg); cursor: pointer;
}
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px var(--grid); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
         gap: 0.75rem; margin-bottom: 1.5rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
        padding: 0.7rem 1rem; }
.stat .k { font-size: 0.7rem; letter-spacing: 0.06em; text-transform: uppercase;
           color: var(--ink-3); font-family: 'SF Mono', Consolas, monospace; }
.stat .v { font-size: 1.25rem; font-variant-numeric: tabular-nums; margin-top: 0.1rem; }

.chartbox { background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
            padding: 1.25rem; }
.chartwrap { position: relative; height: 340px; }
.legend { display: flex; gap: 1.25rem; font-size: 0.8rem; color: var(--ink-2);
          margin-bottom: 0.75rem; font-family: 'SF Mono', Consolas, monospace; }
.legend span::before { content: ""; display: inline-block; width: 18px; height: 3px;
                       border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.legend .l-bf::before { background: var(--bf); }
.legend .l-ac::before { background: var(--ac); }

footer { margin-top: 2rem; font-size: 0.82rem; color: var(--ink-3);
         border-top: 1px solid var(--line); padding-top: 1rem; }
footer code { font-family: 'SF Mono', Consolas, monospace; font-size: 0.78rem; }

/* --- new chrome: tabs, rate editor, import panel ------------------------- */

.tabs { display: flex; gap: 0.25rem; margin-top: 1rem; }
.tab {
  font-family: 'SF Mono', Consolas, monospace; font-size: 0.78rem;
  letter-spacing: 0.06em; text-transform: uppercase; text-decoration: none;
  color: var(--ink-3); padding: 0.4rem 0.85rem;
  border: 1px solid var(--line); border-bottom: none;
  border-radius: 8px 8px 0 0; background: transparent;
}
.tab.on { color: var(--ink); background: var(--panel); }

.rc-head { display: flex; gap: 0.4rem; margin-bottom: 0.9rem; }
.rc-type, .rc-axis, .imp-rp, .imp-example {
  font-family: 'SF Mono', Consolas, monospace; font-size: 0.78rem;
  padding: 0.3rem 0.7rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink-2); cursor: pointer;
}
.rc-type.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.rc-axis.on { border-color: var(--ink); color: var(--ink); }
.imp-rp.active { border-color: var(--ink); color: var(--ink); }
.imp-rp.unsup { opacity: 0.45; }

.rc-axes { display: flex; align-items: center; gap: 0.4rem; margin-bottom: 1rem; }
.rc-link { margin-left: auto; font-size: 0.8rem; color: var(--ink-2); }
.rc-unit { font-size: 0.75rem; color: var(--ink-3); min-width: 2.5rem; }

.row.oor .num { border-color: #c0392b; }
.row.oor .rc-unit { color: #c0392b; }

.imp-bar { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.imp-paste {
  width: 100%; font-family: 'SF Mono', Consolas, monospace; font-size: 0.75rem;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line);
  border-radius: 6px; padding: 0.5rem;
}
.imp-sum, .imp-pick { display: flex; align-items: center; gap: 0.4rem; margin-top: 0.6rem; }
.imp-lbl { font-size: 0.75rem; color: var(--ink-3); }
.imp-craft { font-family: 'SF Mono', Consolas, monospace; font-size: 0.8rem; }
.imp-note, .imp-warn, .imp-err { font-size: 0.78rem; margin: 0.5rem 0 0; }
.imp-note { color: var(--ink-3); }
.imp-warn { color: #b7791f; }
.imp-err  { color: #c0392b; }

/* --- 3D sim tab ----------------------------------------------------------- */

.simwrap { position: relative; height: 420px; background: var(--panel);
           border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.simwrap canvas { display: block; width: 100%; height: 100%; }
.sim-msg { position: absolute; inset: 0; display: grid; place-items: center;
           text-align: center; padding: 2rem; color: var(--ink-2); font-size: 0.9rem; }
/* Any author-origin `display:` rule beats the UA stylesheet's `[hidden] { display: none }`
   (author origin always wins over UA origin), so setting `.hidden = true` on an element
   whose class sets `display` is a SILENT NO-OP -- the element just stays on screen.

   This has now bitten this file three times: first `.simwrap canvas` and `.sim-msg`,
   then `.viewbar`, then `.camrow`. Each was patched with its own per-class rule and its
   own comment explaining the specificity arithmetic. That is three special cases where
   one general rule belongs, and it guaranteed a fourth: every future element that has
   both a `display:` and a `hidden` toggle would reintroduce the same bug.

   So: one rule, once. `!important` is the point rather than a wart -- it is what makes
   `hidden` mean hidden regardless of what any class does, which is the contract the
   attribute is supposed to have. Nothing in this codebase wants a `[hidden]` element to
   stay visible. */
[hidden] { display: none !important; }

.sticks { display: flex; gap: 1.5rem; justify-content: center; align-items: center;
          margin: 1.25rem 0; flex-wrap: wrap; }

/* Reset lives BETWEEN the sticks -- it is what you grab when you are inverted and
   lost, which is mid-flight, so it belongs under the hands rather than below the
   fold. Aligned to the pads themselves, not to the stickbox (which is taller,
   because of the anchors above and below it). */
.reset-slot { display: grid; justify-items: center; gap: 0.4rem; }
.reset-slot .btn { line-height: 1.25; padding: 0.7rem 1rem; }

/* Anchors on all four sides of each pad. Press and hold to jam that axis hard
   over -- the point is a big target you cannot miss, not a corner pixel of the
   pad you have to aim at. */
.stickbox {
  display: grid;
  grid-template-columns: 5.2rem 140px 5.2rem;
  grid-template-rows: 1.7rem 140px 1.7rem auto;
  align-items: center; justify-items: center; gap: 0.3rem;
}
.stickbox .stick { grid-column: 2; grid-row: 2; }
.stickbox .stick-label { grid-column: 1 / -1; grid-row: 4; }
.a-n { grid-column: 2; grid-row: 1; }
.a-w { grid-column: 1; grid-row: 2; }
.a-e { grid-column: 3; grid-row: 2; }
.a-s { grid-column: 2; grid-row: 3; }

.anchor {
  font-family: 'SF Mono', Consolas, monospace; font-size: 0.68rem;
  font-variant-numeric: tabular-nums; white-space: nowrap;
  padding: 0.3rem 0.4rem; width: 100%;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel); color: var(--ink-2);
  cursor: pointer; user-select: none; touch-action: none;
}
.a-n, .a-s { width: 140px; }
.anchor:hover { border-color: var(--ink-3); color: var(--ink); }
.anchor:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--grid); }
.anchor.held { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.anchor.dead { opacity: 0.45; cursor: default; }

.anchor-help {
  max-width: 34rem; margin: 0 auto 1.25rem; text-align: center;
  font-size: 0.8rem; color: var(--ink-3);
}
.stick { width: 140px; height: 140px; border: 1px solid var(--line);
         border-radius: 10px; background: var(--panel); position: relative;
         touch-action: none; cursor: crosshair; }
.stick .dot { position: absolute; width: 14px; height: 14px; border-radius: 50%;
              background: var(--ink); transform: translate(-50%, -50%); pointer-events: none; }
.stick .cross { position: absolute; inset: 0; }
.stick .cross::before, .stick .cross::after {
  content: ""; position: absolute; background: var(--line);
}
.stick .cross::before { left: 50%; top: 8%; bottom: 8%; width: 1px; }
.stick .cross::after  { top: 50%; left: 8%; right: 8%; height: 1px; }
.stick-label { text-align: center; font-size: 0.7rem; color: var(--ink-3);
               font-family: 'SF Mono', Consolas, monospace; margin-top: 0.35rem; }

/* The HUD updates 60 times a second while you are flying, so a tile that changes
   height -- as the attitude readout did the moment an angle hit three digits and
   wrapped to a second line -- shoves every control below it up and down under your
   cursor. Two defences: never wrap, and reserve the height anyway.
   Scoped to .hud: the curve tab's stats carry longer strings and would overflow
   horizontally if forbidden to wrap. */
.hud { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.hud .stat { min-height: 4.1rem; }
.hud .stat .v { font-size: 1.05rem; white-space: nowrap; }
.hud .stat.slow .v { color: #c0392b; }

/* Two fixed rows rather than one reflowing strip: what the sticks are COMMANDING
   (three rates plus throttle) on top, the resulting STATE (three angles) plus the
   frame rate below -- frame rate is not a commanded value, so it lives with the
   other readouts, not the controls. Fixed column counts stop the tiles rearranging
   themselves as values change width -- which is the whole reason attitude was
   split out of one crowded string. Both rows are four cards now, so `.hud-4` is
   the only grid rule needed; `.hud-3` is gone.

   `.hud.hud-4` (0,2,0), not `.hud-4` (0,1,0): the `.hud` base rule above also sets
   margin-bottom, and at equal specificity the LATER rule wins regardless of which
   is more specific-looking. Two classes settles it in both directions. */
.hud.hud-4 { grid-template-columns: repeat(4, 1fr); margin-bottom: 0.6rem; }
@media (max-width: 620px) {
  .hud.hud-4 { grid-template-columns: repeat(2, 1fr); }
}

.pad-axes { display: grid; gap: 0.25rem; margin-top: 0.6rem; }
.pad-axis { display: flex; align-items: center; gap: 0.5rem; font-size: 0.75rem;
            font-family: 'SF Mono', Consolas, monospace; color: var(--ink-2); }
.pad-bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; position: relative; }
.pad-bar i { position: absolute; top: 0; bottom: 0; width: 3px; background: var(--ink);
             border-radius: 2px; }
.bind-row { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.6rem; }
.bind-btn { font-family: 'SF Mono', Consolas, monospace; font-size: 0.75rem;
            padding: 0.3rem 0.6rem; border: 1px solid var(--line); border-radius: 6px;
            background: var(--bg); color: var(--ink-2); cursor: pointer; }
.bind-btn.listening { border-color: var(--ac); color: var(--ac); }
.bind-btn.bound { color: var(--ink); }
.bind-btn.inv { padding: 0.3rem 0.45rem; margin-left: -0.25rem; }

.btn { font-family: 'SF Mono', Consolas, monospace; font-size: 0.8rem;
       padding: 0.45rem 1rem; border: 1px solid var(--ink); border-radius: 6px;
       background: var(--ink); color: var(--bg); cursor: pointer; }

/* --- throttle tab ---------------------------------------------------------- */

/* The first enum control: a segmented button group, reusing the .rc-type styling
   the model toggles already use. */
.rc-enum { display: flex; gap: 0.3rem; flex: 1; }
.rc-enum .rc-type { flex: 0 0 auto; }

/* The active RATE model, shown on the throttle tab where its toggle is not.
   Deliberately not a button -- clicking a rate model from the throttle tab would
   change something with no visible effect on the chart in front of you. */
.rc-chip {
  margin-left: auto;
  font-family: 'SF Mono', Consolas, monospace; font-size: 0.75rem;
  color: var(--ink-3); padding: 0.3rem 0.5rem;
  border: 1px dashed var(--line); border-radius: 6px;
}

/* A control that currently does nothing (limit percent with the limit OFF). */
.row.inert { opacity: 0.5; }
.row.inert .rc-unit { font-style: italic; }

/* --- FPV view --------------------------------------------------------------- */

/* The crosshair is a CSS overlay, not scene geometry. var(--ink) is near-black in
   light mode and near-white in dark, so it is theme-aware with no palette work and no
   contrast test -- and it stays crisp at any device pixel ratio.
   The single `[hidden]` rule at the top of this file makes `hidden` work despite this
   `display: grid`. Do NOT add a per-class override -- that is the trap. */
.crosshair {
  position: absolute; inset: 0;
  pointer-events: none;
  display: grid; place-items: center;
}
.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: var(--ink);
  opacity: 0.75;
}
.crosshair::before { width: 22px; height: 2px; }   /* horizontal bar */
.crosshair::after  { width: 2px;  height: 22px; }  /* vertical bar   */

.viewbar { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap;
           justify-content: center; margin: 0.75rem 0 1.25rem; }
.viewtoggle { display: flex; gap: 0.3rem; }
.camrow { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }


.camctl { display: flex; align-items: center; gap: 0.5rem; }
.camctl label { font-size: 0.8rem; color: var(--ink-2); white-space: nowrap; }
.camctl input[type="range"] { width: 8rem; }
.camctl output {
  font-family: 'SF Mono', Consolas, monospace; font-size: 0.8rem;
  font-variant-numeric: tabular-nums; color: var(--ink-3);
  min-width: 3rem; text-align: right;
}

/* --- lens toggle + fullscreen --------------------------------------------- */

/* No `.lensrow[hidden]` rule. The single global `[hidden] { display: none !important; }`
   near the top of this file already covers it -- adding a per-class override here would
   reintroduce exactly the pattern that rule was created to end. */
.lensrow { display: flex; gap: 0.3rem; }

.fsbtn {
  margin-left: auto;
  font-size: 0.95rem; line-height: 1;
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--ink-2); cursor: pointer;
}
.fsbtn:hover { color: var(--ink); border-color: var(--ink-3); }

/* --- fullscreen ----------------------------------------------------------- */

/* Two mechanisms, one appearance. `:fullscreen` is the native API; `.maximized` is the
   fallback for browsers that refuse it for non-video elements (iOS Safari). They must
   look identical, so they share every declaration. */
#simstage:fullscreen,
#simstage.maximized {
  display: flex; flex-direction: column;
  background: var(--bg);
  padding: 1rem; gap: 0.75rem;
}
#simstage.maximized {
  position: fixed; inset: 0; z-index: 100;
  overflow: auto;
}

/* The canvas takes whatever is left after the controls have had their say -- so the
   picture grows and the sticks stay put, which is the entire point of the stage. */
#simstage:fullscreen .simwrap,
#simstage.maximized .simwrap {
  flex: 1 1 auto;
  height: auto;              /* overrides the fixed 420px */
  min-height: 0;             /* or flex refuses to shrink it below its content */
  border-radius: 0;
}
#simstage:fullscreen .hud,
#simstage.maximized .hud { margin-bottom: 0; }
#simstage:fullscreen .sticks,
#simstage.maximized .sticks { margin: 0; }
