:root {
  color-scheme: dark;
  --bg: #0e0e16;
  --card: #15151f;
  --chip: #24242f;
  --panel: #17171f;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.24);
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.54);
  --faint: rgba(255, 255, 255, 0.38);
  --green: #32d74b;
  --red: #ff453a;
  --card-h: clamp(168px, 18dvh, 220px);
  --radius-card: 16px;
  --font: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  letter-spacing: 0;
  -webkit-tap-highlight-color: transparent;
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  background:
    radial-gradient(circle at 20% 12%, rgba(50, 215, 75, 0.18), transparent 32%),
    linear-gradient(145deg, #0a0a12 0%, #101018 48%, #17171f 100%);
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-gate.hidden {
  display: none;
}

.login-card {
  width: min(440px, 100%);
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: rgba(21, 21, 31, 0.92);
  padding: 30px;
  display: grid;
  gap: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.38);
}

.login-kicker,
.manage-kicker {
  color: var(--green);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: clamp(30px, 6vw, 44px);
  line-height: 1.05;
}

.login-card button {
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  color: #0e0e16;
  background: var(--green);
  font-weight: 900;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 14px;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.quiz-app {
  width: 100vw;
  height: 100dvh;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.counter {
  min-width: 68px;
  text-align: left;
  color: rgba(255, 255, 255, 0.72);
  font-size: 16px;
  font-weight: 700;
}

.quiz-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.question-zone {
  flex: 3 1 0;
  min-height: 0;
  position: relative;
}

.question-scroll {
  position: relative;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  touch-action: pan-y;
  overscroll-behavior: contain;
}

.question-list {
  position: relative;
  min-height: 100%;
  padding: 0 0 40px;
}

.question-row {
  height: var(--card-h);
  display: flex;
  align-items: center;
  justify-content: center;
}

.question-card {
  width: 75%;
  min-height: calc(var(--card-h) - 12px);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  color: var(--text);
  background: var(--card);
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 12px;
  text-align: left;
}

.question-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.question-number {
  color: var(--faint);
  font-size: 18px;
  font-weight: 800;
}

.question-line strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  font-size: clamp(25px, 3.6vw, 34px);
  font-weight: 800;
  line-height: 1.18;
}

.options-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.option-chip {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--chip);
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
}

.option-chip.correct {
  border-color: var(--green);
  border-width: 2.5px;
  background: #12431f;
}

.option-chip b {
  color: rgba(255, 255, 255, 0.54);
  font-size: 15px;
  font-weight: 800;
}

.option-chip.correct b {
  color: var(--green);
}

.option-chip em {
  min-width: 0;
  margin-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: #fff;
  font-size: clamp(17px, 2.2vw, 24px);
  line-height: 1.15;
  font-style: normal;
  font-weight: 650;
}

.answer-panel {
  flex: 0 0 clamp(210px, 28dvh, 330px);
  min-height: 0;
  border-top: 1.5px solid var(--line-strong);
  background: var(--panel);
  padding: 12px 22px;
  display: flex;
  flex-direction: column;
}

.answer-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 0;
}

.answer-index {
  padding: 3px 9px;
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.08);
  font-size: 14px;
  white-space: nowrap;
}

.answer-header strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  color: var(--green);
  font-size: clamp(21px, 3vw, 31px);
  line-height: 1.18;
  font-weight: 800;
}

.answer-panel p {
  flex: 1;
  min-height: 0;
  margin: 8px 0 0;
  overflow: auto;
  color: #fff;
  font-size: clamp(22px, 3.1vw, 34px);
  line-height: 1.4;
}

.bottom-controls {
  min-height: 42px;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.settings-button {
  min-width: 88px;
  height: 38px;
  border: 0;
  border-radius: 11px;
  color: #0e0e16;
  background: var(--green);
  font-weight: 800;
}

.floating-settings-button {
  position: fixed;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 12;
  min-width: 92px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  color: #0e0e16;
  background: var(--green);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.34);
  font-weight: 900;
}

.login-gate:not(.hidden) ~ .floating-settings-button,
.manage-dialog[open] ~ .floating-settings-button {
  display: none;
}

.manage-dialog {
  width: min(1120px, calc(100vw - 28px));
  height: min(860px, calc(100dvh - 28px));
  max-height: calc(100dvh - 28px);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  color: var(--text);
  background: #15151f;
  padding: 0;
}

.manage-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.manage-shell {
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.manage-header {
  min-height: 72px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.manage-header strong {
  display: block;
  margin-top: 3px;
  font-size: clamp(22px, 3vw, 34px);
  line-height: 1.05;
}

.close-button {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  font-size: 25px;
}

.tabs,
.choice-row {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
}

.tab,
.choice,
.small-button,
.primary-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #fff;
  background: #24242f;
  padding: 0 14px;
}

.tab.active,
.choice.active,
.primary-button {
  color: #0e0e16;
  border-color: transparent;
  background: var(--green);
  font-weight: 800;
}

.tab-panel {
  display: none;
  flex: 1;
  min-height: 0;
  padding: 14px 18px 18px;
  overflow: auto;
}

.tab-panel.active {
  display: block;
}

.filter-grid,
.input-action {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 180px auto;
  gap: 8px;
  margin-bottom: 10px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: #fff;
  background: #0e0e16;
  outline: none;
  padding: 10px 12px;
}

input:focus,
textarea:focus {
  border-color: var(--green);
}

textarea {
  resize: vertical;
}

.generate-panel.active {
  display: block;
}

.generate-card {
  max-width: 860px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #1a1a25;
  padding: clamp(16px, 3vw, 28px);
  display: grid;
  gap: 14px;
}

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

.generate-card h2 {
  margin: 4px 0 0;
  font-size: clamp(26px, 4vw, 40px);
  line-height: 1.08;
}

.choice-row.compact {
  padding: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.generate-action {
  min-height: 48px;
}

.generation-summary {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #1d1d28;
  padding: 14px;
  display: grid;
  grid-template-columns: 0.75fr 1.25fr 1fr;
  gap: 12px;
}

.generation-summary span,
.server-key-note {
  color: var(--muted);
  font-size: 13px;
}

.generation-summary strong,
.generation-summary p {
  margin: 5px 0 0;
}

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

.bank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bank-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: #fff;
  background: #1d1d28;
  padding: 10px 12px;
  display: grid;
  gap: 4px;
  text-align: left;
}

.bank-item span,
.muted-line {
  color: var(--muted);
  font-size: 13px;
}

.wide {
  width: 100%;
}

.safe-text {
  color: var(--green);
}

.danger-text {
  color: var(--red);
}

.empty-state {
  width: 75%;
  margin: 24px auto;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-card);
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.empty-state.compact {
  width: 100%;
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(520px, calc(100vw - 32px));
  transform: translateX(-50%);
  border: 1px solid rgba(50, 215, 75, 0.35);
  border-radius: 12px;
  color: #fff;
  background: rgba(21, 21, 31, 0.94);
  padding: 10px 16px;
}

.toast.error {
  border-color: rgba(255, 69, 58, 0.45);
}

.hidden {
  display: none !important;
}

@media (orientation: portrait) and (min-width: 700px) {
  .question-card,
  .empty-state {
    width: 82%;
  }

  .question-line strong {
    font-size: clamp(28px, 4.2vw, 36px);
  }

  .option-chip em {
    font-size: clamp(19px, 2.8vw, 25px);
  }
}

@media (max-width: 699px) {
  :root {
    --card-h: clamp(182px, 20dvh, 230px);
  }

  .counter {
    min-width: 60px;
    font-size: 14px;
  }

  .question-card,
  .empty-state {
    width: calc(100% - 24px);
  }

  .question-card {
    height: calc(var(--card-h) - 12px);
  }

  .question-line strong {
    -webkit-line-clamp: 2;
    font-size: 26px;
  }

  .options-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .option-chip {
    min-height: 46px;
    padding: 7px 6px;
  }

  .option-chip b {
    font-size: 13px;
  }

  .option-chip em {
    margin-left: 3px;
    font-size: clamp(15px, 3.4vw, 20px);
  }

  .answer-panel {
    padding: 10px 14px;
  }

  .answer-header strong {
    font-size: 21px;
  }

  .answer-panel p {
    font-size: 23px;
  }

  .manage-dialog {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .filter-grid,
  .generation-summary {
    grid-template-columns: 1fr;
  }

  .generate-card-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 520px) {
  :root {
    --card-h: 210px;
  }

  .question-line strong {
    font-size: 24px;
  }

  .options-row {
    grid-template-columns: 1fr;
  }

  .option-chip {
    min-height: 34px;
    justify-content: flex-start;
  }

  .answer-panel {
    flex-basis: clamp(230px, 34dvh, 340px);
  }
}
