/* 디스코 미러 — 세로 9:16 마법거울. 신비로운 보라·금빛 무드. */
:root {
    --indigo-0: #0b0716;
    --indigo-1: #1e1b4b;
    --violet: #6d28d9;
    --violet-lite: #a78bfa;
    --gold: #fcd34d;
    --gold-deep: #d4a017;
    --ink: #f5f3ff;
    --muted: #c4b5fd;
    --job: #7c9ee0; /* 선택 직업 색 (JS가 갱신) */
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* class의 display:flex 가 hidden 을 덮지 않게 */
button { font-family: inherit; touch-action: manipulation; } /* 명조 폰트 통일 + 태블릿 더블탭 줌 방지 */
html, body { height: 100%; }
body {
    /* 궁서체풍: 전통 명조/궁서 계열로 마법 거울 분위기 */
    font-family: 'Nanum Myeongjo', 'Gungsuh', 'GungsuhChe', 'Batang', serif;
    background: #050308;
    color: var(--ink);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

/* ── 무대: 화면 높이에 맞춰 9:16 세로 컬럼 중앙 배치 ── */
.stage {
    position: relative;
    width: 100vw; height: 100vh;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background:
        radial-gradient(120% 80% at 50% -10%, #241a4d 0%, #0b0716 55%, #050308 100%);
}

/* ── 마법 거울 (opening.jpg 아트 = 프레임+신비로운 중앙+던전 배경 통짜) ── */
/* 프레임 그림 속 '거울 창'(콘텐츠가 놓일 어두운 안쪽) 여백 — 이 값으로 콘텐츠를 창 안에 가둔다 */
:root { --win-t: 19%; --win-b: 22%; --win-x: 21%; --win-radius: 44px / 78px; }

.mirror {
    position: relative;
    width: min(56.25vh, 100vw);   /* 9:16 → 폭 = 높이*0.5625 */
    height: min(100vh, 177.78vw);
    max-height: 100vh;
    overflow: hidden;
    background: url('/opening.jpg') center / cover no-repeat, var(--indigo-0);
    box-shadow: 0 0 70px rgba(167,139,250,0.28);
}

/* 직업 색 틴트 — 거울 창 안쪽에만, 대화 중에만 은은히 (신비로운 소용돌이는 비쳐 보이게) */
.mirror-bg {
    position: absolute; inset: var(--win-t) var(--win-x) var(--win-b);
    border-radius: var(--win-radius);
    background: radial-gradient(95% 75% at 50% 42%, color-mix(in srgb, var(--job) 50%, transparent) 0%, transparent 72%);
    background-size: cover; background-position: center;
    opacity: 0; transition: opacity .8s ease, background .8s ease;
}
.stage[data-screen="convo"] .mirror-bg { opacity: .9; }

/* 가독성 오버레이 — 거울 창 안쪽만 살짝 어둡게 (금빛 프레임은 밝게 유지) */
.mirror-overlay {
    position: absolute; inset: var(--win-t) var(--win-x) var(--win-b); pointer-events: none;
    border-radius: var(--win-radius);
    background: radial-gradient(85% 65% at 50% 45%, rgba(5,3,8,0.5) 0%, rgba(5,3,8,0.25) 60%, rgba(5,3,8,0.45) 100%);
}

/* 거울 안 떠다니는 입자 (창 안쪽에서만) */
.mirror-particles { position: absolute; inset: var(--win-t) var(--win-x) var(--win-b); pointer-events: none; overflow: hidden; }
.mirror-particles span {
    position: absolute; bottom: -8%;
    border-radius: 50%;
    background: radial-gradient(circle, #fff 0%, var(--violet-lite) 60%, transparent 70%);
    animation: floatUp linear infinite;
    filter: blur(0.3px);
}
@keyframes floatUp {
    0% { transform: translateY(0) scale(1); opacity: 0; }
    15% { opacity: .8; }
    85% { opacity: .5; }
    100% { transform: translateY(-115vh) scale(0.4); opacity: 0; }
}

/* ── 화면 전환 ── */
.screen {
    position: absolute; inset: var(--win-t) var(--win-x) var(--win-b); z-index: 2;
    display: none; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 4% 5%;
    animation: fadeIn .5s ease both;
}
.stage[data-screen="landing"] .screen[data-for="landing"],
.stage[data-screen="name"]    .screen[data-for="name"],
.stage[data-screen="confirm"] .screen[data-for="confirm"],
.stage[data-screen="roster"]  .screen[data-for="roster"],
.stage[data-screen="jobs"]    .screen[data-for="jobs"],
.stage[data-screen="convo"]   .screen[data-for="convo"] { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ── ① 대기 ── */
.orb { width: clamp(96px, 26vw, 176px); aspect-ratio: 1; display: flex; align-items: center; justify-content: center; filter: drop-shadow(0 0 26px rgba(167,139,250,.9)); animation: bob 3.6s ease-in-out infinite; }
.orb .fig-pic { width: 100%; height: 100%; object-fit: contain; }
.orb .fig-emo { display: none; }
.orb.noimg { width: auto; aspect-ratio: auto; font-size: clamp(40px, 11vw, 82px); }
.orb.noimg .fig-pic { display: none; }
.orb.noimg .fig-emo { display: block; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
.brand { font-size: clamp(28px, 7vw, 48px); font-weight: 800; letter-spacing: -0.02em; margin-top: 4%;
    background: linear-gradient(90deg, #fff, var(--gold)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand-sub { color: var(--muted); margin-top: 10px; font-size: clamp(14px, 3.6vw, 20px); }

/* ── 거울 발화 텍스트 ── */
.mirror-face { font-size: clamp(48px, 13vw, 96px); filter: drop-shadow(0 0 20px rgba(167,139,250,.6)); animation: bob 4s ease-in-out infinite; }
.mirror-say { font-size: clamp(24px, 6.5vw, 40px); font-weight: 800; margin-top: 6%; text-shadow: 0 2px 20px rgba(0,0,0,.7); line-height: 1.35; }
.mirror-say.small { font-size: clamp(18px, 5vw, 30px); }
.mirror-say #confirmName { color: var(--gold); }
.listen-dot { margin-top: 26px; color: #fca5a5; font-weight: 700; font-size: clamp(15px, 4vw, 22px); animation: pulse 1.2s ease-in-out infinite; }
.heard { margin-top: 14px; min-height: 1.4em; color: var(--gold); font-size: clamp(18px, 5vw, 28px); font-weight: 800; }
@keyframes pulse { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

/* ── 버튼 ── */
.btn-magic {
    margin-top: 30px; padding: 16px 30px; border: none; border-radius: 999px; white-space: nowrap;
    font-size: clamp(17px, 4.4vw, 24px); font-weight: 800; color: #2b1a05; cursor: pointer;
    background: linear-gradient(180deg, #ffe89a, var(--gold) 55%, var(--gold-deep));
    box-shadow: 0 10px 30px rgba(252,211,77,.35), inset 0 1px 0 rgba(255,255,255,.6);
    transition: transform .12s ease, box-shadow .2s ease;
}
.btn-magic:hover { transform: translateY(-2px); box-shadow: 0 14px 40px rgba(252,211,77,.5); }
.btn-magic:active { transform: scale(.97); }
.btn-magic.sm { margin-top: 0; padding: 12px 22px; font-size: 16px; }
.btn-ghost {
    margin-top: 22px; padding: 13px 26px; border-radius: 999px; cursor: pointer;
    background: rgba(255,255,255,.08); color: var(--ink); border: 1.5px solid rgba(196,181,253,.4);
    font-size: clamp(14px, 3.6vw, 18px); font-weight: 600; transition: background .18s ease;
}
.btn-ghost:hover { background: rgba(255,255,255,.16); }
.btn-ghost.sm { margin-top: 0; padding: 10px 16px; font-size: 14px; }
.confirm-btns { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; }
.confirm-btns .btn-ghost { margin-top: 34px; }

/* 명단·진로 카드는 항목이 많아 창 안에서 세로 스크롤 (프레임 밖으로 안 넘치게) */
.screen-roster, .screen-jobs { justify-content: flex-start; overflow-y: auto; overflow-x: hidden; scrollbar-width: none; }
.screen-roster::-webkit-scrollbar, .screen-jobs::-webkit-scrollbar { display: none; }
.screen-roster .mirror-say, .screen-jobs .mirror-say { position: sticky; top: 0; padding: 6px 0 10px; }

/* ── ④ 명단 ── */
.roster-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: 100%; margin: 4% 0; }
.roster-grid button {
    padding: 13px 6px; border-radius: 14px; cursor: pointer; font-weight: 700; white-space: nowrap;
    font-size: clamp(13px, 3.4vw, 17px); color: var(--ink);
    background: rgba(255,255,255,.09); border: 1.5px solid rgba(196,181,253,.3);
    transition: transform .1s ease, background .15s ease;
}
.roster-grid button:hover { background: rgba(167,139,250,.28); transform: translateY(-2px); }

/* ── ⑤ 진로 카드 ── */
.jobs-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; width: 100%; margin-top: 3%; padding-bottom: 4%; }
.job-card {
    display: flex; flex-direction: column; align-items: center; gap: 5px;
    padding: 12px 6px; border-radius: 18px; cursor: pointer; color: var(--ink);
    background: color-mix(in srgb, var(--c) 26%, #1e1b4b);
    border: 2px solid color-mix(in srgb, var(--c) 70%, transparent);
    box-shadow: 0 6px 16px rgba(0,0,0,.35);
    transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
}
.job-card:hover { transform: translateY(-3px) scale(1.02); box-shadow: 0 12px 28px color-mix(in srgb, var(--c) 45%, transparent); }
.job-card:active { transform: scale(.97); }
.job-name { font-size: clamp(13px, 3.6vw, 18px); font-weight: 800; white-space: nowrap; }

/* ── 캐릭터 이미지/이모지 폴백 (카드) ── */
.job-fig { width: 100%; height: clamp(74px, 19vw, 118px); display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 12px; }
.fig-pic { display: block; width: 100%; height: 100%; object-fit: cover; }
.fig-emo { display: none; }
.job-fig.noimg .fig-pic { display: none; }
.job-fig.noimg .fig-emo { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; font-size: clamp(26px, 7vw, 42px); }

/* ── ⑥ 대화 화면 ── */
.screen-convo { justify-content: flex-start; padding: 0; }
/* 웨이브 아바타: 거울 창(=screen-convo 영역)에 딱 맞게, 콘텐츠 뒤 배경 레이어 */
.mirror-wave { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.screen-convo .expert, .screen-convo .expert-name { position: relative; z-index: 2; }
.convo-top { position: absolute; top: 3%; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; padding: 0 7%; z-index: 4; }
.live-dot { color: #fca5a5; font-weight: 800; font-size: clamp(13px, 3.4vw, 18px); letter-spacing: .04em; }
.live-dot.speaking { color: var(--gold); }
.btn-back { background: rgba(0,0,0,.35); border: 1.5px solid rgba(196,181,253,.4); color: var(--ink); border-radius: 999px; padding: 8px 16px; font-weight: 700; cursor: pointer; font-size: clamp(13px, 3.4vw, 16px); }
/* 전문가 초상: 상단 고정 (작게) — 아래 대화창 공간 확보 */
.expert {
    margin-top: 12%; width: clamp(130px, 38%, 230px); aspect-ratio: 3 / 4;
    display: flex; align-items: center; justify-content: center;
    filter: drop-shadow(0 0 30px color-mix(in srgb, var(--job) 70%, #a78bfa));
    transition: transform .18s ease;
    animation: bob 4.5s ease-in-out infinite;
}
.expert .fig-pic { display: block; width: 100%; height: 100%; object-fit: contain; }
.expert .fig-emo { display: none; }
/* 이미지 없을 때: 큰 이모지 폴백 */
.expert.noimg { width: auto; aspect-ratio: auto; margin-top: 15%; font-size: clamp(70px, 24vw, 150px); }
.expert.noimg .fig-pic { display: none; }
.expert.noimg .fig-emo { display: block; }
.expert.talking { animation: talkBob .5s ease-in-out infinite; }
@keyframes talkBob { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-6px) scale(1.05); } }
.expert-name { margin-top: 10px; font-size: clamp(17px, 4.6vw, 26px); font-weight: 800; color: var(--gold); text-shadow: 0 2px 14px rgba(0,0,0,.7); }

/* 대화창: 이름 아래 고정 높이 박스. 긴 답변은 내부 스크롤(최신 자동) → 절대 넘치지 않음 */
.caption-box {
    position: absolute; top: 48%; bottom: 8%; left: 5%; right: 5%; z-index: 4;
    overflow-y: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin;
    background: linear-gradient(180deg, rgba(11,7,22,.62), rgba(11,7,22,.9));
    border: 1.5px solid rgba(252,211,77,.35); border-radius: 22px;
    box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.caption-box::-webkit-scrollbar { width: 6px; }
.caption-box::-webkit-scrollbar-thumb { background: rgba(252,211,77,.4); border-radius: 3px; }
.caption {
    padding: 16px 18px; font-size: clamp(17px, 4.4vw, 27px); font-weight: 800; line-height: 1.42;
    text-shadow: 0 2px 12px rgba(0,0,0,.8);
}
.screen-convo .status { position: absolute; bottom: 2.5%; left: 0; right: 0; z-index: 4; color: var(--muted); font-size: clamp(12px, 3.2vw, 16px); font-weight: 600; }

/* ── 대화 로그 패널 (거울 밖 우측, 넓은 화면일 때만) ── */
.logpanel {
    position: fixed; top: 4vh; right: 2vw; width: min(320px, 22vw); max-height: 92vh; z-index: 20;
    background: rgba(15,11,35,.82); border: 1.5px solid rgba(167,139,250,.3); border-radius: 18px;
    padding: 14px; display: flex; flex-direction: column; backdrop-filter: blur(6px);
}
.log-title { font-weight: 800; color: var(--gold); margin-bottom: 10px; font-size: 15px; }
.log-list { overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.log-empty { color: var(--muted); font-size: 13px; }
.log-item { background: rgba(255,255,255,.05); border-radius: 12px; padding: 8px 10px; font-size: 13px; line-height: 1.4; }
.log-q { color: #fde68a; }
.log-a { color: #ddd6fe; margin-top: 4px; }
@media (max-width: 1100px) { .logpanel { display: none; } } /* 태블릿 세로에선 자막만 */

/* ── 상단 툴바 (홈 · 음소거 · 학생관리) ── */
.toolbar { position: fixed; top: 10px; left: 0; right: 0; z-index: 40; display: flex; justify-content: space-between; align-items: center; padding: 0 14px; pointer-events: none; }
.toolbar > *, .tb-right > * { pointer-events: auto; }
.tb-right { display: flex; gap: 8px; align-items: center; }
.tb-btn { height: 44px; min-width: 44px; padding: 0 12px; border-radius: 22px; cursor: pointer;
    background: rgba(20,14,40,.62); border: 1.5px solid rgba(252,211,77,.45); color: #fde8a0;
    font-size: 20px; font-family: inherit; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    box-shadow: 0 4px 14px rgba(0,0,0,.4); backdrop-filter: blur(4px); transition: transform .12s ease, background .18s ease; }
.tb-btn:hover { background: rgba(40,28,70,.8); transform: translateY(-1px); }
.tb-btn:active { transform: scale(.95); }
.tb-gear { font-size: 18px; }
.tb-label { font-size: 14px; font-weight: 700; }
@media (max-width: 520px) { .tb-label { display: none; } } /* 좁으면 아이콘만 */

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; background: rgba(5,3,8,.7); backdrop-filter: blur(4px); }
.modal-card { width: min(440px, 92vw); background: #14102b; border: 1.5px solid rgba(167,139,250,.35); border-radius: 22px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal-card h2 { font-size: 20px; margin-bottom: 16px; }
.modal-label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.roster-textarea { width: 100%; height: 180px; resize: vertical; border-radius: 12px; padding: 12px; font-size: 15px; line-height: 1.6;
    background: rgba(0,0,0,.35); border: 1px solid rgba(196,181,253,.3); color: var(--ink); font-family: inherit; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.modal-note { margin-top: 12px; color: var(--gold); font-size: 13px; min-height: 1.2em; }
.modal-close { margin-top: 16px; width: 100%; padding: 12px; border-radius: 12px; cursor: pointer; background: rgba(255,255,255,.08); border: 1px solid rgba(196,181,253,.3); color: var(--ink); font-weight: 700; }

/* ── 푸터 ── */
.footer { position: fixed; bottom: 0; left: 0; right: 0; text-align: center; padding-bottom: 24px; color: #64748b; font-size: 12px; z-index: 10; }
.footer a { color: #64748b; text-decoration: none; }
.footer a:hover { text-decoration: underline; }
