:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --text: #1d1f23;
  --muted: #6b6f76;
  --line: #e2ded5;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --hit: #2f8f5b;
  --half: #c08a1e;
  --miss: #c2493d;
  --danger: #b3382c;
  --banner: #fff3cd;
  --banner-text: #5c4400;
  --bar-h: 88px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #202329;
    --text: #e8e6e1;
    --muted: #9ba0a8;
    --line: #33373e;
    --accent: #5fb39a;
    --accent-text: #0e1512;
    --hit: #5cc48a;
    --half: #e0b04a;
    --miss: #ef7a6e;
    --danger: #ef7a6e;
    --banner: #3a3216;
    --banner-text: #f3df9c;
  }
}

* { box-sizing: border-box; }

/* 터치 처리: 더블탭 확대 끄기 + 탭 하이라이트 끄기 (개념 페이지 기준) */
html, body {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
/* 글자 선택 방지는 버튼에만. 본문·입력창은 선택·붙여넣기가 되어야 한다. */
button, .tab, .grade {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", sans-serif;
  font-size: 18px;
  line-height: 1.6;
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 18px calc(var(--bar-h) + var(--safe-b) + 24px);
}

/* 상단 탭 */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.tabs { display: flex; max-width: 760px; margin: 0 auto; }
.tab {
  flex: 1; min-height: 52px;
  background: none; border: 0; color: var(--muted);
  font: inherit; font-size: 17px; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.screen-title { font-size: 24px; line-height: 1.35; margin: 12px 0 14px; word-break: keep-all; }
h2 { font-size: 17px; margin: 0 0 8px; }
h2 small, .label small { color: var(--muted); font-weight: 400; }
.hint { color: var(--muted); font-size: 15px; margin: 6px 0; }
.center { text-align: center; }
.stat-line { color: var(--muted); font-size: 15px; margin: 4px 0 12px; }

/* 입력 */
.field { display: block; margin-bottom: 14px; }
.label { display: block; font-size: 15px; font-weight: 600; margin-bottom: 6px; }
input[type="text"], textarea {
  width: 100%;
  font: inherit; font-size: 18px; /* 16px 이상: iOS 확대 방지 */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px;
}
textarea { resize: vertical; line-height: 1.7; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* 읽기 본문 */
.prose {
  font-size: 19px; line-height: 1.85;
  white-space: pre-wrap; word-break: keep-all; overflow-wrap: anywhere;
}
.read-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.timer { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 16px; }

/* 하단 고정 버튼 영역: 엄지 닿는 곳 */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 4;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding: 12px 18px calc(12px + var(--safe-b));
}
.actionbar > * { max-width: 724px; margin-left: auto; margin-right: auto; }
.actionbar.stacked { display: flex; flex-direction: column; gap: 10px; }
.actionbar.stacked > * { width: 100%; }

.btn {
  display: block; width: 100%; min-height: 56px;
  font: inherit; font-size: 18px; font-weight: 700;
  border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn:disabled { opacity: .4; }
.btn.small { min-height: 44px; font-size: 15px; width: auto; padding: 0 16px; display: inline-block; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); margin-top: 24px; }
.btn:active:not(:disabled), .grade:active { transform: scale(.98); }

.grades { display: flex; gap: 8px; }
.grade {
  flex: 1; min-height: 52px;
  font: inherit; font-size: 16px; font-weight: 700;
  border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface); color: var(--text);
}
.grade[data-grade="hit"][aria-checked="true"] { border-color: var(--hit); background: var(--hit); color: #fff; }
.grade[data-grade="half"][aria-checked="true"] { border-color: var(--half); background: var(--half); color: #fff; }
.grade[data-grade="miss"][aria-checked="true"] { border-color: var(--miss); background: var(--miss); color: #fff; }

/* 비교: 폰은 위아래, 넓은 화면은 나란히 */
.compare { display: grid; gap: 14px; }
@media (min-width: 700px) { .compare { grid-template-columns: 1fr 1.6fr; align-items: start; } }
.pane { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin-bottom: 14px; }
.compare .pane { margin-bottom: 0; }
.pane .prose { font-size: 17px; line-height: 1.75; }
.my-summary { font-size: 20px; font-weight: 600; line-height: 1.6; margin: 0; word-break: keep-all; white-space: pre-wrap; }

/* 기록 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 12px 0; }
.streak { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.streak-num strong { font-size: 36px; line-height: 1; margin-right: 4px; }
.streak-num span { color: var(--muted); }
.dots { display: flex; gap: 6px; }
.dot { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; color: var(--muted); }
.dot i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); }
.dot.on i { background: var(--accent); border-color: var(--accent); }
.dot.today { color: var(--text); font-weight: 700; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); stroke-width: 1; }
.chart .lbl { fill: var(--muted); font-size: 11px; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; }
.chart .pt { fill: var(--accent); }
.chart .g-hit { fill: var(--hit); } .chart .g-half { fill: var(--half); } .chart .g-miss { fill: var(--miss); }
/* 등급으로 환산한 점은 속을 비운다 (요점 반영률이 실제 값이 아님) */
.chart .est { fill: var(--surface); stroke-width: 2.5; }
.chart .g-hit.est { stroke: var(--hit); } .chart .g-half.est { stroke: var(--half); } .chart .g-miss.est { stroke: var(--miss); }

.list-title { margin-top: 22px; }
.session-list { list-style: none; padding: 0; margin: 0; }
.session-list li { margin-bottom: 8px; }
.session-item {
  width: 100%; text-align: left; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; min-height: 64px;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center;
}
.si-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.si-meta { color: var(--muted); font-size: 14px; grid-column: 1; }
.badge { grid-row: 1 / span 2; grid-column: 2; font-size: 14px; font-weight: 700; padding: 4px 10px; border-radius: 99px; color: #fff; }
.badge.hit { background: var(--hit); } .badge.half { background: var(--half); } .badge.miss { background: var(--miss); }

.switch-row { display: flex; align-items: center; justify-content: space-between; min-height: 48px; gap: 12px; }
.switch-row input { width: 26px; height: 26px; accent-color: var(--accent); }
.row-buttons { display: flex; gap: 10px; margin: 10px 0; }
.usage { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.usage.warn { color: var(--danger); font-weight: 600; }

.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-size: 16px; padding: 12px 0; min-height: 48px; }

/* 안내 띠 (용량 부족 등) */
.banner {
  position: sticky; top: 53px; z-index: 6;
  background: var(--banner); color: var(--banner-text);
  padding: 12px 18px; border-bottom: 1px solid var(--line);
}
.banner p { margin: 0 0 8px; font-weight: 600; max-width: 724px; margin-left: auto; margin-right: auto; }
.banner-actions { display: flex; gap: 8px; max-width: 724px; margin: 0 auto; }

/* 난이도 선택 · 기록 필터 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 14px; }
.chip {
  min-height: 48px; padding: 0 16px;
  font: inherit; font-size: 16px; font-weight: 600;
  border-radius: 99px; border: 2px solid var(--line);
  background: var(--surface); color: var(--text);
}
.chip[aria-checked="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-text); }
#pick-panel h2 { font-size: 19px; margin: 0 0 4px; word-break: keep-all; }
#pick-panel .hint { margin: 0; }

/* 출처 (비교·상세 화면에서만) */
.sources { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 14px; color: var(--muted); }
.sources h3 { font-size: 14px; margin: 0 0 4px; color: var(--text); }
.sources ol { margin: 0; padding-left: 20px; }
.sources li { margin-bottom: 4px; overflow-wrap: anywhere; }
.sources a { color: var(--accent); }

/* AI 채점 */
.ai-panel { margin-bottom: 14px; border-color: var(--accent); }
.ai-panel h3 { font-size: 14px; margin: 12px 0 4px; color: var(--muted); }
.ai-panel ul { margin: 0; padding-left: 20px; font-size: 16px; }
.ai-panel li { margin-bottom: 2px; }
.ai-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ai-head .badge { grid-row: auto; grid-column: auto; }
.ai-reason { margin: 6px 0 0; }
.ai-model-summary { font-size: 18px; font-weight: 600; margin: 0; word-break: keep-all; }
.ai-meta { font-size: 12px; color: var(--muted); margin: 10px 0 0; }
.ai-error { color: var(--danger); font-weight: 600; }
.loading::after { content: ''; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.grade-hint { margin: 0; text-align: center; }
.ai-done { font-weight: 600; }
.ai-notice { margin: 0; line-height: 1.6; word-break: keep-all; }
.hint.small { font-size: 13px; }

[hidden] { display: none !important; }

/* 요점별 반영 (v0.4) */
.ai-count { font-size: 14px; font-weight: 600; color: var(--muted); }
.points { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.points li { display: grid; grid-template-columns: 1.4em 1fr; align-items: baseline; line-height: 1.5; }
.points .mark { font-weight: 700; text-align: center; }
.points li.ok .mark { color: var(--hit); }
.points li.no .mark { color: var(--miss); }
.main-tag { margin-right: 6px; font-size: 12px; font-weight: 700; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--accent); color: var(--accent); }
