*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #0d1117;
  --bg-soft: #141b26;
  --surface: #171f2b;
  --surface-2: #1d2634;
  --border: #26313f;
  --border-soft: #1f2836;
  --text: #e7edf5;
  --text-soft: #9aa8bb;
  --text-dim: #6d7d92;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --easy: #56c48a;
  --medium: #e0a83c;
  --hard: #e2705f;
  --danger: #e2705f;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme='light'] {
  --bg: #f6f8fb;
  --bg-soft: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f4f7fb;
  --border: #dde4ed;
  --border-soft: #e7ecf3;
  --text: #16202e;
  --text-soft: #52637a;
  --text-dim: #7a8798;
  --accent: #2f62e6;
  --accent-soft: rgba(47, 98, 230, 0.1);
  --easy: #2f9d67;
  --medium: #b77b12;
  --hard: #cc4f3c;
  --danger: #cc4f3c;
  --shadow: 0 10px 26px rgba(23, 38, 63, 0.08);
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 0.5em;
  line-height: 1.25;
  font-weight: 650;
  letter-spacing: -0.011em;
}

h1 {
  font-size: 1.75rem;
}

h2 {
  font-size: 1.3rem;
}

h3 {
  font-size: 1.06rem;
}

p {
  margin: 0 0 1em;
}

p:last-child {
  margin-bottom: 0;
}

img {
  max-width: 100%;
  height: auto;
}

.shell {
  width: min(1120px, 100% - 2.5rem);
  margin-inline: auto;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}

.site-header .shell {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 62px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 650;
  color: var(--text);
  letter-spacing: -0.015em;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), #7f5bff);
  color: #fff;
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 700;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.site-nav a {
  padding: 0.42rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text-soft);
  font-size: 0.92rem;
  font-weight: 500;
}

.site-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.site-nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-soft);
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  border-color: var(--text-dim);
}

.icon-button svg {
  width: 17px;
  height: 17px;
}

:root[data-theme='light'] .icon-button .moon,
:root[data-theme='dark'] .icon-button .sun {
  display: none;
}

main {
  padding: 2.5rem 0 4rem;
}

.page-head {
  margin-bottom: 2rem;
}

.page-head p {
  color: var(--text-soft);
  max-width: 62ch;
}

.eyebrow {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero {
  padding: 2.25rem 2rem;
  margin-bottom: 2.25rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background:
    radial-gradient(900px 200px at 8% -30%, var(--accent-soft), transparent),
    var(--surface);
}

.hero h1 {
  font-size: clamp(1.6rem, 3.4vw, 2.15rem);
  margin-bottom: 0.6rem;
}

.hero p {
  color: var(--text-soft);
  max-width: 60ch;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.4rem;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.58rem 1.05rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.93rem;
  font-weight: 560;
  cursor: pointer;
  transition: filter 0.15s ease, background 0.15s ease;
}

.button:hover {
  filter: brightness(1.08);
  text-decoration: none;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

.button-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.button-ghost:hover {
  background: var(--surface-2);
  filter: none;
}

.button-danger {
  background: transparent;
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
  color: var(--danger);
}

.button-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  filter: none;
}

.button-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.85rem;
}

.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.topic-card {
  position: relative;
  display: flex;
  flex-direction: column;
  padding: 1.35rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  overflow: hidden;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.topic-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  background: var(--tone, var(--accent));
}

.topic-card:hover {
  border-color: color-mix(in srgb, var(--tone, var(--accent)) 45%, var(--border));
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  text-decoration: none;
}

.topic-card-top {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  margin-bottom: 0.85rem;
}

.topic-icon {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--tone, var(--accent)) 16%, transparent);
  color: var(--tone, var(--accent));
  flex: none;
}

.topic-icon svg {
  width: 19px;
  height: 19px;
}

.topic-number {
  margin-left: auto;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 0.82rem;
}

.topic-card h3 {
  margin-bottom: 0.3rem;
}

.topic-card .subtitle {
  color: var(--text-soft);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.count-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: auto;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-soft);
  font-size: 0.78rem;
  font-weight: 550;
  white-space: nowrap;
}

.pill-easy {
  background: color-mix(in srgb, var(--easy) 15%, transparent);
  color: var(--easy);
}

.pill-medium {
  background: color-mix(in srgb, var(--medium) 16%, transparent);
  color: var(--medium);
}

.pill-hard {
  background: color-mix(in srgb, var(--hard) 15%, transparent);
  color: var(--hard);
}

.pill-muted {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  margin-bottom: 1.35rem;
}

.filter-group {
  display: inline-flex;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}

.filter-group button {
  padding: 0.34rem 0.75rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-soft);
  font: inherit;
  font-size: 0.87rem;
  font-weight: 520;
  cursor: pointer;
}

.filter-group button:hover {
  color: var(--text);
}

.filter-group button.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

input[type='text'],
input[type='search'],
input[type='password'],
select,
textarea {
  width: 100%;
  padding: 0.52rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.93rem;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  outline-offset: -1px;
  border-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 110px;
  font-family: var(--mono);
  font-size: 0.87rem;
  line-height: 1.55;
}

.search-field {
  position: relative;
  flex: 1 1 220px;
  max-width: 320px;
}

.exercise-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.exercise-row {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  padding: 0.95rem 1.15rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.exercise-row:hover {
  border-color: var(--border);
  transform: translateX(2px);
  text-decoration: none;
}

.exercise-row-main {
  min-width: 0;
  flex: 1;
}

.exercise-row h3 {
  margin: 0 0 0.2rem;
  font-size: 0.99rem;
}

.exercise-row .excerpt {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.87rem;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.exercise-row-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
}

.difficulty-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: none;
}

.difficulty-dot.easy {
  background: var(--easy);
}

.difficulty-dot.medium {
  background: var(--medium);
}

.difficulty-dot.hard {
  background: var(--hard);
}

.detail-head {
  margin-bottom: 1.6rem;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.9rem;
  color: var(--text-dim);
  font-size: 0.87rem;
}

.breadcrumb a {
  color: var(--text-soft);
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.panel {
  padding: 1.5rem 1.7rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 1.1rem;
}

.panel > h2 {
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.prose > :first-child {
  margin-top: 0;
}

.prose > :last-child {
  margin-bottom: 0;
}

.prose h3,
.prose h4,
.prose h5 {
  margin-top: 1.5em;
}

.prose ul,
.prose ol {
  margin: 0 0 1em;
  padding-left: 1.35em;
}

.prose li {
  margin-bottom: 0.35em;
}

.prose code {
  padding: 0.13em 0.38em;
  border-radius: 5px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  font-family: var(--mono);
  font-size: 0.86em;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 1em;
}

.prose table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.prose th,
.prose td {
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  text-align: left;
}

.prose th {
  background: var(--surface-2);
  font-weight: 600;
}

pre.code {
  margin: 0 0 1em;
  padding: 1rem 1.15rem;
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  font-family: var(--mono);
  font-size: 0.855rem;
  line-height: 1.6;
  tab-size: 4;
}

pre.code code {
  padding: 0;
  border: 0;
  background: none;
  font-size: inherit;
}

.tok-keyword {
  color: #ff7ab2;
}

.tok-string {
  color: #a5d6a7;
}

.tok-comment {
  color: var(--text-dim);
  font-style: italic;
}

.tok-number {
  color: #d9a35a;
}

.tok-builtin {
  color: #6cc7f5;
}

.tok-call {
  color: #c3a6ff;
}

.tok-constant {
  color: #ff9d6b;
}

.tok-operator {
  color: #8fa3bd;
}

:root[data-theme='light'] .tok-keyword {
  color: #b3226f;
}

:root[data-theme='light'] .tok-string {
  color: #1f7a3d;
}

:root[data-theme='light'] .tok-number {
  color: #9a5a00;
}

:root[data-theme='light'] .tok-builtin {
  color: #0b6a97;
}

:root[data-theme='light'] .tok-call {
  color: #6733c4;
}

:root[data-theme='light'] .tok-constant {
  color: #b1531b;
}

:root[data-theme='light'] .tok-operator {
  color: #5c6b80;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: inherit;
  font-size: 0.9rem;
}

.file-item:hover {
  border-color: var(--border);
  text-decoration: none;
}

.file-item svg {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--text-dim);
}

.file-item .file-meta {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 0.8rem;
  flex: none;
}

.topic-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.65rem;
  margin-bottom: 1.5rem;
}

.topic-choice {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  padding: 0.95rem 1.05rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.topic-choice:hover {
  border-color: var(--text-dim);
}

.topic-choice input {
  width: 17px;
  height: 17px;
  margin: 2px 0 0;
  accent-color: var(--accent);
  flex: none;
  cursor: pointer;
}

.topic-choice.is-checked {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.topic-choice.is-empty {
  opacity: 0.5;
}

.topic-choice strong {
  display: block;
  font-size: 0.93rem;
  font-weight: 580;
  margin-bottom: 0.15rem;
}

.topic-choice span {
  color: var(--text-soft);
  font-size: 0.82rem;
}

.exam-question {
  padding: 1.5rem 1.7rem;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 1rem;
}

.exam-question-head {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-soft);
}

.question-number {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 650;
  flex: none;
}

.exam-question-head h2 {
  margin: 0;
  font-size: 1.02rem;
  flex: 1;
  min-width: 0;
}

.state {
  padding: 3rem 1.5rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--text-soft);
}

.state h2 {
  color: var(--text);
  font-size: 1.05rem;
}

.state p {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.state-error {
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.state .button {
  margin-top: 1.1rem;
}

.skeleton-card,
.skeleton-row {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 30%, var(--surface-2) 50%, var(--surface) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s infinite linear;
}

.skeleton-card {
  height: 168px;
}

.skeleton-row {
  height: 74px;
  margin-bottom: 0.65rem;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -20% 0;
  }
}

.toast-host {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.65rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 0.9rem;
  max-width: 340px;
  animation: rise 0.2s ease;
}

.toast-success {
  border-color: color-mix(in srgb, var(--easy) 50%, transparent);
}

.toast-error {
  border-color: color-mix(in srgb, var(--danger) 50%, transparent);
}

.toast.is-leaving {
  opacity: 0;
  transition: opacity 0.25s ease;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

.site-footer {
  padding: 1.75rem 0;
  border-top: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-size: 0.86rem;
}

.site-footer .shell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
}

@media (max-width: 640px) {
  .shell {
    width: min(1120px, 100% - 1.75rem);
  }

  .hero,
  .panel,
  .exam-question {
    padding: 1.25rem;
  }

  .site-nav a {
    padding: 0.4rem 0.55rem;
    font-size: 0.88rem;
  }

  .exercise-row {
    flex-wrap: wrap;
  }
}

@media print {
  .site-header,
  .site-footer,
  .no-print {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .exam-question,
  .panel {
    border-color: #ccc;
    break-inside: avoid;
  }
}
