:root {
  color-scheme: dark;
  /* Palette reprise de rmdev.design */
  --bg: #0f1115;
  --card: #181a1e;
  --panel: rgba(15, 17, 21, 0.86);
  --line: rgba(255, 255, 255, 0.1);
  --text: #ffffff;
  --muted: #a1a1aa;
  --accent: #22d3ee;
  --accent-2: #ffd166;
  --danger: #ff7b72;
  --brand-gradient: linear-gradient(120deg, #22d3ee 0%, #818cf8 100%);
  --font-body: "DM Sans", "Segoe UI", system-ui, sans-serif;
  --font-heading: "Bricolage Grotesque", "DM Sans", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(34, 211, 238, 0.1), transparent 40%),
    radial-gradient(circle at bottom right, rgba(129, 140, 248, 0.08), transparent 45%),
    var(--bg);
}

.app-shell {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.panel {
  display: flex;
  flex: 0 0 380px;
  max-width: 420px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
  overflow: hidden;
  transition: flex-basis 0.22s ease;
}

.panel.collapsed {
  flex-basis: 60px;
}

.panel-rail {
  display: flex;
  flex: 0 0 60px;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 0;
  border-right: 1px solid var(--line);
}

.rail-toggle,
.rail-tab {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 0.7rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
}

.rail-toggle,
.rail-tab,
.rail-action {
  box-shadow: none;
}

.rail-toggle:hover,
.rail-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.rail-tab.active {
  color: #fff;
  background: var(--brand-gradient);
}

[hidden] {
  display: none !important;
}

.rail-extras {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-top: auto;
}

.rail-action {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 0.7rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
}

.rail-action:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.rail-lang {
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.rail-tabs {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.panel.collapsed #toggleIcon {
  transform: rotate(180deg);
}

.panel-content {
  flex: 1;
  min-width: 0;
  padding: 2rem;
  overflow-y: auto;
}

.panel.collapsed .panel-content {
  display: none;
}

.panel-pane {
  display: none;
}

.panel-pane.active {
  display: block;
}

.pane-title {
  font-size: clamp(1.4rem, 2.4vw, 1.9rem);
  margin-bottom: 1.2rem;
}

.panel-pane[data-pane="connect"] {
  text-align: center;
}

.panel-pane[data-pane="connect"] h1 {
  font-size: clamp(1.8rem, 3vw, 2.4rem);
  line-height: 1.08;
  text-wrap: balance;
}

.panel-pane[data-pane="connect"] .firmware-card button,
.panel-pane[data-pane="connect"] .firmware-card .button-link {
  display: block;
  width: 100%;
  text-align: center;
}

.panel-pane[data-pane="connect"] .firmware-card .actions {
  flex-direction: column;
  gap: 0.6rem;
}

.brand {
  display: block;
  width: 190px;
  margin: 0 auto 1.5rem;
  opacity: 0.92;
  transition: opacity 0.15s ease;
}

.brand:hover,
.brand:focus-visible {
  opacity: 1;
}

.brand img {
  display: block;
  width: 100%;
  height: auto;
}

.credit {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--muted);
}

.credit a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

.credit a:hover,
.credit a:focus-visible {
  text-decoration: underline;
}

.eyebrow {
  margin: 0 0 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--accent);
}

h1,
h2 {
  font-family: var(--font-heading);
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.intro,
.notes p {
  color: var(--muted);
  line-height: 1.5;
}

.actions {
  display: flex;
  gap: 0.75rem;
  margin: 1.5rem 0;
  flex-wrap: wrap;
}

button,
.button-link {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 0.9rem 1.2rem;
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--brand-gradient);
  box-shadow: 0 14px 34px rgba(34, 211, 238, 0.16);
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.button-link:hover,
.actions button:not(:disabled):hover,
.firmware-card button:not(:disabled):hover,
.load-error button:hover,
button.compact:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 0 22px rgba(129, 140, 248, 0.4);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.button-link {
  display: inline-block;
  text-decoration: none;
}

button.secondary {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: none;
}

button.secondary:not(:disabled):hover {
  border-color: #fff;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

button.compact {
  justify-self: start;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.firmware-card {
  margin: 1.5rem 0;
  padding: 1.1rem;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 16px;
  background: var(--card);
}

.firmware-card h2 {
  margin: 0;
  font-size: 1rem;
}

.firmware-card p {
  margin: 0.65rem 0 1rem;
  color: var(--muted);
  line-height: 1.5;
}

.firmware-card .actions {
  margin: 0;
}

.firmware-card code {
  display: inline;
}

.axis-controls {
  display: grid;
  gap: 0.65rem;
  margin: 0 0 1.5rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
}

.axis-controls h2 {
  margin: 0 0 0.2rem;
  font-size: 1rem;
}

.axis-controls label {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

.axis-controls input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.axis-controls .range-control {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
}

.axis-controls input[type="range"] {
  width: 100%;
  height: 0.35rem;
}

.axis-controls input:disabled + span {
  color: var(--muted);
}

.telemetry {
  display: grid;
  gap: 0.85rem;
  margin: 0;
}

.telemetry div {
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
}

dt {
  margin-bottom: 0.35rem;
  color: var(--muted);
}

dd {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.notes {
  margin-top: 1.5rem;
  padding: 1rem;
  border-radius: 1rem;
  border: 1px solid var(--line);
  background: rgba(255, 209, 102, 0.06);
}

code {
  display: block;
  overflow-wrap: anywhere;
  color: var(--accent-2);
}

.viewer {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

#scene {
  width: 100%;
  height: 100%;
  display: block;
}

.viewer-footer {
  position: absolute;
  left: 1.2rem;
  right: 1.2rem;
  bottom: 1.2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.hud {
  align-self: stretch;
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  padding: 0.8rem 1rem;
  border-radius: 999px;
  background: rgba(15, 17, 21, 0.68);
  border: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.stick-preview {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: min(26vw, 190px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(15, 17, 21, 0.62);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.attitude-indicator {
  position: absolute;
  top: 1rem;
  left: 1rem;
  width: min(26vw, 190px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(15, 17, 21, 0.62);
  backdrop-filter: blur(12px);
  overflow: hidden;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.viewer-badge {
  width: 220px;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(15, 17, 21, 0.62);
  backdrop-filter: blur(12px);
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.viewer-badge:hover,
.viewer-badge:focus-visible {
  opacity: 1;
}

.viewer-badge img {
  display: block;
  width: 100%;
  height: auto;
}

#attitudeHud {
  width: 100%;
  height: 100%;
  display: block;
}

.stick-slot {
  width: 86%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    linear-gradient(rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.12)) center / 1px 100% no-repeat,
    linear-gradient(90deg, rgba(255, 255, 255, 0.12), rgba(255, 255, 255, 0.12)) center / 100% 1px no-repeat;
  perspective: 360px;
}

#stickVisual {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: 50% 64%;
  filter: drop-shadow(0 12px 18px rgba(0, 0, 0, 0.28));
  transition: transform 80ms linear;
  will-change: transform;
}

strong {
  color: var(--accent);
}

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  .panel {
    flex-direction: column;
    flex-basis: auto;
    max-width: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 60vh;
  }

  .panel.collapsed {
    flex-basis: auto;
    max-height: 60px;
  }

  .panel-rail {
    flex-direction: row;
    flex-basis: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0.6rem;
  }

  .rail-tabs {
    flex-direction: row;
    margin-top: 0;
    margin-left: 0.5rem;
  }

  .rail-extras {
    flex-direction: row;
    margin-top: 0;
    margin-left: auto;
    margin-right: 0.4rem;
  }

  .panel-content {
    padding: 1.25rem;
  }

  .viewer {
    flex: 1;
    height: auto;
    min-height: 40vh;
  }

  .stick-preview,
  .attitude-indicator {
    width: 136px;
  }

  .viewer-badge {
    width: 170px;
    padding: 0.45rem 0.8rem;
  }
}

.load-error {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.8rem;
  padding: 2rem;
  text-align: center;
  background: rgba(15, 17, 21, 0.92);
}

.load-error h2,
.load-error p {
  margin: 0;
}

.load-error p {
  max-width: 34ch;
  color: var(--muted);
  line-height: 1.5;
}

/* Petits telephones en portrait : cadrans plus compacts pour degager la 3D. */
@media (max-width: 600px) and (orientation: portrait) {
  .stick-preview,
  .attitude-indicator {
    width: 104px;
    top: 0.6rem;
  }

  .attitude-indicator {
    left: 0.6rem;
  }

  .stick-preview {
    right: 0.6rem;
  }

  .viewer-footer {
    left: 0.6rem;
    right: 0.6rem;
    bottom: 0.6rem;
  }

  .viewer-badge {
    width: 140px;
  }
}

/* Telephone en paysage : panneau a gauche, vue 3D a droite (le layout empile
   ne laisse presque aucune hauteur a la scene). */
@media (orientation: landscape) and (max-height: 520px) {
  .app-shell {
    flex-direction: row;
  }

  .panel {
    flex: 0 0 320px;
    flex-direction: row;
    max-width: 320px;
    max-height: none;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .panel.collapsed {
    flex-basis: 60px;
    max-height: none;
  }

  .panel-rail {
    flex-direction: column;
    flex-basis: 60px;
    padding: 0.6rem 0;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .rail-tabs {
    flex-direction: column;
    margin: 0.3rem 0 0;
  }

  .rail-extras {
    flex-direction: column;
    margin: auto 0 0;
  }

  .panel-content {
    padding: 1rem;
  }

  .brand {
    width: 150px;
    margin-bottom: 1rem;
  }

  .panel-pane[data-pane="connect"] h1 {
    font-size: 1.5rem;
  }

  .viewer {
    height: 100%;
    min-height: 0;
  }

  .stick-preview,
  .attitude-indicator {
    width: 92px;
    top: 0.6rem;
  }

  .attitude-indicator {
    left: 0.6rem;
  }

  .stick-preview {
    right: 0.6rem;
  }

  .viewer-footer {
    left: 0.6rem;
    right: 0.6rem;
    bottom: 0.6rem;
    gap: 0.4rem;
  }

  .hud {
    gap: 0.7rem;
    padding: 0.35rem 0.8rem;
    font-size: 0.8rem;
  }

  .viewer-badge {
    width: 120px;
    padding: 0.25rem 0.6rem;
  }
}

/* Elements de style repris de rmdev.design */
.gradient-text {
  padding-right: 0.06em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.badge-row {
  margin: 0 0 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.95rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.firmware-card h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}

.panel-pane:not([data-pane="connect"]) .firmware-card h2 {
  justify-content: flex-start;
}

.step-num {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  width: 1.45rem;
  height: 1.45rem;
  border: 1px solid rgba(34, 211, 238, 0.5);
  border-radius: 50%;
  background: rgba(34, 211, 238, 0.1);
  color: var(--accent);
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
}
