:root {
  --paper: #0d090c;
  --card: #171016;
  --ink: #ffe8f3;
  --muted: #b0829a;
  --rule: #311e2b;
  --accent: #ff4d94;
  --lab-accent: #ff4d94;
  --shadow-ink: #ff4d94;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 80% 10%, rgba(255, 77, 148, 0.08), transparent 45%),
    radial-gradient(circle at 15% 85%, rgba(255, 77, 148, 0.05), transparent 40%),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='320' height='320'><filter id='p'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .95  0 0 0 0 .35  0 0 0 0 .62  .05 0 0 0 0'/></filter><rect width='100%' height='100%' filter='url(%23p)'/></svg>");
  overflow-x: hidden;
  color: var(--ink);
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  display: flex;
  flex-direction: row;
  align-items: stretch;
  padding: 0;
  min-height: 100vh;
}

/* Sidebar */
nav.side {
  width: 236px;
  flex: none;
  border-right: 1px solid var(--rule);
  background: rgba(13, 9, 12, 0.85);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--rule) transparent;
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}

.brand-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: #0d090c;
  font-weight: 900;
  font-size: 12px;
  display: grid;
  place-items: center;
  flex: none;
  box-shadow: 2px 2px 0 #ffe8f3;
}

nav.side h1 {
  font-size: 14px;
  font-weight: 800;
  margin: 0 0 3px;
  color: var(--accent);
  letter-spacing: 0.03em;
}

nav.side p {
  color: var(--muted);
  margin: 0;
  font-size: 11.5px;
  line-height: 1.4;
}

#nav-links {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

nav.side a {
  color: var(--ink);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}

nav.side a:hover {
  background: rgba(255, 77, 148, 0.1);
  border-color: var(--rule);
}

nav.side a span {
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.08em;
}

nav.side a em {
  font-style: normal;
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--muted);
}

nav.side a[aria-current="true"] {
  background: var(--accent);
  color: #0d090c;
  font-weight: 700;
  box-shadow: 2px 2px 0 #ffe8f3;
}

nav.side a[aria-current="true"] span,
nav.side a[aria-current="true"] em {
  color: rgba(13, 9, 12, 0.78);
}

nav.side small {
  margin-top: auto;
  padding-top: 16px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

/* Main page */
main.page {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 36px;
}

header {
  width: 100%;
  max-width: 760px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}

header h1 {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0.02em;
  color: var(--ink);
}

header span {
  color: var(--muted);
  font-size: 12px;
}

#fig {
  width: 100%;
  max-width: 760px;
  height: auto;
  display: block;
  margin: 4px 0 8px;
  user-select: none;
  overflow: visible;
}

#fig [data-act] {
  cursor: pointer;
  transition: opacity 0.2s, transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
}

#fig [data-act].part-hidden {
  opacity: 0.08;
  pointer-events: none;
}

#fig [data-act].part-selected {
  filter: drop-shadow(0 0 6px var(--accent));
}

#readout {
  display: none;
}

.stage {
  position: relative;
  width: 100%;
  max-width: 760px;
}

.actions {
  position: absolute;
  top: 4px;
  left: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 7px;
  z-index: 3;
  max-width: 225px;
}

.actions .cap {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0 0 2px;
}

html.nolabels #fig .tag {
  display: none;
}

.toast {
  position: absolute;
  left: 0;
  bottom: 12px;
  z-index: 4;
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--card);
  color: var(--ink);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: 5px 10px;
  box-shadow: 2px 2px 0 var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  max-width: 280px;
}

.toast.show {
  opacity: 1;
}

.made-with {
  width: 100%;
  max-width: 760px;
  margin-top: 22px;
  text-align: right;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.made-with a {
  color: var(--muted);
  text-decoration: none;
}

.made-with a:hover {
  color: var(--accent);
}

.stats {
  position: absolute;
  top: 4px;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  z-index: 2;
  text-align: right;
}

.stat .k {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat .v {
  font-size: 34px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.stat.small .v {
  font-size: 20px;
}

.stat .v.bump {
  animation: bump 0.35s ease-out;
  color: var(--accent);
}

@keyframes bump {
  0% {
    transform: scale(1.18);
  }
  100% {
    transform: none;
  }
}

.stepwrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
}

.act {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}

.act:hover {
  background: rgba(255, 77, 148, 0.18);
}

.act.active-btn {
  background: var(--accent);
  color: #0d090c;
  font-weight: 700;
}

.act .car {
  margin-left: 6px;
  font-size: 10px;
}

.act:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.chips {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--card);
  border: 2px solid var(--accent);
  border-radius: 12px;
  box-shadow: 3px 3px 0 var(--accent);
  padding: 8px;
  width: max-content;
  max-width: min(300px, 62vw);
  position: absolute;
  left: calc(100% + 10px);
  top: -4px;
  z-index: 5;
}

.stepwrap.open .chips {
  display: flex;
}

.chip {
  white-space: nowrap;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: 4px 8px;
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--accent);
}

.chip:hover {
  background: var(--accent);
  color: #0d090c;
  transform: translate(-1px, -1px);
}

.chip.current {
  background: var(--accent);
  color: #0d090c;
}

.chip.current:hover {
  transform: none;
}

.chip.off {
  opacity: 0.45;
}

/* Controls */
.controls {
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px 24px;
  border-top: 1px solid var(--rule);
  padding-top: 16px;
}

.ctl {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ctl label {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  font: inherit;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  padding: 5px 14px;
  cursor: pointer;
}

button:hover {
  background: rgba(255, 77, 148, 0.14);
}

button[aria-pressed="true"] {
  background: var(--accent);
  color: #0d090c;
  font-weight: 700;
}

.sw {
  width: 26px;
  height: 26px;
  padding: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.35);
}

.sw[aria-pressed="true"] {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Lesson & Cards */
.wide {
  width: 100%;
  max-width: 760px;
  margin-top: 22px;
  border-top: 1px solid var(--rule);
  padding-top: 18px;
}

.wide h2,
.lesson h2 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 8px;
}

.lesson {
  width: 100%;
  max-width: 760px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 26px 32px;
  margin-top: 22px;
}

.lesson section + section {
  margin-top: 22px;
}

.lesson p {
  margin: 0 0 8px;
  line-height: 1.55;
}

.card {
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  padding: 12px;
  background: var(--card);
  box-shadow: 3px 3px 0 var(--accent);
  line-height: 1.5;
}

.card b {
  display: block;
  margin-bottom: 4px;
  color: var(--accent);
}

.card .k {
  display: block;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dsel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 10px;
  align-items: center;
  margin-bottom: 10px;
}

.dsel label {
  color: var(--muted);
  font-size: 12px;
}

.dsel select {
  font: inherit;
  font-size: 12px;
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  padding: 4px 6px;
  background: var(--paper);
  color: var(--ink);
}

.calc {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 8px 0;
}

.calc div {
  border: 1.5px solid var(--rule);
  border-radius: 10px;
  padding: 6px 8px;
  background: var(--paper);
}

.calc .k {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.calc .v {
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
}

.warn {
  border: 1.5px solid #ff3366;
  color: #ff80a0;
  border-radius: 10px;
  padding: 6px 9px;
  margin: 6px 0;
  font-size: 12px;
  background: rgba(255, 51, 102, 0.12);
}

.ok {
  color: #5ee69c;
  font-size: 12px;
  margin: 6px 0;
}

table.cost {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 6px;
}

table.cost td {
  padding: 3px 4px;
  border-bottom: 1px solid var(--rule);
}

table.cost td.n {
  text-align: right;
}

table.cost tr.t td {
  font-weight: 800;
  border-bottom: 0;
  color: var(--accent);
}

.wiring svg {
  width: 100%;
  height: auto;
  display: block;
}

.plist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.plist button {
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  padding: 4px 9px;
  border-radius: 8px;
  border: 1.5px solid var(--accent);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 2px 2px 0 var(--accent);
}

.plist button.out {
  opacity: 0.4;
  box-shadow: none;
}

.plist button[aria-pressed="true"] {
  background: var(--accent);
  color: #0d090c;
}

pre.code {
  margin: 0;
  background: var(--card);
  color: #ffd4e8;
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  font: 12px/1.55 ui-monospace, Menlo, monospace;
  overflow: auto;
  box-shadow: 3px 3px 0 var(--accent);
  white-space: pre;
}

.term {
  background: #070406;
  color: #ff7ab8;
  border: 1.5px solid var(--accent);
  border-radius: 12px;
  padding: 10px 12px;
  min-height: 140px;
  max-height: 220px;
  overflow-y: auto;
  font: 12px/1.5 ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
}

.keys {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 12px;
  font-size: 12px;
}

.keys kbd {
  font: inherit;
  font-weight: 800;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  padding: 0 6px;
  background: var(--paper);
  color: var(--accent);
  box-shadow: 1px 1px 0 var(--accent);
}

.q {
  margin: 0 0 12px;
}

.q p {
  margin: 0 0 6px;
}

.q .opts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.q .chip {
  white-space: normal;
  text-align: left;
}

.q .chip.ok {
  background: #38c97a;
  color: #0d090c;
  border-color: #38c97a;
}

.q .chip.no {
  text-decoration: line-through;
  opacity: 0.45;
}

.snd button[aria-pressed="true"] {
  background: var(--accent);
  color: #0d090c;
}

/* Flying mode */
.sticks {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}

.stage.flying .sticks {
  display: flex;
}

.pad {
  pointer-events: auto;
  width: 118px;
  height: 118px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  background: rgba(23, 16, 22, 0.85);
  position: relative;
  touch-action: none;
  box-shadow: 2px 2px 0 var(--accent);
}

.pad i {
  position: absolute;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  left: 39px;
  top: 39px;
  box-shadow: 0 0 10px rgba(255, 77, 148, 0.5);
}

.pad span {
  position: absolute;
  bottom: -18px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.stage.flying #fig {
  cursor: crosshair;
  overflow: hidden;
  border: 1.5px solid var(--rule);
  border-radius: 14px;
  background: radial-gradient(circle at 50% 45%, #1c1119 0%, #0a0609 100%);
}

.stage.fpv .stats {
  display: none;
}

.stage.flying .stats {
  background: rgba(13, 9, 12, 0.84);
  border: 1px solid var(--rule);
  border-radius: 12px;
  padding: 6px 10px 8px;
  gap: 6px;
}

.fmsg {
  display: none;
  position: absolute;
  left: 50%;
  bottom: 64px;
  transform: translateX(-50%);
  max-width: min(440px, max(220px, calc(100% - 300px)));
  z-index: 3;
  pointer-events: none;
  background: var(--accent);
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  padding: 6px 14px;
  box-shadow: 2px 2px 0 var(--ink);
  font: 800 12px/1.4 ui-monospace, Menlo, monospace;
  text-align: center;
  color: #0d090c;
}

.stage.flying .fmsg.on {
  display: block;
}

.stage.fpv .fmsg.on {
  display: none;
}

.stage.flying #btns .stepwrap:not(.flyb),
.stage.flying #btns .cap,
.stage:not(.flying) #btns .stepwrap.flyonly {
  display: none;
}

.stage.flying #btns {
  z-index: 4;
}

/* Responsive */
@media (max-width: 760px) {
  html body {
    flex-direction: column;
  }

  nav.side {
    width: auto;
    height: auto;
    position: sticky;
    top: 0;
    z-index: 6;
    background: var(--paper);
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 8px 12px;
  }

  nav.side .brand,
  nav.side small,
  nav.side a span,
  nav.side a em {
    display: none;
  }

  #nav-links {
    flex-direction: row;
    gap: 6px;
  }

  nav.side a {
    flex: none;
    padding: 7px 12px;
    border: 1px solid var(--rule);
    border-radius: 999px;
    white-space: nowrap;
  }

  .lesson {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  main.page {
    padding: 14px 12px 24px;
  }

  header span,
  .actions .cap {
    display: none;
  }

  .actions {
    position: static;
    max-width: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 6px;
    margin: 6px 0 4px;
  }

  .act {
    font-size: 12px;
    padding: 4px 11px;
  }

  .stats {
    position: static;
    flex-direction: row;
    justify-content: flex-end;
    gap: 18px;
    margin-bottom: 4px;
  }

  .chips {
    left: 0;
    top: calc(100% + 8px);
  }

  .stage.flying {
    display: flex;
    flex-direction: column;
  }

  .stage.flying #btns {
    order: 0;
    margin: 4px 0;
    position: relative;
    z-index: 4;
  }

  .stage.flying .stats {
    order: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px 10px;
    text-align: left;
    justify-items: start;
    padding: 8px 10px;
    margin: 0;
  }

  .stage.flying #fig {
    order: 2;
    margin: 4px 0 0;
  }

  .stage.flying .fmsg {
    order: 3;
    position: static;
    transform: none;
    max-width: none;
    margin: 6px 0 0;
    border-radius: 12px;
    font-size: 11.5px;
  }

  .stage.flying .sticks {
    order: 4;
    position: static;
    padding: 10px 6px 24px;
  }

  .stage.flying .stats .stat {
    min-width: 0;
  }

  .stage.flying .stats .stat:first-child {
    grid-column: 1 / -1;
  }

  .stage.flying .stats .k {
    font-size: 9px;
    letter-spacing: 0.08em;
  }

  .stage.flying .stats .v,
  .stage.flying .stats .stat.small .v {
    font-size: 15px;
    line-height: 1.15;
    overflow-wrap: anywhere;
  }

  .stage.fpv .stats {
    display: none;
  }
}
