:root {
  --c-navy: #1d2a4e;
  --c-orange: #ee9b1c;
  --c-orange-soft: #f8be64;
  --c-text: #1d2a4e;
  --c-muted: #6b7280;
  --c-line: #e3e6ee;
  --c-bg: #ffffff;
  --c-bg-soft: #f6f7fa;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--c-bg); color: var(--c-text); font-family: var(--font-body); }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
a { color: var(--c-navy); }
a:hover { color: var(--c-orange); }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--c-line);
  flex-wrap: wrap;
}
.brand {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 760px;
}
.brand-tag {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--c-orange);
  font-weight: 700;
}
.topbar h1 {
  font-size: 26px;
  font-weight: 800;
  margin: 0;
  color: var(--c-navy);
  letter-spacing: -0.015em;
  line-height: 1.2;
}
.lede {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--c-muted);
  line-height: 1.5;
}
.bar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}
.bar-controls select {
  font-size: 13px;
  font-family: var(--font-body);
  padding: 6px 10px;
  border: 1px solid var(--c-line);
  border-radius: 4px;
  background: var(--c-bg-soft);
  color: var(--c-text);
  cursor: pointer;
}
.bar-controls input[type="range"] {
  width: 140px;
  accent-color: var(--c-orange);
}
.btn-play, .btn-stop {
  border: 0;
  border-radius: 4px;
  padding: 7px 18px;
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.05s;
}
.btn-play { background: var(--c-orange); color: white; font-weight: 600; }
.btn-play:hover:not(:disabled) { background: var(--c-orange-soft); }
.btn-stop { background: transparent; color: var(--c-muted); border: 1px solid var(--c-line); }
.btn-stop:hover:not(:disabled) { color: var(--c-navy); border-color: var(--c-navy); }
.btn-play:active, .btn-stop:active { transform: translateY(1px); }
.btn-play:disabled, .btn-stop:disabled { opacity: 0.4; cursor: not-allowed; }
.upload-label {
  font-size: 12.5px;
  font-family: var(--font-body);
  padding: 6px 12px;
  border: 1px dashed var(--c-line);
  border-radius: 4px;
  background: transparent;
  color: var(--c-navy);
  cursor: pointer;
  user-select: none;
}
.upload-label:hover { color: var(--c-orange); border-color: var(--c-orange); }
.upload-name {
  font-size: 12px;
  color: var(--c-muted);
  font-family: var(--font-mono);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fp-stage {
  position: relative;
  margin: 14px 28px 0;
  height: 64vh;
  min-height: 460px;
  background: #1a1f33;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--c-line);
}
#three-root {
  position: absolute;
  inset: 0;
}
#three-root canvas {
  cursor: grab;
  touch-action: none;
}
#three-root canvas.is-dragging { cursor: grabbing; }
#minimap {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 164px;
  height: 164px;
  border-radius: 4px;
  background: rgba(246, 247, 250, 0.95);
  border: 1px solid var(--c-line);
  pointer-events: none;
}
.btn-ghost {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--c-line);
  color: var(--c-navy);
  padding: 6px 12px;
  font-size: 12px;
  font-family: var(--font-body);
  border-radius: 4px;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--c-orange); border-color: var(--c-orange); }

.joystick {
  display: none;
  position: absolute;
  bottom: 16px;
  left: 16px;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.10);
  border: 2px solid rgba(255, 255, 255, 0.30);
  touch-action: none;
  z-index: 2;
}
.joystick-stick {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border-radius: 50%;
  background: rgba(238, 155, 28, 0.78);
  border: 2px solid rgba(238, 155, 28, 0.95);
  pointer-events: none;
  transition: transform 0.06s linear;
}
@media (hover: none) and (pointer: coarse), (max-width: 700px), (any-pointer: coarse) {
  .joystick { display: block; }
}

.live-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 0.55fr);
  gap: 14px;
  padding: 14px 28px 18px;
}
.live-card {
  border: 1px solid var(--c-line);
  border-radius: 8px;
  padding: 12px 14px;
  background: white;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  container-type: inline-size;
}
.live-label {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--c-navy);
  margin-bottom: 8px;
}
#canvas-time, #canvas-spec {
  width: 100%;
  flex: 1;
  display: block;
  background: white;
  border: 1px solid var(--c-line);
  border-radius: 3px;
}
.live-speed {
  justify-content: flex-start;
}
.speed-val {
  font-size: clamp(20px, 22cqi, 64px);
  font-weight: 700;
  color: var(--c-orange);
  line-height: 1.0;
  font-feature-settings: "tnum";
  margin-top: 4px;
  white-space: nowrap;
}
.speed-unit {
  font-size: clamp(9px, 5cqi, 16px);
  color: var(--c-navy);
  font-weight: 600;
  margin-top: 6px;
  white-space: nowrap;
}
.speed-note {
  margin-top: 6px;
  font-size: clamp(8px, 4cqi, 12px);
  letter-spacing: 0.04em;
  color: var(--c-muted);
  white-space: nowrap;
}

.footer {
  border-top: 1px solid var(--c-line);
  padding: 10px 28px 16px;
  font-size: 11.5px;
  color: var(--c-muted);
}

@media (max-width: 1100px) {
  .fp-stage { margin: 12px; height: 60vh; }
}
@media (max-width: 700px) {
  .topbar { padding: 12px 14px; flex-wrap: wrap; }
  .fp-stage { height: 44vh; min-height: 320px; margin: 10px; }
  .live-row {
    padding: 12px;
    gap: 10px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.6fr);
    grid-template-areas:
      "ir inf"
      "spec spec";
  }
  .live-card:nth-child(1) { grid-area: ir; }
  .live-card:nth-child(2) { grid-area: spec; }
  .live-card:nth-child(3) { grid-area: inf; }
  .live-speed { min-height: 110px; }
  .live-speed .speed-val { font-size: clamp(22px, 18cqi, 52px); }
  .footer { padding: 10px 14px 14px; }
  #minimap { width: 120px; height: 120px; }
  .live-card { padding: 10px; min-height: 110px; overflow: hidden; }
}
