/* 영어 강화 — 디자인 토큰
   브랜드: 코발트 블루 → 바이올렛 그라데이션 + 라임 포인트 (제곱 기호 ²)
   메뉴 색: 보카(에메랄드) · 스피킹(코발트) · Study in English(인디고 바이올렛)
   스피킹 단계 색: 블록 이해(스카이) · 영어로 말하기(코발트) · 쉐도잉(퍼플) · 롤플레이(핑크) · 복습(레드) */
:root {
  color-scheme: light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --ink: #141a2e;
  --ink-2: #434c66;
  --muted: #626b84;
  --line: #e0e5ef;

  --brand: #3b5bfd;
  --brand-2: #7a5af8;
  --brand-ink: #2e47d6;
  --lime: #c5f04a;
  --on-lime: #1a2410;

  /* 채움색(배경) · 글자색(밝은 배경 대비 4.5:1 이상) · 진한 채움(흰 글자를 올리는 버튼) */
  --vocab: #12b76a; --vocab-ink: #027a48; --vocab-strong: #08875a;
  --lesson: #0ea5e9; --lesson-ink: #0369a1; --lesson-strong: #0369a1;
  --speak: #3b5bfd; --speak-ink: #2e47d6; --speak-strong: #3451f0;
  --shadow: #a855f7; --shadow-ink: #7e22ce; --shadow-strong: #9333ea;
  --talk: #ec4899; --talk-ink: #be185d; --talk-strong: #db2777;
  --review: #f04438; --review-ink: #c0281d; --review-strong: #d92d20;
  --free: #6d5bf6; --free-ink: #5643d9; --free-strong: #5b47f0; /* Study in English */
  --accent: var(--brand);
  --accent-ink: var(--brand-ink);
  --accent-strong: var(--speak-strong); /* 글자를 올리는 채움색 */
  --on-accent: #ffffff;

  --ok: #12b76a;
  --ok-bg: #e3f8ed;
  --ok-ink: #027a48;
  --warn-ink: #8a5300;
  --warn: #f5a524;
  --warn-bg: #fff4dc;
  --bad: #e5484d;
  --bad-bg: #fdecec;

  --radius: 18px;
  --radius-sm: 12px;
  --shadow-1: 0 1px 2px rgba(20, 26, 46, 0.06), 0 4px 16px rgba(20, 26, 46, 0.06);
  --shadow-2: 0 8px 30px rgba(20, 26, 46, 0.12);
  --font: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Noto Sans KR", "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0d111d;
    --surface: #161b2b;
    --surface-2: #1f2537;
    --ink: #e9ecf5;
    --ink-2: #bcc3d6;
    --muted: #8f98af;
    --line: #2a3146;
    --brand-ink: #8fa3ff;
    --ok-bg: #0f3324;
    --ok-ink: #4ade80;
    --warn-bg: #3a2c10;
    --warn-ink: #f5b544;
    --bad-bg: #3d1a1c;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow-2: 0 8px 30px rgba(0, 0, 0, 0.55);
    --vocab-ink: #4ade80; --lesson-ink: #67c7f2; --speak-ink: #8fa3ff; --shadow-ink: #c79bfb;
    --talk-ink: #f68bbd; --review-ink: #fb7d74; --free-ink: #a99cff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d111d;
  --surface: #161b2b;
  --surface-2: #1f2537;
  --ink: #e9ecf5;
  --ink-2: #bcc3d6;
  --muted: #8f98af;
  --line: #2a3146;
  --brand-ink: #8fa3ff;
  --ok-bg: #0f3324;
  --ok-ink: #4ade80;
  --warn-bg: #3a2c10;
  --warn-ink: #f5b544;
  --bad-bg: #3d1a1c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 8px 30px rgba(0, 0, 0, 0.55);
  --vocab-ink: #4ade80; --lesson-ink: #67c7f2; --speak-ink: #8fa3ff; --shadow-ink: #c79bfb;
  --talk-ink: #f68bbd; --review-ink: #fb7d74; --free-ink: #a99cff;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.5; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.icon { display: inline-flex; line-height: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* ---------------------------------------------------------------- 앱 셸 */
.app { min-height: 100vh; display: flex; }
.sidenav {
  width: 232px; flex-shrink: 0; padding: 24px 14px; border-right: 1px solid var(--line);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; padding: 6px 12px 22px; letter-spacing: -0.02em; text-decoration: none; color: inherit; line-height: 1.2; }
.sidenav .brand { font-size: 20px; }
.brand-mark .sq, .brand-name .sq { color: var(--lime); font-weight: 800; }
.brand-name .sq { color: var(--brand); }
.brand-mark .sq { font-size: 0.7em; vertical-align: super; line-height: 0; margin-left: 1px; }
.brand-mark {
  min-width: 34px; height: 34px; padding: 0 7px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 15px; letter-spacing: -0.03em; font-weight: 800;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}
.nav-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; border: 0; background: none;
  text-align: left; font-weight: 600; color: var(--ink-2); text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-ink); }
.nav-sep { border: 0; border-top: 1px solid var(--line); margin: 10px 8px; width: auto; }
.sidenav-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; }
.sidenav-foot .user-chip { flex: 1; margin-top: 0; min-width: 0; }
.theme-toggle { width: 40px; height: 40px; }
.nav-badge { margin-left: auto; background: var(--review); color: #fff; font-size: 12px; border-radius: 99px; padding: 0 7px; }
.provider-chip { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px 14px; border-top: 1px solid var(--line); text-decoration: none; display: grid; gap: 2px; border-radius: 0 0 10px 10px; }
.provider-chip b { color: var(--ink-2); }
.provider-chip.demo { background: var(--warn-bg); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: 12px; }
.provider-chip.demo b { color: var(--warn); }

.main { flex: 1; min-width: 0; }
.page { max-width: 1040px; margin: 0 auto; padding: 28px 28px 120px; }
.page-narrow { max-width: 640px; }

.tabbar { display: none; }

@media (max-width: 820px) {
  .sidenav { display: none; }
  .page { padding: 18px 16px 110px; }
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar .nav-item { flex: 1; flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 2px; justify-content: center; align-items: center; min-width: 0; white-space: nowrap; }
  .tabbar .nav-badge { position: absolute; margin-left: 18px; margin-top: -4px; }
}

/* 전체 화면 학습 모드 (드릴, 대화) */
.focus { min-height: 100vh; display: flex; flex-direction: column; }
.focus-top {
  position: sticky; top: 0; z-index: 10; background: var(--bg); display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; max-width: 760px; width: 100%; margin: 0 auto;
}
.focus-body { flex: 1; width: 100%; max-width: 680px; margin: 0 auto; padding: 8px 20px 24px; display: flex; flex-direction: column; }
.focus-foot { position: sticky; bottom: 0; background: linear-gradient(to top, var(--bg) 75%, transparent); padding: 16px 20px calc(18px + env(safe-area-inset-bottom)); }
.focus-foot-inner { max-width: 680px; margin: 0 auto; }

/* ---------------------------------------------------------------- 기본 컴포넌트 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-1); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 14px;
  padding: 14px 22px; font-weight: 700; font-size: 16px; background: var(--ink); color: var(--bg);
  transition: transform 0.06s, filter 0.15s; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn-block { width: 100%; }
.btn-accent { background: var(--accent-strong); color: var(--on-accent); box-shadow: 0 3px 0 color-mix(in srgb, var(--accent-strong) 70%, #000); }
.btn-ghost { background: transparent; color: var(--ink-2); border: 1.5px solid var(--line); }
.btn-soft { background: var(--surface-2); color: var(--ink); }
.btn-sm { padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--line); background: var(--surface);
  display: inline-grid; place-items: center; color: var(--ink-2); flex-shrink: 0;
}
.icon-btn:hover { border-color: var(--ink-2); }
.icon-btn.playing { color: var(--accent-ink); border-color: var(--accent); animation: pulse 1s infinite; }
.icon-btn.plain { border: 0; background: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 13px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); }
.tag { display: inline-block; padding: 2px 9px; border-radius: 8px; font-size: 12px; font-weight: 700; color: #fff; }
.step-lesson { --accent: var(--lesson); --accent-ink: var(--lesson-ink); --accent-strong: var(--lesson-strong); --on-accent: #fff; }
.step-speak { --accent: var(--speak); --accent-ink: var(--speak-ink); --accent-strong: var(--speak-strong); --on-accent: #fff; }
.step-review { --accent: var(--review); --accent-ink: var(--review-ink); --accent-strong: var(--review-strong); --on-accent: #fff; }
.step-shadow { --accent: var(--shadow); --accent-ink: var(--shadow-ink); --accent-strong: var(--shadow-strong); --on-accent: #fff; }
.step-talk { --accent: var(--talk); --accent-ink: var(--talk-ink); --accent-strong: var(--talk-strong); --on-accent: #fff; }
.step-free { --accent: var(--free); --accent-ink: var(--free-ink); --accent-strong: var(--free-strong); --on-accent: #fff; }
.step-study { --accent: var(--free); --accent-ink: var(--free-ink); --accent-strong: var(--free-strong); --on-accent: #fff; }
.step-vocab { --accent: var(--vocab); --accent-ink: var(--vocab-ink); --accent-strong: var(--vocab-strong); --on-accent: #fff; }
.bg-accent { background: var(--accent-strong); color: var(--on-accent) !important; }
.c-accent { color: var(--accent-ink); }

.progress { flex: 1; height: 12px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width 0.4s ease; }
.ring { position: relative; display: inline-grid; place-items: center; color: var(--accent); }
.ring svg circle { transition: stroke-dashoffset 0.6s ease; }
.ring-label { position: absolute; font-weight: 800; font-size: 14px; color: var(--ink); }

.spinner-wrap { display: grid; place-items: center; gap: 12px; padding: 40px 0; }
.spinner { width: 36px; height: 36px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -20px); opacity: 0; z-index: 100;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; max-width: min(92vw, 480px);
  font-size: 14px; transition: all 0.25s; box-shadow: var(--shadow-2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--bad); color: #fff; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: 0.55; } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slideup { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------------------------------------------------------------- 말하기 입력 */
.speak-input { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.live-transcript { min-height: 28px; text-align: center; font-size: 18px; font-weight: 600; color: var(--ink); padding: 0 8px; }
.speak-input[data-state="idle"] .live-transcript { color: var(--muted); font-weight: 500; font-size: 15px; }
.mic-row { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; width: 100%; }
.mic-side { display: flex; justify-content: center; }
.mic-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.mic-btn {
  position: relative; width: 76px; height: 76px; border-radius: 50%; border: 0; background: var(--accent-strong); color: var(--on-accent);
  display: grid; place-items: center; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 45%, transparent);
  transition: transform 0.12s, background 0.2s;
}
.mic-btn:active { transform: scale(0.95); }
.mic-btn .icon { position: relative; z-index: 1; }
.mic-ring {
  --level: 0; position: absolute; inset: 0; border-radius: 50%; background: var(--accent); opacity: 0.25;
  transform: scale(calc(1 + var(--level) * 0.7)); transition: transform 0.08s linear; pointer-events: none;
}
.speak-input[data-state="listening"] .mic-btn { background: var(--bad); color: #fff; box-shadow: 0 6px 20px color-mix(in srgb, var(--bad) 45%, transparent); }
.speak-input[data-state="listening"] .mic-ring { background: var(--bad); animation: breathe 1.4s ease-in-out infinite; }
.speak-input[data-state="busy"] .mic-btn { background: var(--muted); color: #fff; box-shadow: none; }
.speak-input[data-state="busy"] .mic-btn .icon { animation: pulse 0.9s infinite; }
@keyframes breathe { 50% { opacity: 0.12; } }
.mic-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.type-row { display: none; width: 100%; gap: 8px; }
.speak-input.typing .type-row { display: flex; }
.type-row .text-input { flex: 1; width: auto; min-width: 0; }
.speak-input.typing .mic-wrap { display: none; }
.speak-input.typing .live-transcript { display: none; }
.text-input { width: 100%; padding: 13px 16px; border-radius: 14px; border: 1.5px solid var(--line); background: var(--surface); font-size: 16px; }
.text-input:focus { outline: none; border-color: var(--accent); }
.send-btn { background: var(--accent-strong); color: var(--on-accent); border: 0; width: 48px; height: 48px; }
.speak-input.typing .mic-row { display: none; }
.speak-input.compact .mic-btn { width: 64px; height: 64px; }

/* ---------------------------------------------------------------- 정답 대조 */
.diff { font-size: 17px; line-height: 1.8; }
.w-ok { color: var(--ok-ink); font-weight: 600; }
.w-miss { color: var(--bad); font-weight: 700; text-decoration: underline wavy color-mix(in srgb, var(--bad) 50%, transparent); text-underline-offset: 4px; }
.listen-btns { display: flex; gap: 8px; }

.link-btn { background: none; border: 0; padding: 0; color: var(--ink-2); font-size: 14px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: var(--accent-ink); }
.live-transcript .link-btn { font-size: inherit; color: var(--accent-ink); }
.compare { display: flex; flex-wrap: wrap; gap: 8px; }
.compare-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 99px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; font-size: 14px; color: var(--ink-2); }
.compare-btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.compare-btn.playing { border-color: var(--accent); color: var(--accent-ink); animation: pulse 1s infinite; }
.edits .e-del { color: var(--bad); text-decoration: line-through; text-decoration-thickness: 2px; opacity: 0.8; }
.edits .e-add { color: var(--ok-ink); font-weight: 800; text-decoration: none; background: color-mix(in srgb, var(--ok) 14%, transparent); border-radius: 4px; padding: 0 3px; }

/* 누르고 있는 동안 말하기: 길게 눌러도 글자 선택·확대 메뉴가 뜨지 않게 */
.mic-btn, .hold-btn { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.mic-btn.held { transform: scale(0.93); }
.hold-btn.held { border-color: var(--bad); color: var(--bad); }
