:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #151922;
  --muted: #687386;
  --line: #d9e0ea;
  --accent: #d9362b;
  --accent-dark: #a92018;
  --accent-soft: #fff0ef;
  --shadow: 0 16px 40px rgba(22, 30, 46, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 0;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

input {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(217, 54, 43, 0.18);
  outline-offset: 2px;
}

.boot-error {
  padding: 28px;
}

.topbar {
  min-height: 64px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(243, 245, 248, 0.96);
}

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

.mark {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
}

.brand h1,
.brand p,
.question-card h2,
.stem-card h3,
.answer-title h3,
.answer-gate h3,
.diagnosis-block h4,
.answer-group h4 {
  margin: 0;
}

.brand h1 {
  font-size: 17px;
  line-height: 1.2;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pwa-status {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.pwa-status.offline {
  color: #9a6200;
  border-color: #e3c37f;
  background: #fff8e8;
}

.ghost-btn,
.secondary-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  padding: 0 13px;
}

.ghost-btn.solid,
.primary-btn {
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  font-weight: 900;
  padding: 0 15px;
}

.drill-layout {
  width: min(1180px, calc(100% - 24px));
  margin: 14px auto 40px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.case-list {
  min-width: 0;
  display: grid;
  gap: 10px;
  position: sticky;
  top: 78px;
}

.search-box,
.question-card,
.answer-gate,
.answer-sheet {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

.search-box {
  padding: 10px;
}

.search-box label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.record-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 9px;
}

.record-strip span {
  min-width: 0;
  min-height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.search-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.status-tabs,
.system-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.status-tabs {
  margin-bottom: 9px;
}

.system-tabs {
  margin-bottom: 9px;
}

.status-tabs button,
.system-tabs button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 900;
}

.status-tabs button.active,
.system-tabs button.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.search-box button {
  border-radius: 8px;
  padding: 0 10px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 900;
}

.case-scroll {
  display: grid;
  gap: 12px;
  max-height: calc(100dvh - 154px);
  overflow: auto;
  padding-right: 2px;
}

.case-group {
  display: grid;
  gap: 8px;
}

.case-group h3 {
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.case-group h3 span {
  min-width: 28px;
  min-height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.case-group > div {
  display: grid;
  gap: 8px;
}

.case-row {
  min-width: 0;
  min-height: 72px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 4px 9px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.case-row span {
  grid-row: span 2;
  min-width: 42px;
  min-height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-weight: 900;
}

.case-row strong,
.case-row small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-row b {
  grid-column: 3;
  grid-row: 1 / span 2;
  align-self: center;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
}

.case-row small,
.empty {
  color: var(--muted);
}

.case-row.active {
  border-color: var(--accent);
  box-shadow: inset 4px 0 0 var(--accent);
}

.case-row.viewed b {
  color: #187247;
  background: #eaf7f0;
}

.case-row.starred b {
  color: var(--accent-dark);
  background: var(--accent-soft);
}

.question-panel,
.answer-panel {
  min-width: 0;
  grid-column: 2;
}

.question-card {
  padding: 18px;
  box-shadow: var(--shadow);
}

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

.case-meta span,
.answer-title span,
.answer-gate span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  padding: 0 10px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 13px;
  font-weight: 900;
}

.case-meta .seen {
  color: #187247;
  background: #eaf7f0;
}

.case-meta .unseen {
  color: #7a5a00;
  background: #fff8e8;
}

.star-btn {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
  font-weight: 900;
}

.star-btn.active {
  color: var(--accent-dark);
  border-color: #f0b8b4;
  background: var(--accent-soft);
}

.question-card h2 {
  margin-top: 12px;
  font-size: clamp(25px, 2.4vw, 34px);
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.case-lead {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.stem-card {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid #cbd7ea;
  border-radius: 10px;
  background: var(--surface-soft);
}

.stem-card h3 {
  font-size: 16px;
}

.stem-text {
  margin: 9px 0 0;
  display: grid;
  gap: 10px;
}

.stem-text p {
  margin: 0;
  font-size: 18px;
  line-height: 1.82;
  overflow-wrap: anywhere;
}

.study-actions {
  display: grid;
  grid-template-columns: minmax(130px, 1.4fr) repeat(2, minmax(98px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.answer-panel {
  margin-top: 14px;
}

.answer-gate {
  min-height: 132px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
}

.answer-gate h3 {
  margin-top: 8px;
  font-size: 22px;
}

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

.answer-sheet {
  padding: 16px;
}

.answer-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.answer-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.answer-title h3 {
  margin-top: 8px;
  font-size: 22px;
  line-height: 1.25;
}

.diagnosis-block {
  margin-top: 14px;
  padding: 15px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid #f0b8b4;
}

.diagnosis-block h4,
.answer-group h4 {
  font-size: 16px;
}

.diagnosis-block ol,
.answer-group ul {
  margin: 10px 0 0;
  padding-left: 22px;
  line-height: 1.75;
}

.diagnosis-block li {
  font-size: 18px;
  font-weight: 900;
}

.answer-groups {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.answer-group {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 13px;
  background: #fff;
}

.answer-group li {
  margin-bottom: 4px;
  color: #303846;
}

.answer-actions {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) minmax(110px, 1fr) minmax(140px, 1.45fr);
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.answer-actions button {
  min-height: 48px;
}

.mobile-nav {
  display: none;
}

@media (max-width: 860px) {
  body {
    padding-bottom: 72px;
  }

  .topbar {
    min-height: 58px;
    padding: 8px 10px;
  }

  .mark {
    width: 36px;
    height: 36px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand p {
    max-width: 44vw;
  }

  .top-actions {
    gap: 6px;
  }

  .top-actions .ghost-btn:not(.solid),
  .install-btn {
    display: none;
  }

  .pwa-status {
    display: none;
  }

  .drill-layout {
    width: calc(100% - 10px);
    max-width: calc(100vw - 10px);
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 8px;
  }

  .case-list,
  .question-panel,
  .answer-panel {
    grid-column: auto;
    position: static;
    margin-top: 0;
  }

  .panel-question .case-list,
  .panel-question .answer-panel,
  .panel-answer .case-list,
  .panel-answer .question-panel,
  .panel-list .question-panel,
  .panel-list .answer-panel {
    display: none;
  }

  .panel-list .case-list,
  .panel-question .question-panel,
  .panel-answer .answer-panel {
    display: grid;
  }

  .case-scroll {
    max-height: none;
  }

  .record-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .status-tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .status-tabs button {
    min-width: 0;
    padding: 0 4px;
  }

  .system-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    margin-inline: -2px;
    padding: 0 2px 3px;
  }

  .system-tabs::-webkit-scrollbar {
    display: none;
  }

  .system-tabs button {
    flex: 0 0 auto;
  }

  .question-card,
  .answer-gate,
  .answer-sheet {
    width: 100%;
    max-width: calc(100vw - 10px);
    border-radius: 10px;
  }

  .question-card,
  .answer-sheet {
    padding: 14px 12px;
  }

  .question-card h2 {
    font-size: 24px;
  }

  .stem-card {
    padding: 14px 12px;
  }

  .stem-text p {
    font-size: 17px;
    line-height: 1.82;
  }

  .study-actions {
    grid-template-columns: 1fr 1fr;
  }

  .study-actions .primary-btn {
    grid-column: 1 / -1;
  }

  .answer-gate {
    display: grid;
  }

  .answer-groups {
    grid-template-columns: 1fr;
  }

  .answer-title {
    display: grid;
  }

  .answer-tools {
    justify-content: flex-start;
  }

  .answer-actions {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }

  .answer-actions .primary-btn {
    grid-column: 1 / -1;
    order: -1;
  }

  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: rgba(243, 245, 248, 0.98);
  }

  .mobile-nav button {
    min-width: 0;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--muted);
    background: #fff;
    font-weight: 900;
  }

  .mobile-nav button.active {
    color: #fff;
    border-color: var(--accent);
    background: var(--accent);
  }
}
