:root {
  color-scheme: light;
  --ink: #1f2933;
  --muted: #66727f;
  --line: #d9e0e7;
  --panel: #ffffff;
  --bg: #f6f7f9;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --accent-soft: #d9f2ee;
  --warn: #a43f14;
  --warn-soft: #ffe7da;
  --ok: #1d7f4f;
  --ok-soft: #dcf4e8;
  --shadow: 0 18px 48px rgba(31, 41, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "Noto Sans CJK SC", "Yu Gothic UI", system-ui, sans-serif;
  background:
    linear-gradient(180deg, #eef4f3 0, rgba(246, 247, 249, 0) 360px),
    var(--bg);
  color: var(--ink);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.unified-shell {
  width: min(1280px, calc(100vw - 32px));
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-end;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.5rem);
  line-height: 1.05;
}

.summary-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  margin: 22px 0;
}

.search-box {
  display: grid;
  grid-template-columns: auto minmax(180px, 320px);
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
}

.search-box select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 38px 10px 12px;
  background: white;
  color: var(--ink);
}

.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}

.unit-card {
  display: flex;
  min-height: 148px;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}

.unit-card:hover,
.unit-card:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.unit-card h2 {
  margin: 0 0 8px;
  font-size: 1.2rem;
}

.unit-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

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

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.level-switch {
  display: inline-flex;
  gap: 6px;
  margin: 0 0 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: var(--shadow);
}

.level-switch button {
  min-width: 92px;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  cursor: pointer;
}

.level-switch button.active,
.level-switch button:hover,
.level-switch button:focus-visible {
  background: var(--accent);
  color: white;
  outline: none;
}

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

.unit-panel {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow);
}

.compact-search {
  width: 100%;
  grid-template-columns: 1fr;
  gap: 7px;
}

.practice-pane {
  min-width: 0;
}

.unit-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 14px;
}

.unit-heading h2 {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vw, 2rem);
  line-height: 1.15;
}

.back-link {
  display: inline-flex;
  margin-bottom: 12px;
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.unit-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0;
  margin: 4px 0 16px;
  background: rgba(246, 247, 249, 0.92);
  backdrop-filter: blur(10px);
}

.unit-nav a {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 11px;
  background: white;
  color: var(--muted);
  text-decoration: none;
  font-weight: 800;
}

.unit-nav a.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.vertical-nav {
  position: static;
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  overflow: visible;
  margin: 0;
  padding: 0;
  background: transparent;
  backdrop-filter: none;
}

.unit-nav button {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: white;
  color: var(--muted);
  font-weight: 900;
  text-align: left;
  cursor: pointer;
}

.unit-nav button.active,
.unit-nav button:hover,
.unit-nav button:focus-visible {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  outline: none;
}

.practice-list {
  display: grid;
  gap: 14px;
}

.grammar-block {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: clip;
}

.grammar-block summary {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 14px;
  align-items: center;
  cursor: pointer;
  padding: 17px 18px;
  list-style: none;
}

.grammar-block summary::-webkit-details-marker {
  display: none;
}

.point-id {
  color: var(--accent-dark);
  font-weight: 900;
}

.pattern-title {
  font-size: 1.08rem;
  font-weight: 900;
}

.meaning {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.join-note {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 26px;
  margin-left: 8px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #eef7f5;
  color: var(--accent-dark);
  font-size: 0.84rem;
  font-weight: 800;
  vertical-align: middle;
}

.base-note {
  margin: -3px 18px 0;
  border-top: 1px solid var(--line);
  padding: 12px 0 2px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.question-count {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.question-stack {
  display: grid;
  gap: 12px;
  padding: 0 18px 18px;
}

.question-card {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

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

.question-head h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.55;
}

.question-number {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 900;
}

.option-grid {
  display: grid;
  gap: 8px;
}

.option-btn {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: start;
  gap: 10px;
  min-height: 52px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: #fbfcfd;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.option-btn:hover:not(:disabled),
.option-btn:focus-visible:not(:disabled) {
  border-color: var(--accent);
  background: #f3fbf9;
  outline: none;
}

.option-btn:disabled {
  cursor: default;
}

.option-key {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #e8edf2;
  color: var(--muted);
  font-weight: 900;
}

.option-btn.correct {
  border-color: var(--ok);
  background: var(--ok-soft);
}

.option-btn.wrong.selected {
  border-color: var(--warn);
  background: var(--warn-soft);
}

.feedback {
  display: none;
  margin-top: 10px;
  border-radius: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #f9fbfc;
}

.feedback.visible {
  display: block;
}

.feedback-title {
  margin: 0 0 10px;
  font-weight: 900;
}

.feedback-title.ok {
  color: var(--ok);
}

.feedback-title.warn {
  color: var(--warn);
}

.explain-list {
  display: grid;
  gap: 8px;
  margin: 0;
}

.explain-row {
  border-left: 4px solid var(--line);
  padding: 8px 10px;
  background: white;
  border-radius: 6px;
  line-height: 1.55;
}

.explain-row.correct {
  border-left-color: var(--ok);
}

.explain-row.selected.wrong {
  border-left-color: var(--warn);
}

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  text-align: center;
}

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

  .unit-panel {
    position: static;
  }

  .vertical-nav {
    display: flex;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .unit-nav button {
    flex: 0 0 auto;
    width: auto;
    min-width: 94px;
    text-align: center;
  }

  .unit-heading {
    align-items: flex-start;
  }

  .grammar-block summary {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .question-count {
    grid-column: 2;
  }
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 20px;
  }

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

  .summary-pill {
    white-space: normal;
  }

  .toolbar {
    justify-content: stretch;
  }

  .search-box {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .grammar-block summary {
    grid-template-columns: 1fr;
  }

  .question-head {
    flex-direction: column;
  }

  .level-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .unit-heading {
    flex-direction: column;
  }

  .join-note {
    display: flex;
    width: fit-content;
    margin: 7px 0 0;
    border-radius: 8px;
  }
}
