@property --bg-a {
  syntax: "<color>";
  inherits: true;
  initial-value: #1ed761;
}

@property --bg-b {
  syntax: "<color>";
  inherits: true;
  initial-value: #064c7f;
}

@property --bg-c {
  syntax: "<color>";
  inherits: true;
  initial-value: #071b4d;
}

@property --bg-d {
  syntax: "<color>";
  inherits: true;
  initial-value: #d92945;
}

@property --accent {
  syntax: "<color>";
  inherits: true;
  initial-value: #69a9ff;
}

:root {
  color-scheme: dark;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --bg-a: #1ed761;
  --bg-b: #064c7f;
  --bg-c: #071b4d;
  --bg-d: #d92945;
  --fg: #f8fbff;
  --muted: rgba(248, 251, 255, 0.72);
  --soft: rgba(248, 251, 255, 0.18);
  --panel: rgba(4, 12, 24, 0.58);
  --panel-strong: rgba(5, 13, 26, 0.86);
  --shadow: rgba(0, 0, 0, 0.28);
  --accent: #69a9ff;
  --danger: #ff4056;
  --radius: 28px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #04101c;
  overscroll-behavior: none;
}

body {
  color: var(--fg);
  transition: background-color 650ms ease;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  overflow: clip;
  padding:
    calc(18px + var(--safe-top))
    calc(18px + var(--safe-right))
    calc(18px + var(--safe-bottom))
    calc(18px + var(--safe-left));
  isolation: isolate;
  background:
    radial-gradient(circle at 11% 11%, var(--bg-a) 0 10%, transparent 32%),
    radial-gradient(circle at 90% 58%, var(--bg-d) 0 11%, transparent 35%),
    radial-gradient(circle at 52% 28%, var(--bg-b) 0 16%, transparent 42%),
    linear-gradient(125deg, var(--bg-a) 0%, var(--bg-b) 37%, var(--bg-c) 64%, var(--bg-d) 100%);
  transition: background 720ms cubic-bezier(0.22, 1, 0.36, 1);
}

.app::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.12), rgba(0, 0, 0, 0.34)),
    radial-gradient(circle at 50% 100%, rgba(255, 255, 255, 0.1), transparent 24%);
  mix-blend-mode: soft-light;
}

.aurora {
  position: absolute;
  inset: -18%;
  z-index: -2;
  background: inherit;
  filter: blur(28px) saturate(118%);
  opacity: 0.78;
  transform: scale(1.04);
  transition: background 720ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Fond uni : une seule couleur pleine, perceptible en vision peripherique
   sans quitter la route des yeux. */
.app.flat {
  background: var(--bg-b);
}

.app.flat::after,
.app.flat .aurora {
  display: none;
}

.app.flat .speed-block,
.app.flat .limit-block {
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.5), 0 0 3px rgba(0, 0, 0, 0.4);
}

/* Sur les teintes lumineuses (vert vif, jaune), le blanc ne contraste plus :
   le JS bascule le texte en sombre via .dark-text. */
.app.flat.dark-text .speed-block,
.app.flat.dark-text .limit-block,
.app.flat.dark-text .status-group {
  color: #07131d;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.22);
}

.app.flat.dark-text .limit-line span,
.app.flat.dark-text .delta-line,
.app.flat.dark-text .ticks,
.app.flat.dark-text .accuracy {
  color: rgba(7, 19, 29, 0.78);
}

.app.flat.dark-text .limit-line strong,
.app.flat.dark-text .risk-labels span:nth-child(3) {
  color: #07131d;
}

.app.flat.dark-text .icon-button,
.app.flat.dark-text .small-button {
  color: #07131d;
  border-color: rgba(7, 19, 29, 0.38);
  background: rgba(7, 19, 29, 0.12);
}

.app.flat.dark-text .status-dot {
  box-shadow: 0 0 0 3px rgba(7, 19, 29, 0.6);
}

.app.flat.dark-text .sim-panel label {
  color: rgba(7, 19, 29, 0.78);
}

.app.flat.dark-text .quick-speeds button:not(.active) {
  color: #07131d;
  border-color: rgba(7, 19, 29, 0.3);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 62px;
}

.status-group {
  display: inline-flex;
  align-items: center;
  flex: 1 1 auto;
  min-width: 0;
  gap: 9px;
  font-size: 1rem;
  font-weight: 760;
  letter-spacing: 0;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.28);
}

#statusText {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: #6cf044;
  box-shadow: 0 0 0 6px rgba(108, 240, 68, 0.12), 0 0 28px rgba(108, 240, 68, 0.62);
}

.status-dot.waiting {
  background: #ffd166;
  box-shadow: 0 0 0 6px rgba(255, 209, 102, 0.13), 0 0 26px rgba(255, 209, 102, 0.48);
}

.status-dot.error {
  background: #ff556b;
  box-shadow: 0 0 0 6px rgba(255, 85, 107, 0.13), 0 0 26px rgba(255, 85, 107, 0.42);
}

.accuracy {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 720;
  white-space: nowrap;
}

.top-actions {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 10px;
}

.icon-button,
.small-button,
.segmented button {
  border: 1px solid var(--soft);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.16), 0 16px 40px var(--shadow);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  padding: 0;
  border-radius: 999px;
}

.icon-button svg {
  width: 26px;
  height: 26px;
  fill: currentColor;
}

.icon-button:hover,
.small-button:hover,
.segmented button:hover {
  border-color: rgba(255, 255, 255, 0.34);
  background: rgba(255, 255, 255, 0.14);
}

.icon-button:active,
.small-button:active,
.segmented button:active {
  transform: scale(0.96);
}

.icon-button.active,
.segmented button.active,
.quick-speeds button.active {
  color: #06111f;
  border-color: rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.9);
}

.dashboard {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  width: min(100%, 860px);
  margin: 0 auto;
  padding: clamp(18px, 5.6vh, 66px) 0 clamp(16px, 3.2vh, 36px);
}

.speed-block {
  align-self: center;
  text-align: center;
  text-shadow: 0 18px 70px rgba(0, 0, 0, 0.38);
}

.speed-row {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  min-width: min(86vw, 740px);
  line-height: 0.82;
}

.speed {
  display: inline-block;
  min-width: 2ch;
  font-size: clamp(8.7rem, 30dvh, 22rem);
  font-weight: 880;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

.decimal {
  margin-left: 0.08em;
  color: rgba(255, 255, 255, 0.82);
  font-size: clamp(2rem, 8dvh, 5rem);
  font-weight: 820;
  font-variant-numeric: tabular-nums;
}

.unit {
  margin-top: clamp(6px, 1.2dvh, 16px);
  font-size: clamp(2rem, 6.4dvh, 4.8rem);
  font-weight: 830;
  line-height: 1;
}

.limit-block {
  width: min(100%, 620px);
  margin: 0 auto;
  text-align: center;
  text-shadow: 0 10px 36px rgba(0, 0, 0, 0.34);
}

.limit-line {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 14px;
  margin-bottom: 8px;
  font-size: clamp(1.35rem, 3.3dvh, 2.45rem);
  font-weight: 740;
}

.limit-line span {
  color: rgba(255, 255, 255, 0.84);
}

.limit-line strong {
  color: var(--accent);
  font-size: 1.28em;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.delta-line {
  min-height: 1.5em;
  margin-bottom: 16px;
  color: rgba(255, 255, 255, 0.76);
  font-size: clamp(0.9rem, 1.9dvh, 1.15rem);
  font-weight: 720;
}

.risk-scale {
  position: relative;
  height: 26px;
  margin: 0 auto;
}

.risk-track {
  position: absolute;
  top: 8px;
  right: 0;
  left: 0;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #55f050 0%, #50d9ff 26%, #63a8ff 47%, #c778ff 69%, #ff3f4d 100%);
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.3), 0 10px 24px rgba(0, 0, 0, 0.2);
}

.risk-thumb {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  border: 3px solid rgba(255, 255, 255, 0.98);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.32);
  transform: translate(-50%, -50%);
  transition: left 460ms cubic-bezier(0.22, 1, 0.36, 1);
}

.ticks,
.risk-labels {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
}

.ticks {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.84);
  font-size: clamp(0.78rem, 1.8dvh, 1rem);
  font-weight: 760;
}

.risk-labels {
  margin-top: 10px;
  font-size: clamp(0.7rem, 1.7dvh, 0.95rem);
  font-weight: 780;
}

.risk-labels span:nth-child(1) {
  color: #68f76e;
}

.risk-labels span:nth-child(2) {
  color: #6bc8ff;
}

.risk-labels span:nth-child(3) {
  color: #f8fbff;
}

.risk-labels span:nth-child(4) {
  color: #cb8bff;
}

.risk-labels span:nth-child(5) {
  color: #ff5668;
}

.sim-panel {
  display: none;
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid var(--soft);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 18px 46px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.sim-panel.open {
  display: grid;
  gap: 10px;
}

.sim-panel label {
  font-size: 0.78rem;
  font-weight: 820;
  color: rgba(255, 255, 255, 0.78);
  text-transform: uppercase;
}

input[type="range"] {
  width: 100%;
  accent-color: #79b8ff;
}

.quick-speeds {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.quick-speeds button,
.small-button,
.wide-button {
  min-width: 46px;
  min-height: 40px;
  border-radius: 999px;
  padding: 0 14px;
  color: #f8fbff;
  font-size: 0.86rem;
  font-weight: 820;
}

.quick-speeds button {
  border: 1px solid var(--soft);
  background: rgba(255, 255, 255, 0.08);
  cursor: pointer;
}

.wide-button {
  width: 100%;
  border: 1px solid var(--soft);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.14), 0 18px 46px rgba(0, 0, 0, 0.22);
  cursor: pointer;
}

.settings-panel {
  position: fixed;
  right: calc(16px + var(--safe-right));
  bottom: calc(16px + var(--safe-bottom));
  z-index: 5;
  width: min(380px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  max-height: min(660px, calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom)));
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 26px;
  background: var(--panel-strong);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px) scale(0.98);
  transition: opacity 180ms ease, transform 180ms ease;
}

.settings-panel.open {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 6;
  background: rgba(0, 0, 0, 0.36);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.sheet-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.install-sheet {
  position: fixed;
  left: 50%;
  bottom: calc(16px + var(--safe-bottom));
  z-index: 7;
  width: min(460px, calc(100vw - 32px - var(--safe-left) - var(--safe-right)));
  max-height: min(720px, calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom)));
  overflow: auto;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 26px;
  background: var(--panel-strong);
  box-shadow: 0 34px 90px rgba(0, 0, 0, 0.52);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 18px) scale(0.98);
  transition: opacity 180ms ease, transform 180ms ease;
}

.install-sheet.open {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0) scale(1);
}

.install-status {
  margin: 0 0 14px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.94rem;
  font-weight: 690;
  line-height: 1.4;
}

.primary-install {
  margin-bottom: 14px;
  color: #06111f;
  border-color: rgba(255, 255, 255, 0.62);
  background: rgba(255, 255, 255, 0.92);
}

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

.install-tabs button {
  min-height: 42px;
  border: 1px solid var(--soft);
  border-radius: 999px;
  color: #f8fbff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  font-weight: 820;
  cursor: pointer;
}

.install-tabs button.active {
  color: #06111f;
  border-color: rgba(255, 255, 255, 0.56);
  background: rgba(255, 255, 255, 0.9);
}

.install-steps {
  display: none;
  margin: 0;
  padding-left: 1.25rem;
  color: rgba(255, 255, 255, 0.88);
  font-size: 0.95rem;
  font-weight: 690;
  line-height: 1.46;
}

.install-steps.active {
  display: grid;
  gap: 8px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-head h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 860;
  letter-spacing: 0;
}

fieldset {
  margin: 0 0 18px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 9px;
  color: rgba(255, 255, 255, 0.66);
  font-size: 0.78rem;
  font-weight: 830;
  text-transform: uppercase;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(82px, 1fr));
  gap: 8px;
}

.segmented button {
  min-height: 46px;
  border-radius: 999px;
  font-size: 0.94rem;
  font-weight: 840;
}

.range-setting {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  align-items: center;
}

.range-setting input {
  grid-column: 1 / -1;
}

.range-setting span,
.switch-row span {
  color: rgba(255, 255, 255, 0.82);
  font-weight: 760;
}

.range-setting strong {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.switch-row input {
  width: 46px;
  height: 26px;
  accent-color: #76e66a;
}

@media (orientation: landscape) and (min-width: 760px) {
  .dashboard {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
    grid-template-rows: 1fr;
    gap: clamp(28px, 5vw, 72px);
    width: min(100%, 1100px);
    padding: clamp(10px, 2vh, 24px) 0 clamp(10px, 2vh, 24px);
  }

  .speed-block {
    text-align: center;
  }

  .speed-row {
    min-width: 0;
  }

  .speed {
    font-size: clamp(7.8rem, 34dvh, 17rem);
  }

  .decimal {
    font-size: clamp(2rem, 10dvh, 4.4rem);
  }

  .unit {
    font-size: clamp(1.8rem, 7.5dvh, 3.6rem);
  }

  .limit-block {
    width: 100%;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app {
    grid-template-rows: auto 1fr;
    padding:
      calc(14px + var(--safe-top))
      calc(16px + var(--safe-right))
      calc(14px + var(--safe-bottom))
      calc(16px + var(--safe-left));
  }

  .topbar {
    min-height: 50px;
  }

  .icon-button {
    width: 46px;
    height: 46px;
  }

  .speed {
    font-size: clamp(6.7rem, 45dvh, 16rem);
  }

  .decimal {
    font-size: clamp(1.8rem, 12dvh, 4rem);
  }

  .unit {
    font-size: clamp(1.5rem, 9dvh, 3.2rem);
  }

  .sim-panel {
    position: fixed;
    right: calc(16px + var(--safe-right));
    bottom: calc(14px + var(--safe-bottom));
    width: min(460px, 46vw);
  }
}

@media (max-width: 430px) {
  .app {
    padding:
      calc(14px + var(--safe-top))
      calc(14px + var(--safe-right))
      calc(14px + var(--safe-bottom))
      calc(14px + var(--safe-left));
  }

  .top-actions {
    gap: 5px;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .icon-button svg {
    width: 22px;
    height: 22px;
  }

  .status-group {
    font-size: 0.9rem;
  }

  .speed {
    font-size: clamp(7.4rem, 28dvh, 12rem);
  }

  .risk-labels {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
