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

:root {
  /* 화이트톤 — 순백 배경 + 잉크 그레이 강조 */
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f7f8f9;
  --ink: #16181d;
  --ink-soft: #4a4f58;
  --muted: #9aa0aa;
  --line: #e9ebef;
  --line-strong: #d6dae0;
  --accent: #16181d;
  --accent-soft: #f2f3f5;
  --shadow: 0 1px 2px rgba(22, 24, 29, 0.04), 0 8px 24px rgba(22, 24, 29, 0.05);
  /* 축별 은은한 색 */
  --subject-bg: #eef3fb; --subject-ink: #2f5b96;
  --tense-bg: #fdf4e6;  --tense-ink: #8a6224;
  --form-bg: #f1eefb;   --form-ink: #5e4a9c;
  --series-bg: #f0f1f3; --series-ink: #4a4f58;
}

html, body, #root { height: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard",
    "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:disabled { cursor: default; }
a { color: inherit; text-decoration: none; }
code {
  background: var(--surface-soft);
  padding: 0.1em 0.35em;
  border-radius: 5px;
  font-size: 0.9em;
}

.icon { width: 1.15rem; height: 1.15rem; display: block; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-soft); color: var(--ink); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn-sm { width: 1.9rem; height: 1.9rem; border-radius: 9px; }

/* ---------- 드릴 스테이지 (화면 전체가 탭 영역) ---------- */

.stage {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  user-select: none;
  touch-action: manipulation;
  background: var(--bg);
}

.stage-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(0.75rem, env(safe-area-inset-top)) 1rem 0.6rem;
}
.header-spacer { width: 3.5rem; }
.progress { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* 세션 진행 바 — 남은 양을 한눈에 */
.progress-bar {
  height: 3px;
  margin: 0 1rem;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.3s ease;
}

.stage-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 0 1.25rem;
  text-align: center;
}

.sentence {
  font-size: clamp(2rem, 9vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.25;
  word-break: keep-all;
}

.fade-in { animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

.tokens { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.token {
  display: inline-block;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-size: clamp(1.2rem, 5vw, 1.6rem);
  font-weight: 600;
}
.token-plus { color: var(--muted); font-size: 1.2rem; }
.token-subject { background: var(--subject-bg); color: var(--subject-ink); }
.token-tense { background: var(--tense-bg); color: var(--tense-ink); }
.token-form { background: var(--form-bg); color: var(--form-ink); }
.token-series { background: var(--series-bg); color: var(--series-ink); }
.token-pred {
  background: transparent;
  border: 1.5px dashed var(--line-strong);
  color: var(--muted);
  font-weight: 500;
}
.token-ko {
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  color: var(--ink);
  font-weight: 600;
  font-size: clamp(1.1rem, 4.5vw, 1.4rem);
}

/* ---------- 문법 슬롯 색상 (be/do/will/have/can/의문사/부정) ----------
   어간은 슬롯색, 부정 표지(n't/not)는 빨강으로 분리해
   "슬롯은 그대로, 부정 조작이 더해졌다"는 구조를 보여준다: is|n't, can|'t. */
:root {
  --gram-be: #1d5fbf;
  --gram-do: #b1560c;
  --gram-future: #6d28d9;
  --gram-perfect: #0f766e;
  --gram-modal: #c026d3;
  --gram-wh: #15803d;
  --gram-neg: #dc2626;
}
.gram { font-weight: 800; }
.gram-be { color: var(--gram-be); }
.gram-do { color: var(--gram-do); }
.gram-future { color: var(--gram-future); }
.gram-perfect { color: var(--gram-perfect); }
.gram-modal { color: var(--gram-modal); }
.gram-wh { color: var(--gram-wh); }
.gram-neg { color: var(--gram-neg); text-decoration: underline; text-underline-offset: 0.15em; }

.gram-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.9rem;
  padding: 0.15rem 0.1rem 0.35rem;
}
.gram-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.gram-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; flex-shrink: 0; }
.gram-dot-be { background: var(--gram-be); }
.gram-dot-do { background: var(--gram-do); }
.gram-dot-future { background: var(--gram-future); }
.gram-dot-perfect { background: var(--gram-perfect); }
.gram-dot-modal { background: var(--gram-modal); }
.gram-dot-wh { background: var(--gram-wh); }
.gram-dot-neg { background: var(--gram-neg); }

.stage-hint {
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

/* 세션 완료 신호 */
.done-mark {
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 2.6rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.done-text { font-size: 1.15rem; font-weight: 700; }

/* ---------- 일반 페이지 ---------- */

.page {
  max-width: 34rem;
  margin: 0 auto;
  padding: max(1.6rem, env(safe-area-inset-top)) 1.1rem calc(2.2rem + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.page-wide { max-width: 44rem; }

.app-title {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.035em;
  text-align: center;
  padding: 0.2rem 0 0.3rem;
}
.page-title { font-size: 1.45rem; font-weight: 800; letter-spacing: -0.03em; }

.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-head h2 { font-size: 1.02rem; font-weight: 700; letter-spacing: -0.02em; }

.field { display: flex; flex-direction: column; gap: 0.5rem; }
.field-label { font-size: 0.76rem; color: var(--muted); letter-spacing: 0; }

.primary-btn {
  padding: 0.85rem 1.2rem;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: opacity 0.15s;
}
.primary-btn:hover { opacity: 0.9; }
.primary-btn:active { transform: scale(0.99); }
.primary-btn:disabled {
  background: var(--surface-soft);
  color: var(--muted);
  border: 1px solid var(--line);
}
.primary-btn:disabled:active { transform: none; }

.ghost-btn {
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  color: var(--ink-soft);
  border: 1px solid var(--line);
  font-size: 0.88rem;
  background: var(--surface);
  transition: background 0.15s;
}
.ghost-btn:hover { background: var(--surface-soft); }
.ghost-btn.wide { width: 100%; padding: 0.8rem; }

.row-gap { display: flex; gap: 0.6rem; align-items: center; }
.empty-note { color: var(--muted); font-size: 0.88rem; line-height: 1.6; }
.error-note {
  border: 1px solid #f0d3ce;
  background: #fdf6f5;
  color: #a8402f;
  border-radius: 12px;
  padding: 0.8rem;
  font-size: 0.9rem;
}

/* ---------- 범위 매트릭스 ---------- */

.matrix {
  display: grid;
  grid-template-columns: 3.6rem 1fr 1fr;
  gap: 0.3rem;
  align-items: stretch;
  /* 드래그 일괄 토글이 스크롤에 뺏기지 않도록 */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.matrix-head {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.4rem 0.2rem;
  border-radius: 8px;
  transition: color 0.15s, background 0.15s;
}
.matrix-head:hover { color: var(--ink); background: var(--surface-soft); }
.matrix-rowhead { text-align: left; padding-left: 0.35rem; }
.matrix-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0 0.3rem;
  min-height: 3rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 0.5rem 0.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.cell-stage {
  flex-basis: 100%;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 500;
  margin-top: 0.1rem;
  letter-spacing: 0;
}
.cell-on .cell-stage { font-weight: 700; }
.matrix-cell:hover { border-color: var(--line-strong); }
.cell-on {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  font-weight: 700;
}
.cell-check { width: 0.85rem; text-align: center; font-size: 0.78rem; }
.cell-span { grid-column: span 2; display: flex; }
.cell-span .matrix-cell { flex: 1; }

/* ---------- 설정 행 (세션·걸음 폭·반복·지시) ---------- */

.settings {
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--line);
}
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--line);
  min-height: 3rem;
}
.set-label { font-size: 0.88rem; color: var(--ink-soft); font-weight: 500; }

/* 세그먼티드 토글 */
.seg {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}
.seg-btn {
  padding: 0.5rem 0.7rem;
  min-width: 3rem;
  border-radius: 7px;
  font-size: 0.84rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg-on {
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(22, 24, 29, 0.08);
}

/* 스테퍼 (걸음 폭) */
.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.stepper-val {
  display: flex;
  align-items: center;
  padding: 0.5rem 0.85rem;
  font-size: 0.92rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  min-width: 3.2rem;
  justify-content: center;
}
.stepper-arrows { display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.stepper-btn {
  flex: 1;
  min-height: 1.35rem;
  padding: 0 0.7rem;
  font-size: 0.58rem;
  line-height: 1;
  color: var(--ink-soft);
  background: var(--surface-soft);
  transition: background 0.12s, color 0.12s;
}
.stepper-btn:first-child { border-bottom: 1px solid var(--line); }
.stepper-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--ink); }
.stepper-btn:disabled { color: #cfd3d9; }

/* 스위치 (반복 노출) */
.switch { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0; }
.switch-track {
  width: 2.5rem;
  height: 1.45rem;
  border-radius: 999px;
  background: #dfe2e7;
  padding: 2px;
  display: flex;
  transition: background 0.18s;
}
.switch-knob {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(22, 24, 29, 0.22);
  transition: transform 0.18s;
}
.switch-on .switch-track { background: var(--accent); }
.switch-on .switch-knob { transform: translateX(1.05rem); }
.switch-text {
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--muted);
  width: 1.9rem;
  text-align: left;
  letter-spacing: 0.02em;
}
.switch-on .switch-text { color: var(--ink); }

/* ---------- 전체 문장표 ---------- */

.table-header { display: flex; align-items: center; gap: 0.8rem; }
.table-header .page-title { font-size: 1.25rem; }

.table-walk-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.walk-btn {
  padding: 0.5rem 0.9rem;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  transition: opacity 0.15s;
}
.walk-btn:hover { opacity: 0.9; }
.walk-btn:active { transform: scale(0.98); }

.tab-row {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  padding-bottom: 0.2rem;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex-shrink: 0;
  padding: 0.38rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.88rem;
  background: var(--surface);
  color: var(--muted);
  transition: all 0.15s;
}
.tab:hover { border-color: var(--line-strong); }
.tab-on { border-color: var(--accent); color: #fff; background: var(--accent); font-weight: 600; }

.table-section { display: flex; flex-direction: column; gap: 0.5rem; }
.table-section h2 { font-size: 0.98rem; font-weight: 700; }
.table-note { color: var(--muted); font-size: 0.85rem; margin-top: -0.5rem; }

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.sentence-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 30rem;
  background: var(--surface);
  font-size: 0.92rem;
}
.sentence-table th,
.sentence-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 0.5rem 0.65rem;
  text-align: left;
  white-space: nowrap;
}
.sentence-table tr:last-child th,
.sentence-table tr:last-child td { border-bottom: none; }
.sentence-table th:last-child,
.sentence-table td:last-child { border-right: none; }
.sentence-table thead th {
  background: var(--surface-soft);
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 700;
}
.sentence-table tbody th {
  background: var(--surface-soft);
  font-weight: 700;
  width: 3rem;
  color: var(--ink-soft);
}

/* ---------- 어휘 바꾸기 ---------- */

.vocab-list { display: flex; flex-direction: column; gap: 0.45rem; }
.vocab-row {
  display: grid;
  grid-template-columns: 2.4rem 6.2rem 1fr 1fr;
  gap: 0.4rem;
  align-items: center;
}
.vocab-subj { font-weight: 700; font-size: 0.92rem; }
.vocab-default { font-size: 0.78rem; color: var(--muted); }
.vocab-input {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 0.45rem 0.6rem;
  font: inherit;
  font-size: 0.88rem;
  background: var(--surface);
  min-width: 0;
  transition: border-color 0.15s;
}
.vocab-input:focus { outline: none; border-color: var(--accent); }
@media (max-width: 480px) {
  .vocab-row { grid-template-columns: 2rem 4.4rem 1fr 1fr; }
}

/* ---------- 푸터 ---------- */

.site-footer {
  margin-top: 0.4rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
}
.credit { font-size: 0.8rem; color: var(--muted); letter-spacing: 0.01em; }

/* ---------- 모바일 (세로 폰) ---------- */

@media (max-width: 480px) {
  .app-title { font-size: 1.65rem; }
  .card { padding: 1rem 0.9rem 1.1rem; border-radius: 14px; }

  /* 설정 행: 라벨과 컨트롤이 좁은 폭에서 겹치지 않게 */
  .set-row { gap: 0.5rem; min-height: 3.2rem; }
  .set-label { font-size: 0.85rem; flex-shrink: 0; }
  .seg-btn { padding: 0.5rem 0.55rem; min-width: 2.6rem; font-size: 0.8rem; }

  .matrix { grid-template-columns: 3.1rem 1fr 1fr; gap: 0.28rem; }
  .matrix-cell { min-height: 3.1rem; font-size: 0.88rem; }
  .matrix-head { font-size: 0.8rem; }

  /* 문장표: 화면 폭에 맞춰 여백을 줄이고 가로 스크롤 여지를 넓힌다 */
  .page-wide { padding-left: 0.7rem; padding-right: 0.7rem; }
  .sentence-table { min-width: 26rem; font-size: 0.86rem; }
  .sentence-table th, .sentence-table td { padding: 0.45rem 0.5rem; }
  .table-walk-row .walk-btn { flex: 1; text-align: center; }
  .tab { padding: 0.45rem 0.8rem; }

  .gram-legend { gap: 0.15rem 0.7rem; }
}

/* 손가락 입력 기기: 호버 스타일이 눌린 것처럼 남지 않게 */
@media (hover: none) {
  .icon-btn:hover, .ghost-btn:hover, .matrix-head:hover,
  .matrix-cell:hover, .tab:hover, .primary-btn:hover, .walk-btn:hover {
    background: inherit;
    opacity: 1;
  }
  .matrix-cell:hover { border-color: var(--line); }
  .cell-on:hover { border-color: var(--accent); background: var(--accent-soft); }
  .tab-on:hover { background: var(--accent); }
}
