:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --text: #14212b;
  --muted: #60717d;
  --primary: #087f8c;
  --primary-dark: #05636e;
  --primary-soft: #e4f4f3;
  --accent: #e9834f;
  --border: #d9e2e7;
  --success: #16865b;
  --danger: #c94b53;
  --shadow: 0 10px 30px rgba(31, 54, 68, 0.08);
  --radius: 16px;
}

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

body {
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(8, 127, 140, 0.08), transparent 28rem),
    linear-gradient(180deg, #f8fafb 0%, var(--bg) 32%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  line-height: 1.65;
}

button, input, textarea, select { font: inherit; }
button { color: inherit; }
.app { width: min(960px, 100%); margin: 0 auto; padding: 34px 20px 64px; }
header { text-align: center; margin-bottom: 28px; }
.home-link {
  display: inline-block;
  margin-bottom: 12px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}
.home-link:hover { color: var(--primary); }
header h1 { font-size: clamp(1.8rem, 4vw, 2.55rem); letter-spacing: -0.04em; }
.subject-mark, .eyebrow {
  display: inline-block;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.18em;
}
.subject-mark { margin-bottom: 7px; }
.subtitle { color: var(--muted); margin-top: 5px; }
.muted { color: var(--muted); }

.tabs {
  position: sticky;
  top: 10px;
  z-index: 20;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  margin-bottom: 24px;
  padding: 5px;
  border: 1px solid rgba(217, 226, 231, 0.8);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.tab {
  flex: 1;
  min-width: 72px;
  padding: 9px 12px;
  border: 0;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}
.tab.active { color: white; background: var(--primary); font-weight: 700; }
.panel { display: none; }
.panel.active { display: block; animation: enter 0.2s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } }

.hero-card, .setup, .done, .workflow-card, .quiz-question {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.hero-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px;
  margin-bottom: 16px;
  background: linear-gradient(135deg, #e7f6f4, #fff);
}
.hero-card h2 { margin: 4px 0; }
.hero-card p { color: var(--muted); }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  padding: 16px 10px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.stat-value { color: var(--primary); font-size: 1.7rem; font-weight: 800; }
.stat-label { color: var(--muted); font-size: 0.78rem; }
.workflow-card { padding: 20px 24px; margin-bottom: 16px; }
.workflow-card h3 { margin-bottom: 7px; }
.workflow-steps { padding-left: 22px; color: var(--muted); font-size: 0.9rem; }
.workflow-steps li + li { margin-top: 3px; }
.action-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  transition: transform 0.15s, border-color 0.15s;
}
.card-btn:hover { transform: translateY(-2px); border-color: var(--primary); }
.card-btn span { color: var(--accent); font-size: 0.75rem; font-weight: 800; letter-spacing: 0.14em; }
.card-btn strong { margin: 7px 0 2px; font-size: 1.05rem; }
.card-btn small { color: var(--muted); }

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 16px;
}
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.filter-bar > * { flex: 1; min-width: 150px; }
input, textarea, select {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 9px;
  background: white;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 127, 140, 0.12);
}
textarea { resize: vertical; }
label { display: block; margin-bottom: 13px; font-size: 0.88rem; font-weight: 650; }

.knowledge-list { display: grid; gap: 12px; }
.knowledge-card {
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 5px 20px rgba(31, 54, 68, 0.04);
}
.knowledge-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.knowledge-card-title { margin-top: 2px; font-size: 1.16rem; font-weight: 750; }
.knowledge-card-meta { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.chapter-tag { color: var(--muted); font-size: 0.8rem; }
.knowledge-content { margin-top: 13px; white-space: pre-wrap; }
.details-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.detail-box {
  padding: 10px 12px;
  color: #425762;
  border-radius: 9px;
  background: var(--bg);
  font-size: 0.86rem;
  white-space: pre-wrap;
}
.detail-box strong { display: block; color: var(--text); margin-bottom: 2px; }
.formula-box {
  min-height: 52px;
  margin-top: 12px;
  padding: 14px;
  overflow-x: auto;
  border-left: 3px solid var(--accent);
  border-radius: 9px;
  background: #fff7f1;
  text-align: center;
}
.knowledge-card-actions { display: flex; gap: 8px; margin-top: 14px; }

.type-tag, .mastery-tag, .domain-tag, .library-tag, .badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
}
.type-tag { margin-bottom: 6px; color: #0b6670; background: #dff3f2; }
.domain-tag { color: #8b4f2d; background: #fff0e7; }
.library-default { color: #405b6a; background: #e7edf1; }
.library-own { color: #694b8e; background: #efe6fa; }
.mastery-0 { color: #963d44; background: #fde8e9; }
.mastery-1 { color: #8a6419; background: #fff3d7; }
.mastery-2 { color: #2b5d8a; background: #e5f0fa; }
.mastery-3, .mastery-4 { color: #176544; background: #dff4e9; }
.badge { color: white; background: var(--primary); }

.btn {
  padding: 10px 18px;
  border: 0;
  border-radius: 9px;
  background: #e4eaed;
  cursor: pointer;
  font-weight: 700;
}
.btn:hover { filter: brightness(0.96); }
.btn.primary { color: white; background: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.correct { color: white; background: var(--success); }
.btn.wrong { color: white; background: var(--danger); }
.btn.small { padding: 6px 11px; font-size: 0.8rem; }
.delete-btn {
  padding: 2px 7px;
  color: var(--muted);
  border: 0;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
}
.delete-btn:hover { color: var(--danger); }

.setup { max-width: 620px; margin: 0 auto; padding: 30px; }
.setup h2 { margin: 4px 0 8px; }
.setup > p { color: var(--muted); margin-bottom: 18px; }
.session { max-width: 720px; margin: 0 auto; }
.progress-row { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.85rem; }
.progress-bar { height: 7px; margin: 7px 0 18px; border-radius: 9px; background: var(--border); overflow: hidden; }
.progress-bar > div { width: 0; height: 100%; border-radius: 9px; background: var(--primary); transition: width 0.25s; }
.flashcard {
  display: grid;
  min-height: 340px;
  padding: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.card-front { text-align: center; }
.card-front h2 { margin: 8px 0; font-size: 1.75rem; }
.flip-hint { margin-top: 38px; color: var(--muted); font-size: 0.86rem; }
.card-back { width: 100%; }
.recall-content { font-size: 1.04rem; white-space: pre-wrap; }
.actions { display: flex; gap: 10px; margin-top: 14px; }
.actions .btn { flex: 1; padding: 13px; }
.done { padding: 38px; text-align: center; }
.done h2 { margin: 5px 0 10px; }
.done p { margin-bottom: 18px; color: var(--muted); }

.quiz-question { padding: 26px; margin-bottom: 14px; }
.quiz-question h2 { margin-top: 7px; font-size: 1.2rem; white-space: pre-wrap; }
.options { display: grid; gap: 9px; }
.option-btn {
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  text-align: left;
}
.option-btn:hover:not(:disabled) { border-color: var(--primary); }
.option-btn.selected-correct { color: #145d3e; border-color: var(--success); background: #e3f5eb; }
.option-btn.selected-wrong { color: #923b42; border-color: var(--danger); background: #fde9ea; }
.numeric-answer { display: grid; grid-template-columns: 2fr 1fr auto; gap: 10px; align-items: end; }
.numeric-answer label { margin: 0; }
.feedback { margin: 13px 0; padding: 13px 15px; border-radius: 10px; white-space: pre-wrap; }
.feedback.correct { color: #145d3e; background: #e3f5eb; }
.feedback.wrong { color: #923b42; background: #fde9ea; }
.score { color: var(--primary) !important; font-size: 2.8rem; font-weight: 850; }

.form-tabs { display: flex; gap: 7px; margin-bottom: 16px; }
.form-tab { padding: 8px 15px; border: 1px solid var(--border); border-radius: 9px; background: white; cursor: pointer; }
.form-tab.active { color: white; border-color: var(--primary); background: var(--primary); }
.form-panel { display: none; padding: 22px; border: 1px solid var(--border); border-radius: 14px; background: white; }
.form-panel.active { display: block; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 14px; }
.library-notice {
  margin-bottom: 16px;
  padding: 9px 12px;
  color: #694b8e;
  border-radius: 9px;
  background: #f4edfb;
  font-size: 0.86rem;
}
.hint { margin-bottom: 12px; color: var(--muted); font-size: 0.84rem; }
.message { margin-top: 12px; padding: 12px; border-radius: 9px; }
.message.success { color: #145d3e; background: #e3f5eb; }
.message.error { color: #923b42; background: #fde9ea; }
.empty-state { padding: 50px 20px; color: var(--muted); text-align: center; }
.hidden { display: none !important; }

.public-list { display: flex; flex-direction: column; gap: 16px; margin-bottom: 16px; }
.public-chapter { border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: white; }
.public-chapter-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: #f4edfb; border-bottom: 1px solid var(--border);
}
.public-chapter-title { font-weight: 650; font-size: 0.95rem; }
.public-item {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.public-item:last-child { border-bottom: none; }
.public-item.already-added { opacity: 0.55; }
.public-item input[type="checkbox"] { margin-top: 4px; width: 18px; height: 18px; flex-shrink: 0; }
.public-item-body { flex: 1; min-width: 0; }
.public-item-title { font-weight: 650; margin: 4px 0; }
.public-item-content { font-size: 0.9rem; color: var(--muted); }
.already-badge {
  display: inline-block; font-size: 0.75rem; color: var(--muted);
  background: var(--bg); padding: 2px 8px; border-radius: 10px; margin-left: 6px;
}
.public-import-bar {
  position: sticky; bottom: 0; display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; background: white; border-radius: 14px;
  border: 1px solid var(--border);
}
.public-import-bar #public-selected-count { flex: 1; color: var(--muted); font-size: 0.9rem; }

@media (max-width: 760px) {
  .app { padding: 24px 12px 48px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .action-cards, .form-grid, .details-grid { grid-template-columns: 1fr; }
  .hero-card { align-items: flex-start; flex-direction: column; }
  .numeric-answer { grid-template-columns: 2fr 1fr; }
  .numeric-answer .btn { grid-column: 1 / -1; }
}

@media (max-width: 460px) {
  .tab { min-width: 62px; padding-inline: 8px; }
  .flashcard { min-height: 320px; padding: 24px 18px; }
  .knowledge-card-header { flex-direction: column; }
  .knowledge-card-meta { width: 100%; justify-content: flex-end; }
}
