/* ============ base & theme ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0a0d16;
  --panel: rgba(16, 20, 34, 0.92);
  --panel-edge: rgba(255, 200, 120, 0.25);
  --ink: #f0e9d8;
  --ink-dim: #a99f88;
  --amber: #ffb45e;
  --amber-deep: #d98324;
  --crystal: #7fd4ff;
  --good: #7fe08a;
  --bad: #ff7f6e;
  --lidenbrock: #ffb45e;
  --axel: #7fd4ff;
  --hans: #a8e6a1;
  --narrator: #d8c9f0;
  --radius: 14px;
  --font-story: Georgia, 'Times New Roman', serif;
  --font-ui: 'Trebuchet MS', Verdana, system-ui, sans-serif;
}
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; z-index: 0; }
#app { position: fixed; inset: 0; z-index: 1; display: flex; flex-direction: column; overflow: hidden; }

button { font-family: inherit; color: inherit; }
.hidden { display: none !important; }

/* ============ buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 26px; min-height: 48px;
  font-size: 18px; font-weight: 700; letter-spacing: 0.5px;
  color: #241505;
  background: linear-gradient(180deg, #ffcf8a, var(--amber) 55%, var(--amber-deep));
  border: 1px solid #8a5a1a; border-radius: var(--radius);
  box-shadow: 0 3px 0 #7a4c12, 0 6px 18px rgba(0,0,0,0.5);
  cursor: pointer; transition: transform 0.08s, filter 0.15s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #7a4c12; }
.btn:disabled { filter: grayscale(0.8) brightness(0.6); cursor: default; }
.btn-ghost {
  background: rgba(255, 255, 255, 0.06); color: var(--ink);
  border: 1px solid rgba(255,255,255,0.25); box-shadow: none;
}
.btn-ghost:active { transform: translateY(1px); }
.btn-small { padding: 8px 16px; min-height: 40px; font-size: 15px; }

/* ============ panels ============ */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.06);
  backdrop-filter: blur(6px);
}

/* ============ HUD ============ */
.hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; z-index: 5; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud-user {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px 6px 8px; border-radius: 999px;
  background: rgba(10, 13, 22, 0.75); border: 1px solid rgba(255,255,255,0.15);
  font-weight: 700; font-size: 15px;
}
.hud-user .avatar { font-size: 22px; }
.hud-score {
  padding: 6px 16px; border-radius: 999px;
  background: rgba(10, 13, 22, 0.75); border: 1px solid var(--panel-edge);
  color: var(--amber); font-weight: 800; font-size: 16px;
}
.depth-badge {
  padding: 6px 16px; border-radius: 999px;
  background: rgba(10, 13, 22, 0.75); border: 1px solid rgba(127, 212, 255, 0.3);
  color: var(--crystal); font-weight: 700; font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* ============ dialogue ============ */
.dialogue-wrap {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: center; padding: 12px;
  z-index: 6;
}
.dialogue-box {
  display: flex; gap: 14px; align-items: flex-start;
  width: min(860px, 100%);
  padding: 16px 18px;
  cursor: pointer;
  animation: rise 0.25s ease-out;
}
@keyframes rise { from { transform: translateY(20px); opacity: 0; } }
.dialogue-portrait {
  flex: 0 0 84px; width: 84px; height: 84px;
  border-radius: 12px; overflow: hidden;
  border: 2px solid rgba(255,255,255,0.2);
  background: radial-gradient(circle at 50% 30%, #2a3352, #141826);
}
.dialogue-portrait svg { width: 100%; height: 100%; display: block; }
.dialogue-body { flex: 1; min-width: 0; }
.dialogue-name { font-weight: 800; font-size: 15px; letter-spacing: 1px; text-transform: uppercase; margin-bottom: 6px; }
.dialogue-text {
  font-family: var(--font-story); font-size: 19px; line-height: 1.45;
  min-height: 3.9em;
}
.dialogue-next {
  align-self: flex-end; color: var(--ink-dim); font-size: 13px;
  animation: blink 1.2s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

/* ============ PIN pad ============ */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  background: rgba(4, 6, 12, 0.75); backdrop-filter: blur(3px);
  animation: fade 0.2s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.pinpad { padding: 24px 28px; text-align: center; max-width: 340px; width: 92%; }
.pinpad h3 { font-size: 20px; margin-bottom: 4px; }
.pinpad .pin-sub { color: var(--ink-dim); font-size: 14px; margin-bottom: 14px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 10px 0 18px; }
.pin-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--amber); background: transparent; transition: background 0.1s;
}
.pin-dot.filled { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.pin-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.pin-key {
  height: 58px; font-size: 24px; font-weight: 700;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.15);
  border-radius: 12px; cursor: pointer;
}
.pin-key:active { background: rgba(255, 180, 94, 0.3); }
.pin-error { color: var(--bad); font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ============ puzzle shell ============ */
.puzzle-wrap {
  position: absolute; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  padding: 12px; overflow: hidden;
}
.puzzle-panel {
  width: min(900px, 100%); max-height: calc(100% - 16px);
  display: flex; flex-direction: column;
  animation: rise 0.3s ease-out;
}
.puzzle-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.puzzle-head h3 { font-size: 18px; color: var(--amber); }
.puzzle-points { font-weight: 800; color: var(--ink); font-size: 15px; white-space: nowrap; }
.puzzle-intro { padding: 12px 18px 0; font-family: var(--font-story); font-size: 17px; color: var(--ink); }
.puzzle-mount { padding: 16px 18px; overflow: auto; flex: 1; }
.puzzle-foot {
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  padding: 12px 18px; border-top: 1px solid rgba(255,255,255,0.1); flex-wrap: wrap;
}
.puzzle-msg { font-size: 15px; min-height: 20px; flex: 1; }
.puzzle-msg.good { color: var(--good); }
.puzzle-msg.bad { color: var(--bad); }
.hint-bubble {
  margin: 0 18px 4px; padding: 10px 14px;
  background: rgba(127, 212, 255, 0.1); border: 1px dashed rgba(127, 212, 255, 0.4);
  border-radius: 10px; font-size: 15px; color: var(--crystal);
}

/* ============ quiz ============ */
.quiz-progress { display: flex; gap: 6px; padding: 0 18px 8px; }
.quiz-progress i {
  flex: 1; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12);
}
.quiz-progress i.done { background: var(--good); }
.quiz-progress i.half { background: var(--amber); }
.quiz-progress i.missed { background: var(--bad); }
.quiz-q { font-family: var(--font-story); font-size: 20px; padding: 6px 18px 14px; line-height: 1.4; }
.quiz-choices { display: flex; flex-direction: column; gap: 10px; padding: 0 18px 6px; }
.quiz-choice {
  text-align: left; padding: 13px 16px; font-size: 17px; line-height: 1.3;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px; cursor: pointer; transition: background 0.12s;
}
.quiz-choice:not(:disabled):hover { background: rgba(255, 180, 94, 0.12); }
.quiz-choice.picked-good { background: rgba(127, 224, 138, 0.2); border-color: var(--good); }
.quiz-choice.picked-bad { background: rgba(255, 127, 110, 0.2); border-color: var(--bad); }
.quiz-choice.reveal { border-color: var(--good); }
.order-list { display: flex; flex-direction: column; gap: 8px; padding: 0 18px; }
.order-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; font-size: 16px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 12px; cursor: pointer;
}
.order-item .slot-num {
  min-width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255, 180, 94, 0.2); color: var(--amber); font-weight: 800;
}
.order-item.placed { border-color: var(--amber); }

/* ============ number pad (depth math etc.) ============ */
.numpad { display: grid; grid-template-columns: repeat(3, 72px); gap: 8px; justify-content: center; }
.numpad button {
  height: 54px; font-size: 22px; font-weight: 700;
  background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.18);
  border-radius: 10px; cursor: pointer;
}
.numpad button:active { background: rgba(255,180,94,0.3); }
.num-display {
  font-size: 30px; font-weight: 800; text-align: center; letter-spacing: 2px;
  padding: 8px 0 14px; color: var(--amber); min-height: 52px;
  font-variant-numeric: tabular-nums;
}

/* ============ misc ============ */
.stars { display: inline-flex; gap: 2px; font-size: inherit; }
.star { color: #554a33; }
.star.lit { color: var(--amber); text-shadow: 0 0 8px rgba(255, 180, 94, 0.7); }

.sound-toggle {
  position: fixed; bottom: 14px; right: 14px; z-index: 30;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(10, 13, 22, 0.75); border: 1px solid rgba(255,255,255,0.2);
  font-size: 20px; cursor: pointer;
}

.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 50; padding: 10px 22px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--panel-edge);
  font-weight: 700; animation: rise 0.25s ease-out;
}

@media (max-width: 640px) {
  .dialogue-portrait { flex-basis: 64px; width: 64px; height: 64px; }
  .dialogue-text { font-size: 17px; }
  .quiz-q { font-size: 18px; }
  .btn { font-size: 16px; padding: 10px 20px; }
  .numpad { grid-template-columns: repeat(3, 64px); }
}
