:root {
  color-scheme: dark;
  --bg: #07111f;
  --panel: rgba(7, 19, 33, 0.86);
  --panel-strong: rgba(10, 26, 43, 0.94);
  --line: rgba(255, 255, 255, 0.08);
  --text: #edf6ff;
  --muted: #98afc7;
  --accent: #4dd0ff;
  --accent-2: #85ffb6;
  --warn: #ffbf52;
  --danger: #ff6f78;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at top, rgba(77, 208, 255, 0.16), transparent 30%),
    linear-gradient(180deg, #08111b 0%, #040913 100%);
  color: var(--text);
}

body {
  min-height: 100vh;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 100vh;
  gap: 12px;
  padding: 12px;
}

.game-panel,
.hud-panel {
  min-height: 0;
}

.game-panel {
  display: flex;
}

.canvas-wrap {
  --drone-inset-width: 780px;
  --drone-inset-height: 352px;
  flex: 1;
  position: relative;
  min-height: calc(100vh - 24px);
  border: 1px solid var(--line);
  border-radius: 28px;
  overflow: hidden;
  background: linear-gradient(180deg, #0e2337 0%, #07121f 100%);
  box-shadow: var(--shadow);
}

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

.station-assist {
  position: absolute;
  left: 22px;
  top: 22px;
  width: min(520px, calc(100% - var(--drone-inset-width) - 68px));
  max-width: calc(100% - var(--drone-inset-width) - 68px);
  padding: 16px 16px 14px;
  border-radius: 20px;
  background: rgba(5, 15, 28, 0.38);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.drone-inset {
  position: absolute;
  bottom: 22px;
  right: 22px;
  width: var(--drone-inset-width);
  height: var(--drone-inset-height);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  padding: 12px;
  border-radius: 22px;
  background: rgba(5, 14, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-width: 256px;
  min-height: 144px;
  max-width: min(62vw, calc(100% - 44px));
  max-height: min(62vh, calc(100% - 44px));
  z-index: 3;
}

.drone-inset__resize-handle {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 24px;
  height: 19px;
  background:
    linear-gradient(135deg, transparent 0 34%, rgba(255, 255, 255, 0.14) 34% 42%, transparent 42% 56%, rgba(255, 255, 255, 0.14) 56% 64%, transparent 64%),
    linear-gradient(135deg, transparent 0 56%, rgba(77, 208, 255, 0.75) 56% 64%, transparent 64%);
  opacity: 0.95;
  cursor: nwse-resize;
  z-index: 2;
}

.drone-inset__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drone-inset__title-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.drone-inset__header .eyebrow {
  margin-bottom: 0;
}

.drone-inset__status {
  color: var(--muted);
  font-size: 0.78rem;
}

.drone-inset__toggle {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(9, 20, 34, 0.62);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.drone-inset__toggle:hover {
  filter: brightness(1.05);
}

.drone-inset__mount {
  position: relative;
  min-height: 0;
  border-radius: 16px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 30%, rgba(122, 198, 244, 0.26), transparent 36%),
    linear-gradient(180deg, rgba(12, 28, 44, 0.92), rgba(6, 15, 26, 0.96));
  border: 1px solid rgba(162, 221, 255, 0.12);
}

.drone-inset__mount canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.drone-inset.is-minimized {
  width: 272px;
  height: auto;
  min-height: 0;
  grid-template-rows: auto;
}

.drone-inset.is-minimized .drone-inset__mount,
.drone-inset.is-minimized .drone-inset__resize-handle {
  display: none;
}

.station-assist h3,
.station-assist p {
  margin-top: 0;
}

.assist-copy {
  min-height: 2.7em;
  margin-bottom: 12px;
  color: var(--text);
  line-height: 1.35;
}

.assist-scale {
  position: relative;
  height: 68px;
  border-radius: 16px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(77, 208, 255, 0.05), rgba(77, 208, 255, 0.015)),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035), rgba(255, 255, 255, 0.015));
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.assist-scale::before {
  content: "";
  position: absolute;
  inset: 50% 0 auto;
  height: 6px;
  background: rgba(186, 209, 228, 0.15);
  transform: translateY(-50%);
}

.assist-window {
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: var(--assist-window-left, 46%);
  width: var(--assist-window-width, 8%);
  border-radius: 12px;
  background: rgba(133, 255, 182, 0.08);
  border: 1px solid rgba(133, 255, 182, 0.22);
}

.assist-target,
.assist-front {
  position: absolute;
  top: 8px;
  bottom: 8px;
  width: 0;
}

.assist-target {
  left: 50%;
  border-left: 2px solid rgba(133, 255, 182, 0.95);
}

.assist-front {
  left: 50%;
  transform: translateX(-50%);
}

.assist-front::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 50%;
  width: 2px;
  height: 38px;
  background: rgba(255, 191, 82, 0.98);
  transform: translateX(-50%);
}

.assist-front::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #ffbf52;
  box-shadow: 0 0 0 4px rgba(255, 191, 82, 0.12);
  transform: translateX(-50%);
}

.assist-legend {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.overlay-card {
  position: absolute;
  left: 28px;
  bottom: 28px;
  width: min(420px, calc(100% - 56px));
  padding: 24px;
  border-radius: 24px;
  background: rgba(5, 14, 26, 0.8);
  backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: var(--shadow);
}

.hidden {
  display: none;
}

.overlay-card h1,
.overlay-card h2,
.overlay-card p,
.overlay-card ul {
  margin-top: 0;
}

.eyebrow,
.label,
.secondary,
.tiny-help {
  color: var(--muted);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.74rem;
  margin-bottom: 10px;
}

.primary-button,
.control-button {
  border: none;
  border-radius: 999px;
  color: #04111d;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease;
}

.primary-button:hover,
.control-button:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
}

.primary-button {
  padding: 12px 20px;
  background: linear-gradient(135deg, var(--accent), #8ff4ff);
}

.finish-stats {
  display: grid;
  gap: 10px;
  margin: 18px 0 20px;
}

.finish-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.hud-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: start;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
  padding-right: 4px;
}

.stat-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card,
.control-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.stat-card-wide {
  grid-column: 1 / -1;
  background: var(--panel-strong);
}

.stat-card h2,
.stat-card h3,
.control-card h3 {
  margin: 4px 0 6px;
}

.progress-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.progress-header .secondary {
  margin: 0;
  text-align: right;
}

.progress-track {
  position: relative;
  height: 12px;
  margin-top: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
}

.progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 18px rgba(77, 208, 255, 0.24);
  transition: width 120ms linear;
}

.stat-card h2 {
  font-size: 1.25rem;
}

.stat-card h3,
.control-card h3 {
  font-size: 1rem;
}

.speed-card {
  background: rgba(8, 20, 34, 0.95);
  border-color: rgba(145, 214, 255, 0.2);
}

.speed-card h3,
.speed-card .secondary {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 12px;
  background: rgba(4, 12, 22, 0.5);
}

.speed-card .secondary {
  margin-top: 4px;
  background: rgba(4, 12, 22, 0.42);
}

.stat-card p,
.control-card p,
.notes-list li {
  line-height: 1.35;
}

.control-card {
  background: rgba(7, 19, 33, 0.94);
}

.control-card.compact {
  padding-top: 12px;
}

.station-progress-list {
  list-style: none;
  padding: 0;
  margin: 10px 0 0;
  display: grid;
  gap: 8px;
}

.station-progress-item,
.station-progress-empty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.station-progress-item strong {
  font-size: 0.94rem;
}

.station-progress-item span,
.station-progress-empty {
  color: var(--muted);
}

.bar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-bar {
  position: relative;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  margin-top: 8px;
}

.bar-center {
  position: absolute;
  inset: 0 auto 0 50%;
  width: 2px;
  background: rgba(255, 255, 255, 0.22);
  transform: translateX(-50%);
}

.bar-fill {
  position: absolute;
  top: 2px;
  bottom: 2px;
  width: 0;
  border-radius: 999px;
  transition: width 80ms linear, left 80ms linear;
}

.actual-fill {
  background: linear-gradient(90deg, #f6a23f, #ffc160);
}

.target-marker {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 50%;
  width: 0;
  border-left: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 0 3px rgba(77, 208, 255, 0.16);
  transform: translateX(-50%);
  transition: left 80ms linear;
}

.control-readout {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.control-button {
  padding: 12px 14px;
  color: white;
}

.control-button.accel {
  background: linear-gradient(135deg, #1890ff, #4dd0ff);
}

.control-button.brake {
  background: linear-gradient(135deg, #f26478, #ff9e6f);
}

.control-button.active {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7), 0 10px 24px rgba(0, 0, 0, 0.2);
}

.notes-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.notes-list li + li {
  margin-top: 6px;
}

.tiny-help {
  margin: 10px 0 0;
  font-size: 0.82rem;
}

.hud-panel::-webkit-scrollbar {
  width: 8px;
}

.hud-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
}

@media (max-width: 1040px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    --drone-inset-width: 600px;
    --drone-inset-height: 270px;
    min-height: 62vh;
  }

  .hud-panel {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
    padding-bottom: 10px;
  }
}

@media (max-height: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) 280px;
    gap: 8px;
    padding: 8px;
  }

  .canvas-wrap {
    --drone-inset-width: 528px;
    --drone-inset-height: 238px;
    min-height: calc(100vh - 16px);
  }

  .hud-panel {
    gap: 8px;
    top: 8px;
    max-height: calc(100vh - 16px);
    font-size: 0.84rem;
  }

  .stat-grid {
    gap: 8px;
  }

  .stat-card,
  .control-card {
    border-radius: 18px;
    padding: 8px 10px;
  }

  .control-card.compact {
    padding-top: 8px;
  }

  .label,
  .secondary,
  .tiny-help,
  .control-readout,
  .notes-list,
  .station-progress-item span,
  .station-progress-empty {
    font-size: 0.72rem;
  }

  .stat-card p,
  .control-card p {
    margin: 0;
  }

  .stat-card h2 {
    font-size: 0.94rem;
  }

  .stat-card h3,
  .control-card h3 {
    font-size: 0.84rem;
  }

  .stat-card h2,
  .stat-card h3,
  .control-card h3 {
    margin: 1px 0 2px;
    line-height: 1.15;
  }

  .speed-card h3,
  .speed-card .secondary {
    padding: 4px 7px;
    border-radius: 10px;
  }

  .speed-card .secondary {
    margin-top: 2px;
  }

  .progress-track {
    height: 8px;
    margin-top: 6px;
  }

  .station-progress-list {
    margin-top: 6px;
    gap: 5px;
  }

  .station-progress-item,
  .station-progress-empty {
    gap: 8px;
    padding: 6px 8px;
    border-radius: 10px;
  }

  .station-progress-item strong {
    font-size: 0.78rem;
  }

  .control-bar {
    height: 10px;
    margin-top: 5px;
  }

  .control-readout {
    margin-top: 6px;
  }

  .button-row {
    gap: 6px;
    margin-top: 8px;
  }

  .control-button {
    padding: 7px 8px;
    font-size: 0.76rem;
  }

  .notes-list {
    margin-top: 4px;
    padding-left: 14px;
  }

  .notes-list li + li {
    margin-top: 3px;
  }

  .tiny-help {
    margin-top: 6px;
  }

  .drone-inset {
    bottom: 12px;
    right: 12px;
    padding: 10px;
    border-radius: 18px;
    min-width: 224px;
    min-height: 126px;
  }

  .drone-inset__status {
    font-size: 0.7rem;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
    gap: 12px;
  }

  .canvas-wrap {
    --drone-inset-width: 308px;
    --drone-inset-height: 173px;
    min-height: 56vh;
    border-radius: 22px;
  }

  .overlay-card {
    left: 14px;
    right: 14px;
    bottom: 14px;
    width: auto;
  }

  .drone-inset {
    bottom: 14px;
    right: 14px;
    padding: 8px;
    border-radius: 16px;
    min-width: 192px;
    min-height: 108px;
  }

  .station-assist {
    left: 14px;
    top: 14px;
    width: calc(100% - 288px);
    max-width: calc(100% - 288px);
    padding: 14px;
  }

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

@media (max-width: 520px) {
  .drone-inset {
    width: 336px;
    height: 151px;
    min-width: 176px;
    min-height: 99px;
  }

  .station-assist {
    width: calc(100% - 238px);
    max-width: calc(100% - 238px);
  }
}

@media (max-width: 820px) {
  body {
    min-height: 100dvh;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    gap: 10px;
    padding: 8px;
  }

  .game-panel {
    min-height: 0;
  }

  .canvas-wrap {
    min-height: clamp(360px, 58dvh, 620px);
    border-radius: 20px;
  }

  .drone-inset {
    display: none;
  }

  .station-assist {
    top: 10px;
    left: 10px;
    width: calc(100% - 20px);
    max-width: calc(100% - 20px);
    padding: 12px 12px 10px;
    border-radius: 16px;
  }

  .station-assist .eyebrow {
    margin-bottom: 6px;
  }

  .station-assist h3 {
    margin-bottom: 6px;
    font-size: 1rem;
  }

  .assist-copy {
    min-height: 0;
    margin-bottom: 8px;
    font-size: 0.86rem;
  }

  .assist-scale {
    height: 56px;
    border-radius: 14px;
  }

  .assist-legend {
    margin-top: 6px;
    font-size: 0.72rem;
  }

  .overlay-card {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    padding: 18px;
    border-radius: 18px;
  }

  .hud-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    position: static;
    top: auto;
    width: 100%;
    min-width: 0;
    align-self: stretch;
    max-height: none;
    overflow: visible;
    align-items: stretch;
    padding: 0 0 calc(env(safe-area-inset-bottom, 0px) + 8px);
  }

  .stat-grid,
  .stations-card,
  .drive-card,
  .notes-card {
    grid-column: 1 / -1;
  }

  .status-card {
    display: none;
  }

  .stat-grid {
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat-card,
  .control-card {
    border-radius: 18px;
    padding: 10px 11px;
  }

  .stat-card h2 {
    font-size: 0.88rem;
  }

  .stat-card h3,
  .control-card h3 {
    font-size: 0.8rem;
  }

  .stat-card h2,
  .stat-card h3,
  .control-card h3 {
    margin: 2px 0 3px;
    line-height: 1.15;
  }

  .stat-card p,
  .control-card p,
  .notes-list li,
  .station-progress-item span,
  .station-progress-empty,
  .control-readout,
  .tiny-help {
    font-size: 0.69rem;
    line-height: 1.22;
  }

  .label,
  .secondary,
  .tiny-help {
    font-size: 0.66rem;
  }

  .progress-header {
    gap: 8px;
    align-items: center;
  }

  .progress-track {
    height: 8px;
    margin-top: 6px;
  }

  .notes-card {
    display: none;
  }

  .stations-card .station-progress-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stations-card .station-progress-item,
  .stations-card .station-progress-empty {
    min-height: 56px;
  }

  .station-progress-item,
  .station-progress-empty {
    padding: 8px 10px;
    border-radius: 12px;
    gap: 8px;
  }

  .station-progress-item strong {
    font-size: 0.8rem;
  }

  .drive-card {
    position: sticky;
    bottom: 8px;
    z-index: 6;
    grid-column: 1 / -1;
    width: 100%;
    margin: 0;
    justify-self: stretch;
    align-self: stretch;
    box-sizing: border-box;
    padding: 14px;
    background: rgba(6, 18, 31, 0.96);
    border-color: rgba(141, 214, 255, 0.18);
    box-shadow: 0 18px 48px rgba(0, 0, 0, 0.4);
  }

  .drive-card .bar-header {
    align-items: baseline;
  }

  .control-bar {
    height: 14px;
    margin-top: 8px;
  }

  .control-readout {
    margin-top: 8px;
  }

  .button-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
    width: 100%;
  }

  .control-button {
    min-height: 54px;
    width: 100%;
    padding: 13px 12px;
    border-radius: 18px;
    font-size: 0.92rem;
    font-weight: 800;
    touch-action: manipulation;
  }

  .tiny-help {
    margin-top: 6px;
  }

  .speed-card h3,
  .speed-card .secondary {
    display: block;
    width: 100%;
    padding: 4px 7px;
    border-radius: 10px;
    font-size: 0.7rem;
    line-height: 1.2;
  }

  .speed-card h3 {
    font-size: 0.86rem;
  }

  .speed-card .secondary {
    margin-top: 3px;
  }

  .speed-card h3 span {
    font-size: 1.1em;
  }
}

@media (max-width: 560px) {
  .canvas-wrap {
    min-height: clamp(340px, 54dvh, 520px);
  }

  .hud-panel {
    grid-template-columns: 1fr;
  }

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

  .stat-card,
  .control-card {
    padding: 9px 10px;
  }

  .stat-card h2 {
    font-size: 0.8rem;
  }

  .stat-card h3,
  .control-card h3 {
    font-size: 0.74rem;
  }

  .stat-card p,
  .control-card p,
  .station-progress-item span,
  .station-progress-empty,
  .control-readout,
  .tiny-help,
  .label,
  .secondary {
    font-size: 0.62rem;
  }

  .stat-card-wide {
    grid-column: 1 / -1;
  }

  .stations-card .station-progress-list {
    grid-template-columns: 1fr;
  }

  .stations-card .station-progress-item,
  .stations-card .station-progress-empty {
    min-height: 0;
  }
}
