:root {
  --brand: #F40009;
  --brand-dark: #C00007;
  --brand-soft: #FEE2E2;
  --ink: #1F2937;
  --muted: #475569;
  --line: #E5E7EB;
  --bg: #F9FAFB;
  --card: #FFFFFF;
  --accent: #FEF3C7;
  --highlight: #FFFBEB;
  --ok: #059669;
  --warn: #D97706;
  --err: #DC2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Pretendard', -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  line-height: 1.7; font-size: 18px;
}

/* ---------- Header ---------- */
header.app-header {
  background: #fff; border-bottom: 3px solid var(--brand);
  padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand .logo {
  font-family: 'Times New Roman', 'Georgia', serif;
  font-style: italic; font-weight: 700; font-size: 34px;
  color: var(--brand); letter-spacing: -0.5px;
}
.brand .subtitle { color: var(--muted); font-size: 15px; font-weight: 600; }
.tool-title {
  font-weight: 800; color: var(--brand-dark); font-size: 22px;
  background: var(--brand-soft); padding: 6px 14px; border-radius: 8px;
  border: 2px solid var(--brand);
}
.header-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.learner-chip {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px; font-size: 15px;
  color: var(--muted); font-weight: 600;
}
.learner-chip strong { color: var(--ink); }

.progress-wrap { display: flex; align-items: center; gap: 14px; min-width: 280px; }
.progress-bar { flex: 1; height: 12px; background: var(--line); border-radius: 6px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand); transition: width .25s ease; width: 0%; }
.progress-text { font-size: 16px; color: var(--ink); white-space: nowrap; font-weight: 700; }
.sync-badge {
  font-size: 15px; color: var(--ok); font-weight: 700;
  display: flex; align-items: center; gap: 6px; transition: color .2s;
  padding: 4px 10px; border-radius: 6px;
}
.sync-badge.flash { animation: flash-save .8s ease; }
.sync-badge.syncing { color: var(--warn); }
.sync-badge.offline { color: var(--err); background: #FEF2F2; }
@keyframes flash-save { 0%{color:var(--ok);transform:scale(1)} 30%{color:var(--brand);transform:scale(1.06)} 100%{color:var(--ok);transform:scale(1)} }

/* ---------- Layout ---------- */
main.app-main {
  display: grid; grid-template-columns: 320px 1fr; gap: 24px;
  max-width: 1320px; margin: 24px auto; padding: 0 24px;
}
nav.step-nav {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  height: fit-content; position: sticky; top: 110px;
  max-height: calc(100vh - 140px); overflow-y: auto;
}
nav.step-nav h3 {
  margin: 0 0 10px; font-size: 15px; color: var(--muted);
  font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
}
nav.step-nav .nav-group { margin-bottom: 18px; }
nav.step-nav button.nav-item {
  width: 100%; text-align: left; background: none; border: none;
  border-left: 4px solid transparent;
  padding: 12px 14px; border-radius: 8px; color: var(--ink);
  font-size: 17px; font-family: inherit; cursor: pointer;
  display: flex; align-items: center; gap: 12px;
  transition: background .15s ease, border-color .15s ease;
  min-height: 48px;
}
nav.step-nav button.nav-item:hover { background: var(--bg); }
nav.step-nav button.nav-item.active {
  background: var(--brand-soft); color: var(--brand-dark);
  font-weight: 800; border-left-color: var(--brand);
}
nav.step-nav button.nav-item.active::after {
  content: "◀"; margin-left: auto; color: var(--brand); font-size: 14px;
}
nav.step-nav button.nav-item .status {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line);
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--muted); font-weight: 700;
}
nav.step-nav button.nav-item.filled .status { background: var(--brand); border-color: var(--brand); color: #fff; }
nav.step-nav button.nav-item.filled .status::after { content: "✓"; }
nav.step-nav button.nav-item.active .status { border-color: var(--brand); }

section.work-area {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 32px; min-height: 500px;
}

/* ---------- Focus banner ---------- */
.focus-banner {
  display: flex; align-items: center; gap: 14px;
  background: linear-gradient(135deg, #FFF5F5 0%, #FFE5E5 100%);
  border: 2px solid var(--brand);
  border-radius: 12px; padding: 16px 20px;
  margin: -8px -8px 24px; font-size: 18px;
}
.focus-banner .focus-step-no {
  background: var(--brand); color: #fff;
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 800; flex-shrink: 0;
}
.focus-banner .focus-text { flex: 1; }
.focus-banner .focus-label { font-size: 15px; color: var(--muted); font-weight: 700; letter-spacing: 0.3px; }
.focus-banner .focus-now { font-size: 20px; font-weight: 800; color: var(--brand-dark); }

/* ---------- Work area ---------- */
.course-badge {
  display: inline-block; background: var(--brand-soft); color: var(--brand-dark);
  padding: 5px 14px; border-radius: 6px; font-size: 16px; font-weight: 800; letter-spacing: 0.5px;
}
.work-area h2 { margin: 14px 0 6px; font-size: 32px; font-weight: 800; color: var(--ink); letter-spacing: -0.3px; }
.work-area .step-subtitle { color: var(--muted); margin-bottom: 24px; font-size: 18px; font-weight: 500; }
.guide-box {
  background: #F0F9FF; border-left: 5px solid #0284C7;
  padding: 16px 18px; border-radius: 8px; margin: 18px 0; font-size: 18px;
}
.guide-box h4 { margin: 0 0 10px; font-size: 17px; color: #0284C7; font-weight: 800; }
.example-box {
  background: var(--accent); border-left: 5px solid #D97706;
  padding: 16px 18px; border-radius: 8px; margin: 18px 0;
  font-size: 17px; white-space: pre-wrap;
  font-family: 'Pretendard', system-ui, sans-serif;
}
.example-box h4 { margin: 0 0 10px; font-size: 17px; color: #D97706; font-weight: 800; }

.write-area {
  background: var(--highlight);
  border: 3px dashed var(--brand);
  border-radius: 12px;
  padding: 20px;
  margin: 24px 0 12px;
}
.write-area .input-label {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 12px; gap: 8px; flex-wrap: wrap;
}
.write-area .input-label h4 { margin: 0; font-size: 20px; font-weight: 800; color: var(--brand-dark); }
.write-area .input-label .actions { display: flex; gap: 8px; flex-wrap: wrap; }

textarea.answer {
  width: 100%; min-height: 240px; padding: 16px;
  border: 2px solid var(--line); border-radius: 10px;
  font-family: 'Pretendard', system-ui, sans-serif;
  font-size: 18px; resize: vertical; line-height: 1.7;
  color: var(--ink); background: #fff;
}
textarea.answer:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
textarea.answer.warn { border-color: var(--err); animation: shake .35s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-4px)} 75%{transform:translateX(4px)} }
textarea.answer::placeholder { color: #94A3B8; }

.empty-warning {
  background: #FEF2F2; border-left: 5px solid var(--err);
  padding: 14px 16px; border-radius: 8px;
  margin: 12px 0 0; font-size: 17px; color: var(--err); font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}

/* ---------- Buttons ---------- */
.button-row {
  display: flex; justify-content: space-between; gap: 12px;
  margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--line); flex-wrap: wrap;
}
button.btn {
  min-height: 48px; padding: 12px 24px; border-radius: 10px; border: none;
  font-family: inherit; font-size: 17px; font-weight: 700;
  cursor: pointer; transition: background .15s, transform .05s;
}
button.btn:active { transform: translateY(1px); }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
button.btn-primary { background: var(--brand); color: #fff; }
button.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
button.btn-secondary { background: var(--bg); color: var(--ink); border: 1px solid var(--line); }
button.btn-secondary:hover:not(:disabled) { background: var(--line); }
button.btn-ghost { background: transparent; color: var(--muted); }
button.btn-ghost:hover:not(:disabled) { color: var(--ink); background: var(--bg); }
button.btn-sm { min-height: 40px; padding: 8px 14px; font-size: 16px; font-weight: 700; }
button.btn-danger { background: var(--err); color: #fff; }
button.btn-danger:hover:not(:disabled) { background: #B91C1C; }

/* ---------- AI feedback ---------- */
.ai-feedback {
  background: #ECFDF5; border-left: 5px solid var(--ok);
  padding: 16px 18px; border-radius: 8px;
  margin: 18px 0 0; font-size: 17px; white-space: pre-wrap; line-height: 1.7;
}
.ai-feedback h4 { margin: 0 0 10px; font-size: 17px; color: var(--ok); font-weight: 800; }
.ai-feedback.loading { background: #FFFBEB; border-left-color: var(--warn); color: var(--warn); }
.ai-feedback.error { background: #FEF2F2; border-left-color: var(--err); color: var(--err); }

/* ---------- Synthesis ---------- */
.synth-result {
  background: #0F172A; color: #E2E8F0;
  padding: 22px; border-radius: 10px;
  font-family: 'JetBrains Mono', 'Menlo', 'Monaco', 'D2Coding', monospace;
  font-size: 16px; line-height: 1.75;
  white-space: pre-wrap; margin: 18px 0;
  max-height: 60vh; overflow-y: auto;
}
.synth-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Toast & modal ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  padding: 16px 26px; border-radius: 10px;
  font-size: 17px; font-weight: 700;
  opacity: 0; pointer-events: none;
  transition: opacity .2s; z-index: 100;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 14px; padding: 28px;
  max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal h3 { margin: 0 0 10px; font-size: 24px; }
.modal p { color: var(--muted); font-size: 17px; margin: 0 0 18px; }
.modal-status { margin: 14px 0 0; padding: 12px 16px; border-radius: 8px; font-size: 16px; font-weight: 700; }
.modal-status.ok { background: #ECFDF5; color: var(--ok); }
.modal-status.err { background: #FEF2F2; color: var(--err); }
.modal-status.loading { background: #FFFBEB; color: var(--warn); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; flex-wrap: wrap; }

/* ---------- Entry / login page ---------- */
.entry-shell {
  max-width: 540px; margin: 80px auto; padding: 0 24px;
}
.entry-card {
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  padding: 40px 36px; box-shadow: 0 12px 32px rgba(15,23,42,0.06);
}
.entry-card h1 {
  margin: 0 0 8px; font-size: 28px; font-weight: 800; color: var(--brand-dark);
}
.entry-card .entry-sub { color: var(--muted); margin: 0 0 28px; font-size: 17px; line-height: 1.65; }
.entry-card label { display: block; font-size: 16px; font-weight: 700; color: var(--ink); margin: 18px 0 8px; }
.entry-card input[type="text"] {
  width: 100%; padding: 14px 16px;
  border: 2px solid var(--line); border-radius: 10px;
  font-size: 18px; font-family: inherit;
}
.entry-card input[type="text"]:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.entry-card .entry-actions { margin-top: 28px; display: flex; gap: 10px; }
.entry-card .entry-actions button { flex: 1; }
.entry-status {
  margin-top: 16px; padding: 12px 14px; border-radius: 8px;
  font-size: 15px; font-weight: 700; text-align: center;
}
.entry-status.err { background: #FEF2F2; color: var(--err); }
.entry-status.loading { background: #FFFBEB; color: var(--warn); }
.entry-status.ok { background: #ECFDF5; color: var(--ok); }
.entry-help {
  margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line);
  font-size: 14px; color: var(--muted); line-height: 1.6;
}

/* ---------- Footer ---------- */
footer.app-footer {
  border-top: 1px solid var(--line); background: #fff;
  padding: 18px 24px; margin-top: 48px;
  font-size: 16px; color: var(--muted);
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  body { font-size: 17px; }
  header.app-header { padding: 12px 16px; gap: 8px; }
  .brand .logo { font-size: 28px; }
  .tool-title { font-size: 19px; }
  .progress-wrap { width: 100%; min-width: 0; }
  .header-actions { width: 100%; }
  main.app-main { grid-template-columns: 1fr; padding: 0 16px; gap: 16px; }
  nav.step-nav { position: static; max-height: none; }
  section.work-area { padding: 22px; }
  .work-area h2 { font-size: 26px; }
  .button-row { flex-direction: column-reverse; }
  button.btn { width: 100%; }
  .focus-banner { padding: 14px; }
  .focus-banner .focus-now { font-size: 18px; }
  .entry-shell { margin: 40px auto; }
  .entry-card { padding: 28px 22px; }
}

@media print {
  header.app-header, nav.step-nav, .button-row, footer.app-footer, .synth-actions, .modal-overlay, .focus-banner { display: none !important; }
  main.app-main { display: block; padding: 0; }
  section.work-area { border: none; padding: 0; }
  .synth-result { background: #fff; color: #000; border: 1px solid #000; max-height: none; }
  .write-area { border: 1px solid #000; background: #fff; }
}
