:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f0f2ee;
  --text: #1c2321;
  --muted: #5f6b67;
  --line: #e1e5df;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d8efe9;
  --danger: #dc2626;
  --c-breath: #3b82f6;
  --c-voice: #8b5cf6;
  --c-artic: #f59e0b;
  --c-script: #10b981;
  --c-record: #ef4444;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 6px 24px rgba(16, 24, 20, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --surface: #171e1c;
    --surface-2: #1f2825;
    --text: #e8eeeb;
    --muted: #97a59f;
    --line: #2a3531;
    --accent: #2dd4bf;
    --accent-ink: #062a25;
    --accent-soft: #123a34;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Pretendard Variable", Pretendard, -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
a { color: inherit; }
button { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5em; letter-spacing: -0.01em; }
h1 { font-size: clamp(1.5rem, 3.6vw, 2.1rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand-mark { font-size: 1.3rem; }
.topnav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.topnav a { text-decoration: none; padding: 6px 12px; border-radius: 999px; color: var(--muted); white-space: nowrap; font-size: .95rem; }
.topnav a.active, .topnav a:hover { background: var(--accent-soft); color: var(--text); }
@media (max-width: 640px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 6px; padding: 8px 12px; }
  .brand-text { font-size: .95rem; }
  .topnav a { padding: 5px 10px; font-size: .88rem; }
}

.footer { text-align: center; color: var(--muted); font-size: .85rem; padding: 24px 16px 40px; border-top: 1px solid var(--line); }

/* Cards & buttons */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-title h2, .card-title h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-weight: 600; text-decoration: none;
  transition: transform .06s ease, background .15s;
  min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.rec { background: var(--c-record); border-color: var(--c-record); color: #fff; }
.btn.sm { padding: 5px 10px; min-height: 34px; font-size: .88rem; border-radius: 10px; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.chip.kind { color: #fff; }

/* Home */
.hero { display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: center; margin-bottom: 20px; }
.hero .eyebrow { color: var(--accent); font-weight: 700; font-size: .85rem; letter-spacing: .08em; }
.hero p { color: var(--muted); max-width: 60ch; }
.progress-ring { width: 150px; height: 150px; position: relative; }
.progress-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.progress-ring .center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.progress-ring .big { font-size: 2rem; font-weight: 800; line-height: 1; }
@media (max-width: 640px) { .hero { grid-template-columns: 1fr; } .progress-ring { width: 120px; height: 120px; } }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat .v { font-size: 1.5rem; font-weight: 800; }
.stat .k { color: var(--muted); font-size: .85rem; }

.next-up { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; background: linear-gradient(135deg, var(--accent-soft), var(--surface)); }

.week { margin-top: 28px; }
.week-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.week-head h2 { margin: 0; }
.week-meta { color: var(--muted); font-size: .88rem; margin-bottom: 12px; }
.day-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.day-card {
  position: relative; display: block; text-decoration: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 14px 12px;
  transition: border-color .15s, transform .1s;
}
.day-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.day-card .dnum { font-weight: 800; color: var(--accent); font-size: .9rem; }
.day-card .dtitle { font-weight: 700; margin: 2px 0; line-height: 1.35; }
.day-card .dtopic { color: var(--muted); font-size: .85rem; line-height: 1.4; }
.day-card .dfoot { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.day-card.done { background: var(--accent-soft); border-color: transparent; }
.day-card.done::after { content: "✓"; position: absolute; top: 10px; right: 12px; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: .85rem; }
.day-card.today { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg-strip { display: flex; height: 6px; border-radius: 3px; overflow: hidden; margin-top: 10px; gap: 2px; }

/* Day page layout */
.day-header { margin-bottom: 16px; }
.day-header .crumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .9rem; margin-bottom: 6px; flex-wrap: wrap; }
.day-header .crumbs a { color: var(--accent); text-decoration: none; }
.day-nav { display: flex; gap: 8px; }
.day-layout { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 16px; align-items: start; }
.day-layout > div > .card + .card { margin-top: 16px; }
@media (max-width: 960px) { .day-layout { grid-template-columns: 1fr; } }
.sticky-col { position: sticky; top: 76px; }
@media (max-width: 960px) { .sticky-col { position: static; } }

/* Timer */
.timer-wrap { display: grid; place-items: center; position: relative; margin: 4px auto 12px; width: min(300px, 100%); aspect-ratio: 1; }
.timer-wrap svg { width: 100%; height: 100%; }
.timer-center { position: absolute; inset: 14%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; border-radius: 50%; }
.timer-seg-name { font-weight: 700; font-size: .95rem; line-height: 1.3; max-width: 90%; }
.timer-time { font-size: clamp(2.4rem, 9vw, 3.2rem); font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; letter-spacing: -0.02em; }
.timer-total { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.timer-controls { display: flex; justify-content: center; gap: 8px; flex-wrap: wrap; }
.timer-controls .btn.primary { min-width: 120px; }

.timeline { list-style: none; padding: 0; margin: 16px 0 0; display: grid; gap: 6px; }
.timeline li {
  display: grid; grid-template-columns: 6px 1fr auto; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent;
}
.timeline li:hover { background: var(--surface-2); }
.timeline li.active { background: var(--surface-2); border-color: var(--line); }
.timeline li.passed { opacity: .55; }
.timeline .bar { width: 6px; height: 100%; min-height: 28px; border-radius: 3px; }
.timeline .t { font-weight: 600; font-size: .93rem; line-height: 1.35; }
.timeline .k { font-size: .78rem; color: var(--muted); }
.timeline .m { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .88rem; white-space: nowrap; }

/* Current segment panel */
.seg-panel .seg-detail { font-size: 1.02rem; }
.word-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.word-chips span { background: var(--surface-2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 10px; font-weight: 600; font-size: 1.02rem; }
.twister { font-size: 1.15rem; font-weight: 600; padding: 12px 14px; background: var(--surface-2); border-radius: 12px; margin: 10px 0; line-height: 1.7; }
.emphasis-list { display: grid; gap: 8px; margin: 10px 0; padding: 0; list-style: none; }
.emphasis-list li { padding: 10px 12px; background: var(--surface-2); border-radius: 10px; font-size: 1.05rem; }
.emphasis-list b { color: var(--accent); }

/* Breathing */
.breath-box { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; margin-top: 12px; padding: 14px; background: var(--surface-2); border-radius: 14px; }
.breath-orb-wrap { width: 120px; height: 120px; display: grid; place-items: center; }
.breath-orb {
  width: 120px; height: 120px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #93c5fd, var(--c-breath));
  transform: scale(.45); transition: transform .25s linear;
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 1.6rem;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--c-breath) 18%, transparent);
}
.breath-phase { font-size: 1.3rem; font-weight: 800; }
.breath-reps { color: var(--muted); font-size: .9rem; }

/* Metronome */
.metro { display: flex; align-items: center; gap: 14px; margin-top: 12px; padding: 12px 14px; background: var(--surface-2); border-radius: 14px; flex-wrap: wrap; }
.metro-dot { width: 28px; height: 28px; border-radius: 50%; background: var(--line); transition: background .08s; }
.metro-dot.on { background: var(--accent); }

/* Mirror */
.mirror { margin-top: 12px; }
.mirror video { width: 100%; border-radius: 12px; transform: scaleX(-1); background: #000; max-height: 320px; object-fit: cover; }
.gaze-guide { display: flex; justify-content: space-between; font-weight: 700; color: var(--muted); font-size: .85rem; margin-top: 4px; }

/* Script */
.stage-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.stage-tabs button { border: 1px solid var(--line); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: .9rem; font-weight: 600; }
.stage-tabs button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.stage-hint { font-size: .9rem; color: var(--muted); margin-bottom: 10px; min-height: 1.4em; }
.script {
  font-size: var(--script-size, 1.22rem); line-height: 2.05; padding: 18px; background: var(--surface-2);
  border-radius: 14px; letter-spacing: -0.005em;
}
.script .chunk { transition: background .2s, color .2s; border-radius: 6px; padding: 1px 2px; }
.script .chunk.read { color: var(--muted); }
.script .chunk.now { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--text); }
.script b { color: var(--accent); font-weight: 800; }
.script .p1, .script .p2 { display: inline-block; font-weight: 800; margin: 0 .2em; color: var(--c-breath); user-select: none; }
.script .p2 { color: var(--c-record); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); margin-top: 8px; }
.legend .p1 { color: var(--c-breath); font-weight: 800; }
.legend .p2 { color: var(--c-record); font-weight: 800; }
.legend b { color: var(--accent); }
.pace-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.pace-progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin-top: 10px; }
.pace-progress > div { height: 100%; width: 0; background: var(--accent); }
select, input[type=number], textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px;
}
textarea { width: 100%; min-height: 80px; resize: vertical; }
details.rehearsal { margin-top: 14px; }
details.rehearsal summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.rehearsal-part { margin-top: 12px; }
.rehearsal-part h4 { margin: 0 0 4px; font-size: .95rem; color: var(--accent); }
.rehearsal-part .script { font-size: 1.02rem; line-height: 1.9; padding: 12px 14px; }

/* Mic */
.mic-meter { position: relative; height: 14px; background: var(--surface-2); border-radius: 7px; overflow: hidden; border: 1px solid var(--line); }
.mic-meter > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--c-script), var(--c-artic) 75%, var(--c-record)); transition: width .05s; }
.mic-meter .zone { position: absolute; top: 0; bottom: 0; border-left: 2px dashed color-mix(in srgb, var(--text) 30%, transparent); }
.mic-readout { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; flex-wrap: wrap; gap: 8px; }
.mic-canvas { width: 100%; height: 130px; display: block; margin-top: 10px; border-radius: 12px; background: var(--surface-2); }
.mic-legend { display: flex; gap: 12px; font-size: .8rem; color: var(--muted); margin-top: 4px; flex-wrap: wrap; }
.mic-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.rec-status { display: flex; align-items: center; gap: 10px; font-weight: 700; font-variant-numeric: tabular-nums; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c-record); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.mic-off { text-align: center; padding: 18px; background: var(--surface-2); border-radius: 12px; }

.rec-list { display: grid; gap: 10px; margin-top: 14px; }
.rec-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
.rec-item .rec-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.rec-item audio { width: 100%; height: 40px; margin: 6px 0; }
.rec-item canvas { width: 100%; height: 56px; display: block; border-radius: 8px; background: var(--surface-2); }
.rec-metrics { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.metric { font-size: .82rem; padding: 3px 9px; border-radius: 8px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.metric.good { background: color-mix(in srgb, var(--c-script) 20%, transparent); }
.metric.warn { background: color-mix(in srgb, var(--c-artic) 25%, transparent); }
.compare-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
@media (max-width: 560px) { .compare-grid { grid-template-columns: 1fr; } }

/* Checklist */
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checklist label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.checklist input { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: none; }
.checklist label.on { background: var(--accent-soft); }
.complete-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }

/* Guide */
.guide-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.routine-table { display: grid; gap: 8px; }
.routine-row { display: grid; grid-template-columns: 84px 1fr; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; border-left: 5px solid; }
.routine-row .r { font-weight: 800; font-variant-numeric: tabular-nums; }
.week-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.week-table th, .week-table td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.week-table th { color: var(--muted); font-weight: 600; font-size: .85rem; }
.table-scroll { overflow-x: auto; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .25s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.done-banner { text-align: center; padding: 18px; border-radius: 14px; background: var(--accent-soft); margin-top: 12px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
