:root {
  --bg: #f6f7f3;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --ink: #171a1f;
  --muted: #667085;
  --line: #dfe5dc;
  --accent: #256f54;
  --accent-strong: #174f3b;
  --accent-soft: #dcebe4;
  --warn: #a45b13;
  --danger: #b42318;
  --blue: #315d8f;
  --radius: 8px;
  --shadow: 0 18px 48px rgba(48, 64, 54, .10);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 0;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .58;
}

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 30;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  transform: translateY(-140%);
}

.skip-link:focus {
  transform: translateY(0);
}

.app-loading {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.boot-panel {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.boot-mark,
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.boot-panel span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.login-screen,
.state-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.state-card {
  width: min(540px, 100%);
  padding: 28px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.state-card h1 {
  margin: 14px 0 8px;
  font-size: 28px;
  line-height: 1.15;
  text-wrap: balance;
}

.state-card p {
  color: var(--muted);
  margin: 0 0 22px;
}

.layout {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  padding: 18px 14px;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, .72);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
}

.brand strong {
  display: block;
  line-height: 1.15;
}

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

.nav-group {
  margin: 14px 0;
}

.nav-group-title {
  padding: 0 10px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.nav-link {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 0;
  border-radius: var(--radius);
  padding: 10px;
  margin: 2px 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  transition: transform .2s cubic-bezier(.2,.8,.2,1), background .2s cubic-bezier(.2,.8,.2,1);
}

.nav-link:hover,
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.nav-link:active,
.btn:active {
  transform: translateY(1px) scale(.99);
}

.nav-icon {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 243, .86);
  backdrop-filter: blur(14px);
}

.menu-toggle {
  display: none;
}

.topbar-title {
  min-width: 0;
}

.topbar-title strong {
  display: block;
  font-size: 18px;
}

.topbar-title span {
  color: var(--muted);
  font-size: 13px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.content {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 18px;
}

.page-head h1 {
  margin: 0;
  font-size: clamp(26px, 3vw, 38px);
  line-height: 1.12;
  text-wrap: balance;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
  max-width: 70ch;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.textarea {
  min-height: 96px;
  resize: vertical;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 111, 84, .16);
}

.btn {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  padding: 9px 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  white-space: nowrap;
  transition: transform .18s cubic-bezier(.2,.8,.2,1), background .18s cubic-bezier(.2,.8,.2,1), color .18s;
}

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

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

.btn-secondary {
  background: var(--surface-2);
  color: var(--ink);
}

.btn-danger {
  background: #fde8e7;
  color: var(--danger);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 1px 0 rgba(23, 26, 31, .04);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

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

.panel {
  min-width: 0;
  padding: 18px;
  border-radius: 12px;
  background: var(--surface);
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  background: var(--surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

.data-table th,
.data-table td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: #fbfcfa;
}

.data-table td {
  max-width: 320px;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.badge.active,
.badge.published,
.badge.completed,
.badge.valid {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge.pending,
.badge.grading,
.badge.not_started {
  background: #fff2d8;
  color: var(--warn);
}

.badge.disabled,
.badge.offline,
.badge.revoked,
.badge.deleted {
  background: #fde8e7;
  color: var(--danger);
}

.muted {
  color: var(--muted);
}

.empty {
  padding: 34px 18px;
  text-align: center;
  color: var(--muted);
}

.skeleton {
  min-height: 16px;
  border-radius: 6px;
  background: linear-gradient(90deg, #eef1ec, #f9faf7, #eef1ec);
  background-size: 180% 100%;
  animation: shimmer 1.2s infinite;
}

@keyframes shimmer {
  to {
    background-position: -180% 0;
  }
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  background: rgba(23, 26, 31, .28);
}

.drawer {
  width: min(620px, 100%);
  height: 100dvh;
  overflow-y: auto;
  padding: 22px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.drawer-head h2 {
  margin: 0;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 50;
  display: grid;
  gap: 8px;
}

.toast {
  width: min(360px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.learn-layout,
.exam-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
}

.chapter-list,
.answer-card {
  display: grid;
  gap: 10px;
}

.chapter-item,
.question-card,
.notice-item {
  padding: 14px;
  border-radius: 10px;
  background: var(--surface);
}

.question-card {
  margin-bottom: 12px;
}

.option-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.answer-sheet {
  position: sticky;
  top: 90px;
  align-self: start;
  padding: 14px;
  border-radius: 12px;
  background: var(--surface);
}

.answer-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.answer-dot {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-weight: 800;
}

.answer-dot.done {
  background: var(--accent);
  color: #fff;
}

.mobile-cards {
  display: none;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 25;
    width: min(300px, 86vw);
    transform: translateX(-105%);
    transition: transform .24s cubic-bezier(.2,.8,.2,1);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .menu-toggle {
    display: inline-flex;
  }

  .content {
    padding: 16px;
  }

  .topbar {
    padding: 12px 16px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .grid-2,
  .learn-layout,
  .exam-layout {
    grid-template-columns: 1fr;
  }

  .answer-sheet {
    position: static;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 14px;
  }

  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr;
  }

  .table-wrap {
    display: none;
  }

  .mobile-cards {
    display: grid;
    gap: 10px;
  }

  .mobile-card {
    padding: 14px;
    border-radius: 12px;
    background: var(--surface);
  }

  .mobile-card dl {
    display: grid;
    gap: 6px;
    margin: 10px 0;
  }

  .mobile-card div {
    min-width: 0;
  }

  .mobile-card dt {
    color: var(--muted);
    font-size: 12px;
  }

  .mobile-card dd {
    margin: 0;
    overflow-wrap: anywhere;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .drawer {
    width: 100%;
    padding: 18px;
  }

  .user-pill .user-meta {
    display: none;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .answer-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}
