/* IT 기초 퀘스트 — 모바일 우선, 다크 테마 + LED 게이미피케이션 */
:root {
  --bg:      #0d1117;
  --bg2:     #161b22;
  --bg3:     #1c2230;
  --line:    #2b3340;
  --text:    #e6edf3;
  --muted:   #9da7b3;
  --amber:   #ffd02f;
  --cyan:    #5ad1ff;
  --green:   #3fdd97;
  --red:     #ff6b6b;
  --purple:  #b388ff;
  --mono:    'JetBrains Mono', 'Courier New', monospace;
  --body:    'Noto Sans KR', -apple-system, 'Malgun Gothic', sans-serif;
  --radius:  14px;
  --shadow:  0 8px 32px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  line-height: 1.7;
  overflow-x: hidden;
}

/* 배경 그라디언트 */
body {
  background-image:
    radial-gradient(900px 500px at 90% -5%, rgba(90,209,255,.07), transparent 60%),
    radial-gradient(700px 500px at 5% 25%, rgba(255,208,47,.05), transparent 55%),
    radial-gradient(600px 600px at 50% 90%, rgba(63,221,151,.04), transparent 60%);
}

/* 그레인 오버레이 */
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none; z-index: 9999; opacity: .025;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ===== 헤더 ===== */
#hdr {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .7rem 1rem;
  background: rgba(13,17,23,.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-family: var(--mono);
  font-weight: 700; font-size: .95rem; letter-spacing: .5px;
  color: var(--text);
}
.brand span { color: var(--amber); }

.stats { display: flex; align-items: center; gap: .45rem; }

.stat {
  font-family: var(--mono);
  font-size: .8rem; font-weight: 700;
  background: #050810;
  border: 1px solid var(--line);
  padding: .28rem .6rem;
  border-radius: 999px;
  white-space: nowrap;
  letter-spacing: .3px;
}

/* LED 글로우 효과 */
#streak { color: var(--amber); text-shadow: 0 0 8px rgba(255,208,47,.6); }
#xp     { color: var(--cyan);  text-shadow: 0 0 8px rgba(90,209,255,.6); }
#lvl    { color: var(--green); text-shadow: 0 0 8px rgba(63,221,151,.6); border-color: rgba(63,221,151,.25); }

/* XP 팝 애니메이션 (app.js에서 트리거) */
@keyframes xp-flash {
  0%   { transform: scale(1); }
  25%  { transform: scale(1.35); color: #fff; text-shadow: 0 0 20px #fff, 0 0 10px var(--cyan); }
  100% { transform: scale(1); }
}
.xp-flash { animation: xp-flash .5s ease-out; }

.reset {
  background: var(--bg2); color: var(--muted);
  border: 1px solid var(--line); border-radius: 999px;
  width: 30px; height: 30px; font-size: 1rem; cursor: pointer;
  font-family: var(--mono);
}
.reset:hover { color: var(--red); border-color: var(--red); }

/* ===== XP 진행바 (헤더 바로 아래) ===== */
#xp-bar-wrap {
  height: 3px;
  background: var(--bg2);
  position: sticky; top: 52px; z-index: 9;
}
#xp-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--amber), var(--cyan));
  box-shadow: 0 0 8px var(--cyan);
  transition: width .6s cubic-bezier(.2,.8,.3,1);
}

/* ===== 레벨업 토스트 ===== */
.lvl-toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: var(--bg3); border: 1px solid var(--amber);
  color: var(--amber); font-family: var(--mono); font-size: .9rem; font-weight: 700;
  padding: .6rem 1.4rem; border-radius: 999px;
  box-shadow: 0 0 24px rgba(255,208,47,.3);
  opacity: 0; transition: opacity .3s, transform .3s; z-index: 100;
  pointer-events: none; white-space: nowrap;
}
.lvl-toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
  animation: toast-pulse 2.2s ease forwards;
}
@keyframes toast-pulse {
  0%   { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(.9); }
  15%  { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.05); }
  85%  { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-8px) scale(.95); }
}

/* ===== 3D 섬 맵 (배경 캔버스) ===== */
#scene {
  position: fixed; inset: 0; z-index: 0;
  background: radial-gradient(120% 90% at 50% 0%, #1a4a63 0%, #0d1117 72%);
  transition: right .3s ease, bottom .3s ease;
}
#scene canvas { display: block; width: 100%; height: 100%; }
/* 퀘스트 중: 데스크탑 = 좌측, 화면 우측은 퀴즈 패널 */
body.quest #scene { right: min(460px, 46%); }

/* 위치 라벨 레이어 (3D 위에 투영) */
#labels { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
.map-label {
  position: absolute; top: 0; left: 0;
  display: flex; flex-direction: column; align-items: center; gap: .15rem;
  font-family: var(--mono); white-space: nowrap;
  text-align: center; will-change: transform;
}
.map-label .ml-t {
  font-size: .82rem; font-weight: 700; color: var(--text);
  background: rgba(13,17,23,.78); border: 1px solid var(--line);
  padding: .2rem .6rem; border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0,0,0,.5);
}
.map-label .ml-c { font-size: .68rem; color: var(--amber); letter-spacing: .5px; }
.map-label.done .ml-t { border-color: rgba(63,221,151,.5); }
.map-label.done .ml-c { color: var(--green); }
.map-label.locked { opacity: .55; }
.map-label.locked .ml-c { color: var(--muted); }
.map-label.shake { animation: wrong-shake .3s ease-out; }

/* ===== 퀘스트 패널 (화면 2분할 — 데스크탑 우측) ===== */
#app {
  position: fixed; z-index: 5;
  top: 0; right: 0; bottom: 0; width: min(460px, 46%);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 64px 1.2rem 2rem;
  background: rgba(13,17,23,.97);
  border-left: 1px solid var(--line);
  box-shadow: -16px 0 48px rgba(0,0,0,.55);
}
#app[hidden] { display: none; }
#app > * { max-width: 600px; margin: 0 auto; }

/* 모바일: 화면 상(3D)/하(퀴즈) 2분할 */
@media (max-width: 640px) {
  body.quest #scene { right: 0; bottom: 54%; }
  #app {
    top: auto; left: 0; right: 0; width: auto; height: 54%;
    border-left: none; border-top: 1px solid var(--line);
    box-shadow: 0 -16px 48px rgba(0,0,0,.55);
    padding: 1rem 1rem 1.4rem;
  }
}

.unit-panel { animation: fade .22s ease; }
.panel-back {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  padding: .4rem 1rem; font-size: .82rem; font-weight: 700;
  font-family: var(--mono); cursor: pointer; margin-bottom: 1.1rem;
}
.panel-back:hover { border-color: var(--amber); color: var(--amber); }

/* ===== 학습 경로 ===== */
.unit { margin-bottom: 2rem; }

.unit-h {
  font-size: 1.1rem; font-weight: 800;
  margin: 0 0 .85rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: .5rem;
}
.unit-ic { font-size: 1.2rem; }

.unit-progress {
  font-family: var(--mono);
  font-size: .72rem; color: var(--muted);
  margin-left: auto; letter-spacing: .5px;
}
.unit-h--done .unit-progress { color: var(--green); text-shadow: 0 0 6px rgba(63,221,151,.5); }
.unit-h--done { border-bottom-color: rgba(63,221,151,.3); }
.unit-h--done .unit-ic::after { content: ' ✅'; font-size: .75rem; }

.nodes { display: flex; flex-direction: column; gap: .55rem; }

.node {
  display: flex; align-items: center; gap: .85rem;
  width: 100%; text-align: left;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s, border-color .15s, box-shadow .15s;
  position: relative; overflow: hidden;
}

/* 호버 shimmer */
.node::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,208,47,.04), transparent);
  transform: translateX(-100%);
  transition: transform .4s ease;
}
.node:hover::before { transform: translateX(100%); }

.node:hover { transform: translateY(-2px); border-color: rgba(255,208,47,.5); box-shadow: 0 0 0 1px rgba(255,208,47,.1), var(--shadow); }
.node.done  { border-color: rgba(63,221,151,.4); background: rgba(63,221,151,.04); }
.node.done:hover { border-color: var(--green); box-shadow: 0 0 12px rgba(63,221,151,.15), var(--shadow); }
.node.open  { border-color: rgba(255,208,47,.4); box-shadow: 0 0 0 1px rgba(255,208,47,.08) inset; }
.node.locked { opacity: .45; cursor: not-allowed; }
.node.locked:hover { transform: none; border-color: var(--line); box-shadow: none; }

.node-ic { font-size: 1.3rem; flex: 0 0 auto; }
.node-main { display: flex; flex-direction: column; flex: 1; }
.node-t { font-weight: 700; font-size: 1rem; }
.node-meta { font-size: .78rem; color: var(--muted); font-family: var(--mono); letter-spacing: .2px; }
.node-xp {
  font-family: var(--mono); font-size: .75rem;
  color: var(--cyan); flex: 0 0 auto;
}
.node.done .node-xp { color: var(--green); }

/* ===== 레슨 화면 ===== */
.lesson { animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.lhead {
  display: flex; align-items: center; gap: .7rem;
  margin-bottom: 1.3rem;
}
.exit {
  flex: 0 0 auto; background: none; border: none;
  color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1;
}
.exit:hover { color: var(--text); }

.lprog-bar { flex: 1 1 auto; height: 8px; background: var(--bg3); border-radius: 999px; overflow: hidden; }
.lprog-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--cyan));
  border-radius: 999px;
  box-shadow: 0 0 8px rgba(90,209,255,.4);
  transition: width .35s ease;
}
.lhearts { flex: 0 0 auto; font-size: .95rem; letter-spacing: 2px; min-width: 64px; text-align: right; }

/* ===== 개념 카드 ===== */
.intro-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-left: 4px solid var(--cyan);
  border-radius: var(--radius);
  padding: 1.5rem 1.4rem;
  box-shadow: var(--shadow);
}
.intro-body { font-size: 1.06rem; margin-bottom: 1.4rem; }
.intro-body b, .q-text b { color: var(--amber); }
.intro-body code, .q-text code {
  background: #0a0e14;
  border: 1px solid var(--line);
  padding: .12em .45em;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: .88em;
  color: var(--cyan);
}

/* ===== 문항 카드 ===== */
.q-card {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.3rem 1.2rem;
  box-shadow: var(--shadow);
}
.q-text { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.1rem; line-height: 1.55; }

.q-choices { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.q-choice {
  text-align: left;
  background: var(--bg3);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: .82rem 1rem;
  color: var(--text);
  font-size: .98rem;
  cursor: pointer;
  transition: border-color .12s, background .12s, transform .1s;
  position: relative; overflow: hidden;
}
.q-choice:hover { border-color: rgba(255,208,47,.5); transform: translateX(3px); }
.q-choice.sel   { border-color: var(--amber); background: rgba(255,208,47,.06); }
.q-choice.lock  { cursor: default; transform: none; }

/* 정답 — 초록 글로우 */
.q-choice.correct {
  border-color: var(--green);
  background: rgba(63,221,151,.08);
  animation: correct-flash .4s ease-out;
}
@keyframes correct-flash {
  0%   { box-shadow: 0 0 0 0 rgba(63,221,151,.7); }
  50%  { box-shadow: 0 0 0 8px rgba(63,221,151,.2); }
  100% { box-shadow: 0 0 0 0 rgba(63,221,151,0); }
}

/* 오답 — 빨간 흔들기 */
.q-choice.wrong {
  border-color: var(--red);
  background: rgba(255,107,107,.08);
  animation: wrong-shake .3s ease-out;
}
@keyframes wrong-shake {
  0%,100% { transform: translateX(0); }
  20%  { transform: translateX(-6px); }
  40%  { transform: translateX(6px); }
  60%  { transform: translateX(-4px); }
  80%  { transform: translateX(4px); }
}

.q-input {
  width: 100%;
  background: var(--bg3);
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: .82rem 1rem;
  color: var(--text);
  font-family: var(--mono);
  font-size: 1rem;
  margin-bottom: 1rem;
  letter-spacing: .3px;
}
.q-input:focus { outline: none; border-color: var(--amber); box-shadow: 0 0 0 3px rgba(255,208,47,.1); }

.q-feedback {
  padding: .85rem 1rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: .93rem;
}
.q-feedback.ok  { background: rgba(63,221,151,.07);  border: 1px solid rgba(63,221,151,.35); color: var(--green); }
.q-feedback.no  { background: rgba(255,107,107,.07); border: 1px solid rgba(255,107,107,.35); color: var(--red); }
.q-explain { color: var(--muted); font-size: .9rem; margin-top: .3rem; }

/* ===== 버튼 ===== */
.btn {
  display: inline-block; width: 100%;
  border: none; border-radius: 12px;
  padding: .88rem 1rem;
  font-family: var(--body);
  font-size: .98rem; font-weight: 800;
  cursor: pointer;
  transition: transform .1s, filter .15s, box-shadow .15s;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn:not(:disabled):hover { filter: brightness(1.1); }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn.primary {
  background: var(--amber); color: #1a1206;
  box-shadow: 0 0 16px rgba(255,208,47,.25);
}
.btn.primary:hover { box-shadow: 0 0 24px rgba(255,208,47,.4); }
.btn.ghost { background: var(--bg3); color: var(--text); border: 1px solid var(--line); }

/* ===== 결과 / 실패 화면 ===== */
.result { text-align: center; padding-top: 1.5rem; }

.result-emoji {
  font-size: 4rem; line-height: 1;
  margin-bottom: .6rem;
  display: block;
  animation: result-pop .5s cubic-bezier(.2,1.6,.4,1);
}
@keyframes result-pop {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}

.result h2 { margin: .3rem 0 .8rem; font-size: 1.5rem; }
.result-score { color: var(--text); margin-bottom: .3rem; }
.result-xp {
  font-family: var(--mono);
  color: var(--amber); font-weight: 800; font-size: 1.25rem;
  text-shadow: 0 0 12px rgba(255,208,47,.5);
  animation: xp-pop .6s .2s both cubic-bezier(.2,1.6,.4,1);
}
@keyframes xp-pop {
  0%   { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}
.result-streak { color: var(--muted); font-size: .9rem; margin-top: .3rem; }

.btn-row { display: flex; flex-direction: column; gap: .6rem; margin-top: 1.5rem; }

/* 실패 화면 */
.fail .result-emoji { filter: grayscale(.3); }

/* ===== 파티클 (정답 시) ===== */
.particle {
  position: fixed; width: 7px; height: 7px; border-radius: 50%;
  pointer-events: none; z-index: 9998;
  animation: particle-fly .65s ease-out forwards;
}
@keyframes particle-fly {
  0%   { transform: translate(0,0) scale(1); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; }
}

/* ===== 접근성 ===== */
:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }

@media (min-width: 520px) {
  .btn-row { flex-direction: row; }
  .btn-row .btn { flex: 1; }
}
