:root {
  --bg: #0b0e14;
  --panel: #131824;
  --panel-border: #263049;
  --text: #e7ecf5;
  --text-dim: #8a93a8;
  --accent: #4ea8de;
  --accent-2: #f1c40f;
  --danger: #e74c3c;
  --good: #3fbf6f;
  font-family: -apple-system, "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}

#app { width: 100vw; height: 100vh; display: flex; flex-direction: column; }

#topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  flex: 0 0 auto;
  font-size: 14px;
}
#topbar .brand { font-weight: 700; letter-spacing: 0.5px; }
#topbar-status { color: var(--text-dim); font-size: 12px; flex: 1; text-align: right; margin-right: 10px; }
#btn-mute {
  background: #1a2131; border: 1px solid var(--panel-border); color: var(--text);
  border-radius: 6px; padding: 5px 9px; cursor: pointer; font-size: 13px; flex: 0 0 auto;
}
#btn-mute:hover { border-color: var(--accent); }

.screen { flex: 1 1 auto; min-height: 0; display: flex; position: relative; }
.screen.hidden { display: none; }

/* ---------------- VAB ---------------- */
#vab-screen { flex-direction: row; }

#part-palette {
  width: 240px; flex: 0 0 auto;
  background: var(--panel);
  border-right: 1px solid var(--panel-border);
  overflow-y: auto;
  padding: 8px;
}
.palette-category h4 {
  margin: 10px 4px 6px; font-size: 12px; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.part-card {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 8px; margin-bottom: 4px;
  background: #1a2131; border: 1px solid var(--panel-border); border-radius: 6px;
  cursor: pointer; font-size: 12.5px;
  transition: background 0.1s;
}
.part-card:hover { background: #212a40; border-color: var(--accent); }
.part-card:active { background: #29344d; }
.part-swatch { width: 14px; height: 14px; border-radius: 3px; flex: 0 0 auto; }
.part-icon {
  width: 36px; height: 36px; flex: 0 0 auto; border-radius: 5px;
  background: radial-gradient(ellipse at center, #232c42 0%, #171d2c 100%);
  object-fit: contain; padding: 2px;
}
.part-card .pname { flex: 1; }
.part-card .ptag { font-size: 10px; color: var(--text-dim); }

#vab-main { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; }
#vab-toolbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--panel-border);
}
#rocket-name-input {
  background: #1a2131; border: 1px solid var(--panel-border); color: var(--text);
  padding: 6px 8px; border-radius: 5px; font-size: 13px; width: 160px;
}
#vab-toolbar button, .preset-buttons button {
  background: #1a2131; border: 1px solid var(--panel-border); color: var(--text);
  padding: 6px 10px; border-radius: 5px; cursor: pointer; font-size: 12px;
}
#vab-toolbar button:hover { border-color: var(--accent); }
.preset-buttons { display: flex; gap: 6px; }

#vab-canvas { flex: 1 1 auto; width: 100%; min-height: 0; background: radial-gradient(ellipse at center, #182238 0%, #0b0e14 80%); cursor: grab; }
#vab-canvas:active { cursor: grabbing; }
#vab-hint { padding: 6px 10px; font-size: 11.5px; color: var(--text-dim); background: var(--panel); border-top: 1px solid var(--panel-border); }

#stats-panel {
  width: 300px; flex: 0 0 auto;
  background: var(--panel); border-left: 1px solid var(--panel-border);
  display: flex; flex-direction: column; padding: 10px; gap: 10px; overflow-y: auto;
}
#stats-body { font-size: 12.5px; display: flex; flex-direction: column; gap: 4px; }
#stats-body .stat-row { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed #22293a; }
#stats-body .stat-row b { color: var(--accent); }
#stats-body .warn { color: var(--danger); }

#staging-panel h3, #stats-panel h3 { margin: 4px 0; font-size: 13px; color: var(--text-dim); }
#staging-list { display: flex; flex-direction: column; gap: 4px; max-height: 260px; overflow-y: auto; }
.stage-row {
  display: flex; align-items: center; gap: 6px;
  background: #1a2131; border: 1px solid var(--panel-border); border-radius: 5px; padding: 5px 7px; font-size: 11.5px;
}
.stage-row .stage-num {
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent-2); color: #1a1a1a;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 11px; flex: 0 0 auto;
}
.stage-row .stage-parts { flex: 1; color: var(--text-dim); }
.stage-row button { background: none; border: 1px solid var(--panel-border); color: var(--text-dim); border-radius: 4px; cursor: pointer; font-size: 10px; padding: 2px 5px; }

#launch-btn {
  margin-top: auto; padding: 12px; font-size: 15px; font-weight: 700;
  background: linear-gradient(180deg, #4ea8de, #2d7dbd); color: white;
  border: none; border-radius: 8px; cursor: pointer;
}
#launch-btn:hover { filter: brightness(1.1); }
#launch-btn:disabled { background: #333; color: #777; cursor: not-allowed; }

/* ---------------- Flight ---------------- */
#flight-screen { background: #000; }
#flight-canvas { width: 100%; height: 100%; display: block; cursor: grab; }
#flight-canvas:active { cursor: grabbing; }

.hud-panel {
  position: absolute; background: rgba(11, 14, 20, 0.72);
  border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px 10px;
  font-size: 12.5px; backdrop-filter: blur(2px);
}
#hud-topleft { top: 12px; left: 12px; min-width: 168px; }
#hud-topright { top: 12px; right: 12px; min-width: 168px; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 2px 0; }
.hud-row span { color: var(--text-dim); }
.hud-row b { color: var(--text); }

.bar { width: 100px; height: 8px; background: #1a2131; border-radius: 4px; overflow: hidden; border: 1px solid var(--panel-border); }
.bar-fill { height: 100%; width: 0%; }
.bar-fill.fuel { background: var(--accent-2); }
.bar-fill.ec { background: var(--accent); }

#hud-bottom {
  bottom: 12px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px;
}
#hud-bottom button {
  background: #1a2131; border: 1px solid var(--panel-border); color: var(--text);
  padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 12px; white-space: nowrap;
}
#hud-bottom button:hover { border-color: var(--accent); }
#hud-bottom .toggle-btn.active { background: var(--accent); color: #0b1420; border-color: var(--accent); }
#hud-bottom .stage-btn { background: linear-gradient(180deg, #e77a5a, #c0392b); color: white; font-weight: 700; border: none; }

#throttle-block { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.throttle-track { width: 26px; height: 46px; background: #1a2131; border: 1px solid var(--panel-border); border-radius: 4px; position: relative; overflow: hidden; }
#throttle-fill { position: absolute; bottom: 0; left: 0; width: 100%; height: 0%; background: linear-gradient(0deg, #3fbf6f, #f1c40f); }
#throttle-label { font-size: 10.5px; color: var(--text-dim); }

#warp-block { display: flex; align-items: center; gap: 4px; }
#warp-block button { padding: 8px 9px; }
#warp-label { font-size: 11.5px; width: 42px; text-align: center; color: var(--accent-2); }

#hud-message {
  position: absolute; top: 45%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(11, 14, 20, 0.9); border: 1px solid var(--panel-border); border-radius: 10px;
  padding: 20px 28px; text-align: center; font-size: 16px;
}
#hud-message.hidden { display: none; }
#hud-message button {
  margin-top: 12px; padding: 8px 16px; background: var(--accent); color: #0b1420; border: none;
  border-radius: 6px; cursor: pointer; font-weight: 700;
}

#help-panel {
  position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(11, 14, 20, 0.92); border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 12px 16px; font-size: 12px; min-width: 260px;
}
#help-panel.hidden { display: none; }
#help-panel h3 { margin: 0 0 8px; font-size: 13px; }
#help-panel ul { margin: 0; padding-left: 18px; line-height: 1.7; color: var(--text-dim); }

#nav-panel {
  position: absolute; bottom: 70px; right: 12px;
  background: rgba(11, 14, 20, 0.92); border: 1px solid var(--panel-border); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; width: 240px; max-height: 60vh; display: flex; flex-direction: column;
}
#nav-panel.hidden { display: none; }
#nav-panel h3 { margin: 0 0 8px; font-size: 13px; }
#nav-list { overflow-y: auto; max-height: 45vh; display: flex; flex-direction: column; gap: 3px; }
.nav-group-label { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; margin: 6px 0 2px; letter-spacing: 0.5px; }
.nav-item {
  background: #1a2131; border: 1px solid var(--panel-border); border-radius: 5px;
  padding: 5px 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px;
}
.nav-item:hover { border-color: var(--accent); }
.nav-item.active { background: #22406a; border-color: var(--accent); }
.nav-item .nd { color: var(--text-dim); font-size: 10.5px; white-space: nowrap; }
#nav-target-info { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--panel-border); }
#nav-target-info.hidden { display: none; }
#nav-target-info button {
  width: 100%; margin-top: 6px; padding: 6px; background: #1a2131; border: 1px solid var(--panel-border);
  color: var(--text); border-radius: 5px; cursor: pointer; font-size: 11.5px;
}
#nav-target-info button.active { background: var(--accent); color: #0b1420; border-color: var(--accent); font-weight: 700; }

#body-labels { position: absolute; inset: 0; pointer-events: none; }
.body-label {
  position: absolute; font-size: 11px; color: var(--text-dim); transform: translate(-50%, 6px);
  white-space: nowrap; background: rgba(11,14,20,0.6); padding: 1px 6px; border-radius: 4px;
}
.body-label.hovered { color: var(--text); background: rgba(20,26,40,0.85); font-weight: 600; }
.body-label.nav-target { color: var(--accent-2); border: 1px solid var(--accent-2); }
.body-label.own-ship { color: var(--good); border: 1px solid var(--good); font-weight: 700; background: rgba(20,26,40,0.85); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #263049; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

#scene-transition {
  position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none;
  z-index: 100; transition: opacity 0.35s ease;
}
#scene-transition.active { opacity: 1; }

/* ---------------- 모바일(좁은 화면) ---------------- */
/* 데스크톱 레이아웃은 VAB가 팔레트(240px)+캔버스+제원(300px)을 가로로 나란히 놓는데, 폭이
   좁은 화면에서는 두 고정폭 패널만으로 화면을 다 채우고도 남아서 정작 로켓을 보는 캔버스가
   0px로 완전히 찌그러지는 문제가 있었다. 비행화면 하단 버튼줄도 줄바꿈 없이 한 줄로 늘어서다
   보니 화면보다 훨씬 넓어져서(가운데 정렬 때문에 양쪽 밖으로) 버튼 절반이 화면 밖으로
   밀려나 아예 손이 안 닿는 문제가 있었다. */
@media (max-width: 700px) {
  #vab-screen { flex-direction: column; overflow-y: auto; }
  #part-palette {
    width: 100%; flex: 0 0 auto; max-height: 220px;
    border-right: none; border-bottom: 1px solid var(--panel-border);
  }
  #vab-main { flex: 0 0 auto; height: 54vh; min-height: 300px; }
  #stats-panel {
    width: 100%; flex: 0 0 auto; max-height: 320px;
    border-left: none; border-top: 1px solid var(--panel-border);
  }
  #vab-toolbar { justify-content: center; }
  #rocket-name-input { width: 120px; }

  .hud-panel { font-size: 11.5px; padding: 6px 8px; }
  #hud-topleft { min-width: 148px; left: 8px; top: 8px; }
  #hud-topright { min-width: 130px; right: 8px; top: 8px; }

  #hud-bottom {
    left: 8px; right: 8px; bottom: 8px; width: auto; transform: none;
    flex-wrap: wrap; justify-content: center; row-gap: 8px;
    max-height: 42vh; overflow-y: auto;
  }
  #hud-bottom button { padding: 7px 9px; font-size: 11px; }

  #nav-panel { width: calc(100% - 24px); right: 12px; }
  #help-panel { width: calc(100% - 32px); min-width: 0; }
}
