:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --ink: #12142e;
  --muted: #62667f;
  --line: #e4e6f1;
  --brand: #3a45f0;
  --brand-hover: #2b35d8;
  --brand-soft: #eceefe;
  --brand-text: #3a45f0;
  --accent: #f4ec5a;
  --danger: #e5484d;
  --danger-soft: #fde9ea;
  --ok: #17a673;
  --shadow: 0 1px 2px rgba(18, 20, 46, .05), 0 8px 24px rgba(18, 20, 46, .06);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e1f;
    --surface: #161936;
    --ink: #eceefc;
    --muted: #9a9fc0;
    --line: #262a52;
    --brand: #4c58f5;
    --brand-hover: #6069ff;
    --brand-soft: #1f2350;
    --brand-text: #98a1ff;
    --danger: #ff6b70;
    --danger-soft: #3a1c2a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard Variable", Pretendard, -apple-system, "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  line-height: 1.55;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand-text); outline-offset: 2px; }

/* 공통 아이콘 */
.ghost svg, .tabs svg, .mark svg, .settings summary svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none;
}

/* 헤더 */
.top {
  max-width: 720px; margin: 0 auto; padding: 18px 20px 6px;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { display: flex; align-items: center; gap: 3px; height: 32px; padding: 0 9px; border-radius: 10px; background: var(--brand); }
.logo i { width: 3px; border-radius: 2px; background: var(--accent); }
.logo i:nth-child(1) { height: 9px; }
.logo i:nth-child(2) { height: 17px; }
.logo i:nth-child(3) { height: 12px; }
.logo i:nth-child(4) { height: 20px; }
.top h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.03em; }
.tagline { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

.intro { margin-bottom: 14px; padding: 20px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); }
.intro h2 { margin: 0 0 6px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.intro p { margin: 0 0 14px; color: var(--muted); font-size: 14px; word-break: keep-all; }
.intro ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.intro li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--brand-soft); }
.intro li b { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--brand); color: #fff; font-size: 14px; }
.intro li span { display: grid; font-weight: 700; line-height: 1.3; }
.intro li small { font-weight: 500; color: var(--muted); font-size: 12.5px; }

.account { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.account input { width: 160px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.chip { padding: 3px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-text); font-weight: 600; font-size: 12px; }

main { max-width: 720px; margin: 0 auto; padding: 8px 20px calc(110px + env(safe-area-inset-bottom)); }

/* 덱 선택 */
.deckbar { display: flex; gap: 8px; margin: 10px 0 14px; }
.select-wrap { position: relative; flex: 1; min-width: 0; }
.select-wrap::after {
  content: ""; position: absolute; right: 16px; top: 50%; width: 8px; height: 8px; margin-top: -6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none;
}
.deckbar select {
  width: 100%; appearance: none; -webkit-appearance: none; padding: 12px 40px 12px 16px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); font-weight: 700;
}
.ghost {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 14px; border: 1px solid var(--line);
  border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); font-weight: 700; color: var(--brand-text);
}
.ghost:hover { border-color: var(--brand); }
.ghost svg { width: 16px; height: 16px; }

/* 탭: 모바일은 하단 고정, 넓은 화면은 상단 세그먼트 */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around; gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border: 0; border-radius: 12px; background: none; color: var(--muted); font-size: 12px; font-weight: 700;
}
.tabs button[aria-selected="true"] { color: var(--brand-text); background: var(--brand-soft); }

@media (min-width: 640px) {
  .tabs {
    position: static; display: flex; justify-content: stretch; gap: 4px; padding: 4px; margin-bottom: 18px;
    background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
    backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tabs button { max-width: none; flex-direction: row; justify-content: center; gap: 8px; padding: 10px; font-size: 14px; }
  .tabs button[aria-selected="true"] { background: var(--brand); color: #fff; }
  main { padding-bottom: 60px; }
}

/* 플레이어 */
.player {
  position: relative; overflow: hidden; color: #fff; border-radius: 26px;
  background: radial-gradient(120% 80% at 90% -10%, #5a66ff 0%, transparent 55%), linear-gradient(160deg, #2a33d6 0%, #161c78 100%);
  padding: 20px 20px 22px; min-height: 480px; display: flex; flex-direction: column;
  box-shadow: 0 18px 40px rgba(42, 51, 214, .28);
}
.meta { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-weight: 700; }
.phase { padding: 4px 12px; border-radius: 999px; background: rgba(255,255,255,.14); color: var(--accent); }
.counter { opacity: .8; font-variant-numeric: tabular-nums; }

.track { height: 6px; margin: 14px 0 0; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.18); }
.track i { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .3s; }

.steps { display: flex; gap: 6px; list-style: none; margin: 12px 0 0; padding: 0; font-size: 12px; font-weight: 700; }
.steps li { padding: 3px 10px; border-radius: 999px; color: rgba(255,255,255,.5); }
.player[data-step="q"] .steps [data-s="q"],
.player[data-step="t"] .steps [data-s="t"],
.player[data-step="a"] .steps [data-s="a"],
.player[data-step="e"] .steps [data-s="e"] { background: #fff; color: #1d25b8; }

.stage { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 18px; padding: 26px 0 10px; }
.q { margin: 0; font-size: clamp(24px, 6vw, 32px); font-weight: 800; letter-spacing: -0.03em; line-height: 1.3; word-break: keep-all; }
.a {
  margin: 0; padding: 14px 16px; border-radius: 16px; background: rgba(255,255,255,.12);
  font-size: clamp(19px, 4.6vw, 24px); font-weight: 700; color: var(--accent); line-height: 1.4; word-break: keep-all;
}
.a::before { content: "정답"; display: block; margin-bottom: 2px; font-size: 12px; font-weight: 700; color: rgba(255,255,255,.65); }
.cta { padding: 12px 20px; border: 0; border-radius: 14px; background: var(--accent); color: #12142e; font-weight: 800; }
.cta:hover { filter: brightness(1.05); }

.wave { display: flex; align-items: flex-end; gap: 5px; height: 30px; margin-bottom: 14px; }
.wave span { width: 5px; height: 6px; border-radius: 3px; background: rgba(255,255,255,.4); }
.player.playing .wave span { animation: bar 0.9s ease-in-out infinite; background: var(--accent); }
.wave span:nth-child(2) { animation-delay: .15s !important; }
.wave span:nth-child(3) { animation-delay: .3s !important; }
.wave span:nth-child(4) { animation-delay: .05s !important; }
.wave span:nth-child(5) { animation-delay: .4s !important; }
.wave span:nth-child(6) { animation-delay: .2s !important; }
.wave span:nth-child(7) { animation-delay: .35s !important; }
@keyframes bar { 0%,100% { height: 6px; } 50% { height: 28px; } }

.controls { display: flex; align-items: center; justify-content: center; gap: 24px; }
.round {
  width: 54px; height: 54px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.14); color: #fff; display: grid; place-items: center; padding: 0;
  transition: background .15s, transform .1s;
}
.round svg { width: 22px; height: 22px; fill: currentColor; }
.round:hover { background: rgba(255,255,255,.24); }
.round:active { transform: scale(.94); }
.round.big { width: 80px; height: 80px; background: var(--accent); color: #12142e; box-shadow: 0 8px 22px rgba(0,0,0,.25); }
.round.big svg { width: 34px; height: 34px; }
.round.big:hover { background: #fff36a; }
.player :focus-visible { outline-color: #fff; }

.marks { display: flex; gap: 10px; margin-top: 22px; }
.mark {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 10px; border-radius: 16px;
  border: 0; background: rgba(255,255,255,.12); color: #fff; font-weight: 800; text-align: left; transition: background .15s;
}
.mark span { display: grid; line-height: 1.25; }
.mark small { font-size: 11px; font-weight: 500; opacity: .7; }
.mark.wrong:hover { background: var(--danger); }
.mark.known:hover { background: #fff; color: #1d25b8; }

/* 설정 */
.settings { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); padding: 2px 18px; }
.settings summary { display: flex; align-items: center; gap: 10px; padding: 14px 0; font-weight: 700; cursor: pointer; list-style: none; }
.settings summary::-webkit-details-marker { display: none; }
.settings summary::after { content: ""; margin-left: auto; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; }
.settings[open] summary::after { transform: rotate(-135deg); }
.settings .grid { display: grid; gap: 16px; padding: 4px 0 18px; }
.settings label { display: grid; gap: 8px; font-size: 14px; font-weight: 700; }
.settings label.check { display: flex; align-items: center; justify-content: space-between; flex-direction: row-reverse; font-weight: 600; }
.settings select, .settings input[type="number"] { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.settings input[type="range"] { accent-color: var(--brand); }
.settings output { color: var(--brand-text); margin-left: 6px; }
.settings input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none; width: 44px; height: 26px; margin: 0; border-radius: 999px;
  background: var(--line); position: relative; transition: background .2s; cursor: pointer;
}
.settings input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
.settings input[type="checkbox"]:checked { background: var(--brand); }
.settings input[type="checkbox"]:checked::after { transform: translateX(18px); }

/* 만들기 */
.sec-title { margin: 6px 0 4px; font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.sec-sub { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.field { display: grid; gap: 8px; font-weight: 700; }
textarea, .draft input {
  width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow); font-weight: 400; resize: vertical;
}
textarea:focus, .account input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.mic-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.stt-status { margin: 8px 0 0; }
.stt-status.busy::before { content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; border: 2px solid var(--brand); border-right-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.mic svg { width: 18px; height: 18px; }
.mic.on { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.4s ease-in-out infinite; }
.mic:disabled { opacity: .5; cursor: not-allowed; }
.interim { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, .5); } 50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0); } }
.row { display: flex; align-items: center; gap: 14px; margin: 14px 0; flex-wrap: wrap; }
.primary { padding: 13px 22px; border: 0; border-radius: 14px; background: var(--brand); color: #fff; font-weight: 800; box-shadow: 0 6px 16px rgba(58, 69, 240, .3); }
.primary:hover { background: var(--brand-hover); }
.primary:disabled { opacity: .5; cursor: wait; }
.hint { font-size: 13px; color: var(--muted); }

.draft { display: grid; gap: 12px; }
.draft-card { background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 14px; box-shadow: var(--shadow); padding: 14px; display: grid; gap: 10px; }
.draft-card label { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.draft-card textarea { padding: 10px 12px; box-shadow: none; background: var(--bg); }

.link { background: none; border: 0; padding: 4px 0; font-weight: 700; justify-self: start; color: var(--brand-text); }
.link:hover { text-decoration: underline; }
.danger { color: var(--danger); }

/* 관리 */
/* 음성 미리 만들기 진행 표시 */
.warm-status {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0 0 12px; padding: 10px 14px;
  border-radius: 14px; background: var(--brand-soft); color: var(--brand-text); font-size: 14px; font-weight: 700;
}
.warm-status span::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%;
  border: 2px solid var(--brand-text); border-right-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px;
}
.warm-row { margin: 0 0 12px; }
.save-voice { display: grid; gap: 8px; margin: 14px 0 4px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.save-voice > label { font-weight: 700; font-size: 14px; }
.save-voice .hint { margin: 0; }
.item .tags { display: flex; flex-wrap: wrap; gap: 6px; }
.item.editing select[data-k="voice"] { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 400; }

/* 목소리 선택 */
.settings .field-row { display: grid; gap: 8px; }
.settings .field-row > label { font-size: 14px; font-weight: 700; }
.voice-row { display: flex; gap: 8px; }
.voice-row select { flex: 1; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.voice-row .ghost { flex: none; padding: 8px 14px; box-shadow: none; }

/* 만들기 방식 선택 */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 4px 0 12px; }
.seg button {
  display: grid; gap: 2px; justify-items: start; text-align: left; padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); color: var(--ink);
}
.seg button b { font-weight: 800; }
.seg button small { font-size: 12px; color: var(--muted); }
.seg button[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); }
.seg button[aria-checked="true"] b { color: var(--brand-text); }
.opt { font-weight: 500; color: var(--muted); }
.tag { padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-text); font-weight: 700; }
.item .txt { color: var(--ink); font-size: 14.5px; line-height: 1.6; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }

/* 오디오북 재생: 문제/정답 단계 표시와 헷갈림 버튼은 숨기고, 본문을 크게 */
.player[data-kind="note"] .steps, .player[data-kind="note"] .marks { display: none; }
.player[data-kind="note"] .q { font-size: clamp(18px, 4.6vw, 22px); color: var(--accent); }
.player[data-kind="note"] .a {
  background: none; padding: 0; color: #fff; font-weight: 600; font-size: clamp(19px, 4.8vw, 24px); line-height: 1.7;
  max-height: 46vh; overflow-y: auto; width: 100%;
}
.player[data-kind="note"] .a::before { display: none; }

.folder-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.folder-head .sec-title { word-break: keep-all; }
.folder-head .ghost { flex: none; }
.save-target { margin: -6px 0 12px; font-size: 13px; font-weight: 700; color: var(--brand-text); }
.drag-hint { margin: 0 0 12px; }

.cardlist { display: grid; gap: 10px; margin-bottom: 20px; }
.item { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 12px 14px 12px 6px; display: flex; gap: 6px; align-items: stretch; transition: box-shadow .15s, transform .15s; }
.item .body { flex: 1; min-width: 0; display: grid; gap: 4px; align-content: start; }
.item.editing { padding-left: 14px; border-color: var(--brand); }
.item.editing label { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
.item.editing textarea { padding: 10px 12px; box-shadow: none; background: var(--bg); }
.item.editing .row { margin: 6px 0 0; }
.item b { font-weight: 700; }
.item .ans { color: var(--brand-text); font-weight: 700; }
.item .exp { color: var(--muted); font-size: 14px; }
.item .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; font-size: 13px; color: var(--muted); }
.item .acts { display: flex; gap: 14px; }
.item.dragging { box-shadow: 0 14px 34px rgba(18, 20, 46, .28); transform: scale(1.02); border-color: var(--brand); position: relative; z-index: 5; }
.grip {
  flex: none; width: 34px; border: 0; background: none; color: var(--muted); border-radius: 10px;
  display: grid; place-items: center; cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none;
}
.grip svg { width: 20px; height: 20px; fill: currentColor; }
.grip:hover { background: var(--brand-soft); color: var(--brand-text); }
.dragging .grip { cursor: grabbing; }
.badge { padding: 2px 10px; border-radius: 999px; background: var(--danger-soft); color: var(--danger); font-weight: 700; }
.empty { padding: 40px 10px; color: var(--muted); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 20; transform: translate(-50%, 20px);
  max-width: min(90vw, 520px); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 14px;
  font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 640px) { .toast { bottom: 28px; } }

@media (prefers-reduced-motion: reduce) {
  .player.playing .wave span { animation: none; height: 16px; }
  .track i, .toast, .round, .settings summary::after { transition: none; }
  .mic.on, .stt-status.busy::before, .warm-status span::before { animation: none; }
}
