:root {
  --bg: #14110e;
  --bg-elev: #1c1814;
  --bg-card: #26211b;
  --bg-card-2: #2e2821;
  --ink: #f4ebe0;
  --ink-soft: #cbbba6;
  --ink-mute: #8d7f6e;
  --line: rgba(244, 235, 224, 0.09);
  --amber: #e0a14a;
  --amber-2: #c4842a;
  --amber-ink: #1a140c;
  --amber-dim: rgba(224, 161, 74, 0.16);
  --again: #d4654f;
  --hard: #d4923a;
  --good: #3f9a74;
  --easy: #4a82c8;
  --upgrade: #e0a14a;
  --correction: #d4654f;
  --phrase: #3f9a74;
  --pronunciation: #4a82c8;
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  --radius: 22px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: calc(64px + env(safe-area-inset-bottom, 0px));
  --font: "Apple SD Gothic Neo", "Noto Sans KR", "Noto Sans CJK KR",
    "Malgun Gothic", ui-sans-serif, system-ui, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Songti TC",
    "Noto Serif CJK KR", Georgia, serif;
}

[data-theme="light"] {
  --bg: #f3eee6;
  --bg-elev: #fffaf2;
  --bg-card: #fffdf8;
  --bg-card-2: #f7f1e7;
  --ink: #2a2218;
  --ink-soft: #5c5146;
  --ink-mute: #8a7d6d;
  --line: rgba(42, 34, 24, 0.08);
  --amber: #c4842a;
  --amber-2: #a86c18;
  --amber-ink: #fff8ec;
  --amber-dim: rgba(196, 132, 42, 0.12);
  --shadow: 0 14px 36px rgba(80, 56, 24, 0.1);
}

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

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  text-size-adjust: 100%;
}

body {
  background:
    radial-gradient(1100px 520px at 50% -12%, rgba(224, 161, 74, 0.16), transparent 55%),
    radial-gradient(700px 380px at 110% 110%, rgba(63, 154, 116, 0.08), transparent 50%),
    var(--bg);
}

button, input, textarea { font: inherit; color: inherit; }

button {
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(12px + var(--safe-t)) 20px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
}

.brand { min-width: 0; }
.brand-row { display: flex; align-items: center; gap: 10px; }

.mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(160deg, #f0c27a, #c4842a);
  color: #1a140c;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 700;
  font-size: 20px;
  box-shadow: 0 6px 16px rgba(196, 132, 42, 0.28);
  flex: none;
}

.logo {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 650;
  font-size: 28px;
  letter-spacing: -0.03em;
  line-height: 1;
}

.subtitle {
  margin-top: 3px;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--ink-soft);
  background: var(--bg-card);
  border: 1px solid var(--line);
}

.icon-btn:active { transform: scale(0.96); }

.top-actions { display: flex; gap: 8px; }

.main {
  flex: 1;
  padding: 8px 20px calc(var(--tab-h) + 16px);
}

.main.review-mode { padding-bottom: 24px; }

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  height: var(--tab-h);
  padding: 8px 18px var(--safe-b);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  z-index: 6;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--ink-mute);
  min-height: 48px;
  border-radius: 12px;
}

.tab svg { width: 22px; height: 22px; }
.tab span { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--amber); }

.hello {
  color: var(--ink-soft);
  font-size: 15px;
  margin: 4px 0 14px;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 10px 0 18px;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px 16px;
  min-height: 108px;
}

.stat-label {
  font-size: 13px;
  color: var(--ink-mute);
  font-weight: 600;
}

.stat-num {
  display: block;
  margin-top: 8px;
  font-family: var(--serif);
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-num.due { color: var(--amber); }
.stat-num.new { color: var(--ink); }

.study-btn {
  width: 100%;
  min-height: 58px;
  border-radius: 18px;
  background: linear-gradient(180deg, #ebbc6a, #c4842a);
  color: var(--amber-ink);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
  box-shadow: 0 10px 28px rgba(196, 132, 42, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.study-btn:active { transform: translateY(1px) scale(0.99); }
.study-btn:disabled {
  opacity: 0.45;
  box-shadow: none;
  cursor: default;
}

.meta-row {
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--ink-soft);
  font-size: 14px;
}

.chip-line strong { color: var(--ink); font-weight: 700; }

.install {
  margin-top: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--amber-dim);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
}

.install b { color: var(--ink); }

.done-card {
  margin-top: 8px;
  padding: 28px 20px;
  text-align: center;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 24px;
}

.done-card h2 {
  font-family: var(--serif);
  font-style: italic;
  font-size: 28px;
  margin: 8px 0 6px;
}

.done-card p { color: var(--ink-soft); font-size: 14px; }

.progress-wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.progress-track {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #ebbc6a, #c4842a);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.progress-count {
  font-size: 13px;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}

.study-card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 26px;
  min-height: 280px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}

.card-kicker {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--ink-mute);
  font-weight: 700;
  text-transform: uppercase;
}

.card-front, .card-back {
  font-size: clamp(20px, 5.4vw, 26px);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.35;
  word-break: keep-all;
}

.card-back { color: var(--amber); }

.card-extra {
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 14px;
  line-height: 1.55;
}

.reveal-btn {
  margin-top: auto;
  min-height: 52px;
  border-radius: 16px;
  background: var(--bg-card-2);
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 700;
}

.reveal-btn:active { transform: scale(0.99); }

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.grade {
  min-height: 72px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

.grade small {
  font-weight: 600;
  font-size: 11px;
  opacity: 0.85;
}

.grade.again { background: #b24d3b; }
.grade.hard { background: #b47a24; }
.grade.good { background: #2f7d5d; }
.grade.easy { background: #3b6eae; }
.grade:active { transform: scale(0.97); }

.search {
  width: 100%;
  min-height: 48px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  padding: 0 16px;
  outline: none;
}

.search:focus { border-color: color-mix(in srgb, var(--amber) 50%, var(--line)); }

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 4px;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }

.filter {
  flex: none;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 650;
}

.filter.active {
  background: var(--amber-dim);
  color: var(--ink);
  border-color: transparent;
}

.list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }

.row {
  text-align: left;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px 12px;
}

.row-front {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
}

.row-back {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 14px;
}

.row-meta {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg-card-2);
  color: var(--ink-mute);
}

.tag.upgrade { color: var(--upgrade); background: color-mix(in srgb, var(--upgrade) 14%, transparent); }
.tag.correction { color: var(--correction); background: color-mix(in srgb, var(--correction) 14%, transparent); }
.tag.phrase { color: var(--phrase); background: color-mix(in srgb, var(--phrase) 14%, transparent); }
.tag.pronunciation { color: var(--pronunciation); background: color-mix(in srgb, var(--pronunciation) 14%, transparent); }
.tag.user { color: var(--amber); }

.row.open .row-extra {
  display: block;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.5;
}

.row-extra { display: none; }

.row-actions { margin-top: 10px; }

.danger {
  color: var(--again);
  font-size: 13px;
  font-weight: 700;
  min-height: 36px;
}

.form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--ink-mute); font-weight: 700; }

.field, .area {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--bg-card);
  padding: 14px 16px;
  outline: none;
}

.area { min-height: 96px; resize: vertical; }

.save-btn {
  min-height: 54px;
  border-radius: 16px;
  background: linear-gradient(180deg, #ebbc6a, #c4842a);
  color: var(--amber-ink);
  font-weight: 800;
}

.empty {
  text-align: center;
  color: var(--ink-mute);
  padding: 36px 10px;
  font-size: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + 12px);
  transform: translateX(-50%) translateY(12px);
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 20;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.settings {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.settings button {
  color: var(--ink-mute);
  font-size: 13px;
  min-height: 40px;
}

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (min-width: 720px) {
  body { padding: 24px 0; }
  .app {
    min-height: calc(100dvh - 48px);
    border: 1px solid var(--line);
    border-radius: 28px;
    overflow: hidden;
    background: color-mix(in srgb, var(--bg) 92%, #000);
    box-shadow: var(--shadow);
  }
  .tabbar { width: 480px; border-radius: 0 0 28px 28px; }
}

::selection { background: rgba(224, 161, 74, 0.35); }

html { overscroll-behavior-y: none; }

.card-front, .card-back { overflow-wrap: anywhere; }

.study-card {
  overflow: auto;
  max-height: calc(100dvh - 260px);
  -webkit-overflow-scrolling: touch;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

.notify-btn {
  width: 100%;
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--amber-dim);
  color: var(--amber);
  font-weight: 650;
}

html, body { overscroll-behavior-y: contain; }

.ptr {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translate(-50%, -140%);
  z-index: 20;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--ink-soft);
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: color 0.15s ease, opacity 0.15s ease;
}
.ptr.show {
  opacity: 1;
  visibility: visible;
}
.ptr.ready { color: var(--amber); }
.ptr.spin { color: var(--amber); }
