:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --ink: #1c2033;
  --muted: #646b85;
  --line: #e3e6f0;
  --brand: #4f46e5;
  --brand-ink: #ffffff;
  --brand-soft: #eef0ff;
  --green: #15803d;
  --green-soft: #e7f7ec;
  --yellow: #a16207;
  --yellow-soft: #fdf6dd;
  --red: #dc2626;
  --red-soft: #fdecec;
  --none-soft: #eef0f4;
  --shadow: 0 1px 2px rgba(20, 24, 50, .05), 0 6px 20px rgba(20, 24, 50, .06);
  --radius: 16px;
  --top-h: 56px;
  --tab-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11131c;
    --card: #1a1d2a;
    --ink: #e8eaf3;
    --muted: #9aa1bb;
    --line: #2b2f42;
    --brand: #818cf8;
    --brand-ink: #11131c;
    --brand-soft: #23264a;
    --green: #4ade80;
    --green-soft: #15301f;
    --yellow: #facc15;
    --yellow-soft: #342c10;
    --red: #f87171;
    --red-soft: #3a1919;
    --none-soft: #252838;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  word-break: keep-all;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
button, a, summary, label { touch-action: manipulation; }
button { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ── 상단 ── */
.top {
  position: sticky; top: 0; z-index: 20; height: var(--top-h);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px; padding-top: env(safe-area-inset-top, 0px); box-sizing: content-box;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 700; }
.logo-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: var(--brand-ink); font-size: 17px; }
.logo-text small { color: var(--muted); font-weight: 500; margin-left: 2px; }
.nav { display: flex; gap: 4px; }
.nav a { padding: 8px 14px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: .95rem; }
.nav a.on { background: var(--brand-soft); color: var(--brand); }
.tabbar { display: none; }

.app { max-width: 880px; margin: 0 auto; padding: 20px 16px 40px; min-height: 70vh; }
.foot { max-width: 880px; margin: 0 auto; padding: 8px 16px 40px; font-size: .8rem; color: var(--muted); }

/* ── 카드·버튼 ── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 14px; }
.card.tight { padding: 14px 16px; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid + .card, .stats + .card { margin-top: 14px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.nowrap { flex-wrap: nowrap; }
.stack { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; margin-top: 10px; }
.two-btn { margin-top: 16px; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.spread.nowrap { flex-wrap: nowrap; }
.spread.line { padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: nowrap; }
.spread.line:last-of-type { border-bottom: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px;
  padding: 10px 18px; border-radius: 12px; border: 1px solid transparent;
  background: var(--brand); color: var(--brand-ink); font-weight: 700; cursor: pointer;
  transition: transform .05s ease, filter .15s ease; text-align: center; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
@media (hover: hover) { .btn:hover { filter: brightness(1.06); } }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.small { min-height: 38px; padding: 7px 13px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.big-btn { min-height: 52px; font-size: 1.02rem; margin-top: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 7px 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); cursor: pointer; font-size: .92rem; font-weight: 600; color: var(--ink);
}
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .76rem; font-weight: 700; vertical-align: 2px; white-space: nowrap; }
.lv-green { background: var(--green-soft); color: var(--green); }
.lv-yellow { background: var(--yellow-soft); color: var(--yellow); }
.lv-red { background: var(--red-soft); color: var(--red); }
.lv-none { background: var(--none-soft); color: var(--muted); }
.lv-text-green { color: var(--green) !important; } .lv-text-yellow { color: var(--yellow) !important; } .lv-text-red { color: var(--red) !important; }
.kicker { font-size: .82rem; font-weight: 700; color: var(--brand); margin-bottom: 4px; }
.kicker.back { display: inline-flex; align-items: center; min-height: 40px; margin: -8px 0 -4px; font-size: .92rem; }
.note { font-size: .86rem; color: var(--muted); }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.empty { text-align: center; padding: 26px 10px; color: var(--muted); }

.hero { background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%); color: #fff; border: none; }
.hero .kicker { color: rgba(255,255,255,.9); }
.hero .muted, .hero small { color: rgba(255,255,255,.88); }
.hero .btn { background: #fff; color: #3730a3; }
.dday { font-size: 2rem; font-weight: 800; line-height: 1; white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stats.three { grid-template-columns: repeat(3, 1fr); }
.stats .card { margin: 0; }
.stat { text-align: center; padding: 14px 6px; }
.stat .num { font-size: 1.6rem; font-weight: 800; line-height: 1.15; }
.stat .num small { font-size: .9rem; font-weight: 700; margin-left: 1px; color: inherit; }
.stat > small { display: block; margin-top: 4px; font-size: .8rem; }

.task { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; }
.task + .task { border-top: 1px solid var(--line); }
.task b { display: block; }
.task small { display: block; font-size: .82rem; margin-top: 2px; }
.link-card { color: inherit; }
.link-card p { margin: 4px 0 0; }

/* ── 폼 ── */
label.field, div.field { display: block; margin-bottom: 20px; }
.field > span { display: block; font-weight: 700; margin-bottom: 8px; }
.field > span small { font-weight: 500; margin-left: 4px; }
input[type=text], textarea, select {
  width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; /* 16px 미만이면 iOS가 확대함 */
}
select { width: auto; padding: 8px 12px; min-height: 40px; }
textarea { resize: none; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.opt-grid.five { grid-template-columns: repeat(5, 1fr); }
.opt-grid.four { grid-template-columns: repeat(4, 1fr); }
.opt-grid.three { grid-template-columns: repeat(3, 1fr); }
.opt {
  min-height: 48px; padding: 9px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  cursor: pointer; text-align: center; font-weight: 600; font-size: .95rem; line-height: 1.35;
}
.opt small { display: block; font-weight: 500; font-size: .76rem; margin-top: 2px; }
.opt.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }

/* ── 문제 ── */
.src { font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.problem .q { font-size: 1.05rem; line-height: 1.8; margin-bottom: 16px; overflow-x: auto; }
.choices { display: grid; gap: 8px; }
.choice {
  display: flex; gap: 12px; align-items: center; text-align: left; min-height: 52px; width: 100%;
  padding: 10px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer;
}
.choice .no { flex: none; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--none-soft); font-weight: 700; font-size: .85rem; }
.choice .ct { min-width: 0; overflow-x: auto; }
.choice.sel { border-color: var(--brand); background: var(--brand-soft); }
.choice.sel .no { background: var(--brand); color: var(--brand-ink); }
.choice.right { border-color: var(--green); background: var(--green-soft); }
.choice.wrong { border-color: var(--red); background: var(--red-soft); }
.choice:disabled { cursor: default; color: inherit; }
.result { margin-top: 14px; padding: 14px 16px; border-radius: 12px; font-weight: 600; }
.result.ok { background: var(--green-soft); color: var(--green); }
.result.no { background: var(--red-soft); color: var(--red); }
.result-sub { font-weight: 500; margin-top: 6px; color: var(--ink); }
.result-sub p:last-child { margin: 0; }
.sol { margin-top: 12px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); }
.sol summary { padding: 14px 16px; font-weight: 700; cursor: pointer; }
.sol-body { padding: 0 16px 14px; line-height: 1.8; overflow-x: auto; }
.progress { height: 8px; border-radius: 99px; background: var(--none-soft); overflow: hidden; margin: 8px 0 16px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s; }
.check-unsure { display: flex; align-items: center; gap: 8px; min-height: 44px; margin-top: 6px; font-size: .92rem; color: var(--muted); cursor: pointer; }
.check-unsure input { width: 20px; height: 20px; accent-color: var(--brand); }
.cause-card { background: var(--brand-soft); box-shadow: none; border-color: transparent; }

/* ── 개념 지도 ── */
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.map-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.node { display: block; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.node b { display: block; font-size: .95rem; line-height: 1.4; }
.node-meta { display: flex; justify-content: space-between; gap: 8px; font-size: .78rem; margin-top: 2px; }
.node.lv-green { border-color: color-mix(in srgb, var(--green) 40%, var(--line)); }
.node.lv-yellow { border-color: color-mix(in srgb, var(--yellow) 45%, var(--line)); }
.node.lv-red { border-color: color-mix(in srgb, var(--red) 45%, var(--line)); }
.node.lv-green, .node.lv-yellow, .node.lv-red, .node.lv-none { background: var(--card); color: var(--ink); }
.bar { display: block; height: 6px; background: var(--none-soft); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; }

/* ── 개념 카드 ── */
.concept-card .core { font-size: 1.02rem; line-height: 1.8; }
.box { padding: 12px 14px; border-radius: 12px; margin-bottom: 10px; line-height: 1.75; }
.box.trap { background: var(--red-soft); }
.box.analogy { background: var(--yellow-soft); }
.box.root { background: var(--brand-soft); }
.box b { display: block; font-size: .8rem; margin-bottom: 2px; }
.mode-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.mode { padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; text-align: left; min-height: 64px; }
.mode b { display: block; }
.mode small { font-size: .8rem; line-height: 1.4; display: block; margin-top: 2px; }

/* ── AI 쌤 대화 ── */
.tutor-head { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top, 0px)); z-index: 5; background: var(--bg); margin: -8px -16px 0; padding: 8px 16px 6px; border-bottom: 1px solid var(--line); }
.modes-scroll { display: flex; gap: 6px; overflow-x: auto; padding: 6px 0 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity; }
.modes-scroll::-webkit-scrollbar { display: none; }
.modes-scroll .chip { flex: none; scroll-snap-align: start; }
.chat { display: flex; flex-direction: column; gap: 12px; margin: 14px 0 16px; }
.msg { max-width: 92%; padding: 13px 16px; border-radius: 18px; line-height: 1.75; scroll-margin-top: calc(var(--top-h) + 110px); scroll-margin-bottom: 90px; }
.msg.me { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.ai .meta { font-size: .76rem; font-weight: 700; color: var(--brand); margin-bottom: 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 0 0 .8em; padding-left: 1.3em; }
.msg li + li { margin-top: 4px; }
.msg .katex-display { margin: .5em 0; }
.msg .actions { margin-top: 14px; display: flex; gap: 6px; flex-wrap: wrap; }
.typing { color: var(--muted); font-size: .92rem; }
.typing i { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.mini-quiz { margin-top: 14px; padding: 12px; border-radius: 14px; background: var(--bg); }
.mq-q { margin: 4px 0 10px; }
.mini-quiz .choice { min-height: 46px; padding: 8px 12px; }
.composer {
  position: sticky; bottom: 0; z-index: 6; display: flex; gap: 8px; align-items: flex-end;
  background: var(--bg); margin: 0 -16px; padding: 10px 16px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line);
}
.composer textarea { min-height: 46px; max-height: 140px; line-height: 1.45; padding: 11px 14px; }
.composer .btn { flex: none; min-height: 46px; }

/* ── 위기 배너 ── */
.crisis {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + var(--safe-b) + 12px); z-index: 50; max-width: 560px; margin: 0 auto;
  background: var(--card); border: 2px solid var(--red); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.crisis a { font-weight: 800; }

.katex { font-size: 1.04em; }
.katex-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 휴대폰 ── */
@media (max-width: 680px) {
  :root { --top-h: 52px; }
  .nav { display: none; }
  .top { padding-left: 16px; padding-right: 16px; }
  .logo-text small { display: none; }
  .app { padding: 14px 14px 24px; }
  .foot { padding: 4px 16px calc(var(--tab-h) + var(--safe-b) + 20px); }
  .card { padding: 18px 16px; border-radius: 14px; }
  h1 { font-size: 1.32rem; }
  h2 { font-size: 1.12rem; }
  .dday { font-size: 1.65rem; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; height: calc(var(--tab-h) + var(--safe-b));
    background: color-mix(in srgb, var(--card) 94%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
  }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: .72rem; color: var(--muted); font-weight: 600; }
  .tabbar a span { font-size: 1.2rem; line-height: 1.3; }
  .tabbar a.on { color: var(--brand); }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stats.three { grid-template-columns: repeat(3, 1fr); }
  .stat { padding: 12px 4px; }
  .stat .num { font-size: 1.4rem; }
  .task { flex-direction: column; align-items: stretch; gap: 8px; }
  .task .row .btn { flex: 1; }
  .stack { grid-template-columns: 1fr; }
  .two-btn .btn { flex: 1 1 100%; }
  .map-list { grid-template-columns: 1fr 1fr; }
  .node { padding: 11px 12px; }
  .node b { font-size: .9rem; }
  .node-meta { flex-direction: column; gap: 0; }
  .mode-grid { grid-template-columns: 1fr 1fr; }
  .opt-grid.three { grid-template-columns: 1fr; }
  .opt-grid.three .opt { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; text-align: left; }
  .opt-grid.three .opt small { margin: 0; }
  .opt-grid.five .opt { font-size: .88rem; padding: 8px 2px; }
  .msg { max-width: 96%; }
  .tutor-head { margin: -14px -14px 0; padding: 8px 14px 6px; }
  .composer { margin: 0 -14px; padding: 8px 14px calc(8px + var(--safe-b)); }
  .chip { font-size: .9rem; }
  .crisis { bottom: calc(var(--tab-h) + var(--safe-b) + 10px); }

  /* 대화 화면에서는 하단 탭과 푸터를 숨겨 입력창이 키보드 바로 위에 붙게 한다 */
  body.chatting .tabbar, body.chatting .foot { display: none; }
  body.chatting .crisis { bottom: 90px; }
}
@media (max-width: 360px) {
  .map-list, .mode-grid { grid-template-columns: 1fr; }
  .opt-grid.five { grid-template-columns: repeat(5, 1fr); gap: 5px; }
}
body.chatting .foot { display: none; }
.stat .num-sub { font-size: 1rem; font-weight: 700; color: var(--muted); }

/* 짧은 선택지는 수능 시험지처럼 한 줄에 다섯 개 */
.choices.compact { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.choices.compact .choice { flex-direction: column; justify-content: center; gap: 4px; min-height: 76px; padding: 8px 2px; text-align: center; }
.choices.compact .choice .no { width: 24px; height: 24px; font-size: .78rem; }
.choices.compact .choice .ct { max-width: 100%; }
.mini-quiz .choices.compact .choice { min-height: 68px; }

/* 나만의 쌤의 약속 */
.promises { display: grid; gap: 10px; margin-top: 14px; }
.promise { display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 14px; background: rgba(255, 255, 255, .14); }
.promise .p-icon { flex: none; font-size: 1.5rem; line-height: 1.2; }
.promise b { display: block; font-size: 1.02rem; margin-bottom: 2px; }
.promise p { margin: 0; font-size: .92rem; line-height: 1.6; color: rgba(255, 255, 255, .92); }
.promises.compact { margin-top: 6px; gap: 6px; }
.card:not(.hero) .promise { background: var(--brand-soft); padding: 10px 12px; align-items: center; }
.card:not(.hero) .promise b { margin: 0; font-size: .95rem; }
@media (min-width: 681px) { .hero .promises { grid-template-columns: repeat(3, 1fr); } .hero .promise { flex-direction: column; } }
.tutor-promise { margin: 12px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--brand-soft); color: var(--brand); font-size: .88rem; font-weight: 600; text-align: center; }

/* 새로 나타난 버튼이 상단바·하단 탭에 가리지 않게 */
.btn, .result, .cause-card, .stack { scroll-margin-top: calc(var(--top-h) + 16px); scroll-margin-bottom: calc(var(--tab-h) + var(--safe-b) + 16px); }

/* 요금제 */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-top: 14px; }
.plans .card { margin: 0; display: flex; flex-direction: column; position: relative; }
.plan.best { border: 2px solid var(--brand); }
.plan-badge { position: absolute; top: -11px; left: 16px; background: var(--brand); color: var(--brand-ink); }
.price { margin: 12px 0 8px; }
.price b { font-size: 1.5rem; font-weight: 800; }
.feat { margin: 0 0 16px; padding-left: 1.1em; flex: 1; font-size: .92rem; line-height: 1.6; }
.feat li + li { margin-top: 4px; }
@media (max-width: 680px) { .plans { grid-template-columns: 1fr; } }

/* 로그인 */
.otp { font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums; }
.auth-msg { min-height: 1.4em; margin: 12px 0 0; font-weight: 600; color: var(--green); }
.auth-msg.bad { color: var(--red); }
.returning { display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--ink); padding: 14px 16px; }
.returning b { color: var(--brand); }
.returning span[aria-hidden] { font-size: 1.4rem; color: var(--muted); }
.account b { display: block; }

/* 로그인·이용권 안내 */
.gate { margin-top: 14px; padding: 14px 16px; border-radius: 14px; background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 30%, var(--line)); }
.gate b { display: block; color: var(--brand); margin-bottom: 4px; }
.gate p { margin: 0 0 10px; font-size: .92rem; line-height: 1.6; color: var(--ink); }
