*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #03040a;
  --chrome-bg: rgba(8, 10, 18, 0.84);
  --chrome-border: rgba(255, 255, 255, 0.14);
  --text: #e8ecf4;
  --muted: #9aa3b5;
  --accent: #7ec8ff;
  --accent-dim: rgba(126, 200, 255, 0.18);
  --gold: #ffd27a;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "Cascadia Code", "Consolas", ui-monospace, monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#cosmos-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#cosmos-canvas.is-dragging { cursor: grabbing; }
#cosmos-canvas.is-hover-planet { cursor: pointer; }

.chrome {
  position: absolute;
  z-index: 2;
  background: var(--chrome-bg);
  border: 1px solid var(--chrome-border);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 0;
}

header.chrome {
  top: 16px;
  left: 16px;
  padding: 12px 16px;
  max-width: min(460px, calc(100vw - 32px));
}

.chrome-title {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chrome-title .dot {
  width: 8px; height: 8px;
  background: var(--accent);
  flex-shrink: 0;
}
.chrome-title h1 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.2;
}
.badge {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(126, 200, 255, 0.35);
  padding: 2px 6px;
}
.slogan {
  margin-top: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.04em;
}
.subtitle {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}

.panel {
  top: 16px;
  right: 16px;
  width: 220px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 14px 14px 12px;
}
.panel h2 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin-bottom: 10px;
}
.panel h2.picker-heading {
  margin-top: 12px;
  margin-bottom: 8px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.hints {
  list-style: none;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hints li {
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}
kbd {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid rgba(126, 200, 255, 0.3);
  padding: 2px 5px;
  min-width: 44px;
  text-align: center;
  border-radius: 0;
}
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}
.row label { font-size: 12px; color: var(--muted); }
.btn {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--chrome-border);
  border-radius: 0;
  padding: 4px 10px;
  min-width: 52px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.28);
}
.btn[aria-pressed="true"] {
  color: #0a1220;
  background: var(--accent);
  border-color: var(--accent);
}
.btn:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 2px;
}

.planet-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.planet-pick {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 5px 6px;
  font-family: var(--font);
  font-size: 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  cursor: pointer;
  text-align: left;
  border-radius: 0;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.planet-pick:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
}
.planet-pick.is-active {
  background: var(--accent-dim);
  border-color: rgba(126, 200, 255, 0.45);
}
.planet-pick .swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(255, 255, 255, 0.25);
}
.planet-pick .nm {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.planet-pick kbd {
  min-width: 18px;
  padding: 1px 4px;
  font-size: 9px;
  opacity: 0.85;
}

.kb-panel {
  top: 50%;
  left: 16px;
  transform: translateY(-50%);
  width: min(320px, calc(100vw - 32px));
  padding: 18px 18px 16px;
  z-index: 3;
}
.kb-panel.hidden { display: none; }
.kb-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: 1px solid var(--chrome-border);
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: 0;
}
.kb-close:hover { color: var(--text); border-color: rgba(255,255,255,0.35); }
.kb-planet-swatch {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,0.2);
  box-shadow: 0 0 16px rgba(126, 200, 255, 0.25);
}
.kb-panel h2 {
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0.02em;
  margin-bottom: 2px;
  padding-right: 28px;
}
.kb-en {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  margin-bottom: 10px;
}
.kb-body {
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
  margin-bottom: 12px;
}
.kb-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 10px;
  line-height: 1.5;
}

.status {
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 6px 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  pointer-events: none;
}

.mobile-only { display: none; }
.desktop-only { display: revert; }
.hints .mobile-only { display: none; }
.hints .desktop-only { display: flex; }

.hud-toggle {
  margin-top: 10px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--chrome-border);
  border-radius: 0;
  padding: 8px 12px;
  min-height: 40px;
  width: 100%;
  cursor: pointer;
}

.btn, .planet-pick, .kb-close, .hud-toggle {
  touch-action: manipulation;
}

@media (max-width: 720px) {
  .mobile-only { display: block; }
  .desktop-only { display: none !important; }
  .hints .mobile-only { display: flex; }
  .hints .desktop-only { display: none !important; }

  header.chrome {
    top: max(8px, env(safe-area-inset-top));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    max-width: none;
    padding: 10px 12px;
  }
  .chrome-title h1 { font-size: 13px; }
  .badge { font-size: 9px; }
  .slogan { font-size: 13px; margin-top: 6px; }
  .subtitle { font-size: 11px; }

  .panel {
    top: auto;
    bottom: max(48px, calc(env(safe-area-inset-bottom) + 44px));
    right: max(8px, env(safe-area-inset-right));
    left: max(8px, env(safe-area-inset-left));
    width: auto;
    max-height: min(42vh, 320px);
    padding: 12px;
    display: none;
  }
  .panel.is-open { display: block; }

  .kb-panel {
    top: auto;
    bottom: max(52px, calc(env(safe-area-inset-bottom) + 48px));
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    transform: none;
    width: auto;
    max-height: min(46vh, 360px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* When controls panel is open, tuck KB above it */
  body.hud-open .kb-panel {
    bottom: max(calc(42vh + 56px), calc(env(safe-area-inset-bottom) + 280px));
    max-height: 34vh;
  }

  .planet-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .planet-pick {
    min-height: 40px;
    padding: 8px;
    font-size: 13px;
  }
  .row { padding: 8px 0; }
  .btn {
    min-height: 36px;
    min-width: 64px;
    padding: 8px 12px;
    font-size: 12px;
  }
  .kb-close {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
  .status {
    bottom: max(8px, env(safe-area-inset-bottom));
    left: 50%;
    right: auto;
    max-width: calc(100vw - 24px);
    white-space: normal;
    text-align: center;
    font-size: 10px;
    padding: 5px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
  .planet-pick { transition: none; }
}
