/* The page around the 3D view. Big type, big buttons, one warm paper color. */

:root {
  color-scheme: light;
  --ink: #1c2430;
  --paper: rgba(247, 241, 230, 0.94);
  --line: rgba(28, 36, 48, 0.12);
  --orange: #c45312;
  --orange-ink: #fff8f3;
  --good: #1f7a3a;
  --warn: #9a6208;
  --bad: #a32626;
  --blue: #2f6fdb;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* The hidden attribute has to win over layout rules like display:flex. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background: #d5e2ef;
  touch-action: none;
  overscroll-behavior: none;
}

#view {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

button, input {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid var(--line);
  background: #fffdf8;
  border-radius: 10px;
  padding: 8px 10px;
  min-height: 40px;
  cursor: pointer;
}

button:hover { border-color: #8aa0b4; }

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

button.primary {
  background: var(--orange);
  color: var(--orange-ink);
  border-color: transparent;
}

button.selected {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 2px var(--blue);
}

#topbar {
  position: absolute;
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  min-height: 64px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: calc(8px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 8px calc(14px + env(safe-area-inset-left));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex: 0 0 auto;
  text-align: left;
  min-width: 0;
}

.brand strong {
  font-size: 20px;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.brand span { font-size: 13px; opacity: 0.75; }

#version-link {
  font-size: 0.72em;
  font-weight: 600;
  color: rgba(28, 36, 48, 0.5);
  text-decoration: none;
  margin-left: 0.2em;
}

#version-link:hover,
#version-link:focus-visible {
  color: var(--ink);
  text-decoration: underline;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  flex: 1;
}

.stat {
  display: flex;
  flex-direction: column;
  min-width: 72px;
}

.stat span { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.65; }
.stat strong { font-size: 16px; }
.stat strong.good { color: var(--good); }
.stat strong.warn { color: var(--warn); }
.stat strong.bad { color: var(--bad); }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }

.meter { min-width: 140px; }
.meter span { font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.65; }
.track {
  height: 12px;
  background: #e4dccb;
  border-radius: 999px;
  overflow: hidden;
  margin-top: 4px;
}
.track div {
  height: 100%;
  width: 0%;
  background: var(--blue);
}
#battery-fill.low { background: var(--bad); }
#throttle-fill { background: var(--orange); }

#build-panel, #flight-panel {
  position: absolute;
  z-index: 2;
  top: calc(78px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  width: min(320px, calc(100vw - 24px));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  -webkit-overflow-scrolling: touch;
}

#build-panel {
  bottom: 12px;
  overflow: auto;
}

#flight-panel {
  max-height: calc(100% - 220px);
  overflow: auto;
}

h2 {
  margin: 12px 0 6px;
  font-size: 14px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.starter {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  margin-bottom: 6px;
  text-align: left;
}

.starter small { opacity: 0.75; }

#tool-row, .save-row, .flight-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

#palette h3 {
  margin: 10px 0 4px;
  font-size: 13px;
}

.part-btn {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  margin-bottom: 4px;
  text-align: left;
}

.part-btn small { opacity: 0.65; white-space: nowrap; }

#swatches { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }

.swatch {
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border-radius: 50%;
}

#hint, #flight-readout, #challenge p {
  margin: 6px 0;
  line-height: 1.35;
}

.warnings { list-style: none; padding: 0; margin: 8px 0; }
.warnings li {
  padding: 6px 8px;
  border-radius: 8px;
  margin-bottom: 4px;
  background: #fff;
}
.warnings .good { background: #e5f6ea; }
.warnings .warn { background: #fff4d6; }
.warnings .bad { background: #fde4e4; }
.warnings .info { background: #eef3f8; }

.name-row { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.name-row input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  background: white;
}

#saved-list { list-style: none; padding: 0; margin: 8px 0 0; }
#saved-list li { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
#saved-list .save-name { flex: 1; text-align: left; }
#saved-list .rename-save {
  width: 40px;
  min-width: 40px;
  padding: 0;
  font-size: 18px;
}
#saved-list .save-rename {
  flex: 1;
  min-width: 0;
  min-height: 40px;
  border: 2px solid var(--blue);
  border-radius: 10px;
  padding: 8px 10px;
  background: white;
}
#saved-list .empty { display: block; opacity: 0.7; }

#controls-card {
  position: absolute;
  z-index: 2;
  right: 12px;
  bottom: 12px;
  width: min(360px, calc(100vw - 24px));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
}

#controls-card h2 { margin-top: 0; }
#controls-card ul { margin: 0; padding-left: 18px; }
#controls-card li { margin: 3px 0; }

#toast {
  position: absolute;
  z-index: 4;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 14px;
  border-radius: 12px;
  max-width: min(480px, calc(100vw - 24px));
}

#fail {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: #f7f1e6;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.panel-toggle { display: none; }

#touch-flight {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.stick {
  pointer-events: auto;
  touch-action: none;
  position: absolute;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(28, 36, 48, 0.28);
  border: 3px solid rgba(255, 255, 255, 0.7);
  bottom: calc(18px + env(safe-area-inset-bottom));
}

#stick-left { left: calc(18px + env(safe-area-inset-left)); }
#stick-right { right: calc(18px + env(safe-area-inset-right)); }

.stick-nub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: #fffdf8;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.stick-label {
  position: absolute;
  left: 0;
  right: 0;
  top: -22px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: #1c2430;
  text-shadow: 0 1px 0 #fff;
  pointer-events: none;
}

#touch-actions {
  pointer-events: auto;
  position: absolute;
  left: 50%;
  bottom: calc(28px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: calc(100vw - 300px);
}

#touch-actions button {
  min-height: 48px;
  min-width: 64px;
  background: rgba(247, 241, 230, 0.94);
  font-weight: 700;
}

#rotate-hint {
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 42%;
  transform: translate(-50%, -50%);
  margin: 0;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(28, 36, 48, 0.88);
  color: white;
  font-size: 18px;
  text-align: center;
}

#notes {
  position: absolute;
  z-index: 5;
  left: 0;
  right: 0;
  bottom: 0;
  top: calc(64px + env(safe-area-inset-top));
}

#notes-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  min-height: 0;
  background: rgba(28, 36, 48, 0.18);
  cursor: pointer;
}

.notes-card {
  position: absolute;
  top: 8px;
  right: calc(12px + env(safe-area-inset-right));
  width: min(440px, calc(100vw - 24px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  max-height: calc(100% - 16px - env(safe-area-inset-bottom));
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px 18px;
  text-align: left;
}

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

.notes-head h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 20px; }

#notes-body h3 { margin: 16px 0 4px; font-size: 16px; }
#notes-body p, #notes-body li { margin: 4px 0; line-height: 1.35; }
#notes-body ul { margin: 4px 0 8px; padding-left: 18px; }

@media (pointer: coarse) {
  button { min-height: 44px; }
  .swatch { width: 44px; height: 44px; min-height: 44px; }
}

#build-panel, #flight-panel { touch-action: pan-y; }

@media (max-width: 900px) {
  .panel-toggle { display: inline-flex; }
  body:not(.panel-open) #build-panel,
  body:not(.panel-open) #flight-panel,
  #controls-card {
    display: none !important;
  }
  #build-panel, #flight-panel {
    width: min(420px, calc(100vw - 16px - env(safe-area-inset-left)));
    max-height: calc(100dvh - 88px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    bottom: calc(8px + env(safe-area-inset-bottom));
  }
  .brand span { display: none; }
  .brand strong { font-size: 16px; }
  .top-actions button { padding: 6px 8px; }
  #build-stats { display: none; }
  .top-actions { flex-wrap: nowrap; }
  .meter { min-width: 84px; }
}

body.touch-layout #controls-card {
  display: none !important;
}

@media (max-height: 520px) {
  #topbar { min-height: 48px; padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  #notes { top: calc(48px + env(safe-area-inset-top)); }
  #flight-panel { max-height: 46dvh; }
  #touch-actions { bottom: calc(8px + env(safe-area-inset-bottom)); }
  .stick { width: 112px; height: 112px; }
}
