/* 엘리멘탈 워리어즈 — 3D UI */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05070c;
  color: #e8f0ff;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

/* ---------- 3D 캔버스 ---------- */
#stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #05070c;
  touch-action: none;
}

#flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  background: radial-gradient(circle at 50% 55%, rgba(255,60,60,0) 35%, rgba(255,40,40,0.55) 100%);
}

#ui { position: fixed; inset: 0; pointer-events: none; }
button { pointer-events: auto; }
.hidden { display: none !important; }

/* ---------- 공용 버튼 ---------- */
.btn {
  pointer-events: auto;
  font-family: inherit;
  cursor: pointer;
  padding: 8px 14px;
  font-size: clamp(11px, 1.8vmin, 14px);
  color: #e8f0ff;
  background: #16233a;
  border: 2px solid #4f6f95;
  border-radius: 6px;
}

.btn:hover:not(:disabled) { background: #22375a; border-color: #ffe08a; }
.btn:active { transform: translateY(1px); }
.btn.primary { border-color: #ffe08a; color: #ffe08a; }
.btn.big { padding: 11px 18px; font-size: clamp(13px, 2.1vmin, 16px); }
.btn.tiny { padding: 4px 9px; font-size: clamp(10px, 1.5vmin, 12px); }

/* ---------- 플레이 상태 ---------- */
#hud {
  position: absolute;
  inset: max(10px, env(safe-area-inset-top)) auto auto max(10px, env(safe-area-inset-left));
  width: min(246px, calc(100% - 20px));
  padding: 12px 15px 10px;
  border: 1px solid #57647a;
  border-radius: 10px;
  background: rgba(17, 24, 38, 0.94);
  color: #bfcadd;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.hud-line { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.hud-line b, .hud-stats b { color: #f4f4f6; }
.hud-line .score b { color: #ffda8d; }
#hud-objective { margin: 9px 0; color: #fff3d6; font-size: 16px; font-weight: 700; line-height: 1.35; }
.hp .bar { flex: 1; height: 5px; border-radius: 3px; background: #3d4857; overflow: hidden; }
#hp-fill { display: block; width: 100%; height: 100%; background: #8cdcb0; }
#hud-details { margin-top: 7px; border-top: 1px solid #3d495b; }
#hud-details summary { width: fit-content; padding: 7px 5px 2px 0; cursor: pointer; pointer-events: auto; }
.hud-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
#btn-quit { margin-top: 9px; }
.controls-help { font-size: 13px; color: #c9d6e8; line-height: 1.6; }
.touch-help, .has-touch .keyboard-help { display: none; }
.has-touch .touch-help { display: inline; }
#stage:focus { outline: none; }

/* ---------- 조작 ---------- */
#dpad {
  position: absolute;
  right: clamp(12px, 3vw, 30px);
  bottom: clamp(14px, 5vh, 40px);
  display: none;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  gap: 5px;
  pointer-events: none;
  touch-action: none;
}

body.has-touch #dpad { display: grid; }

.dbtn {
  pointer-events: auto;
  width: clamp(44px, 11vmin, 62px);
  height: clamp(44px, 11vmin, 62px);
  padding: 0;
  font-size: clamp(13px, 2.8vmin, 19px);
  color: #e8f0ff;
  background: rgba(18, 30, 52, 0.78);
  border: 2px solid #4f6f95;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.dbtn:active { background: #33507f; border-color: #ffe08a; }
.dbtn.up { grid-area: 1 / 2; }
.dbtn.left { grid-area: 2 / 1; }
.dbtn.right { grid-area: 2 / 3; }
.dbtn.down { grid-area: 3 / 2; }

/* ---------- 시작 화면 ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: clamp(8px, 2vmin, 18px);
}

.title-box {
  pointer-events: none;
  text-align: center;
  margin-top: clamp(6px, 3vh, 40px);
  padding: 12px 20px;
  background: rgba(9, 14, 26, 0.82);
  border: 2px solid #4f6f95;
  border-radius: 10px;
  max-width: 560px;
}

.title-box h1 {
  margin: 0 0 6px;
  font-size: clamp(18px, 3.6vmin, 30px);
  color: #ffe08a;
  letter-spacing: 0.04em;
}

.title-box p { margin: 0; font-size: clamp(11px, 1.9vmin, 15px); color: #b9cdf0; }
.title-box b { color: #a8ff5a; }

.char-row {
  pointer-events: auto;
  margin-top: auto;
  margin-bottom: clamp(6px, 3vh, 30px);
  display: flex;
  gap: clamp(8px, 2vmin, 18px);
  justify-content: center;
  flex-wrap: wrap;
}

.char-card {
  pointer-events: auto;
  cursor: pointer;
  min-width: 104px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  color: #e8f0ff;
  background: #101c30;
  border: 2px solid #4f6f95;
  border-radius: 8px;
  transition: background 0.12s, border-color 0.12s;
}

.char-card:hover { background: #1d2f4d; border-color: #ffe08a; }
.char-card b { font-size: clamp(13px, 2.2vmin, 17px); color: #ffe08a; }
.char-card span { font-size: clamp(10px, 1.6vmin, 12px); color: #a8bde0; }

.hint {
  margin: 0 0 clamp(10px, 3vh, 28px);
  text-align: center;
  font-size: clamp(10px, 1.7vmin, 13px);
  color: #8fa4c8;
}

/* ---------- 패널 ---------- */
.panel {
  pointer-events: auto;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(540px, 92vw);
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #0b1424;
  border: 2px solid #4f6f95;
  border-radius: 10px;
}

.panel h2 { margin: 0; font-size: clamp(15px, 2.4vmin, 20px); color: #ffe08a; }
.story-list { display: flex; flex-direction: column; gap: 8px; }

.story-scene {
  padding: 10px 12px;
  background: #14203a;
  border: 1px solid #2f4a6b;
  border-radius: 8px;
}

.story-scene p {
  margin: 3px 0;
  font-size: clamp(11px, 1.8vmin, 14px);
  line-height: 1.55;
  color: #d5e0ff;
  word-break: keep-all;
}

.story-scene p.goal { color: #a8ff5a; font-weight: 700; }

.result-body p { margin: 4px 0; font-size: clamp(12px, 1.9vmin, 15px); color: #cdd8f5; }
.result-body p.big { color: #a8ff5a; font-size: clamp(14px, 2.2vmin, 18px); }
.result-body p.bonus { color: #ffe08a; }
.result-body ul { margin: 4px 0; padding-left: 18px; }
.result-body li { margin: 3px 0; font-size: clamp(12px, 1.9vmin, 15px); color: #cdd8f5; }
.result-body li.score b { color: #a8ff5a; font-size: 1.15em; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 오가네손의 기억 읽기 ---------- */
#panel-memory { border-color: #ffe08a; }

.memory-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 12px 14px;
  background: #1b1a2e;
  border: 1px solid #6b5a2f;
  border-radius: 8px;
}

.memory-body p {
  margin: 0;
  font-size: clamp(11px, 1.8vmin, 14px);
  line-height: 1.6;
  color: #f0e2c0;
  word-break: keep-all;
}

/* 기억 속 그림 — 코드로 그린 오가네손과 우라늄의 마지막 만남 */
.memory-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.memory-art {
  display: block;
  width: 100%;
  height: auto;
  background: #080f28;
  border: 1px solid #6b5a2f;
  border-radius: 8px;
}

.memory-figure figcaption {
  text-align: center;
  font-size: clamp(10px, 1.6vmin, 12px);
  color: #cbb98a;
}

/* 마지막 만남의 대사 */
.memory-dialogue {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 10px 12px;
  background: #141a2e;
  border: 1px solid #4a4f7a;
  border-radius: 8px;
}

.memory-dialogue p {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: clamp(11px, 1.8vmin, 14px);
  line-height: 1.5;
  color: #e6ecff;
  word-break: keep-all;
}

.memory-dialogue b {
  font-size: clamp(10px, 1.6vmin, 12px);
  color: #a8ff5a;
}

.memory-dialogue p.u b { color: #9fd4ff; }

#panel-memory .hint { margin: 0; text-align: left; }

/* ---------- 토스트 / 안내 문구 ---------- */
#toast {
  pointer-events: none;
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translateX(-50%);
  padding: 8px 14px;
  font-size: clamp(11px, 1.8vmin, 14px);
  color: #ffe08a;
  background: rgba(9, 14, 26, 0.92);
  border: 2px solid #ffe08a;
  border-radius: 8px;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

#narration {
  pointer-events: none;
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  width: min(620px, 94vw);
  padding: 10px 16px;
  text-align: center;
  font-size: clamp(12px, 2vmin, 16px);
  line-height: 1.5;
  color: #e4ecff;
  background: rgba(9, 16, 30, 0.94);
  border: 2px solid #7fc94a;
  border-radius: 10px;
  word-break: keep-all;
}
