:root {
  --bg: #f6f7f3;
  --panel: #ffffff;
  --panel-soft: #fbfcf8;
  --text: #1d2328;
  --muted: #66706b;
  --line: #dfe4dc;
  --accent: #1f7a5a;
  --accent-strong: #176848;
  --accent-weak: #e5f3ed;
  --warn: #b76623;
  --danger: #b44242;
  --danger-weak: #fae9e7;
  --ok: #24764d;
  --ok-weak: #e7f4ec;
  --ink: #263238;
  --shadow: 0 12px 34px rgba(31, 45, 39, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  border: 0;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.mobile-menu-btn,
.drawer-overlay {
  display: none;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(31, 122, 90, 0.2);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #fbfcf8;
  backdrop-filter: blur(10px);
}

.brand h1 {
  margin: 0;
  color: var(--text);
  font-size: 23px;
  line-height: 1.25;
}

.brand p,
.topbar p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.mode-tabs {
  display: grid;
  gap: 10px;
  margin: 22px 0;
}

.sub-menu {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mode-tab,
.filters select,
.filters input,
.list-head button,
.ghost,
.mark-btn,
.self-check button,
.pager button,
.fill-area button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
}

.mode-tab.active,
.mode-tab:hover,
.list-head button:hover,
.ghost:hover {
  border-color: #9ac9b6;
  background: var(--accent-weak);
  color: var(--accent);
}

.mode-tab.active {
  box-shadow: inset 0 0 0 1px rgba(31, 122, 90, 0.16);
  font-weight: 700;
}

.main-menu {
  width: 100%;
  min-height: 46px;
  font-size: 16px;
  font-weight: 800;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stats div {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.stats span {
  display: block;
  font-weight: 800;
  font-size: 20px;
  color: var(--accent);
}

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

.filters {
  display: grid;
  gap: 12px;
}

.filters label {
  display: grid;
  gap: 6px;
}

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

.filters select,
.filters input {
  width: 100%;
  padding: 0 12px;
}

.filters select:hover,
.filters input:hover {
  border-color: #9ac9b6;
}

.study-tools {
  display: grid;
  gap: 8px;
  margin: 18px 0 0;
}

.study-tools button,
.import-btn {
  display: inline-grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.study-tools button:hover,
.import-btn:hover {
  border-color: #9ac9b6;
  background: var(--accent-weak);
  color: var(--accent);
}

#importHint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 22px 0 10px;
}

.list-head button {
  padding: 0 14px;
}

.question-nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 8px;
  padding-bottom: 24px;
}

.nav-item {
  position: relative;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.nav-item.done {
  background: var(--ok-weak);
  border-color: #b7dcc7;
  color: var(--ok);
}

.nav-item.wrong {
  background: var(--danger-weak);
  border-color: #e3b5ad;
  color: var(--danger);
}

.nav-item:hover {
  transform: translateY(-1px);
  border-color: #9ac9b6;
}

.nav-item.active,
.nav-item.active.done,
.nav-item.active.wrong {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(31, 122, 90, 0.18);
}

.nav-item.marked::after {
  content: "★";
  position: absolute;
  top: -7px;
  right: -4px;
  color: var(--warn);
  font-size: 13px;
}

.main {
  min-width: 0;
  padding: 30px clamp(18px, 4vw, 46px);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  max-width: 1040px;
  margin-bottom: 22px;
}

.topbar h2 {
  margin: 2px 0 0;
  font-size: 26px;
}

.top-actions {
  display: flex;
  gap: 10px;
}

.ghost {
  padding: 0 14px;
}

.question-card {
  max-width: 1040px;
  min-height: 640px;
  padding: clamp(20px, 3vw, 30px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #edf0e8;
  color: #3b463d;
  font-size: 13px;
  font-weight: 700;
}

.progress-text {
  margin-left: 10px;
  color: var(--muted);
  font-size: 13px;
}

.progress-bar {
  height: 8px;
  margin: 18px 0 0;
  overflow: hidden;
  border-radius: 999px;
  background: #edf0e8;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.24s ease;
}

.mark-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
}

.mark-btn.active {
  border-color: #e0b269;
  background: #fff4df;
  color: #8a5a10;
}

.question-card h3 {
  margin: 22px 0 12px;
  font-size: clamp(20px, 2.3vw, 24px);
  line-height: 1.35;
}

.prompt,
#answerText {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  line-height: 1.72;
}

.prompt {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.question-image {
  display: none;
  max-width: min(100%, 520px);
  margin: 16px 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.choice-area {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.option-btn {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
  line-height: 1.55;
}

.option-key {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #eef1ec;
  font-weight: 800;
}

.option-btn:hover {
  border-color: #9ac9b6;
  box-shadow: 0 8px 20px rgba(31, 45, 39, 0.06);
}

.option-btn.correct {
  border-color: #83c49b;
  background: var(--ok-weak);
}

.option-btn.correct .option-key {
  background: var(--ok);
  color: #fff;
}

.option-btn.wrong {
  border-color: #df9a90;
  background: var(--danger-weak);
}

.option-btn.wrong .option-key {
  background: var(--danger);
  color: #fff;
}

.fill-area,
.subjective-area {
  display: none;
  gap: 10px;
  margin-top: 22px;
}

.fill-area {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.fill-area label,
.subjective-area label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 13px;
}

.fill-area input,
.subjective-area textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--text);
}

.fill-area button {
  padding: 0 18px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.result-line {
  min-height: 28px;
  margin-top: 16px;
  font-weight: 700;
}

.result-line.ok {
  color: var(--ok);
}

.result-line.bad {
  color: var(--danger);
}

.answer-panel {
  display: none;
  margin-top: 18px;
  padding: 18px;
  border: 1px solid #cfe5d9;
  border-radius: 8px;
  background: #f7fbf8;
}

.answer-panel.visible {
  display: block;
}

.answer-panel.floating {
  position: absolute;
  left: 26px;
  right: 26px;
  top: 128px;
  z-index: 12;
  max-height: min(58vh, 430px);
  overflow: auto;
  margin: 0;
  border-color: #efb4aa;
  background: rgba(255, 250, 248, 0.98);
  cursor: pointer;
  box-shadow: 0 18px 46px rgba(31, 45, 39, 0.18);
  animation: float-answer-in 0.24s ease;
}

.answer-panel.floating::before {
  content: "参考答案";
  display: inline-flex;
  margin-bottom: 10px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--danger-weak);
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
}

.answer-panel.floating h4:first-child {
  display: none;
}

.answer-panel h4 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}

.answer-panel p {
  margin: 0 0 12px;
  line-height: 1.7;
}

.confetti-burst {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  overflow: hidden;
}

.correct-pop {
  position: absolute;
  left: 50%;
  top: 34%;
  display: grid;
  gap: 4px;
  min-width: 150px;
  padding: 14px 20px;
  border: 1px solid #9ac9b6;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--accent);
  text-align: center;
  box-shadow: 0 16px 42px rgba(31, 45, 39, 0.18);
  animation: correct-pop 1.2s ease forwards;
}

.correct-pop strong {
  font-size: 24px;
  line-height: 1.1;
}

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

.confetti-burst > span {
  position: absolute;
  top: -18px;
  left: var(--x);
  width: 8px;
  height: 14px;
  border-radius: 2px;
  background: var(--color);
  animation: confetti-drop 1.25s ease-out var(--delay) forwards;
}

@keyframes correct-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, 12px) scale(0.84);
  }

  16% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.06);
  }

  28% {
    transform: translate(-50%, 0) scale(1);
  }

  82% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(-50%, -12px) scale(0.96);
  }
}

@keyframes confetti-drop {
  0% {
    opacity: 0;
    transform: translate3d(0, -24px, 0) rotate(0deg);
  }

  18% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate3d(var(--dx), 78vh, 0) rotate(var(--rot));
  }
}

@keyframes float-answer-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.self-check,
.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.self-check button,
.pager button {
  padding: 0 18px;
}

#showAnswerBtn,
#nextBtn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#showAnswerBtn:hover,
#nextBtn:hover,
.fill-area button:hover {
  background: var(--accent-strong);
}

#knownBtn {
  background: var(--ok-weak);
  border-color: #b7dcc7;
  color: var(--ok);
}

#unknownBtn {
  background: var(--danger-weak);
  border-color: #e3b5ad;
  color: var(--danger);
}

.pager button:disabled:hover {
  background: var(--panel);
  color: var(--ink);
}

.empty {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    backdrop-filter: none;
  }

  .main {
    padding: 18px;
  }

  .question-card {
    min-height: 0;
    padding: 18px;
  }

  .question-nav {
    grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
    max-height: 220px;
    overflow: auto;
    padding-right: 2px;
  }
}

@media (max-width: 560px) {
  .sidebar {
    padding: 18px 16px;
  }

  .mode-tabs {
    grid-template-columns: 1fr;
    gap: 6px;
    margin: 18px 0;
  }

  .sub-menu {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    margin-bottom: 18px;
  }

  .stats div {
    padding: 9px 4px;
  }

  .stats span {
    font-size: 18px;
  }

  .stats small,
  .mode-tab {
    font-size: 12px;
  }

  .topbar,
  .question-meta {
    align-items: stretch;
    flex-direction: column;
  }

  .fill-area {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 16px;
  }

  .question-nav {
    max-height: 150px;
  }

  .top-actions,
  .top-actions button,
  .self-check button,
  .pager button {
    width: 100%;
  }

  .self-check,
  .pager {
    display: grid;
    grid-template-columns: 1fr;
  }

  .option-btn {
    grid-template-columns: 32px 1fr;
    padding: 12px;
  }

  .option-key {
    width: 30px;
    height: 30px;
  }
}

@media (max-width: 360px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 700px) {
  body {
    background: var(--panel);
  }

  button:not(:disabled):active {
    transform: scale(0.97);
  }

  body.drawer-open {
    overflow: hidden;
  }

  .app-shell {
    display: block;
    min-height: 100dvh;
  }

  .mobile-menu-btn {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 35;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border: 1px solid #9ac9b6;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 22px rgba(31, 45, 39, 0.1);
  }

  .mobile-menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    margin: 2px 0;
    border-radius: 999px;
    background: var(--accent);
    transition: transform 0.2s ease, opacity 0.2s ease;
  }

  body.drawer-open .mobile-menu-btn span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  body.drawer-open .mobile-menu-btn span:nth-child(2) {
    opacity: 0;
  }

  body.drawer-open .mobile-menu-btn span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .drawer-overlay {
    position: fixed;
    inset: 0 0 0 min(86vw, 340px);
    z-index: 25;
    display: block;
    background: rgba(29, 35, 40, 0.24);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease;
  }

  body.drawer-open .drawer-overlay {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 30;
    width: min(86vw, 340px);
    height: 100dvh;
    padding: 64px 16px 20px;
    overflow: auto;
    border-right: 1px solid var(--line);
    border-bottom: 0;
    background: rgba(251, 252, 248, 0.96);
    backdrop-filter: blur(10px);
    box-shadow: 18px 0 38px rgba(31, 45, 39, 0.16);
    transform: translateX(-105%);
    transition: transform 0.28s ease;
  }

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

  .topbar {
    display: none;
  }

  .mode-tabs {
    display: grid;
    grid-template-columns: 1fr;
    gap: 6px;
    margin: 0;
  }

  .sub-menu {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .mode-tab {
    min-height: 32px;
    border-radius: 8px;
    font-size: 13px;
  }

  .main-menu {
    min-height: 36px;
    font-size: 14px;
  }

  .main {
    padding: 54px 0 0;
  }

  .question-card {
    min-height: calc(100dvh - 54px);
    padding: 14px 16px 18px;
    border: 0;
    border-radius: 0;
    background: var(--panel);
    box-shadow: none;
    touch-action: pan-y;
  }

  .question-meta {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .question-meta > div {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .badge {
    min-height: 24px;
    padding: 0 8px;
    font-size: 12px;
  }

  .progress-text {
    margin-left: 8px;
    font-size: 12px;
  }

  .mark-btn {
    width: 36px;
    min-height: 32px;
    justify-content: center;
    padding: 0;
  }

  .mark-btn span:last-child {
    display: none;
  }

  .progress-bar {
    height: 5px;
    margin: 10px 0 0;
  }

  .question-card h3 {
    display: none;
  }

  .prompt {
    margin-top: 14px;
    padding: 14px;
    font-size: 17px;
    line-height: 1.68;
  }

  .question-image {
    max-width: 100%;
    margin: 12px 0 0;
  }

  .choice-area {
    gap: 8px;
    margin-top: 14px;
  }

  .option-btn {
    grid-template-columns: 32px 1fr;
    min-height: 54px;
    padding: 10px 12px;
    font-size: 16px;
  }

  .option-key {
    width: 30px;
    height: 30px;
  }

  .fill-area,
  .subjective-area {
    margin-top: 14px;
  }

  .fill-area {
    grid-template-columns: 1fr;
  }

  .subjective-area textarea {
    min-height: 128px;
  }

  .result-line {
    min-height: 22px;
    margin-top: 10px;
    font-size: 14px;
  }

  .answer-panel {
    margin-top: 10px;
    padding: 12px;
  }

  .answer-panel.floating {
    left: 16px;
    right: 16px;
    top: 118px;
    width: auto;
    max-height: 48vh;
    box-shadow: 0 18px 54px rgba(31, 45, 39, 0.22);
  }

  .answer-panel h4 {
    font-size: 13px;
  }

  .self-check {
    display: grid;
    grid-template-columns: 1.2fr 0.9fr 0.9fr;
    gap: 8px;
    margin-top: 12px;
  }

  .pager {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-top: 8px;
  }

  .self-check button,
  .pager button,
  .fill-area button {
    width: 100%;
    min-height: 42px;
    padding: 0 10px;
  }

  .stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .stats div {
    padding: 9px 4px;
  }

  .stats span {
    font-size: 18px;
  }

  .filters {
    gap: 10px;
  }

  .question-nav {
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    max-height: none;
    padding: 0 0 24px;
  }
}
