/* 새김 SAEGIM — 디자인 시스템 */
:root {
  --bg: #f6f5f1;
  --bg2: #fffefb;
  --surface: #ffffff;
  --surface-2: #faf8fd;
  --ink: #211d3a;
  --ink2: #514c6e;
  --muted: #938ead;
  --faint: #b9b4cc;
  --line: #ece9f1;
  --line-strong: #ddd8ea;
  --primary: #4f46e5;
  --primary-soft: #eef0fe;
  --primary-ink: #3b2fb8;
  --accent: #f0643a;
  --accent-soft: #fde9e1;
  --amber: #f5a524;
  --again: #e5484d;
  --hard: #f5a524;
  --good: #18a45b;
  --easy: #3b82f6;
  --shadow: 0 8px 30px rgba(33, 29, 58, 0.08);
  --shadow-lg: 0 18px 50px rgba(33, 29, 58, 0.14);
  --radius: 16px;
  --radius-lg: 22px;
  --r-sm: 10px;
}
[data-theme="dark"] {
  --bg: #13111d;
  --bg2: #18142a;
  --surface: #201b35;
  --surface-2: #261f42;
  --ink: #f1eef9;
  --ink2: #c8c2e2;
  --muted: #948db4;
  --faint: #6f6a90;
  --line: #322b52;
  --line-strong: #423a68;
  --primary: #8b84ff;
  --primary-soft: #2c2658;
  --primary-ink: #c9c3ff;
  --accent: #ff7a52;
  --accent-soft: #3a2230;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  background:
    radial-gradient(900px 500px at 90% -10%, var(--primary-soft) 0%, transparent 55%),
    radial-gradient(700px 500px at -10% 110%, var(--accent-soft) 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  letter-spacing: -0.01em;
}
a { color: inherit; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .86em; background: var(--primary-soft); color: var(--primary-ink); padding: 1px 5px; border-radius: 5px; }

/* topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem clamp(.9rem, 4vw, 2.2rem);
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .55rem; background: none; border: none; cursor: pointer; padding: 0; color: var(--ink); }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff; font-size: 1.1rem; box-shadow: 0 6px 16px color-mix(in srgb, var(--primary) 40%, transparent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { font-size: 1.12rem; font-weight: 800; }
.brand-text small { font-size: .58rem; letter-spacing: .28em; color: var(--muted); }
.tabs { display: flex; gap: .25rem; background: var(--surface); border: 1px solid var(--line); padding: 4px; border-radius: 999px; box-shadow: var(--shadow); }
.tab { border: none; background: none; cursor: pointer; font: inherit; color: var(--muted); padding: .5rem 1rem; border-radius: 999px; font-weight: 600; font-size: .92rem; transition: all .2s; }
.tab:hover { color: var(--ink); }
.tab.active { background: var(--primary); color: #fff; box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 35%, transparent); }

/* layout */
main { max-width: 980px; margin: 0 auto; padding: clamp(1rem, 3vw, 2.2rem) clamp(.9rem, 4vw, 2.2rem) 4rem; }
.view { display: none; animation: rise .45s ease both; }
.view.active { display: block; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.site-foot { text-align: center; color: var(--faint); font-size: .82rem; padding: 2rem 1rem 3rem; }

/* hero */
.hero { text-align: center; padding: clamp(1.6rem, 5vw, 3rem) 0 1.4rem; }
.hero-tag { color: var(--accent); font-weight: 700; letter-spacing: -.01em; margin: 0 0 .6rem; font-size: .98rem; }
.hero-title { font-size: clamp(1.8rem, 6vw, 3rem); font-weight: 800; line-height: 1.18; margin: 0; letter-spacing: -.03em; }
.hero-title .accent { background: linear-gradient(120deg, var(--primary), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero-sub { color: var(--ink2); margin: 1rem auto 0; max-width: 34rem; line-height: 1.7; font-size: 1.02rem; }
.hero-actions { display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap; margin-top: 1.6rem; }

/* buttons */
.btn { font: inherit; font-weight: 700; cursor: pointer; border-radius: 999px; padding: .72rem 1.35rem; font-size: .95rem; border: 1px solid transparent; transition: transform .12s, box-shadow .2s, background .2s, color .2s; }
.btn.big { padding: .95rem 1.9rem; font-size: 1.05rem; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 60%, var(--accent))); color: #fff; box-shadow: 0 8px 22px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.ghost { background: var(--surface); color: var(--ink2); border-color: var(--line-strong); }
.btn.ghost:hover { color: var(--ink); border-color: var(--primary); }
.btn.danger-btn { background: var(--surface); color: var(--again); border-color: color-mix(in srgb, var(--again) 40%, var(--surface)); }
.link { background: none; border: none; color: var(--primary); font: inherit; font-weight: 700; cursor: pointer; padding: 0; }
.link:hover { text-decoration: underline; }

/* streak bar */
.streak-bar { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin: 1.6rem 0 2rem; }
.streak-flame, .streak-best, .streak-today {
  display: flex; align-items: baseline; gap: .35rem; padding: .6rem 1.1rem; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); font-size: .95rem; color: var(--ink2);
}
.streak-flame { background: linear-gradient(135deg, var(--accent-soft), var(--surface)); }
.streak-flame b { font-size: 1.3rem; color: var(--accent); font-weight: 800; }
.streak-best b, .streak-today b { color: var(--primary); font-weight: 800; }
small { font-size: .78rem; color: var(--muted); }

/* stat grid */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 2rem; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1rem; box-shadow: var(--shadow); text-align: center; }
.stat-num { font-size: clamp(1.3rem, 4vw, 1.9rem); font-weight: 800; color: var(--ink); letter-spacing: -.02em; }
.stat-lbl { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* heatmap */
.home-bottom { margin-bottom: 2rem; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 .7rem; }
.block-head h3 { font-size: 1rem; font-weight: 700; margin: 0; }
.heatmap-mini, .heatmap-full { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr); gap: 3px; overflow-x: auto; padding-bottom: .3rem; }
.hm-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--line); }
.hm-cell[data-l="1"] { background: color-mix(in srgb, var(--good) 30%, var(--line)); }
.hm-cell[data-l="2"] { background: color-mix(in srgb, var(--good) 55%, var(--line)); }
.hm-cell[data-l="3"] { background: color-mix(in srgb, var(--good) 80%, var(--line)); }
.hm-cell[data-l="4"] { background: var(--good); }
.hm-legend { display: flex; align-items: center; gap: 4px; font-size: .76rem; color: var(--muted); margin-top: .5rem; }
.hm-legend span { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.hm-legend .hm-l0 { background: var(--line); }
.hm-legend .hm-l1 { background: color-mix(in srgb, var(--good) 30%, var(--line)); }
.hm-legend .hm-l2 { background: color-mix(in srgb, var(--good) 55%, var(--line)); }
.hm-legend .hm-l3 { background: color-mix(in srgb, var(--good) 80%, var(--line)); }
.hm-legend .hm-l4 { background: var(--good); }

/* empty hint */
.empty-hint { background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius-lg); padding: 2rem 1.5rem; text-align: center; box-shadow: var(--shadow); }
.empty-hint .eh-icon { font-size: 2.4rem; }
.empty-hint h3 { margin: .5rem 0 .3rem; }
.empty-hint p { color: var(--ink2); margin: 0 auto 1.2rem; max-width: 26rem; }
.eh-actions { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* features */
.features { margin-top: 2.6rem; }
.features-title { font-size: 1.2rem; font-weight: 800; margin: 0 0 1rem; }
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; }
.feature { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); transition: transform .15s, box-shadow .2s; }
.feature:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.feature .fi { font-size: 1.5rem; }
.feature h4 { margin: .5rem 0 .35rem; font-size: 1rem; }
.feature p { color: var(--ink2); font-size: .9rem; line-height: 1.7; margin: 0; }

/* view heads */
.view-head { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.view-head h2 { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: -.02em; }
.view-actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }
.back { font: inherit; font-weight: 700; cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink2); border-radius: 999px; padding: .4rem .9rem; font-size: .88rem; }
.back:hover { color: var(--ink); border-color: var(--primary); }
.deck-title-wrap { display: flex; align-items: center; gap: .6rem; }
.exam-badge { font-size: .72rem; font-weight: 700; padding: .25rem .6rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary-ink); }

/* deck grid */
.deck-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.deck-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); cursor: pointer; position: relative; overflow: hidden; transition: transform .15s, box-shadow .2s; }
.deck-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.deck-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--primary); }
.deck-card.t-blue::before { background: #3b82f6; }
.deck-card.t-slate::before { background: #64748b; }
.deck-card.t-teal::before { background: #14b8a6; }
.deck-card.t-violet::before { background: #8b5cf6; }
.deck-card.t-indigo::before { background: var(--primary); }
.deck-card h3 { margin: 0 0 .5rem; font-size: 1.1rem; }
.deck-meta { display: flex; gap: .8rem; color: var(--muted); font-size: .84rem; }
.deck-meta b { color: var(--ink2); }
.deck-due { color: var(--accent); font-weight: 700; }
.deck-actions-mini { position: absolute; top: .6rem; right: .5rem; display: flex; gap: .2rem; opacity: 0; transition: opacity .15s; }
.deck-card:hover .deck-actions-mini,
.deck-card:focus-within .deck-actions-mini { opacity: 1; }
.icon-btn { border: none; background: var(--surface-2); color: var(--muted); cursor: pointer; width: 36px; height: 36px; border-radius: 8px; font-size: .95rem; display: grid; place-items: center; }
.icon-btn:hover { color: var(--again); background: var(--accent-soft); }
.new-deck-card { border: 2px dashed var(--line-strong); background: transparent; box-shadow: none; display: grid; place-items: center; color: var(--muted); font-weight: 700; min-height: 120px; }

/* deck detail */
.deck-detail-actions { display: flex; gap: .6rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.card-list { display: flex; flex-direction: column; gap: .6rem; }
.card-row { display: flex; align-items: center; gap: .8rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm); padding: .8rem 1rem; box-shadow: var(--shadow); }
.card-row .cr-front { font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-row .cr-back { color: var(--muted); font-size: .86rem; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-row .cr-due { font-size: .74rem; padding: .15rem .5rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary-ink); white-space: nowrap; }
.card-row .cr-due.over { background: var(--accent-soft); color: var(--accent); }
.card-row .cr-due.new { background: var(--surface-2); color: var(--muted); }

/* review */
.review-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.review-prog { font-weight: 700; color: var(--ink2); font-size: 1.1rem; }
.review-stage { display: flex; flex-direction: column; align-items: center; gap: 1rem; }
.flip-card { width: min(440px, 92vw); height: 300px; perspective: 1400px; cursor: pointer; }
.flip-inner { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.2,.7,.2,1); }
.flip-card.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; border-radius: var(--radius-lg); padding: 2rem 1.6rem; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; box-shadow: var(--shadow-lg); border: 1px solid var(--line); }
.flip-face.front { background: linear-gradient(160deg, var(--surface), var(--surface-2)); color: var(--ink); }
.flip-face.back { transform: rotateY(180deg); background: linear-gradient(160deg, var(--primary-soft), var(--surface)); color: var(--ink); border-color: color-mix(in srgb, var(--primary) 25%, var(--line)); }
.flip-face .fc-type { position: absolute; top: .9rem; left: 1rem; font-size: .68rem; font-weight: 700; letter-spacing: .04em; color: var(--primary); background: var(--primary-soft); padding: .2rem .55rem; border-radius: 999px; }
.flip-face .fc-q { font-size: clamp(1.5rem, 6vw, 2.1rem); font-weight: 800; line-height: 1.3; letter-spacing: -.02em; word-break: keep-all; }
.flip-face .fc-a { font-size: clamp(1.3rem, 5vw, 1.8rem); font-weight: 800; color: var(--primary-ink); line-height: 1.4; }
.flip-face .fc-extra { margin-top: .8rem; color: var(--ink2); font-size: .92rem; line-height: 1.6; max-width: 22rem; }
.flip-face .fc-blank { display: inline-block; min-width: 4.5rem; border-bottom: 3px solid var(--accent); color: transparent; }
.flip-card.flipped .fc-blank { color: var(--accent); }
.review-hint { color: var(--muted); font-size: .9rem; }
.rate-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; width: min(440px, 92vw); }
.rate { font: inherit; cursor: pointer; border: none; border-radius: var(--r-sm); padding: .8rem .4rem; color: #fff; font-weight: 700; display: flex; flex-direction: column; gap: .15rem; align-items: center; transition: transform .1s, filter .2s; }
.rate b { font-size: 1rem; }
.rate small { color: rgba(255,255,255,.8); font-size: .72rem; }
.rate:hover { transform: translateY(-2px); filter: brightness(1.08); }
.rate:disabled { opacity: .45; cursor: default; transform: none; }
.rate.again { background: var(--again); }
.rate.hard { background: var(--hard); }
.rate.good { background: var(--good); }
.rate.easy { background: var(--easy); }
.rate-next { font-size: .8rem; color: var(--muted); min-height: 1.1em; text-align: center; }

/* review done */
.review-done { text-align: center; padding: 2rem 1rem; position: relative; }
.rd-emoji { font-size: 3rem; }
.review-done h2 { margin: .5rem 0 .3rem; }
.review-done p { color: var(--ink2); margin: 0 0 1.4rem; }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti span { position: absolute; top: -10px; width: 8px; height: 12px; opacity: 0; animation: fall 2.4s ease-in forwards; }
@keyframes fall { 0% { opacity: 1; transform: translateY(-20px) rotate(0); } 100% { opacity: 0; transform: translateY(360px) rotate(540deg); } }

/* editor */
.editor-form { max-width: 36rem; margin: 0 auto; display: flex; flex-direction: column; gap: 1.1rem; }
.field { display: flex; flex-direction: column; gap: .4rem; }
.field label, .field > label { font-weight: 700; font-size: .9rem; color: var(--ink2); }
.input { font: inherit; width: 100%; background: var(--surface); border: 1px solid var(--line-strong); color: var(--ink); border-radius: var(--r-sm); padding: .8rem .95rem; outline: none; transition: border-color .2s, box-shadow .2s; font-size: 1rem; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { resize: vertical; min-height: 90px; line-height: 1.6; }
[contenteditable].input { white-space: pre-wrap; min-height: 90px; line-height: 1.6; }
[contenteditable].input:empty::before { content: attr(data-ph); color: var(--faint); }
.chip-group { display: flex; gap: .45rem; flex-wrap: wrap; }
.chip { font: inherit; cursor: pointer; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink2); border-radius: 999px; padding: .45rem .95rem; font-size: .9rem; font-weight: 600; transition: all .15s; }
.chip:hover { border-color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.cloze-helper { background: var(--primary-soft); border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--line)); border-radius: var(--r-sm); padding: .9rem 1rem; display: flex; flex-direction: column; gap: .6rem; }
.cloze-helper[hidden] { display: none; }
.ch-tip { margin: 0; font-size: .86rem; color: var(--ink2); line-height: 1.6; }
.editor-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* settings */
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: .8rem; flex-wrap: wrap; }
.setting-row b { display: block; font-size: 1rem; }
.setting-row p { margin: .15rem 0 0; color: var(--muted); font-size: .86rem; }
.setting-row.danger { border-color: color-mix(in srgb, var(--again) 30%, var(--line)); }
.slider-wrap { display: flex; align-items: center; gap: .7rem; }
.slider-wrap input[type="range"] { accent-color: var(--primary); width: 140px; }
.settings-foot { color: var(--faint); font-size: .82rem; text-align: center; margin-top: 1.5rem; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%) translateY(20px); z-index: 50; background: var(--ink); color: var(--bg2); padding: .7rem 1.2rem; border-radius: 999px; font-size: .9rem; font-weight: 600; opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; box-shadow: var(--shadow-lg); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* responsive */
@media (max-width: 640px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .tabs .tab { padding: .45rem .75rem; font-size: .86rem; }
  .brand-text small { display: none; }
  .rate b { font-size: .9rem; }
  .deck-grid { grid-template-columns: 1fr; }
}

/* i18n language switcher — 새김은 라이트 테마가 기본이므로 런타임 중립 기본값을
   밝은 톤으로 덮어쓴다(헤더 충돌 회피: 스위처는 topbar 안 data-i18n-switcher 자리). */
.topbar .i18n-switch {
  --i18n-switch-bg: var(--surface);
  --i18n-switch-border: var(--line-strong);
  --i18n-switch-fg: var(--ink2);
  --i18n-switch-active-bg: var(--primary-soft);
  --i18n-switch-active-fg: var(--primary-ink);
  --i18n-switch-menu-bg: var(--surface);
  --i18n-switch-menu-border: var(--line-strong);
  --i18n-switch-shadow: var(--shadow);
}
[data-theme="dark"] .topbar .i18n-switch {
  --i18n-switch-bg: var(--surface-2);
  --i18n-switch-fg: var(--ink2);
}
