/* =========================================================================
   DB 기말고사 학습 사이트 — 공유 디자인 시스템
   Korea University COSE371 Databases / Silberschatz 기반
   ========================================================================= */

:root {
  /* Palette — Korea University crimson 계열 + 모던 뉴트럴 */
  --crimson: #8c1d40;
  --crimson-dark: #6e1531;
  --crimson-light: #b03a5b;
  --crimson-50: #fbeef2;
  --crimson-100: #f6dbe3;

  --ink: #1c2128;
  --ink-soft: #3d444d;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --bg-sunken: #eef1f5;

  --ok: #1f9d57;
  --ok-bg: #e6f6ed;
  --warn: #c2410c;
  --warn-bg: #fdf0e7;
  --bad: #c02929;
  --bad-bg: #fbeaea;
  --info: #1f6feb;
  --info-bg: #e7f0fd;

  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow: 0 4px 16px rgba(16,24,40,.08), 0 2px 6px rgba(16,24,40,.05);
  --shadow-lg: 0 18px 48px rgba(16,24,40,.16);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
          "Noto Sans KR", "Malgun Gothic", Roboto, sans-serif;

  --maxw: 1080px;
}

[data-theme="dark"] {
  --ink: #e6e8eb;
  --ink-soft: #c2c7cf;
  --muted: #9aa3af;
  --line: #2b313a;
  --line-strong: #3a414c;
  --bg: #0f1318;
  --bg-soft: #161b22;
  --bg-sunken: #1c222b;
  --crimson: #e0567d;
  --crimson-light: #ef7c9b;
  --crimson-dark: #c43e64;
  --crimson-50: #241319;
  --crimson-100: #311a23;
  --ok-bg: #102a1c;
  --warn-bg: #2a1a0f;
  --bad-bg: #2a1414;
  --info-bg: #0f1f33;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 6px 20px rgba(0,0,0,.45);
  --shadow-lg: 0 18px 48px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 78px; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
}

/* ---------- Top navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 100;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 11px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 800; color: var(--ink); text-decoration: none;
  font-size: 1.02rem; white-space: nowrap;
}
.brand .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--crimson); box-shadow: 0 0 0 4px var(--crimson-50); }
.topnav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; align-items: center; }
.topnav a {
  color: var(--ink-soft); text-decoration: none; font-size: .86rem; font-weight: 600;
  padding: 6px 10px; border-radius: 8px;
}
.topnav a:hover { background: var(--bg-sunken); color: var(--crimson); }
.topnav a.active { color: var(--crimson); background: var(--crimson-50); }
.theme-toggle {
  border: 1px solid var(--line-strong); background: var(--bg-soft); color: var(--ink-soft);
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer; font-size: 1rem;
  display: inline-flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { border-color: var(--crimson); color: var(--crimson); }

/* ---------- Layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }
main.wrap { padding-bottom: 96px; }
section[id] { scroll-margin-top: 80px; padding-top: 26px; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden;
  background:
    radial-gradient(1100px 380px at 78% -12%, var(--crimson-50), transparent 60%),
    linear-gradient(180deg, var(--bg-soft), var(--bg));
  border-bottom: 1px solid var(--line);
}
.hero-inner { max-width: var(--maxw); margin: 0 auto; padding: 54px 20px 44px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 7px; font-size: .8rem; font-weight: 700;
  color: var(--crimson); background: var(--crimson-50); border: 1px solid var(--crimson-100);
  padding: 5px 12px; border-radius: 999px; letter-spacing: .02em;
}
.hero h1 { font-size: clamp(1.9rem, 4.4vw, 3rem); line-height: 1.18; margin: 18px 0 10px; font-weight: 850; }
.hero h1 .accent { color: var(--crimson); }
.hero p.lead { font-size: 1.08rem; color: var(--ink-soft); max-width: 64ch; margin: 0; }

/* ---------- Headings ---------- */
h2.sec-title {
  font-size: clamp(1.4rem, 2.6vw, 1.85rem); font-weight: 820; margin: 8px 0 4px;
  display: flex; align-items: center; gap: 11px;
}
h2.sec-title .num {
  font-size: .78rem; font-weight: 800; color: var(--crimson); background: var(--crimson-50);
  border: 1px solid var(--crimson-100); border-radius: 8px; padding: 3px 9px; font-variant-numeric: tabular-nums;
}
.sec-sub { color: var(--muted); margin: 2px 0 20px; font-size: 1rem; }
h3.sub { font-size: 1.18rem; font-weight: 750; margin: 30px 0 12px; }
h4.sub { font-size: 1.02rem; font-weight: 720; margin: 22px 0 8px; color: var(--ink); }

/* ---------- Cards ---------- */
.card {
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm);
}
.card.soft { background: var(--bg-soft); }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 820px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }

/* Chapter cards on home */
.chapter-card {
  display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: inherit;
  background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm); transition: transform .14s, box-shadow .14s, border-color .14s;
  position: relative; overflow: hidden;
}
.chapter-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--crimson); opacity: .85;
}
.chapter-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--crimson-light); }
.chapter-card .ch-emoji { font-size: 1.7rem; }
.chapter-card .ch-tag { font-size: .76rem; font-weight: 800; color: var(--crimson); letter-spacing: .04em; }
.chapter-card h3 { margin: 2px 0 4px; font-size: 1.15rem; font-weight: 780; }
.chapter-card p { margin: 0; color: var(--muted); font-size: .92rem; }
.chapter-card .ch-topics { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Chips / tags / badges ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; font-weight: 650;
  padding: 3px 9px; border-radius: 999px; background: var(--bg-sunken); color: var(--ink-soft);
  border: 1px solid var(--line);
}
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: .72rem; font-weight: 800;
  padding: 2px 8px; border-radius: 6px; letter-spacing: .02em;
}
.badge.core { color: var(--bad); background: var(--bad-bg); }
.badge.supp { color: var(--info); background: var(--info-bg); }

/* ---------- Callouts ---------- */
.callout {
  border-radius: var(--radius-sm); padding: 14px 16px 14px 16px; margin: 16px 0;
  border: 1px solid var(--line); border-left-width: 4px; background: var(--bg-soft);
  font-size: .95rem;
}
.callout . co-title { font-weight: 800; display: flex; align-items: center; gap: 7px; margin-bottom: 4px; }
.callout p:last-child { margin-bottom: 0; }
.callout.exam { border-left-color: var(--bad); background: var(--bad-bg); }
.callout.exam .co-title { color: var(--bad); }
.callout.info { border-left-color: var(--info); background: var(--info-bg); }
.callout.info .co-title { color: var(--info); }
.callout.tip { border-left-color: var(--ok); background: var(--ok-bg); }
.callout.tip .co-title { color: var(--ok); }
.callout.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.callout.warn .co-title { color: var(--warn); }
.callout.supp { border-left-color: var(--info); background: var(--info-bg); }
.callout.supp .co-title { color: var(--info); }

/* ---------- Tables ---------- */
.tbl-wrap { overflow-x: auto; margin: 16px 0; border: 1px solid var(--line); border-radius: var(--radius-sm); }
table.data { border-collapse: collapse; width: 100%; font-size: .92rem; }
table.data th, table.data td { padding: 9px 13px; text-align: left; border-bottom: 1px solid var(--line); }
table.data thead th { background: var(--bg-sunken); font-weight: 750; color: var(--ink); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--crimson-50); }
table.data td.c, table.data th.c { text-align: center; }
table.data .yes { color: var(--ok); font-weight: 750; }
table.data .no { color: var(--bad); font-weight: 750; }

/* ---------- Compatibility matrix ---------- */
.matrix { border-collapse: separate; border-spacing: 4px; font-size: .9rem; margin: 8px 0; }
.matrix th, .matrix td { width: 56px; height: 44px; text-align: center; border-radius: 8px; font-weight: 700; }
.matrix th { background: var(--bg-sunken); color: var(--ink-soft); }
.matrix td { cursor: pointer; transition: transform .1s; user-select: none; }
.matrix td.t { background: var(--ok-bg); color: var(--ok); }
.matrix td.f { background: var(--bad-bg); color: var(--bad); }
.matrix td:hover { transform: scale(1.08); outline: 2px solid var(--crimson); }
.matrix td.hot { outline: 3px solid var(--crimson); transform: scale(1.08); }

/* ---------- Code ---------- */
pre, code { font-family: var(--mono); }
code.inline { background: var(--bg-sunken); padding: 1px 6px; border-radius: 5px; font-size: .88em; color: var(--crimson); }
pre.code {
  background: #0d1117; color: #e6edf3; border-radius: var(--radius-sm); padding: 15px 17px;
  overflow-x: auto; font-size: .86rem; line-height: 1.6; border: 1px solid #1f2630; margin: 14px 0;
}
pre.code .cm { color: #8b949e; }
pre.code .kw { color: #ff7b72; }
pre.code .st { color: #a5d6ff; }
pre.code .fn { color: #d2a8ff; }

/* formula block */
.formula {
  background: var(--bg-soft); border: 1px solid var(--line); border-left: 4px solid var(--crimson);
  border-radius: var(--radius-sm); padding: 13px 17px; margin: 14px 0; font-family: var(--mono);
  font-size: .98rem; overflow-x: auto; color: var(--ink);
}
.formula .hl { color: var(--crimson); font-weight: 700; }

/* ---------- Simulator shell ---------- */
.sim {
  border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden;
  margin: 20px 0; box-shadow: var(--shadow-sm); background: var(--bg);
}
.sim-head {
  display: flex; align-items: center; gap: 9px; padding: 12px 16px;
  background: linear-gradient(180deg, var(--bg-sunken), var(--bg-soft));
  border-bottom: 1px solid var(--line); font-weight: 750; font-size: .95rem;
}
.sim-head .tag-int {
  margin-left: auto; font-size: .68rem; font-weight: 800; letter-spacing: .04em; color: #fff;
  background: var(--crimson); padding: 3px 8px; border-radius: 6px;
}
.sim-body { padding: 18px 16px; }
.sim-stage {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 16px; min-height: 80px;
}
.sim-controls { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; margin: 14px 0 4px; }
.sim-note { font-size: .85rem; color: var(--muted); margin-top: 10px; min-height: 1.2em; }
.sim-readout {
  font-family: var(--mono); font-size: .88rem; background: var(--bg-sunken); border-radius: var(--radius-sm);
  padding: 10px 13px; margin-top: 12px; white-space: pre-wrap; border: 1px solid var(--line); color: var(--ink-soft);
}

/* ---------- Buttons & inputs ---------- */
.btn {
  font-family: inherit; font-size: .9rem; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink);
  padding: 8px 15px; border-radius: 9px; transition: all .12s; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { border-color: var(--crimson); color: var(--crimson); background: var(--crimson-50); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--crimson); color: #fff; border-color: var(--crimson); }
.btn.primary:hover { background: var(--crimson-dark); color: #fff; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.sm { padding: 5px 11px; font-size: .82rem; }
.btn.ghost { background: transparent; }

.field { display: inline-flex; flex-direction: column; gap: 3px; font-size: .8rem; color: var(--muted); }
.field label { font-weight: 650; }
.field input[type="number"], .field input[type="text"], .field select {
  font-family: var(--mono); font-size: .9rem; padding: 6px 9px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--ink); width: 110px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--crimson); border-color: var(--crimson); }
input[type="range"] { accent-color: var(--crimson); }

.kpi { display: flex; gap: 14px; flex-wrap: wrap; }
.kpi .k {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; min-width: 110px;
}
.kpi .k .lbl { font-size: .74rem; color: var(--muted); font-weight: 650; }
.kpi .k .val { font-size: 1.4rem; font-weight: 820; font-family: var(--mono); color: var(--crimson); font-variant-numeric: tabular-nums; }

/* ---------- Step / list helpers ---------- */
ul.clean, ol.clean { padding-left: 1.25em; margin: 10px 0; }
ul.clean li, ol.clean li { margin: 6px 0; }
.def { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0; }
.def dt { font-weight: 750; color: var(--crimson); }
.def dd { margin: 0; color: var(--ink-soft); }
@media (max-width: 640px) { .def { grid-template-columns: 1fr; gap: 2px 0; } .def dd { margin-bottom: 8px; } }

/* ---------- Schedule table (transactions) ---------- */
table.sched { border-collapse: collapse; font-family: var(--mono); font-size: .86rem; width: 100%; }
table.sched th { background: var(--bg-sunken); padding: 7px 12px; border: 1px solid var(--line); font-weight: 750; }
table.sched td { padding: 5px 12px; border: 1px solid var(--line); height: 28px; vertical-align: middle; }
table.sched td.active { background: var(--crimson-50); outline: 2px solid var(--crimson); }
table.sched .op-r { color: var(--info); }
table.sched .op-w { color: var(--bad); }

/* progress dots */
.dots { display: inline-flex; gap: 6px; }
.dots .d { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); }
.dots .d.on { background: var(--crimson); }

/* page footer & roadmap link bar */
.page-foot { border-top: 1px solid var(--line); margin-top: 56px; padding: 28px 0; color: var(--muted); font-size: .88rem; }
.page-foot a { color: var(--crimson); }
.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 40px; flex-wrap: wrap; }
.pager a {
  text-decoration: none; color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 16px; flex: 1; min-width: 220px; background: var(--bg-soft);
}
.pager a:hover { border-color: var(--crimson); }
.pager .dir { font-size: .76rem; color: var(--muted); font-weight: 700; }
.pager .ttl { font-weight: 750; color: var(--crimson); }
.pager a.next { text-align: right; }

/* TOC sidebar inside chapter */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; }

/* svg helpers */
svg .lbl { font-family: var(--sans); font-size: 12px; fill: var(--ink); }
svg .lbl-mono { font-family: var(--mono); font-size: 12px; fill: var(--ink); }
.svg-box { width: 100%; height: auto; overflow: visible; }

/* misc */
.hr { border: none; border-top: 1px solid var(--line); margin: 30px 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.fade-in { animation: fadeIn .4s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.pulse { animation: pulse .6s ease; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.06); } }
