* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #F2F8F6;
  --card: #FFFFFF;
  --text: #1F2A28;
  --muted: #6B7A77;
  --line: #D9E6E2;
  --primary: #2A7F72;       /* 청록 — 지구·탐험 느낌 */
  --primary-text: #FFFFFF;
  --primary-soft: #DCEFEA;
  --ok: #2F8F5B;
  --ok-soft: #DDF2E5;
  --bad: #C8423A;
  --bad-soft: #FBE1DE;
  --shadow: 0 2px 10px rgba(30, 60, 50, 0.08);
}

/* 다크 — 설정(⚙️)에서 고른 값(html[data-theme])이 우선, 없으면 기기 설정 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15201D; --card: #1F2C29; --text: #E8F0ED; --muted: #9DB0AB; --line: #2E3F3B;
    --primary: #5CC4B2; --primary-text: #15201D; --primary-soft: #24433D;
    --ok: #6CCB93; --ok-soft: #233D2E; --bad: #F08A80; --bad-soft: #4A2724; --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #15201D; --card: #1F2C29; --text: #E8F0ED; --muted: #9DB0AB; --line: #2E3F3B;
  --primary: #5CC4B2; --primary-text: #15201D; --primary-soft: #24433D;
  --ok: #6CCB93; --ok-soft: #233D2E; --bad: #F08A80; --bad-soft: #4A2724; --shadow: none;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }

/* ── 레이아웃 ─────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--bg); border-bottom: 1px solid var(--line); }
.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 32px);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card h2 { font-size: 22px; }
.card h3 { font-size: 17px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.greeting { color: var(--muted); font-size: 15px; }
.back-link { font-weight: 600; align-self: flex-start; }
.msg { font-size: 15px; color: var(--muted); }
.msg-error { color: var(--bad); }

/* ── 버튼 ─────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 18px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-text { background: none; border: none; color: var(--primary); min-height: 40px; }
.btn-block { width: 100%; }
.btn-big { min-height: 58px; font-size: 20px; }
input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ── 홈: 대분류 카드 ──────────────────────── */
.cat-grid { display: grid; gap: 12px; }
.cat-card { align-items: flex-start; gap: 4px; color: var(--text); position: relative; }
.cat-card:not(.cat-soon):active { transform: scale(.99); }
.cat-icon { font-size: 40px; line-height: 1; }
.cat-name { font-size: 20px; font-weight: 800; }
.cat-desc { color: var(--muted); font-size: 14px; }
.cat-best { font-size: 13px; color: var(--primary); font-weight: 700; }
.cat-go { margin-top: 6px; color: var(--primary); font-weight: 700; }
.cat-soon { opacity: .6; }
.cat-soon .cat-go { color: var(--muted); }
@media (min-width: 640px) { .cat-grid { grid-template-columns: 1fr 1fr 1fr; } .app { max-width: 900px; } .cat-card { min-height: 190px; } }

/* ── 수도 퀴즈 ────────────────────────────── */
.big-icon { font-size: 56px; line-height: 1; text-align: center; }
.setup { align-items: stretch; text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; text-align: left; }
.field-name { font-size: 13px; font-weight: 700; color: var(--muted); }
.seg { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg button {
  flex: 1; min-height: 44px; padding: 6px 8px; border: none; background: none;
  color: var(--text); font: inherit; font-size: 15px; cursor: pointer;
}
.seg button.on { background: var(--primary); color: var(--primary-text); font-weight: 700; }
.best { font-weight: 700; color: var(--primary); text-align: center; }

.quiz-head { display: flex; align-items: center; justify-content: space-between; }
.progress { color: var(--muted); font-weight: 700; }
.question { align-items: center; text-align: center; padding: 22px 16px; }
.prompt-label { color: var(--muted); font-size: 15px; }
.flag { font-size: 72px; line-height: 1.1; }
/* 사자성어·한자 퀴즈 — 크게 보여 줄 한자 */
.hz-big { font-family: "Noto Serif KR", "Batang", serif; font-size: 56px; font-weight: 700; line-height: 1.15; letter-spacing: 0.08em; color: var(--on-surface, inherit); word-break: keep-all; }
.hz-big.one { font-size: 88px; }
.option-big { font-family: "Noto Serif KR", "Batang", serif; font-size: 30px; }
.prompt { font-size: 28px; font-weight: 800; color: var(--primary); word-break: keep-all; }

.options { display: grid; gap: 10px; }
.option { min-height: 56px; font-size: 18px; }
.option.correct { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 800; }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.feedback { text-align: center; font-weight: 700; min-height: 1.5em; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.next-btn { min-height: 52px; font-size: 18px; }

.result { align-items: center; text-align: center; padding: 28px 18px; }
.result.perfect { background: var(--primary-soft); border-color: transparent; }
.review { gap: 10px; }
.review h3 { margin: 0; }
.review-item { display: flex; gap: 10px; align-items: center; }
.review-flag { font-size: 30px; line-height: 1; }
.review-q { font-weight: 700; }
.review-a { font-size: 14px; color: var(--bad); }

/* 글자 크기 설정(설정 메뉴) — 공통 키 yeon.font */
html[data-font="small"] body { zoom: 0.9; }
html[data-font="large"] body { zoom: 1.15; }

/* ── 공통 진행 화면 추가 (해설, 긴 문제, 줄바꿈 세그먼트) ── */
.prompt-long { font-size: 21px; }
.feedback-main { font-weight: 700; }
.explain { font-size: 14px; color: var(--muted); margin-top: 4px; text-align: center; }
.review-explain { font-size: 13px; color: var(--muted); margin-top: 2px; }
.seg-wrap { flex-wrap: wrap; }
.seg-wrap button { flex: 1 1 30%; }

/* ── 통계 ── */
.stats-link { align-self: flex-end; font-weight: 700; }
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; }
.tile { background: var(--bg); border-radius: 12px; padding: 10px 6px; text-align: center; }
.tile-value { font-size: 22px; font-weight: 800; color: var(--primary); }
.tile-label { font-size: 12px; color: var(--muted); }
.stats-hero { align-items: center; text-align: center; }
.stat-rows { display: flex; flex-direction: column; gap: 12px; }
.stat-head { display: flex; justify-content: space-between; font-weight: 700; }
.stat-pct { color: var(--primary); }
.stat-bar { height: 10px; border-radius: 999px; background: var(--line); overflow: hidden; margin: 4px 0; }
.stat-fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width .4s; }
.stat-fill.good { background: var(--ok); }
.stat-fill.low { background: var(--bad); }

/* ── 퀴즈 아고라 ── */
.cat-battle { background: var(--primary-soft); border-color: var(--primary); }
.battle-hero { align-items: center; text-align: center; }
.section-title { font-size: 16px; color: var(--muted); margin-top: 4px; }
.room-card { gap: 2px; color: var(--text); }
.room-card:not(.room-off):active { transform: scale(.99); }
.room-off { opacity: .6; }
.room-title { font-weight: 800; font-size: 17px; }
.room-meta { display: flex; justify-content: space-between; margin-top: 4px; font-weight: 700; }
.room-go { color: var(--primary); }
.empty-rooms { text-align: center; padding: 12px 0; }
.center { text-align: center; }
.config-title { font-weight: 800; font-size: 17px; }
.player-list { list-style: none; display: flex; flex-direction: column; gap: 6px; width: 100%; }
.player { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-radius: 12px; background: var(--bg); }
.player.me { outline: 2px solid var(--primary); }
.player.empty { border: 1px dashed var(--line); background: none; }
.player-name { font-weight: 700; }
.player-status { font-size: 14px; color: var(--muted); }
.player-status.ok { color: var(--ok); font-weight: 700; }
.net-banner, .toast { text-align: center; font-weight: 700; border-radius: 12px; padding: 8px 12px; }
.net-banner { background: var(--bad-soft); color: var(--bad); }
.toast { background: var(--primary-soft); color: var(--primary); }
.countdown { align-items: center; text-align: center; padding: 28px 16px; }
.countdown-num { font-size: 96px; font-weight: 900; line-height: 1; color: var(--primary); animation: pop 1s ease-out infinite; }
@keyframes pop { 0% { transform: scale(1.25); opacity: .4; } 30% { transform: scale(1); opacity: 1; } }
.timer { display: flex; align-items: center; gap: 10px; }
.timer-track { flex: 1; height: 12px; border-radius: 999px; background: var(--line); overflow: hidden; }
.timer-fill { height: 100%; width: 100%; border-radius: 999px; background: var(--primary); transition: width .1s linear; }
.timer-fill.low { background: var(--bad); }
.timer-sec { min-width: 3em; text-align: right; font-weight: 800; }
.option.picked { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 800; opacity: 1; }
.reveal-option { display: flex; flex-direction: column; align-items: center; justify-content: center; cursor: default; }
.pickers { font-size: 13px; font-weight: 600; opacity: .85; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.chip { font-size: 14px; padding: 4px 10px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.chip.done { border-color: var(--ok); color: var(--ok); font-weight: 700; }
.scoreboard { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.score-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.score-row.me { border-color: var(--primary); background: var(--primary-soft); }
.score-row.left { opacity: .55; }
.score-rank { min-width: 2.2em; font-size: 20px; text-align: center; }
.score-name { flex: 1; font-weight: 700; }
.score-gain { color: var(--ok); font-weight: 800; font-size: 14px; }
.score-pts { font-weight: 800; color: var(--primary); }
.scoreboard.final .score-row { padding: 12px; font-size: 18px; }
.feedback-main.ok { color: var(--ok); }
.feedback-main.bad { color: var(--bad); }
.chat { gap: 8px; }
.chat h3 { margin: 0; }
.chat-list { max-height: 180px; min-height: 64px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-radius: 12px; background: var(--bg); }
.chat-line { font-size: 15px; word-break: break-word; }
.chat-line b { color: var(--primary); }
.chat-line.mine b { color: var(--ok); }
.chat-line.system { font-size: 13px; color: var(--muted); text-align: center; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; min-width: 0; }
.chat-form .btn { flex: none; }
.seg-half button { flex-basis: 45%; }
.head-right { display: flex; align-items: center; gap: 10px; }
.sound-btn { background: none; border: none; font-size: 20px; line-height: 1; padding: 4px; cursor: pointer; }
.mid-scores { text-align: center; font-weight: 800; color: var(--primary); background: var(--primary-soft); border-radius: 12px; padding: 8px; }
.secret { padding: 6px 0; }
.replay-btn { border-color: var(--primary); color: var(--primary); font-weight: 800; background: var(--primary-soft); }

/* 퀴즈 아고라 방 채팅 — 넓은 화면(PC)은 로비 채팅처럼 오른쪽에 고정된 세로 칸 (대기실·대결 중·결과 모두, 본문은 그만큼 왼쪽) */
@media (min-width: 1200px) {
  body:has(.battle-chat) { padding-right: 320px; }
  .battle-chat {
    position: fixed; top: 0; right: 0; bottom: 0; width: 320px; z-index: 20;
    padding: calc(env(safe-area-inset-top) + 12px) 12px 12px;
    border: none; border-left: 1px solid var(--line); border-radius: 0; box-shadow: none;
    display: flex; flex-direction: column;
  }
  .battle-chat .chat-list { flex: 1; max-height: none; min-height: 0; }
}
