:root {
  --bg: #0b1020;
  --panel: rgba(13, 18, 34, 0.78);
  --border: rgba(255, 255, 255, 0.12);
  --text: #e8ecf5;
  --muted: #9aa4bd;
  --accent: #39d353;
  --accent-2: #f2b134;
  --danger: #ff7b72;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene:active { cursor: grabbing; }

.panel {
  position: fixed;
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  width: min(320px, calc(100vw - 32px));
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.collapse {
  padding: 2px 9px;
  font-size: 14px;
  transition: transform 0.2s;
}
.panel.collapsed .collapse { transform: rotate(-90deg); }
.panel.collapsed #panel-body { display: none; }

h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.02em;
}
h1 span { color: var(--accent); }

form { display: flex; gap: 8px; }

input, button {
  font: inherit;
  color: inherit;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
}

input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
}
input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button[type="submit"] {
  background: var(--accent);
  border-color: transparent;
  color: #08130b;
  font-weight: 600;
}
button[type="submit"]:hover { filter: brightness(1.1); }
button[aria-pressed="true"] {
  background: rgba(57, 211, 83, 0.2);
  border-color: var(--accent);
}

.status {
  margin: 8px 0 0;
  color: var(--muted);
  min-height: 1.4em;
}
.status.warn { color: var(--accent-2); }
.status.error { color: var(--danger); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  margin: 10px 0 0;
}
.stats div { min-width: 0; }
.stats dt { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; }
.stats dd { margin: 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }

.toolbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.toolbar button { padding: 7px 4px; font-size: 12px; }

.lost {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 12px 18px;
  background: var(--accent);
  border-color: transparent;
  color: #08130b;
  font-weight: 650;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  z-index: 4;
}
.lost:hover { background: var(--accent); filter: brightness(1.1); }
.lost[hidden] { display: none; }

.help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}
.note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 11px;
  opacity: 0.85;
}

.help kbd {
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 1px 4px;
  border: 1px solid var(--border);
  border-radius: 4px;
}

.tooltip {
  position: fixed;
  left: 0;
  top: 0;
  pointer-events: none;
  padding: 6px 10px;
  background: rgba(8, 12, 24, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 14px));
  z-index: 5;
}
.tooltip strong { color: var(--accent); }

.touchpad {
  position: fixed;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
}
.touchpad[hidden] { display: none; }
.pad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 6px;
  pointer-events: auto;
}
.pad button {
  background: var(--panel);
  font-size: 18px;
  padding: 0;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad button.active { background: rgba(57, 211, 83, 0.35); }
.pad [data-key="KeyW"] { grid-column: 2; grid-row: 1; }
.pad [data-key="KeyA"] { grid-column: 1; grid-row: 2; }
.pad [data-key="KeyS"] { grid-column: 2; grid-row: 2; }
.pad [data-key="KeyD"] { grid-column: 3; grid-row: 2; }
.pad-vertical {
  grid-template-columns: 52px;
}
.pad-vertical button { grid-column: 1; }

.credit {
  position: fixed;
  right: 12px;
  bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  text-decoration: none;
  opacity: 0.7;
}
.credit:hover { opacity: 1; text-decoration: underline; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 600px) {
  .panel { padding: 12px; }
  h1 { font-size: 17px; }
  .panel-head { margin-bottom: 8px; }
  .stats dd { font-size: 15px; }
  .help { display: none; }
  .credit { display: none; }
}

body.touch-fly .credit { display: none; }
