:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0b192b;
  --surface-2: #10233a;
  --surface-3: #142b46;
  --line: #24415e;
  --line-bright: #3c6589;
  --text: #f1f7fb;
  --muted: #9bb0c3;
  --cyan: #31d9ff;
  --cyan-deep: #0da7cc;
  --lime: #b8f54a;
  --coral: #ff6d69;
  --shadow: 0 28px 90px rgb(0 0 0 / 35%);
  --radius: 18px;
  font-family: "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    linear-gradient(rgb(7 17 31 / 92%), rgb(7 17 31 / 98%)),
    repeating-linear-gradient(90deg, transparent 0 79px, rgb(49 217 255 / 5%) 80px),
    repeating-linear-gradient(0deg, transparent 0 79px, rgb(49 217 255 / 5%) 80px);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgb(49 217 255 / 45%);
  outline-offset: 3px;
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 420px;
  height: 420px;
  border-radius: 999px;
  filter: blur(120px);
  opacity: 0.16;
  pointer-events: none;
}

.ambient-one {
  top: -180px;
  right: -100px;
  background: var(--cyan);
}

.ambient-two {
  bottom: -240px;
  left: -160px;
  background: #406eff;
}

.site-header,
footer {
  width: min(1180px, calc(100% - 40px));
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-header {
  min-height: 92px;
  border-bottom: 1px solid rgb(60 101 137 / 55%);
}

.brand {
  display: inline-flex;
  gap: 12px;
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  color: var(--bg);
  background: var(--cyan);
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
  font: 700 12px/1 "IBM Plex Mono", monospace;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 18px;
  letter-spacing: 0.04em;
}

.brand small,
.eyebrow,
.timer,
.question-number,
.source-badge {
  font-family: "IBM Plex Mono", monospace;
  letter-spacing: 0.09em;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 16px var(--lime);
}

.app-shell {
  width: min(1180px, calc(100% - 40px));
  min-height: calc(100vh - 170px);
  margin: 0 auto;
  padding: 54px 0 70px;
}

.view {
  display: none;
  animation: view-in 260ms ease-out;
}

.view.active {
  display: block;
}

@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.start-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1.1fr);
  gap: clamp(44px, 7vw, 96px);
  align-items: center;
}

.intro-panel h1,
.result-layout h1,
.subpage-header h1 {
  margin: 12px 0 18px;
  font-size: clamp(38px, 5.8vw, 74px);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.intro-panel > p {
  max-width: 520px;
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.8;
}

.eyebrow {
  color: var(--cyan);
  font-size: 12px;
  font-weight: 600;
}

.source-meter {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  max-width: 480px;
  margin-top: 48px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.source-meter div {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 18px 12px;
}

.source-meter div + div {
  border-left: 1px solid var(--line);
}

.source-meter span {
  color: var(--cyan);
  font: 600 13px "IBM Plex Mono", monospace;
}

.source-meter strong {
  text-align: right;
  font: 600 clamp(22px, 3vw, 32px) "IBM Plex Mono", monospace;
}

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

.setup-panel,
.question-card,
.result-details,
.history-list,
.admin-login,
.admin-dashboard {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgb(16 35 58 / 96%), rgb(9 24 42 / 98%));
  box-shadow: var(--shadow);
}

.setup-panel {
  padding: clamp(24px, 4vw, 42px);
}

.auth-panel h2 {
  margin: 12px 0 8px;
  font-size: clamp(28px, 4vw, 38px);
}

.auth-copy {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.7;
}

.auth-tabs {
  grid-template-columns: 1fr 1fr;
  margin-bottom: 24px;
}

.auth-tabs button {
  min-height: 42px;
  color: var(--muted);
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
}

.auth-tabs button.active {
  color: var(--bg);
  background: var(--cyan);
}

.field-help {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.password-label {
  margin-top: 20px;
}

.account-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -8px 0 24px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.account-strip small,
.account-strip strong {
  display: block;
}

.account-strip small {
  color: var(--muted);
  font-size: 12px;
}

.account-strip strong {
  margin-top: 3px;
  font-size: 18px;
}

.field-label,
fieldset legend {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.text-input,
.select-input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  color: var(--text);
  border: 1px solid var(--line-bright);
  border-radius: 10px;
  background: rgb(5 17 31 / 72%);
}

.text-input::placeholder {
  color: #657f97;
}

fieldset {
  min-width: 0;
  margin: 26px 0 0;
  padding: 0;
  border: 0;
}

.segmented {
  display: grid;
  gap: 5px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgb(4 14 25 / 55%);
}

.segmented.four {
  grid-template-columns: repeat(4, 1fr);
}

.segmented label,
.mode-card {
  position: relative;
  cursor: pointer;
}

.segmented input,
.mode-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border-radius: 8px;
  color: var(--muted);
  font-weight: 700;
}

.segmented input:checked + span {
  color: var(--bg);
  background: var(--cyan);
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.mode-card {
  display: grid;
  min-height: 112px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.mode-card:has(input:checked) {
  border-color: var(--cyan);
  background: rgb(49 217 255 / 8%);
  box-shadow: inset 0 0 0 1px rgb(49 217 255 / 25%);
}

.mode-icon {
  color: var(--cyan);
  font: 600 12px "IBM Plex Mono", monospace;
}

.mode-card strong {
  align-self: end;
  margin-top: 12px;
}

.mode-card small {
  margin-top: 3px;
  color: var(--muted);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 26px;
}

.history-button {
  align-self: end;
  min-height: 52px;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.history-button span,
.history-button small {
  display: block;
}

.history-button small {
  color: var(--muted);
  font-size: 12px;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button {
  min-height: 50px;
  padding: 0 20px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 22px;
  color: var(--bg);
  border: 1px solid var(--cyan);
  background: var(--cyan);
}

.primary-button:hover {
  background: #7ce9ff;
}

.primary-button.compact {
  width: auto;
  min-width: 142px;
  margin: 0;
  justify-content: center;
}

.secondary-button,
.ghost-button {
  border: 1px solid var(--line-bright);
  background: transparent;
}

.danger-button {
  color: #220807;
  border: 1px solid var(--coral);
  background: var(--coral);
}

.form-error,
.answer-error {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--coral);
  font-size: 14px;
}

.quiz-topbar {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr) 90px;
  gap: 24px;
  align-items: center;
  max-width: 880px;
  margin: 0 auto 22px;
}

.quiz-topbar .ghost-button {
  min-height: 42px;
}

.progress-copy {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress-copy strong {
  color: var(--cyan);
  font-family: "IBM Plex Mono", monospace;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--surface-3);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--cyan);
  box-shadow: 0 0 14px var(--cyan);
  transition: width 240ms ease;
}

.timer {
  color: var(--muted);
  text-align: right;
  font-size: 14px;
}

.question-card {
  max-width: 880px;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 52px);
}

.question-meta {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 13px;
}

.source-badge {
  padding: 5px 8px;
  color: var(--cyan);
  border: 1px solid rgb(49 217 255 / 45%);
  border-radius: 5px;
  font-size: 11px;
}

.question-card h2 {
  margin: 0 0 28px;
  font-size: clamp(21px, 3vw, 29px);
  line-height: 1.65;
  white-space: pre-line;
}

.question-images {
  display: grid;
  gap: 12px;
  margin: 0 0 26px;
}

.question-images:empty {
  display: none;
}

.question-images img {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.answer-area {
  display: grid;
  gap: 11px;
}

.option {
  position: relative;
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 13px;
  align-items: start;
  min-height: 62px;
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgb(5 17 31 / 42%);
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.option:hover {
  transform: translateY(-1px);
  border-color: var(--line-bright);
}

.option input {
  position: absolute;
  opacity: 0;
}

.option-key {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-bright);
  border-radius: 7px;
  color: var(--muted);
  font: 600 13px "IBM Plex Mono", monospace;
}

.option-text {
  padding-top: 4px;
  line-height: 1.65;
}

.option:has(input:checked) {
  border-color: var(--cyan);
  background: rgb(49 217 255 / 8%);
}

.option:has(input:checked) .option-key {
  color: var(--bg);
  border-color: var(--cyan);
  background: var(--cyan);
}

.option.correct {
  border-color: var(--lime);
  background: rgb(184 245 74 / 9%);
}

.option.incorrect {
  border-color: var(--coral);
  background: rgb(255 109 105 / 8%);
}

.boolean-item {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgb(5 17 31 / 42%);
}

.boolean-item p {
  margin: 0 0 13px;
  line-height: 1.7;
}

.boolean-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.boolean-controls label {
  position: relative;
}

.boolean-controls input {
  position: absolute;
  opacity: 0;
}

.boolean-controls span {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
}

.boolean-controls input:checked + span {
  color: var(--bg);
  border-color: var(--cyan);
  background: var(--cyan);
}

.selfcheck-note {
  padding: 16px;
  color: var(--muted);
  border-left: 3px solid var(--cyan);
  background: rgb(49 217 255 / 6%);
  line-height: 1.7;
}

.selfcheck-answer {
  margin-top: 12px;
  padding: 18px;
  color: var(--lime);
  border: 1px solid rgb(184 245 74 / 38%);
  border-radius: 10px;
  background: rgb(184 245 74 / 6%);
  line-height: 1.8;
  white-space: pre-line;
}

.selfcheck-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.selfcheck-controls button {
  min-height: 48px;
  border: 1px solid var(--line-bright);
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}

.selfcheck-controls button.selected {
  color: var(--bg);
  border-color: var(--cyan);
  background: var(--cyan);
}

.feedback {
  display: none;
  margin-top: 16px;
  padding: 16px;
  border-radius: 10px;
  line-height: 1.7;
}

.feedback.visible {
  display: block;
}

.feedback.success {
  color: var(--lime);
  border: 1px solid rgb(184 245 74 / 35%);
  background: rgb(184 245 74 / 7%);
}

.feedback.failure {
  color: #ffaaa7;
  border: 1px solid rgb(255 109 105 / 35%);
  background: rgb(255 109 105 / 7%);
}

.question-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 24px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.question-number {
  color: var(--muted);
  font-size: 12px;
}

.result-layout {
  display: grid;
  grid-template-columns: 0.8fr 1.2fr;
  gap: clamp(36px, 7vw, 90px);
  align-items: center;
  max-width: 980px;
  margin: 20px auto 0;
}

.score-panel {
  text-align: center;
}

.score-panel .eyebrow {
  display: block;
  margin-bottom: 24px;
}

.score-ring {
  --score: 0deg;
  position: relative;
  display: grid;
  place-items: center;
  width: 210px;
  height: 210px;
  margin: 0 auto 28px;
  border-radius: 50%;
  background: conic-gradient(var(--cyan) var(--score), var(--surface-3) 0);
}

.score-ring::before {
  position: absolute;
  inset: 14px;
  content: "";
  border-radius: 50%;
  background: var(--bg);
}

.score-ring strong,
.score-ring span {
  position: relative;
  z-index: 1;
  display: block;
}

.score-ring strong {
  align-self: end;
  font: 600 46px "IBM Plex Mono", monospace;
}

.score-ring span {
  align-self: start;
  color: var(--muted);
}

.score-panel h1 {
  margin-bottom: 8px;
  font-size: clamp(34px, 5vw, 56px);
}

.score-panel p {
  margin: 0;
  color: var(--muted);
}

.result-details {
  padding: clamp(24px, 4vw, 38px);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.stat-row div {
  padding: 22px 12px;
  text-align: center;
}

.stat-row div + div {
  border-left: 1px solid var(--line);
}

.stat-row small,
.stat-row strong {
  display: block;
}

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

.stat-row strong {
  margin-top: 7px;
  font: 600 28px "IBM Plex Mono", monospace;
}

.result-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 28px;
}

.result-actions .primary-button {
  margin: 0;
  justify-content: center;
}

.save-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.subpage-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  max-width: 1000px;
  margin: 0 auto 28px;
}

.subpage-header h1 {
  margin-bottom: 0;
  font-size: clamp(36px, 5vw, 58px);
}

.history-list,
.admin-dashboard,
.admin-login {
  max-width: 1000px;
  margin: 0 auto;
  padding: clamp(20px, 4vw, 34px);
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 20px;
  align-items: center;
  padding: 18px 4px;
  border-bottom: 1px solid var(--line);
}

.history-item:last-child {
  border-bottom: 0;
}

.history-item small,
.empty-state {
  color: var(--muted);
}

.history-score {
  color: var(--cyan);
  font: 600 22px "IBM Plex Mono", monospace;
}

.history-review {
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-bright);
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
}

.admin-login {
  max-width: 560px;
}

.password-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.admin-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin-bottom: 24px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--line);
}

.admin-summary div {
  padding: 18px;
  background: var(--surface);
}

.admin-summary small,
.admin-summary strong {
  display: block;
}

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

.admin-summary strong {
  margin-top: 6px;
  font: 600 26px "IBM Plex Mono", monospace;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
}

.hidden {
  display: none !important;
}

.text-button {
  padding: 6px;
  color: var(--muted);
  border: 0;
  background: transparent;
  cursor: pointer;
}

.text-button:hover {
  color: var(--cyan);
}

footer {
  min-height: 78px;
  color: var(--muted);
  border-top: 1px solid rgb(60 101 137 / 35%);
  font-size: 13px;
}

dialog {
  width: min(460px, calc(100% - 32px));
  padding: 0;
  color: var(--text);
  border: 1px solid var(--line-bright);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgb(1 6 12 / 75%);
  backdrop-filter: blur(4px);
}

dialog form {
  padding: 30px;
}

dialog h2 {
  margin: 12px 0 8px;
}

dialog p {
  margin: 0;
  color: var(--muted);
}

.dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 28px;
}

@media (max-width: 820px) {
  .app-shell {
    padding-top: 32px;
  }

  .start-grid,
  .result-layout {
    grid-template-columns: 1fr;
  }

  .intro-panel h1 {
    font-size: 44px;
  }

  .intro-panel > p {
    font-size: 16px;
  }

  .source-meter {
    margin-top: 28px;
  }

  .quiz-topbar {
    grid-template-columns: 70px minmax(0, 1fr) 60px;
    gap: 10px;
  }

  .result-layout {
    max-width: 620px;
  }
}

@media (max-width: 560px) {
  .site-header,
  footer,
  .app-shell {
    width: min(100% - 24px, 1180px);
  }

  .site-header {
    min-height: 74px;
  }

  .header-status {
    font-size: 12px;
  }

  .header-status span:last-child {
    max-width: 92px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
  }

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

  .intro-panel h1 {
    font-size: 38px;
  }

  .setup-panel,
  .question-card {
    padding: 22px 18px;
  }

  .field-row,
  .result-actions {
    grid-template-columns: 1fr;
  }

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

  .question-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .question-number {
    order: 2;
    text-align: center;
  }

  .primary-button.compact {
    width: 100%;
  }

  .score-ring {
    width: 180px;
    height: 180px;
  }

  .stat-row div {
    padding-inline: 6px;
  }

  .stat-row strong {
    font-size: 22px;
  }

  .history-item {
    grid-template-columns: 1fr auto;
  }

  .history-review {
    grid-column: 1 / -1;
  }

  .subpage-header {
    align-items: center;
  }

  .subpage-header h1 {
    font-size: 34px;
  }

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

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