:root {
  color-scheme: light dark;
  --bg: #edf4f1;
  --surface: #fbfdfb;
  --surface-soft: #f4f8f6;
  --text: #173331;
  --muted: #5d716c;
  --accent: #0f766e;
  --accent-strong: #0a5e58;
  --accent-soft: #dcefea;
  --line: #cbd8d3;
  --correct: #176b42;
  --correct-bg: #e5f4ea;
  --danger: #af3333;
  --danger-bg: #fbeeee;
  --shadow: 0 12px 32px rgb(22 52 48 / 0.08);
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  min-width: 320px;
  margin: 0;
  background:
    linear-gradient(110deg, rgb(255 255 255 / 0.42), transparent 46%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.55;
}

button,
input,
select { font: inherit; }

button { cursor: pointer; }

main {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.view { margin-top: 28px; }

.search-view { max-width: 680px; }

.login-view {
  max-width: 420px;
  margin: min(16vh, 120px) auto 0;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hidden { display: none !important; }

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 6vw, 36px);
  line-height: 1.12;
  letter-spacing: -0.04em;
}

.intro {
  margin: 10px 0 24px;
  color: var(--muted);
  font-size: 15px;
}

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

header .eyebrow { margin-bottom: 4px; }
header h1 { font-size: 28px; }

.field-label {
  display: block;
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

input[type="password"],
input[type="search"],
select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background-color 160ms ease;
}

input::placeholder { color: #71827e; }

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgb(15 118 110 / 0.18);
}

button:not(.link) {
  min-height: 46px;
  padding: 10px 18px;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-weight: 700;
  white-space: nowrap;
  transition: background-color 160ms ease, border-color 160ms ease, transform 100ms ease;
}

.passcode-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: stretch;
}

.passcode-row button {
  width: auto;
  padding: 10px 16px;
}

button:not(.link):hover { background: var(--accent-strong); border-color: var(--accent-strong); }
button:not(.link):active { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: 0.68; }

button.link {
  min-height: 36px;
  padding: 6px 8px;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
}

button.link:hover,
button.link:focus-visible {
  color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.searchbox {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  margin-top: 12px;
}

.field-group .field-label { margin-bottom: 7px; }

.result-status {
  display: flex;
  align-items: center;
  min-height: 44px;
}

.meta,
.error {
  margin: 0;
  font-size: 14px;
}

.meta { color: var(--muted); }
.error { color: var(--danger); }

#search-error {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--danger-bg);
  border-radius: var(--radius);
}

#results {
  display: grid;
  gap: 8px;
}

#results.loading::before,
#results.loading::after {
  display: block;
  height: 70px;
  content: "";
  background: linear-gradient(90deg, var(--surface-soft) 25%, var(--surface) 45%, var(--surface-soft) 65%);
  background-size: 300% 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  animation: skeleton 1.15s ease-in-out infinite;
}

#results.loading::after { animation-delay: 0.12s; }

.card {
  overflow: clip;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 7px rgb(22 52 48 / 0.04);
}

.card[open] { border-color: #97c2b9; }

.card-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  padding: 15px 16px;
  cursor: pointer;
  list-style: none;
}

.card-head::-webkit-details-marker { display: none; }
.card-head::marker { content: ""; }

.card-head:hover { background: var(--surface-soft); }
.card-head:focus-visible {
  outline: 3px solid rgb(15 118 110 / 0.24);
  outline-offset: -3px;
}

.type {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-top: 1px;
  padding: 1px 7px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.stem {
  min-width: 0;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.52;
}

.affordance {
  padding-top: 2px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.card[open] .affordance { font-size: 0; }
.card[open] .affordance::after { content: "收起"; font-size: 12px; }

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

.options {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.options li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 7px;
  align-items: baseline;
  padding: 9px 10px;
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
}

.options li.correct {
  color: var(--correct);
  background: var(--correct-bg);
  border-color: #a8d6b9;
}

.options b { font-weight: 750; }

.mark {
  color: var(--correct);
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  white-space: nowrap;
}

.answer {
  margin: 12px 0 0;
  padding: 10px 12px;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: var(--radius);
  font-size: 14px;
}

.answer strong { margin-left: 3px; font-weight: 800; }

@keyframes skeleton {
  from { background-position: 100% 0; }
  to { background-position: 0 0; }
}

@media (max-width: 480px) {
  main { padding: 20px 12px 36px; }
  .view { margin-top: 12px; }
  .login-view { margin-top: 48px; padding: 22px 18px; }
  .searchbox { padding: 14px; }
  .search-actions { grid-template-columns: 1fr; }
  .search-actions button { width: 100%; }
  .card-head { gap: 8px; padding: 14px; }
  .card-body { padding: 12px 14px 14px; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #102725;
    --surface: #173331;
    --surface-soft: #1d3c39;
    --text: #edf6f2;
    --muted: #b5c6c0;
    --accent: #4ab5a8;
    --accent-strong: #82d1c6;
    --accent-soft: #204b47;
    --line: #37615b;
    --correct: #8fdbab;
    --correct-bg: #17472e;
    --danger: #ffafa8;
    --danger-bg: #572c2a;
    --shadow: 0 12px 32px rgb(0 0 0 / 0.18);
  }

  body { background: linear-gradient(110deg, rgb(255 255 255 / 0.04), transparent 46%), var(--bg); }
  input::placeholder { color: #a7bbb4; }
  .card[open] { border-color: #609d93; }
  .options li.correct { border-color: #438a5e; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
