:root {
  color-scheme: light;
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-alt: #eef4f1;
  --ink: #1f2933;
  --muted: #64707d;
  --line: #d9e1e7;
  --accent: #1f7a6d;
  --accent-strong: #135c52;
  --accent-soft: #d9f0ea;
  --warn: #b54708;
  --danger: #b42318;
  --ok: #16703a;
  --shadow: 0 18px 45px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    "Pretendard",
    "Noto Sans KR",
    "Segoe UI",
    system-ui,
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

button:hover,
.link-btn:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "top top"
    "side main";
  min-height: 100vh;
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
}

.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 800;
  text-decoration: none;
}

.control-panel {
  grid-area: side;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
  overflow: auto;
}

.control-panel section + section {
  margin-top: 26px;
}

.control-panel h2 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #344450;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface);
}

.chip.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: #9ed8cc;
  font-weight: 700;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf1f4;
  gap: 3px;
}

.mode-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
}

.mode-btn.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 6px rgba(31, 41, 51, 0.08);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-card {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-card strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

#searchInput {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.stats-list {
  display: grid;
  gap: 8px;
  font-size: 13px;
}

.stat-row {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 8px;
}

.mini-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3e9ee;
}

.mini-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
}

.quiz-area {
  grid-area: main;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: 24px;
  min-width: 0;
}

.progress-strip,
.quiz-panel,
.quiz-nav {
  width: min(980px, 100%);
  margin: 0 auto;
}

.progress-strip {
  display: grid;
  gap: 10px;
}

.progress-strip > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
}

.progress-strip strong {
  color: var(--ink);
}

.progress-track {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e1e7ec;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), #6a8f42);
  transition: width 0.2s ease;
}

.quiz-panel {
  align-self: stretch;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef2f6;
  color: #40505d;
  font-size: 12px;
}

.meta-pill.source {
  background: var(--surface-alt);
  color: var(--accent-strong);
}

.question-tools {
  display: flex;
  justify-content: flex-end;
  margin: -6px 0 14px;
}

.bookmark-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 8px;
}

.bookmark-btn.active {
  color: #7a4b00;
  border-color: #f5ca6a;
  background: #fff5d6;
  font-weight: 700;
}

.question-text {
  margin: 0 0 22px;
  font-size: 22px;
  line-height: 1.58;
  word-break: keep-all;
}

.choices {
  display: grid;
  gap: 10px;
}

.choice-btn {
  min-height: 48px;
  padding: 10px 14px;
  text-align: left;
  line-height: 1.45;
  word-break: keep-all;
}

.choice-btn.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 700;
}

.answer-input {
  width: 100%;
  min-height: 48px;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.feedback {
  display: none;
  margin-top: 20px;
  padding: 16px;
  border-radius: 8px;
  line-height: 1.6;
}

.feedback.visible {
  display: block;
}

.feedback.correct {
  background: #e7f7ed;
  color: var(--ok);
}

.feedback.wrong {
  background: #fff1e6;
  color: var(--warn);
}

.source-snippet {
  margin-top: 10px;
  color: #43515f;
}

.quiz-nav {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 10px;
}

.primary-btn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.primary-btn:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.ghost-btn {
  background: #f2f6f8;
}

.danger-btn {
  color: var(--danger);
  background: #fff7f7;
  border-color: #ffd5d2;
}

.empty-state {
  display: grid;
  min-height: 320px;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "side"
      "main";
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 18px;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }

  .top-actions .link-btn {
    flex: 1 1 100%;
  }

  .control-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 16px;
  }

  .quiz-area {
    padding: 16px;
  }

  .quiz-panel {
    padding: 20px;
  }

  .question-text {
    font-size: 18px;
    line-height: 1.55;
  }
}

@media (max-width: 520px) {
  .quiz-nav {
    grid-template-columns: 1fr;
  }

  .stat-row {
    grid-template-columns: 48px 1fr;
  }

  .stat-row span:last-child {
    grid-column: 2;
  }
}
