/* ============================================================
   칸토어의 마지막 수업 : 집합의 방 — 스타일시트
   테마: 다크 아카데미아 (고서관 · 금박 · 벨벳)
   ============================================================ */

:root {
  --bg-void: #0a0b0f;
  --bg-panel: #14100f;
  --bg-panel-2: #1c1613;
  --line: #4a3c2a;
  --gold: #d4af37;
  --gold-soft: #e9d18b;
  --parchment: #efe6cf;
  --parchment-dim: #cbbfa0;
  --ink: #17130f;
  --danger: #c1483f;
  --success: #6fae7c;
  --silver: #c7cdd6;
  --bronze: #b8794f;
  --font-display: 'Black Han Sans', 'Nanum Myeongjo', serif;
  --font-serif: 'Nanum Myeongjo', serif;
  --font-mono: 'Courier New', ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-void);
  color: var(--parchment);
  font-family: var(--font-serif);
  overflow-x: hidden;
}

body { min-height: 100vh; }

::selection { background: var(--gold); color: var(--ink); }

.hidden { display: none !important; }

/* ---------------- HUD ---------------- */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 50;
  background: linear-gradient(180deg, rgba(10,8,6,.95), rgba(10,8,6,.75));
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.hud-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  gap: 12px;
}
.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; }
.hud-label {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--gold-soft);
  opacity: .8;
  white-space: nowrap;
}
.progress-dots { display: flex; gap: 6px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1px solid var(--gold);
  background: transparent;
  transition: background .3s, box-shadow .3s;
}
.dot.filled { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.timer {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--parchment);
  padding: 2px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(0,0,0,.3);
}
.timer.warn { color: var(--danger); border-color: var(--danger); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.45;} }
.hint-counter { font-size: 12px; color: var(--parchment-dim); white-space: nowrap; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--parchment);
  border-radius: 6px;
  width: 30px; height: 30px;
  cursor: pointer;
  font-size: 14px;
}
.icon-btn:hover { border-color: var(--gold); }

/* ---------------- 화면(스크린) 공통 ---------------- */
#app { position: relative; width: 100%; min-height: 100vh; }

.screen {
  display: none;
  position: relative;
  min-height: 100vh;
  padding: 90px 16px 60px;
  align-items: flex-start;
  justify-content: center;
}
.screen.active { display: flex; }

.screen-bg {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 0;
}
.screen-veil {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at center, rgba(10,8,6,.35) 0%, rgba(6,5,4,.88) 78%);
  z-index: 1;
}
.veil-red { background: radial-gradient(ellipse at center, rgba(60,10,10,.45) 0%, rgba(10,4,4,.9) 80%); }

/* 배경 이미지 슬롯 + 무드에 맞는 그라디언트 폴백(이미지가 없어도 자연스럽게 보임) */
.bg-intro   { background-image: url('../images/bg-intro.jpg'),   linear-gradient(160deg,#1a140f,#0a0b0f 70%); }
.bg-stage1  { background-image: url('../images/bg-stage1.jpg'),  linear-gradient(160deg,#1c150e,#0a0b0f 70%); }
.bg-stage2  { background-image: url('../images/bg-stage2.jpg'),  linear-gradient(160deg,#16130f,#0a0b0f 70%); }
.bg-stage3  { background-image: url('../images/bg-stage3.jpg'),  linear-gradient(160deg,#111524,#0a0b0f 70%); }
.bg-stage4  { background-image: url('../images/bg-stage4.jpg'),  linear-gradient(160deg,#181410,#0a0b0f 70%); }
.bg-stage5  { background-image: url('../images/bg-stage5.jpg'),  linear-gradient(160deg,#151013,#0a0b0f 70%); }
.bg-success { background-image: url('../images/bg-success.jpg'), linear-gradient(160deg,#241c0c,#0a0b0f 70%); }
.bg-fail    { background-image: url('../images/bg-fail.jpg'),    linear-gradient(160deg,#2a0e0e,#0a0b0f 70%); }

/* ---------------- 서사 박스 (인트로/엔딩) ---------------- */
.narrative-box {
  position: relative;
  z-index: 2;
  max-width: 640px;
  width: 100%;
  background: linear-gradient(180deg, rgba(20,16,14,.92), rgba(14,11,9,.96));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  text-align: center;
  animation: fadeUp .6s ease both;
}
@keyframes fadeUp { from { opacity:0; transform: translateY(14px);} to {opacity:1; transform:none;} }

.eyebrow {
  font-family: var(--font-mono);
  letter-spacing: .25em;
  font-size: 11px;
  color: var(--gold-soft);
  text-transform: uppercase;
  margin: 0 0 10px;
}
.game-title {
  font-family: var(--font-display);
  font-size: 40px;
  color: var(--gold);
  margin: 0 0 4px;
  letter-spacing: .02em;
  text-shadow: 0 0 22px rgba(212,175,55,.35);
}
.game-title.small { font-size: 30px; }
.game-subtitle {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 16px;
  color: var(--parchment-dim);
  letter-spacing: .3em;
  margin: 0 0 24px;
}
.story-text { text-align: left; margin: 0 0 26px; }
.story-text p { line-height: 1.85; font-size: 15px; color: var(--parchment); margin: 0 0 14px; }
.story-text .quote {
  font-style: italic;
  color: var(--gold-soft);
  border-left: 2px solid var(--gold);
  padding-left: 14px;
  margin: 18px 0;
}
.story-text .system-voice {
  font-family: var(--font-mono);
  font-size: 13px;
  color: #9fd6c9;
  background: rgba(0,0,0,.35);
  border: 1px dashed #3a4a44;
  padding: 12px 14px;
  border-radius: 6px;
  line-height: 1.8;
}

/* ---------------- 버튼 ---------------- */
.btn {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 16px;
  padding: 13px 30px;
  border-radius: 8px;
  border: 1px solid var(--gold);
  cursor: pointer;
  letter-spacing: .04em;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: linear-gradient(180deg, var(--gold-soft), var(--gold)); color: var(--ink); }
.btn-primary:hover { box-shadow: 0 0 20px rgba(212,175,55,.5); }
.btn-secondary { background: transparent; color: var(--gold-soft); }
.btn-secondary:hover { background: rgba(212,175,55,.12); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }

/* ---------------- 관문(스테이지) 레이아웃 ---------------- */
.stage-wrap {
  position: relative;
  z-index: 2;
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
}
.stage-panel {
  background: linear-gradient(180deg, rgba(20,16,14,.93), rgba(14,11,9,.97));
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px 26px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  animation: fadeUp .5s ease both;
}
.stage-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .18em;
  color: var(--ink);
  background: var(--gold-soft);
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
}
.stage-title {
  font-family: var(--font-display);
  color: var(--gold);
  font-size: 26px;
  margin: 0 0 14px;
}
.stage-flavor {
  font-size: 14px;
  line-height: 1.8;
  color: var(--parchment-dim);
  border-left: 2px solid var(--line);
  padding-left: 12px;
  margin: 0 0 20px;
}
.stage-instruction {
  font-size: 15px;
  line-height: 1.85;
  color: var(--parchment);
  background: rgba(0,0,0,.28);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  margin: 0 0 22px;
}
.stage-instruction strong { color: var(--gold-soft); }

/* ---------------- 선택형 아이템(1,5관문) ---------------- */
.item-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }
.item-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  width: 100%;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--line);
  color: var(--parchment);
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.5;
  transition: border-color .15s, background .15s, opacity .2s;
}
.item-chip:hover:not(:disabled) { border-color: var(--gold-soft); background: rgba(212,175,55,.06); }
.item-chip .chip-num {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1px solid var(--gold);
  color: var(--gold-soft);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.item-chip.selected {
  border-color: var(--gold);
  background: rgba(212,175,55,.14);
  opacity: .55;
}
.item-chip.selected .chip-num { background: var(--gold); color: var(--ink); }
.item-chip:disabled { cursor: not-allowed; }

/* ---------------- 벤다이어그램(3관문) ---------------- */
.venn-wrap { display: flex; justify-content: center; margin: 4px 0 22px; }
.venn-svg text { font-family: var(--font-mono); font-weight: 700; fill: var(--parchment); }
.venn-svg .set-label { font-family: var(--font-serif); font-weight: 700; fill: var(--gold-soft); font-size: 17px; }
.venn-svg .circle-a { fill: rgba(212,175,55,.14); stroke: var(--gold); stroke-width: 2; }
.venn-svg .circle-b { fill: rgba(111,174,197,.14); stroke: #6faec5; stroke-width: 2; }
.venn-svg .u-box { fill: rgba(255,255,255,.02); stroke: var(--line); stroke-width: 1.5; }

/* ---------------- 자물쇠(코드 입력) 공통 ---------------- */
.lock-box { border-top: 1px dashed var(--line); padding-top: 20px; margin-top: 4px; }
.lock-caption {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .12em;
  color: var(--parchment-dim);
  text-align: center;
  margin-bottom: 12px;
}
.digit-display {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 18px;
}
.digit-box {
  width: 44px; height: 54px;
  border: 2px solid var(--gold);
  border-radius: 6px;
  background: rgba(0,0,0,.4);
  color: var(--gold-soft);
  font-family: var(--font-mono);
  font-size: 26px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.digit-display.shake { animation: shake .5s; }
.digit-display.correct .digit-box { border-color: var(--success); color: var(--success); box-shadow: 0 0 14px rgba(111,174,124,.6); }
.digit-display.wrong .digit-box { border-color: var(--danger); color: var(--danger); }
@keyframes shake {
  10%,90%{ transform: translateX(-2px); }
  20%,80%{ transform: translateX(4px); }
  30%,50%,70%{ transform: translateX(-8px); }
  40%,60%{ transform: translateX(8px); }
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 260px;
  margin: 0 auto 18px;
}
.keypad button {
  padding: 14px 0;
  font-size: 18px;
  font-family: var(--font-mono);
  font-weight: 700;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  color: var(--parchment);
  border-radius: 8px;
  cursor: pointer;
}
.keypad button:hover { border-color: var(--gold-soft); }
.keypad button.zero { grid-column: 2; }
.keypad button.clear-key { color: var(--danger); border-color: rgba(193,72,63,.4); }

.lock-actions { display: flex; justify-content: center; gap: 10px; margin-bottom: 6px; }

.feedback-msg {
  text-align: center;
  min-height: 20px;
  font-size: 13px;
  margin-top: 6px;
  font-family: var(--font-mono);
}
.feedback-msg.ok { color: var(--success); }
.feedback-msg.bad { color: var(--danger); }

/* ---------------- 힌트 ---------------- */
.hint-row { margin-top: 22px; border-top: 1px dashed var(--line); padding-top: 16px; }
.hint-btn {
  background: transparent;
  border: 1px solid var(--gold-soft);
  color: var(--gold-soft);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
}
.hint-btn:hover { background: rgba(212,175,55,.12); }
.hint-btn:disabled { opacity: .4; cursor: not-allowed; }
.hint-text {
  display: none;
  margin-top: 12px;
  font-size: 13px;
  line-height: 1.75;
  color: #b9d8c9;
  background: rgba(0,0,0,.3);
  border-left: 2px solid var(--success);
  padding: 10px 14px;
  border-radius: 4px;
}
.hint-text.visible { display: block; animation: fadeUp .3s ease both; }

/* ---------------- 결과 카드(엔딩) ---------------- */
.result-card {
  background: rgba(0,0,0,.3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 24px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  color: var(--parchment-dim);
}
.result-row:last-of-type { border-bottom: none; }
.result-row strong { color: var(--parchment); font-family: var(--font-mono); }
.rank-row { padding-top: 14px; }
.rank-badge {
  font-family: var(--font-display);
  font-size: 22px !important;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--ink) !important;
  background: var(--gold);
}
.rank-badge.grade-A { background: var(--silver); }
.rank-badge.grade-B { background: var(--bronze); }
.rank-label { text-align: center; color: var(--gold-soft); font-style: italic; margin: -8px 0 0; }

/* ---------------- 반응형 ---------------- */
@media (max-width: 480px) {
  .game-title { font-size: 30px; }
  .digit-box { width: 38px; height: 48px; font-size: 22px; }
  .stage-panel, .narrative-box { padding: 22px 18px; }
  .hud-label { display: none; }
}
