:root {
  --bg: #11141a; --surface: #1b1f27; --surface-2: #252a35; --line: #313848;
  --text: #eef1f6; --muted: #9aa3b5; --accent: #6ea8ff; --accent-text: #0b1530;
  --good: #3ecf8e; --bad: #ff6b6b; --warn: #ffc857;
  --radius: 14px; --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6fa; --surface: #ffffff; --surface-2: #eceff5; --line: #d6dbe5;
    --text: #151922; --muted: #5d6677; --accent: #2f6fe0; --accent-text: #ffffff;
    --good: #138a55; --bad: #d63b3b; --warn: #a86b00;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.5 system-ui, -apple-system, "Noto Sans KR", "Malgun Gothic", sans-serif;
  overscroll-behavior: contain;   /* 당겨서 새로고침 방지 */
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 560px; margin: 0 auto; padding: 0 16px calc(var(--tab-h) + var(--safe-b) + 16px); }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 18px 0 10px; }
.card h2 { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
[hidden] { display: none !important; }

.page-head { padding: 20px 0 12px; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 12px 0; background: var(--bg); }
.bar h1 { flex: 1; font-size: 1.15rem; }
.icon-btn { min-width: 48px; min-height: 48px; border: 0; border-radius: 12px; background: var(--surface);
  color: var(--text); font-size: 1.3rem; }
.title-input { flex: 1; min-height: 48px; font: 600 1.15rem/1 inherit; color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 10px; padding: 0 10px; }
.title-input:focus { border-color: var(--line); background: var(--surface); outline: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin: 12px 0; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.row-2 .card { margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: 600 1rem/1.2 inherit; text-decoration: none;
  cursor: pointer; user-select: none; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.good { background: color-mix(in srgb, var(--good) 22%, var(--surface-2)); border-color: var(--good); }
.btn.bad { background: color-mix(in srgb, var(--bad) 20%, var(--surface-2)); border-color: var(--bad); }
.btn.big { min-height: 56px; font-size: 1.05rem; }
.btn.block { display: flex; width: 100%; margin: 10px 0; }
.small-btn { min-height: 40px; font-size: .9rem; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.hero { text-align: center; }
.hero-num { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.hero-num small { font-size: 1.1rem; font-weight: 600; color: var(--muted); }
.stat { text-align: center; }
.stat-num { font-size: 1.4rem; font-weight: 700; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 18px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.chart .bar-fill { width: 100%; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 3px; position: relative; }
.chart .bar-fill.none { background: var(--surface-2); }
.chart .bar-fill span { position: absolute; top: -17px; left: 50%; transform: translateX(-50%); font-size: .62rem; color: var(--muted); white-space: nowrap; }
.chart .lbl { font-size: .62rem; color: var(--muted); margin-top: 4px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 10px; padding: 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line); min-height: 56px; }
.item.tap { cursor: pointer; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; overflow-wrap: anywhere; }
.item .sub { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.item .acts { display: flex; gap: 4px; }
.item .acts button { min-width: 44px; min-height: 44px; border: 0; border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: 1.05rem; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .75rem; background: var(--surface-2); color: var(--muted); margin-left: 4px; }
.badge.due { background: color-mix(in srgb, var(--warn) 25%, transparent); color: var(--warn); }

.upload-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 36px; height: 36px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 1rem; }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px;
  border-radius: 12px; background: var(--surface-2); margin: 10px 0; }
.seg-btn { min-height: 44px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: 600 .95rem inherit; }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.25); }

.field { display: block; margin: 12px 0; font-weight: 600; }
.field input, .field textarea, .add-row input, .modal input, .modal textarea, .sel-card input {
  display: block; width: 100%; margin-top: 6px; min-height: 48px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: 400 1rem/1.4 inherit; }
.field textarea { min-height: 160px; resize: vertical; }
.add-row { display: flex; gap: 8px; margin: 10px 0; }
.add-row input { margin: 0; flex: 1; }

.note { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 18%, transparent);
  color: var(--warn); font-size: .88rem; }
.source { white-space: pre-wrap; word-break: break-word; font: .92rem/1.6 inherit; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin: 8px 0; max-height: 50vh; overflow: auto; }
details summary { cursor: pointer; font-weight: 600; min-height: 32px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 500 .98rem inherit; }
.chip.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.chip small { opacity: .7; margin-left: 4px; }
.sel-card { padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.sel-card .head { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.sel-card input { margin-top: 6px; }

.progress { height: 12px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 10px 0 4px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

.sticky-bottom { position: sticky; bottom: 0; padding: 10px 0 calc(10px + var(--safe-b)); background: linear-gradient(transparent, var(--bg) 30%); }

/* 전체 화면 보기(학습·퀴즈 등)에서는 하단 탭을 숨긴다 */
body.fullscreen .tabbar { display: none; }
body.fullscreen main { padding-bottom: calc(24px + var(--safe-b)); }

.wait { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; }
.wait-text { font-size: 1.25rem; font-weight: 700; }
.spinner { width: 56px; height: 56px; border-radius: 50%; border: 5px solid var(--surface-2); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 플래시카드 */
/* 날아가는 카드가 가로 스크롤(모바일 줌 아웃)을 만들지 않도록 잘라낸다 */
.stage { touch-action: pan-y; padding: 8px 0 16px; user-select: none; overflow: hidden; overflow: clip; }
.flashcard { position: relative; height: min(58vh, 440px); perspective: 1200px; cursor: pointer;
  touch-action: pan-y; transition: transform .25s ease; }
.flashcard.dragging { transition: none; }
.fc-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .35s ease; }
.flashcard.flipped .fc-inner { transform: rotateY(180deg); }
.flashcard .face { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 24px; border-radius: 20px; background: var(--surface); border: 1px solid var(--line);
  backface-visibility: hidden; -webkit-backface-visibility: hidden; text-align: center; }
.flashcard .back { transform: rotateY(180deg); }
.fc-word { font-size: 2.2rem; font-weight: 800; overflow-wrap: anywhere; }
.fc-meaning { font-size: 1.5rem; font-weight: 700; }
.fc-ex { font-size: 1rem; }
.tap-hint { position: absolute; bottom: 16px; }
.swipe-tag { position: absolute; top: 18px; padding: 4px 12px; border-radius: 8px; font-weight: 800; opacity: 0; pointer-events: none; }
.swipe-tag.left { left: 18px; color: var(--bad); border: 2px solid var(--bad); }
.swipe-tag.right { right: 18px; color: var(--good); border: 2px solid var(--good); }
.study-actions { display: grid; grid-template-columns: 1fr 56px 56px 1fr; gap: 8px; }
.study-actions .btn { padding: 0 8px; white-space: nowrap; }

/* 퀴즈 */
.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); font-size: .8rem; }
.quiz-q { font-size: 1.2rem; font-weight: 700; white-space: pre-wrap; overflow-wrap: anywhere; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choice { min-height: 56px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: 500 1rem/1.35 inherit; text-align: left; }
.choice.correct { border-color: var(--good); background: color-mix(in srgb, var(--good) 20%, var(--surface)); }
.choice.wrong { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 18%, var(--surface)); }
.feedback { margin: 12px 0; padding: 12px; border-radius: 12px; white-space: pre-wrap; background: var(--surface); border: 1px solid var(--line); }
.feedback.ok { border-color: var(--good); }
.feedback.ng { border-color: var(--bad); }
.feedback b { display: block; margin-bottom: 4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0 0 10px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

/* 로그인 */
.login { min-height: 86vh; display: flex; flex-direction: column; justify-content: center; text-align: center; gap: 10px; }
.login-heart { font-size: 3.4rem; }
.login h1 { font-size: 1.4rem; }
.login input { min-height: 52px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: 400 1.05rem inherit; text-align: center; }
.login-error { color: var(--bad); margin: 0; }

/* 하단 탭 */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--line); }
.tabbar button { border: 0; background: transparent; color: var(--muted); font: 600 .78rem inherit; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tabbar button span { font-size: 1.3rem; }
.tabbar button.active { color: var(--accent); }

/* 모달·토스트 */
.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(16px + var(--safe-b)); }
.modal h3 { margin: 0 0 8px; font-size: 1.15rem; }
.modal .body { white-space: pre-wrap; margin-bottom: 12px; }
.modal .actions { display: flex; flex-direction: column; gap: 8px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); transform: translateX(-50%); z-index: 60;
  width: max-content; max-width: calc(100% - 32px); padding: 12px 16px; border-radius: 12px; background: var(--text); color: var(--bg);
  font-weight: 600; text-align: center; }
/* 전체 화면(학습·퀴즈)에서는 하단 버튼을 가리지 않도록 위에 띄운다 */
body.fullscreen .toast { bottom: auto; top: calc(12px + env(safe-area-inset-top, 0px)); }
