/* Play page styles. Local system fonts only (no external font requests). Colors are tokens on :root. */
:root {
  --ink: #0c1220;
  --ink-raised: #151d2f;
  --ink-line: #2a3650;
  /* Borders that outline a control (button). 3:1 against --ink and --ink-raised (WCAG 1.4.11). */
  --control-line: #5c6d8f;
  --moon: #e9eef5;
  --moon-muted: #b4bfcf;
  --gold: #d2ab62;
  --glass: #8fb8d6;
  --warn: #e8b07a;
  --error: #f0a3a3;
  --focus: #ffd98a;
  --radius: 10px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  background: var(--ink);
  color: var(--moon);
  font-family: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

a {
  color: var(--glass);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.lab-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  justify-content: space-between;
  padding: 10px 16px;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--ink-line);
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  padding: 8px 12px;
  background: var(--gold);
  color: var(--ink);
  border-radius: var(--radius);
}

.skip-link:focus {
  top: 8px;
}

.game-header,
.game-main,
.game-footer {
  width: 100%;
  max-width: 680px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.game-header {
  padding-top: 12px;
}

.eyebrow {
  margin: 0;
  color: var(--gold);
  font-size: 0.875rem;
  letter-spacing: 0.08em;
}

.game-title {
  margin: 4px 0 0;
  font-size: 1.5rem;
  line-height: 1.35;
}

.save-status {
  margin: 8px 0 0;
  color: var(--moon-muted);
  font-size: 0.875rem;
}

.game-main {
  padding-top: 8px;
  padding-bottom: 32px;
}

.game-footer {
  padding-top: 16px;
  padding-bottom: 32px;
  color: var(--moon-muted);
  font-size: 0.875rem;
}

.view {
  display: block;
}

.view-title {
  margin: 8px 0 12px;
  font-size: 1.3rem;
  line-height: 1.4;
}

.view-title:focus {
  outline: none;
}

/* Banner art above the title on the intro and setup screens (the class is on the <img> itself).
   Hidden on short viewports (see the 760px query below). */
.scene-art {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: auto;
  max-height: 26vh;
  object-fit: cover;
  margin: 0 0 12px;
  border-radius: var(--radius);
  border: 1px solid var(--ink-line);
}

.lead {
  font-size: 1.05rem;
}

.muted {
  color: var(--moon-muted);
}

.plain-list {
  padding-left: 1.2em;
}

.plain-list li {
  margin-bottom: 6px;
}

.callout {
  padding: 12px 14px;
  border-left: 3px solid var(--gold);
  background: var(--ink-raised);
  border-radius: var(--radius);
}

.notice {
  padding: 10px 12px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  color: var(--warn);
  background: var(--ink-raised);
}

.error-text {
  color: var(--error);
}

.confirm {
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  background: var(--ink-raised);
}

.confirm-text {
  margin: 0 0 8px;
}

.confirm-text:focus {
  outline: none;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  max-width: 100%;
  padding: 8px 16px;
  border: 1px solid var(--control-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--moon);
  font: inherit;
  text-align: center;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.btn:hover {
  border-color: var(--gold);
}

.btn:active {
  transform: translateY(1px);
}

/* Unavailable reads as "outlined and quiet", not as a faded solid: opacity 0.5 turned the gold fill into a muddy brown
   (ink text 3.0:1 on it) that still looked like a live button. The dashed frame is the non-colour cue; the text stays
   readable (moon-muted on ink). Declared after .btn-primary and .btn:hover so it overrides their fill, border and hover filter. */
.btn:disabled {
  background: var(--ink);
  color: var(--moon-muted);
  border-style: dashed;
  border-color: var(--ink-line);
  cursor: not-allowed;
  filter: none;
}

.btn-primary {
  background: var(--gold);
  border-color: var(--gold);
  color: var(--ink);
  font-weight: 600;
}

.btn-primary:hover {
  filter: brightness(1.06);
}

.btn-quiet {
  background: transparent;
}

.btn-danger {
  border-color: var(--error);
  color: var(--error);
}

.field-group {
  margin: 16px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
}

.field-group legend {
  padding: 0 6px;
  color: var(--gold);
}

.check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  min-height: 44px;
  padding: 6px 0;
  cursor: pointer;
}

.check input {
  width: 22px;
  height: 22px;
  margin: 2px 0 0;
  flex: 0 0 auto;
  accent-color: var(--gold);
}

.check small {
  display: block;
  color: var(--moon-muted);
  font-size: 0.875rem;
}

/* Question view */
.q-top {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}

.q-progress-text {
  margin: 0;
  flex: 1 1 180px;
  color: var(--moon-muted);
  font-size: 0.9rem;
}

#q-progress {
  flex: 1 1 100%;
  width: 100%;
  height: 8px;
  accent-color: var(--gold);
}

.q-top .btn {
  min-height: 44px;
}

.q-theme {
  margin: 8px 0 0;
  color: var(--glass);
  font-size: 0.9rem;
}

/* Question art is capped at 18% of the viewport height so the options stay above the fold on desktop.
   R19 A+B+C: a framed card layer (border-box, so the frame sits inside the 18vh cap and the layout height is unchanged),
   a gold double-line frame made with box-shadow (no layout effect), and the light/shade overlay in .q-art::after. */
.q-image {
  display: block;
  box-sizing: border-box;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 18vh;
  object-fit: contain;
  margin: 8px auto 0;
  padding: 6px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
  box-shadow:
    0 0 0 3px var(--ink),
    0 0 0 4px color-mix(in srgb, var(--gold) 45%, transparent);
}

/* R18 F-2: on phones the options take priority over the art. At 390×844 the options ended 25–36 px below the fold
   (with the page at its natural scroll of 157 px). The art cap (12vh) and a one-line top row (progress text, bar,
   pause) bring the options and the lock button into the first screen for every drawn question. */
@media (max-width: 639px) {
  .q-image {
    max-height: 12vh;
  }

  .q-top {
    flex-wrap: nowrap;
    gap: 6px;
  }

  .q-progress-text {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  #q-progress {
    flex: 1 1 auto;
    width: auto;
    min-width: 40px;
  }
}

/* R18 F-2, user decision (2026-10-20): on phones the question view keeps the art and the options and gives up
   page-header space, so the options and the lock button fit in the first screen even at scroll 0. Only while the
   question view is open: the lab bar, eyebrow, title line and save status are compacted or hidden, and the card
   heading is visually hidden (the progress line already says "第 N 題"; the heading keeps focus and the name). */
@media (max-width: 639px) {
  body:has(#view-question:not([hidden])) .lab-bar {
    padding: 4px 12px;
    font-size: 0.8rem;
    line-height: 1.5;
  }

  body:has(#view-question:not([hidden])) .game-header {
    padding-top: 2px;
  }

  body:has(#view-question:not([hidden])) .eyebrow,
  body:has(#view-question:not([hidden])) .save-status {
    display: none;
  }

  body:has(#view-question:not([hidden])) .game-title {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.2;
  }

  body:has(#view-question:not([hidden])) .game-main {
    padding-top: 4px;
  }

  body:has(#view-question:not([hidden])) .q-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  body:has(#view-question:not([hidden])) .q-theme {
    margin-top: 4px;
  }

  body:has(#view-question:not([hidden])) .q-prompt {
    margin: 6px 0 10px;
  }
}

/* The container shrinks to the art so the overlay covers the art box only, not the full content column. */
.q-art {
  position: relative;
  width: fit-content;
  margin: 0 auto;
}

/* Light from above (gold 14%, fading out by 40%) and the lower edge sinking into the page colour. */
.q-art::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--gold) 14%, transparent) 0%,
    transparent 40%,
    var(--ink) 100%
  );
}

/* Result art is capped at 35% of the viewport height. */
.ending-image {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  max-height: 35vh;
  object-fit: contain;
  margin: 10px auto 10px;
  border-radius: var(--radius);
}

.q-title {
  margin: 14px 0 4px;
  font-size: 1.2rem;
}

.q-title:focus,
.feedback-title:focus {
  outline: none;
}

/* A new question moves focus to its heading; keyboard focus must show a frame there (R12 C3). */
.q-title:focus-visible,
.feedback-title:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 4px;
}

/* Read by screen readers only (the countdown expiry notice, R12 C2). */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.q-speaker {
  margin: 0;
  color: var(--gold);
  font-weight: 600;
}

.q-prompt {
  margin: 8px 0 14px;
  font-size: 1.08rem;
}

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

.option {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: 100%;
  min-height: 44px;
  padding: 12px 14px;
  /* R19 C2: unselected options take a muted gold hairline instead of the grey --ink-line. */
  border: 1px solid color-mix(in srgb, var(--gold) 30%, transparent);
  border-radius: var(--radius);
  background: var(--ink-raised);
  color: var(--moon);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.option:hover:not(:disabled) {
  border-color: var(--glass);
}

.option[aria-checked="true"] {
  border-color: var(--gold);
  box-shadow: inset 4px 0 0 var(--gold);
}

.option:disabled {
  cursor: default;
}

.option:disabled:not([aria-checked="true"]) {
  opacity: 0.6;
}

.option-key {
  flex: 0 0 auto;
  min-width: 1.6em;
  color: var(--gold);
  font-weight: 600;
}

.option-text {
  flex: 1 1 auto;
  min-width: 0;
}

.countdown {
  margin: 12px 0 0;
  color: var(--warn);
}

.hint {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--glass);
  background: var(--ink-raised);
  border-radius: var(--radius);
}

.feedback {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--ink-line);
  border-radius: var(--radius);
  background: var(--ink-raised);
}

.feedback-title {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.feedback-text {
  margin: 0 0 4px;
}

/* Result view */
.result-section {
  margin-top: 20px;
}

.result-section h3 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 1rem;
}

.ending-name {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 600;
}

.axis-list,
.theme-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.axis-list li {
  display: grid;
  gap: 4px 10px;
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 10px;
}

.axis-list meter {
  grid-column: 1 / -1;
  width: 100%;
  height: 14px;
  accent-color: var(--gold);
}

.theme-list li {
  padding: 8px 0;
  border-bottom: 1px solid var(--ink-line);
}

.theme-list small {
  color: var(--moon-muted);
}

/* Each theme row on the result page: a small picture, then the label and the answered count. */
.theme-item {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  align-items: center;
}

.theme-art {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--ink-line);
}

.card-text {
  margin: 0;
  padding: 12px 14px;
  border-left: 3px solid var(--glass);
  background: var(--ink-raised);
  border-radius: var(--radius);
}

.faint {
  color: var(--moon-muted);
  font-size: 0.875rem;
}

@media (min-width: 640px) {
  .options {
    grid-template-columns: 1fr 1fr;
  }
}

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

/* Short viewports (640px-tall phones). Declared LAST so these override the base rules above (source order matters).
   The first screen must hold the question and all four options: question art hidden, heading kept for screen readers
   and shown as the progress line, save-status line hidden (the save notice still appears in the notice area),
   and tighter spacing. Checked in a browser at 320x640 with the longest bank items. */
@media (max-height: 760px) {
  .q-art,
  .scene-art,
  .eyebrow,
  .q-theme,
  .save-status {
    display: none;
  }

  .lab-bar {
    padding: 4px 12px;
    font-size: 0.8rem;
    line-height: 1.5;
  }

  .game-header {
    padding-top: 2px;
  }

  .game-title {
    margin: 0;
    font-size: 1.1rem;
    line-height: 1.2;
  }

  /* The heading text is shown as the progress line ("第 N 題，共 10 題"); the h2 stays for focus and screen readers. */
  .q-title {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .q-top {
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
  }

  .q-progress-text {
    flex: 0 0 auto;
    margin: 0;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  #q-progress {
    flex: 1 1 auto;
    width: auto;
    min-width: 40px;
    height: 8px;
  }

  .q-top .btn {
    min-height: 44px;
    padding: 0 12px;
  }

  .q-speaker {
    font-size: 0.9rem;
    line-height: 1.4;
  }

  .q-prompt {
    margin: 4px 0 8px;
    font-size: 0.95rem;
    line-height: 1.4;
  }

  .options {
    gap: 6px;
  }

  /* Keep the 44px touch target even when an option fits on one line (min-height 0 measured ~30px, R12). */
  .option {
    min-height: 44px;
    padding: 4px 10px;
    font-size: 0.95rem;
    line-height: 1.3;
  }

  .option-key {
    min-width: 1.2em;
  }

  .button-row {
    gap: 6px;
    margin-top: 10px;
  }
}
