:root {
  --ink: #101820;
  --navy: #16324f;
  --navy-2: #1e4063;
  --gold: #c99212;
  --gold-2: #e8b923;
  --cream: #f4efe4;
  --paper: #fbf7ef;
  --terracotta: #c45c26;
  --sage: #3d6b54;
  --rose: #9c3b3b;
  --muted: #6b6458;
  --line: #ddd4c4;
  --white: #fffdf8;
  --shadow: 0 16px 40px rgba(16, 24, 32, 0.12);
  --radius: 18px;
  --sidebar: 268px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
  font-family: "Outfit", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #2a5278 0%, transparent 50%),
              linear-gradient(180deg, #0d1824 0%, #13283a 40%, #1a334c 100%);
  color: var(--ink);
  letter-spacing: 0.01em;
}
button, input, select, textarea { font-family: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }

#app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #0f2032 0%, #16324f 100%);
  color: #f3ead6;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(232, 185, 35, 0.18);
  z-index: 20;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 8px 16px;
  cursor: pointer;
}
.brand-mark {
  width: 46px; height: 46px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #e8b923, #c99212);
  color: #1a1204;
  font-weight: 800;
  font-size: 18px;
  box-shadow: 0 8px 18px rgba(201, 146, 18, 0.28);
}
.brand strong { display: block; font-size: 18px; letter-spacing: 0.04em; }
.brand small { color: #c9bfa8; }

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; overflow: auto; }
.nav-item {
  background: transparent;
  border: 0;
  color: #d9d0be;
  text-align: left;
  padding: 11px 12px;
  border-radius: 12px;
  font-size: 14.5px;
  font-weight: 500;
}
.nav-item:hover, .nav-item.active {
  background: rgba(232, 185, 35, 0.12);
  color: #ffe9a6;
}
.nav-item.active { box-shadow: inset 3px 0 0 var(--gold-2); }
.side-foot { display: flex; flex-direction: column; gap: 10px; }
.streak-chip {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(232,185,35,0.25);
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  color: #ffe9a6;
}
.ghost-btn {
  background: transparent;
  border: 1px solid rgba(243,234,214,0.2);
  color: #f3ead6;
  padding: 10px 12px;
  border-radius: 12px;
}

.main-wrap { min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 22px;
  position: sticky;
  top: 0;
  z-index: 15;
  background: rgba(19, 40, 58, 0.72);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(232,185,35,0.12);
}
.search-wrap { position: relative; flex: 1; }
.search-wrap input {
  width: 100%;
  background: #fbf7ef;
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  outline: none;
  font-size: 14px;
}
.search-results {
  position: absolute;
  top: 48px; left: 0; right: 0;
  background: var(--white);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 30;
}
.search-results button {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
}
.top-actions { display: flex; gap: 8px; align-items: center; }
.mode-pill {
  background: rgba(232,185,35,0.15);
  color: #ffe9a6;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}
.menu-btn {
  display: none;
  width: 42px; height: 42px;
  background: #fbf7ef;
  border: 0;
  border-radius: 12px;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 10px;
}
.menu-btn span { height: 2px; background: var(--navy); display: block; }

#viewRoot { padding: 22px; }

.hero {
  background:
    linear-gradient(135deg, rgba(16,24,32,0.18), transparent 40%),
    url("data:image/svg+xml,%3Csvg width='80' height='80' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 80L80 0H60L0 60z' fill='%23c99212' fill-opacity='0.05'/%3E%3C/svg%3E"),
    linear-gradient(135deg, #fbf7ef, #efe3c8 60%, #e8d7a8);
  border-radius: 28px;
  padding: 32px;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 24px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.hero h1 {
  font-family: "Source Serif 4", Georgia, serif;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.12;
  color: #13283a;
}
.hero p { margin: 12px 0 20px; color: var(--muted); max-width: 560px; }
.kicker {
  display: inline-block;
  background: #13283a;
  color: #e8b923;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 8px;
}
.stat-card, .panel, .card, .topic-card, .result-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stat-card { padding: 12px; }
.stat-card b { display: block; font-size: 22px; color: var(--navy); }
.stat-card span { color: var(--muted); font-size: 12px; }
.hero-aside {
  background: #13283a;
  color: #f3ead6;
  border-radius: 22px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.hero-aside h3 { font-family: "Source Serif 4", serif; }
.progress-ring-wrap { display: flex; align-items: center; gap: 14px; }
.ring {
  width: 92px; height: 92px;
  border-radius: 50%;
  background: conic-gradient(#e8b923 var(--p), #2a425c 0);
  display: grid; place-items: center;
}
.ring span {
  width: 68px; height: 68px;
  background: #13283a;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700;
}

.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin: 28px 0 14px;
}
.section-head h2 {
  font-family: "Source Serif 4", serif;
  font-size: 26px;
  color: #f4efe4;
}
.section-head p, .muted { color: #c9bfa8; }
.card { padding: 18px; }
.card h3 { font-size: 17px; margin-bottom: 6px; }
.card p { color: var(--muted); font-size: 13.5px; }
.meta { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.chip {
  background: #efe6d4;
  color: #3d3424;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}
.chip.gold { background: #f3e1a8; color: #6a4b08; }
.chip.green { background: #d7eadf; color: #214c38; }
.chip.red { background: #f3d5d0; color: #7a2b22; }
.chip.blue { background: #d7e4f3; color: #1a3d63; }

.primary-btn, .secondary-btn, .danger-btn, .ghost-dark {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  font-weight: 600;
}
.primary-btn {
  background: linear-gradient(180deg, #e8b923, #c99212);
  color: #1a1204;
}
.primary-btn.compact { padding: 10px 14px; font-size: 13px; }
.secondary-btn { background: #13283a; color: #f3ead6; }
.danger-btn { background: var(--terracotta); color: white; }
.ghost-dark {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--navy);
}
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.topic-card {
  padding: 16px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.topic-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.topic-card .bar {
  height: 7px;
  background: #ece4d4;
  border-radius: 99px;
  overflow: hidden;
  margin-top: 12px;
}
.topic-card .bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #c99212, #3d6b54);
}

.exam-shell {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
  min-height: calc(100vh - 110px);
}
.exam-main {
  background: var(--paper);
  border-radius: 22px;
  padding: 18px;
  border: 1px solid var(--line);
}
.exam-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.timer {
  background: #13283a;
  color: #e8b923;
  font-variant-numeric: tabular-nums;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 700;
  letter-spacing: 0.06em;
}
.timer.warn { background: #9c3b3b; color: #fff; }
.q-text {
  font-size: 18px;
  line-height: 1.55;
  margin: 10px 0 16px;
  font-family: "Source Serif 4", serif;
}
.options { display: grid; gap: 10px; }
.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: white;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  text-align: left;
}
.option.selected { border-color: #c99212; background: #fff6dc; }
.option.correct { border-color: #3d6b54; background: #e6f4ec; }
.option.wrong { border-color: #9c3b3b; background: #f8e4e1; }
.opt-key {
  min-width: 28px; height: 28px;
  border-radius: 8px;
  background: #efe6d4;
  display: grid; place-items: center;
  font-weight: 700;
}
.explain {
  margin-top: 14px;
  background: #eef6f1;
  border-left: 4px solid #3d6b54;
  padding: 12px 14px;
  border-radius: 10px;
}
.exam-actions {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.palette {
  background: var(--white);
  border-radius: 22px;
  padding: 14px;
  border: 1px solid var(--line);
  height: fit-content;
  position: sticky;
  top: 88px;
}
.palette h4 { margin-bottom: 10px; }
.palette-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.p-btn {
  height: 34px;
  border-radius: 8px;
  border: 0;
  background: #ece4d4;
  font-weight: 600;
}
.p-btn.answered { background: #3d6b54; color: white; }
.p-btn.marked { background: #c99212; color: #1a1204; }
.p-btn.current { outline: 2px solid #13283a; }
.p-btn.unanswered { background: #9c3b3b; color: white; }
.p-btn.skipped { background: #7a6a4a; color: white; }
.legend { display: grid; gap: 6px; margin-top: 12px; font-size: 12px; color: var(--muted); }

.result-hero {
  background: linear-gradient(135deg, #13283a, #1e4d73);
  color: #f3ead6;
  border-radius: 24px;
  padding: 28px;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 16px;
}
.score-xl {
  font-family: "Source Serif 4", serif;
  font-size: 64px;
  color: #e8b923;
  line-height: 1;
}
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 90px 1fr 40px; gap: 8px; align-items: center; font-size: 13px; }
.bar-row i { height: 8px; background: #2a425c; border-radius: 99px; overflow: hidden; display: block; }
.bar-row i b { display: block; height: 100%; background: #e8b923; }

table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: 16px; overflow: hidden; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
th { background: #efe6d4; }

.modal-back {
  position: fixed; inset: 0;
  background: rgba(10,16,24,0.55);
  display: grid; place-items: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  background: var(--paper);
  border-radius: 20px;
  padding: 22px;
  max-width: 520px;
  width: 100%;
  box-shadow: var(--shadow);
}
.toast {
  position: fixed;
  right: 18px; bottom: 78px;
  background: #13283a;
  color: #f3ead6;
  padding: 12px 16px;
  border-radius: 12px;
  z-index: 60;
  box-shadow: var(--shadow);
}

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
}
.tab.active { background: #13283a; color: #e8b923; border-color: #13283a; }

.typing-box {
  width: 100%;
  min-height: 160px;
  border-radius: 16px;
  border: 1.5px solid var(--line);
  padding: 14px;
  font-size: 16px;
  line-height: 1.6;
  background: white;
}
.passage {
  background: #fff;
  border-radius: 16px;
  padding: 16px;
  border: 1px dashed #c99212;
  margin-bottom: 12px;
  font-size: 16.5px;
  line-height: 1.7;
}
.passage .ok { background: #d7eadf; }
.passage .bad { background: #f3d5d0; }
.passage .cur { border-bottom: 2px solid #c99212; }

.profile-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
}

.hidden { display: none !important; }
.overlay-exam .sidebar, .overlay-exam .topbar, .overlay-exam .mobile-nav { display: none !important; }
.overlay-exam #app { grid-template-columns: 1fr; }
.overlay-exam #viewRoot { padding: 12px; }

.mobile-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: #0f2032;
  z-index: 25;
  grid-template-columns: repeat(5, 1fr);
}
.mobile-nav button {
  background: transparent;
  border: 0;
  color: #d9d0be;
  padding: 12px 4px 16px;
  font-size: 12px;
}

.notice {
  background: #fff6dc;
  border: 1px solid #e8b923;
  color: #5b4308;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
}
.mini-q {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.subject-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .exam-shell { grid-template-columns: 1fr; }
  .palette { position: static; }
  .hero, .result-hero { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    transform: translateX(-110%);
    transition: transform .2s ease;
    width: min(84vw, 300px);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: flex; }
  .grid-3, .grid-2, .profile-grid { grid-template-columns: 1fr; }
  .mobile-nav { display: grid; }
  #viewRoot { padding: 14px 14px 88px; }
  .mode-pill { display: none; }
}
