/* 영어 단어 놀이터 메인 사이트·Word Hunt와 같은 톤: 밝은 바탕, 흰 카드, 보라 그라데이션, 선 아이콘.
   게임 화면만 우주 느낌의 어두운 무대를 씀 */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --primary: #667eea; --secondary: #764ba2;
    --text: #2d3748; --text-light: #718096; --line: #e2e8f0;
    --bg: #f7fafc; --white: #ffffff;
    --ok: #10b981; --ok-dark: #059669; --bad: #ef4444; --gold: #f59e0b;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.08); --radius: 20px;
}
body {
    font-family: "Segoe UI", "Malgun Gothic", sans-serif; background: var(--bg); color: var(--text);
    min-height: 100vh; display: flex; flex-direction: column; align-items: center; overflow-x: hidden;
    background-image: radial-gradient(circle at 12% 0%, rgba(102, 126, 234, .10), transparent 40%),
                      radial-gradient(circle at 92% 8%, rgba(118, 75, 162, .08), transparent 38%);
    background-attachment: fixed;
}
button, input { font-family: inherit; }
[hidden] { display: none !important; }
.ic { width: 1.1em; height: 1.1em; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.18em; }

/* ── 상단 바 ── */
.topbar {
    position: sticky; top: 0; z-index: 100; width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: 64px; padding: 0 24px; background: rgba(255, 255, 255, .92);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: #1a1a2e; min-width: 0; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; color: #fff; flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--secondary)); box-shadow: 0 4px 12px rgba(102, 126, 234, .35); }
.brand-mark .ic { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-title { font-size: 1.12em; font-weight: 800; letter-spacing: -.3px; }
.brand-sub { font-size: .76em; color: var(--text-light); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.icon-btn {
    width: 38px; height: 38px; display: grid; place-items: center; border-radius: 12px; cursor: pointer;
    background: #f1f3fb; border: 1px solid var(--line); color: #4c51bf; text-decoration: none; transition: background .15s, color .15s;
}
.icon-btn:hover { background: #e6e9fb; }
.icon-btn.muted { background: #fff1f2; border-color: #fecdd3; color: #e11d48; }

/* ── 화면 전환 ── */
.screen { display: none; width: 100%; max-width: 1200px; padding: 28px 20px 40px; }
.screen.active { display: flex; flex-direction: column; align-items: center; animation: fadeIn .45s cubic-bezier(.2, 1, .3, 1); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

/* ── 카드 ── */
.card {
    width: 100%; max-width: 540px; background: var(--white); border-radius: var(--radius); padding: 34px 32px 28px;
    box-shadow: var(--shadow); border: 1px solid rgba(226, 232, 240, .8); text-align: center;
}
.hero-icon {
    width: 72px; height: 72px; margin: 0 auto 16px; border-radius: 22px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, var(--primary), var(--secondary)); box-shadow: 0 10px 26px rgba(102, 126, 234, .38);
}
.hero-icon .ic { width: 34px; height: 34px; }
.card h1, .card h2 { font-size: 1.7em; font-weight: 800; letter-spacing: -.5px; color: #1a1a2e; margin-bottom: 6px; }
.lead { color: var(--text-light); font-size: .98em; line-height: 1.6; }
.lead strong { color: var(--primary); }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 14px 0 4px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; font-size: .84em; font-weight: 700; background: #fff7ed; color: #c2410c; }
.chip.green { background: #f0fdf4; color: #15803d; }
.chip.blue { background: #eef2ff; color: #4338ca; }

.room-code-input {
    width: 100%; margin: 22px 0 14px; padding: 18px 16px; border: 2px solid var(--line); border-radius: 16px; background: #f8faff; color: #1a1a2e;
    font-family: Consolas, "Segoe UI", monospace; font-size: 1.7em; font-weight: 800; letter-spacing: .32em; text-align: center; text-transform: uppercase;
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.room-code-input::placeholder { font-family: "Segoe UI", "Malgun Gothic", sans-serif; font-size: .52em; font-weight: 600; letter-spacing: 0; color: #a0aec0; text-transform: none; }
.room-code-input:focus, .name-input:focus { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(102, 126, 234, .15); }
.name-input {
    width: 100%; margin: 18px 0 6px; padding: 14px 16px; border: 2px solid var(--line); border-radius: 14px; background: #f8faff;
    font-size: 1.05em; color: var(--text); transition: border-color .15s, box-shadow .15s, background .15s;
}
.name-input.shake { border-color: var(--bad); animation: shake .4s ease; }

.primary-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 52px; padding: 0 30px; margin: 6px;
    border: none; border-radius: 99px; cursor: pointer; background: linear-gradient(135deg, var(--primary), var(--secondary)); color: #fff;
    font-size: 1.05em; font-weight: 800; box-shadow: 0 8px 22px rgba(102, 126, 234, .35); transition: transform .15s, box-shadow .15s, filter .15s;
}
.primary-btn:hover { transform: translateY(-2px); filter: brightness(1.05); }
.primary-btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.primary-btn.block { width: 100%; margin: 0; }
.ghost-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 44px; padding: 0 20px; margin: 6px;
    border-radius: 99px; cursor: pointer; background: #fff; color: var(--text-light); border: 1.5px solid var(--line); font-size: .92em; font-weight: 700;
}
.ghost-btn:hover { background: #f7f8fc; color: var(--text); }
.primary-btn:focus-visible, .ghost-btn:focus-visible, .ready-btn:focus-visible, .team-btn:focus-visible, .icon-btn:focus-visible {
    outline: 3px solid rgba(102, 126, 234, .45); outline-offset: 2px;
}

.error-message { display: none; margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; background: #fef2f2; border: 1px solid #fecaca; color: #dc2626; font-size: .92em; font-weight: 600; }
.info-box { display: flex; gap: 10px; align-items: flex-start; text-align: left; margin-top: 18px; padding: 14px 16px; border-radius: 14px; background: #f5f7ff; color: #4a5568; font-size: .88em; line-height: 1.6; }
.info-box .ic { color: var(--primary); margin-top: 2px; }

.room-display { display: inline-flex; align-items: center; gap: 10px; margin: 12px 0 4px; padding: 8px 16px; border-radius: 99px; background: #f5f7ff; border: 1px solid #e0e6ff; }
.room-label { font-size: .82em; color: var(--text-light); font-weight: 600; }
.room-code-display { font-family: Consolas, monospace; font-size: 1.15em; font-weight: 800; letter-spacing: .18em; color: var(--primary); }

/* ── 모둠 선택 ── */
.team-selection { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 18px 0 14px; }
.team-btn {
    --tc: #667eea; --tc-soft: #eef1ff;
    display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 12px 4px 10px; border: 2px solid transparent; border-radius: 14px;
    cursor: pointer; background: var(--tc-soft); color: var(--tc); font-size: .9em; font-weight: 800; transition: transform .15s, border-color .15s, box-shadow .15s;
}
.team-btn .team-no { font-size: 1.6em; line-height: 1.1; }
.team-btn:hover { transform: translateY(-3px); border-color: var(--tc); box-shadow: 0 8px 20px rgba(0, 0, 0, .08); }
.team-btn.team-1 { --tc: #e11d48; --tc-soft: #fff1f2; } .team-btn.team-2 { --tc: #0d9488; --tc-soft: #f0fdfa; }
.team-btn.team-3 { --tc: #ea580c; --tc-soft: #fff7ed; } .team-btn.team-4 { --tc: #4f46e5; --tc-soft: #eef2ff; }
.team-btn.team-5 { --tc: #16a34a; --tc-soft: #f0fdf4; } .team-btn.team-6 { --tc: #c026d3; --tc-soft: #fdf4ff; }
.team-btn.team-7 { --tc: #0891b2; --tc-soft: #ecfeff; } .team-btn.team-8 { --tc: #ca8a04; --tc-soft: #fefce8; }

/* ── 대기실 ── */
.team-members-list { margin: 20px 0 6px; text-align: left; }
.team-members-list h3 { display: flex; align-items: center; gap: 8px; font-size: .95em; color: var(--text-light); font-weight: 700; }
.member-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.waiting-member-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 14px; background: #f8faff; border: 1px solid var(--line); font-weight: 700; }
.waiting-member-item .st { display: inline-flex; align-items: center; gap: 6px; font-size: .85em; color: var(--text-light); }
.waiting-member-item.ready { background: #ecfdf5; border-color: #a7f3d0; }
.waiting-member-item.ready .st { color: var(--ok-dark); }
.waiting-member-item.me .mn::after { content: "나"; margin-left: 6px; font-size: .72em; font-weight: 800; color: #fff; background: var(--primary); border-radius: 6px; padding: 1px 6px; vertical-align: 2px; }
.ready-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 60px; margin: 16px 0 4px; border: none; border-radius: 99px;
    cursor: pointer; background: linear-gradient(135deg, #34d399, var(--ok-dark)); color: #fff; font-size: 1.2em; font-weight: 800;
    box-shadow: 0 10px 26px rgba(5, 150, 105, .35); transition: transform .15s, box-shadow .15s, filter .15s;
}
.ready-btn:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.05); }
.ready-btn:disabled { opacity: .6; cursor: not-allowed; box-shadow: none; }
.waiting-note { margin-top: 10px; font-size: .9em; color: var(--text-light); line-height: 1.7; }

/* ── 게임 화면 ── */
#gameScreen { max-width: 1400px; padding-top: 18px; }
.game-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 16px; width: 100%; align-items: start; }
.panel { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.pcard { background: var(--white); border-radius: 18px; padding: 16px 18px; box-shadow: var(--shadow); border: 1px solid rgba(226, 232, 240, .8); }
.plabel { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: .78em; font-weight: 700; color: var(--text-light); }
.meaning-card { background: linear-gradient(135deg, var(--primary), var(--secondary)); border: none; color: #fff; box-shadow: 0 10px 28px rgba(102, 126, 234, .35); }
.meaning-card .plabel { color: rgba(255, 255, 255, .85); }
.meaning { font-size: 1.9em; font-weight: 800; letter-spacing: -.5px; line-height: 1.25; margin: 4px 0 12px; overflow-wrap: anywhere; }
.slots { display: flex; flex-wrap: wrap; gap: 5px; }
.slot {
    width: 34px; height: 40px; display: grid; place-items: center; border-radius: 9px; background: rgba(255, 255, 255, .16); border: 1.5px dashed rgba(255, 255, 255, .5);
    font-family: Consolas, "Segoe UI", monospace; font-size: 1.3em; font-weight: 800; color: #fff;
}
.slot.on { background: #fff; color: var(--secondary); border: 1.5px solid #fff; animation: pop .3s ease; }
.slot.next { border-style: solid; border-color: #fde68a; box-shadow: 0 0 0 3px rgba(253, 230, 138, .25); }
@keyframes pop { 0% { transform: scale(.6); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
.pstats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pstat { background: var(--white); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); border: 1px solid rgba(226, 232, 240, .8); min-width: 0; }
.pstat span { display: flex; align-items: center; gap: 5px; font-size: .76em; font-weight: 700; color: var(--text-light); }
.pstat b { display: block; font-family: Consolas, "Segoe UI", monospace; font-size: 1.65em; font-weight: 800; color: #1a1a2e; line-height: 1.2; margin-top: 2px; }
.pstat.time b { color: var(--secondary); }
.pstat.time.hurry b { color: var(--bad); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .45; } }
.tbar { height: 6px; border-radius: 99px; background: #edf0f7; overflow: hidden; margin-top: 6px; }
.tbar i { display: block; height: 100%; width: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--secondary)); transition: width .25s linear; }
.pstat.time.hurry .tbar i { background: linear-gradient(90deg, #f87171, #dc2626); }
.pstat.combo b { color: #ea580c; }
.pstat.combo.hot { background: #fff7ed; border-color: #fed7aa; }
.controls { font-size: .84em; color: var(--text-light); line-height: 1.75; }
.controls .row { display: flex; align-items: flex-start; gap: 8px; }
.controls .ic { color: var(--primary); margin-top: 3px; }
.controls kbd { font-family: inherit; font-size: .9em; font-weight: 800; padding: 0 6px; border-radius: 5px; border: 1px solid #cfd6e6; background: #f7f8fc; color: var(--text); }
.quit-btn { width: 100%; margin: 0; height: 44px; color: #dc2626; border-color: #fecaca; }
.quit-btn:hover { background: #fef2f2; color: #dc2626; }

.stage { position: relative; min-width: 0; border-radius: 22px; overflow: hidden; box-shadow: 0 14px 40px rgba(26, 26, 64, .25); background: #0b1026; }
#gameCanvas { display: block; width: 100%; height: auto; cursor: crosshair; touch-action: none; }
.message {
    position: absolute; top: 18px; left: 50%; transform: translateX(-50%); z-index: 5; display: none; max-width: calc(100% - 40px);
    padding: 10px 22px; border-radius: 99px; background: rgba(15, 18, 45, .82); border: 1.5px solid rgba(255, 255, 255, .25); color: #fff;
    font-size: 1.15em; font-weight: 800; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none;
    -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); animation: messageIn .3s cubic-bezier(.2, 1.3, .4, 1);
}
@keyframes messageIn { from { opacity: 0; transform: translate(-50%, -10px) scale(.9); } to { opacity: 1; transform: translateX(-50%); } }
.correct-hit { color: #6ee7b7; border-color: rgba(110, 231, 183, .6); }
.wrong-hit { color: #fca5a5; border-color: rgba(252, 165, 165, .6); }
.word-completed { color: #fde68a; border-color: rgba(253, 230, 138, .7); }

/* ── 결과 화면 ── */
.result-card { max-width: 620px; }
.result-trophy {
    width: 88px; height: 88px; margin: 0 auto 14px; border-radius: 50%; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, #fbbf24, #f59e0b); box-shadow: 0 0 0 10px rgba(245, 158, 11, .12), 0 14px 34px rgba(245, 158, 11, .4);
}
.result-trophy .ic { width: 44px; height: 44px; }
.my-result { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0 14px; }
.my-result div { padding: 14px 10px; border-radius: 16px; background: #f5f7ff; }
.my-result span { display: block; font-size: .8em; font-weight: 700; color: var(--text-light); }
.my-result b { font-family: Consolas, "Segoe UI", monospace; font-size: 2em; font-weight: 800; color: var(--secondary); }
.team-results { text-align: left; padding: 16px 18px; border-radius: 16px; border: 1px solid var(--line); background: #fbfcff; }
.team-results-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; font-weight: 800; color: #1a1a2e; }
.team-results-head b { font-family: Consolas, monospace; font-size: 1.3em; color: var(--ok-dark); }
.result-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; font-size: .92em; font-weight: 700; }
.result-item + .result-item { margin-top: 4px; }
.result-item:nth-child(odd) { background: #f3f5fb; }
.result-item .rv { color: var(--text-light); white-space: nowrap; }
.result-item.me { background: #eef2ff; color: #4338ca; }
.result-item .wait { color: #ea580c; }
.result-note { margin-top: 10px; font-size: .82em; color: var(--text-light); }
.result-actions { margin-top: 14px; }

/* ── 알림 · 확인 창 ── */
.toast {
    position: fixed; top: 78px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; align-items: center; gap: 9px;
    max-width: calc(100vw - 40px); padding: 12px 18px; border-radius: 14px; background: #fff; border: 1px solid #fecaca; color: var(--text);
    font-size: .92em; font-weight: 700; box-shadow: 0 14px 34px rgba(0, 0, 0, .14); animation: toastIn .3s ease;
}
.toast .ic { color: #dc2626; }
.toast.ok { border-color: #a7f3d0; }
.toast.ok .ic { color: var(--ok-dark); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translateX(-50%); } }
.modal-overlay { display: none; position: fixed; inset: 0; z-index: 9999; align-items: center; justify-content: center; padding: 20px; background: rgba(20, 22, 40, .55); }
.modal-overlay.active { display: flex; }
.modal-content { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; overflow: hidden; box-shadow: 0 24px 70px rgba(0, 0, 0, .35); animation: pop .25s cubic-bezier(.2, 1.3, .4, 1); }
.modal-content h3 { padding: 18px 22px 14px; font-size: 1.1em; font-weight: 800; color: #fff; background: linear-gradient(135deg, var(--primary), var(--secondary)); }
.modal-content p { padding: 20px 22px 8px; font-size: .95em; line-height: 1.7; color: var(--text); word-break: keep-all; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 18px; border-top: 1.5px solid #eef0f6; }
.modal-buttons button { height: 42px; padding: 0 18px; margin: 0; border-radius: 12px; font-size: .92em; }
.danger-btn { border: 0; cursor: pointer; color: #fff; font-weight: 800; background: linear-gradient(135deg, #f87171, #dc2626); box-shadow: 0 4px 14px rgba(220, 38, 38, .3); }

@keyframes shake {
    0%, 100% { transform: translateX(0); } 20% { transform: translateX(-8px); } 40% { transform: translateX(8px); }
    60% { transform: translateX(-5px); } 80% { transform: translateX(5px); }
}

@media (max-width: 1100px) {
    .game-layout { grid-template-columns: 1fr; }
    .panel { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
    .panel .controls { display: none; }
    .panel .quit-btn { grid-column: 1 / -1; }
    .meaning { font-size: 1.5em; margin-bottom: 8px; }
}
@media (max-width: 640px) {
    .topbar { padding: 0 14px; }
    .brand-sub { display: none; }
    .card { padding: 26px 18px 22px; }
    .panel { grid-template-columns: 1fr; }
    .pstats { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .pstat { padding: 8px; }
    .pstat b { font-size: 1.2em; }
    .slot { width: 28px; height: 34px; font-size: 1.1em; }
    .message { font-size: .95em; }
}
