:root {
  --bg: #edf3f8;
  --panel: #fbfdff;
  --panel-soft: #f6f9fc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d5dee8;
  --shadow: 0 18px 42px rgba(31, 41, 55, 0.09);
  --blue: #4f7faa;
  --green: #6f9d45;
  --indigo: #6476b8;
  --violet: #7a68ad;
  --amber: #b7802c;
  --red: #b65646;
  --rose: #bb4f66;
  --accent: var(--blue);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(237, 243, 248, 0.92)),
    var(--bg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

button,
input {
  font: inherit;
}

.app-shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 28px 0 38px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 0 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 32px;
  line-height: 1.18;
  letter-spacing: 0;
}

.subhead {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.topbar-actions span,
.mode-button,
.level-button,
.category-button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.75);
  color: #334155;
}

.topbar-actions span {
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 10px 28px rgba(31, 41, 55, 0.05);
}

.search-box {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 240px;
  gap: 10px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--panel);
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box span {
  color: var(--muted);
  font-size: 20px;
}

.search-box input {
  width: 100%;
  height: 42px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.toggle-row {
  display: flex;
  gap: 8px;
}

.mode-button,
.category-button {
  min-height: 38px;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.mode-button.active,
.category-button.active {
  border-color: color-mix(in srgb, var(--accent) 62%, white);
  background: color-mix(in srgb, var(--accent) 12%, white);
  color: color-mix(in srgb, var(--accent) 80%, #111827);
  font-weight: 800;
}

.layout {
  display: grid;
  grid-template-columns: 310px minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.level-nav,
.content-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow);
}

.level-nav {
  padding: 14px;
}

.level-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.level-nav-head strong {
  color: var(--ink);
}

.level-list {
  display: grid;
  gap: 8px;
}

.level-button {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 58px;
  padding: 10px;
  border-radius: 8px;
  text-align: left;
  cursor: pointer;
}

.level-button:hover,
.term-card:hover {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  transform: translateY(-1px);
}

.level-button.active {
  border-color: color-mix(in srgb, var(--accent) 70%, white);
  background: color-mix(in srgb, var(--accent) 13%, white);
}

.level-kicker {
  color: var(--accent);
  font-weight: 900;
}

.level-title {
  display: block;
  color: var(--ink);
  font-weight: 900;
}

.level-subtitle {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.level-count {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.reference-figure {
  margin: 14px 0 0;
}

.reference-figure img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  object-position: center top;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.reference-figure figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.content-panel {
  min-height: 720px;
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.section-head h2 {
  margin-bottom: 0;
  font-size: 28px;
  letter-spacing: 0;
}

.section-head p:last-child {
  max-width: 460px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

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

.term-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 248px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.term-card.active {
  border-color: color-mix(in srgb, var(--accent) 75%, white);
  background: color-mix(in srgb, var(--accent) 9%, white);
}

.term-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.term-card h3 {
  margin-bottom: 0;
  font-size: 21px;
  line-height: 1.25;
  letter-spacing: 0;
}

.term-card p {
  margin-bottom: 0;
  color: #475569;
  line-height: 1.72;
}

.term-card .definition {
  font-weight: 700;
  color: #263241;
}

.term-card .explanation {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 5;
  -webkit-box-orient: vertical;
}

.detail-panel {
  padding: 18px;
}

.detail-sticky {
  position: sticky;
  top: 18px;
}

.detail-panel h2 {
  margin-bottom: 8px;
  font-size: 30px;
  line-height: 1.24;
  letter-spacing: 0;
}

.detail-category {
  margin-bottom: 18px;
  color: var(--muted);
  font-weight: 800;
}

.detail-block {
  padding: 16px 0;
  border-top: 1px solid var(--line);
}

.detail-block h3 {
  margin-bottom: 10px;
  color: color-mix(in srgb, var(--accent) 72%, #111827);
  font-size: 14px;
  letter-spacing: 0;
}

.detail-block p {
  margin-bottom: 0;
  color: #334155;
  line-height: 1.85;
}

.detail-foot {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.detail-foot button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--ink);
  cursor: pointer;
  font-size: 24px;
}

.detail-foot span {
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 900;
}

.empty-state {
  grid-column: 1 / -1;
  padding: 46px 20px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(255, 255, 255, 0.64);
}

@media (max-width: 1180px) {
  .layout {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .detail-panel {
    grid-column: 1 / -1;
  }

  .detail-sticky {
    position: static;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 24px, 720px);
    padding-top: 18px;
  }

  .topbar,
  .toolbar,
  .section-head {
    flex-direction: column;
    align-items: stretch;
  }

  h1 {
    font-size: 28px;
  }

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

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

  .toggle-row {
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .mode-button {
    flex: 0 0 auto;
  }

  .content-panel {
    min-height: 0;
    padding: 16px;
  }
}
