/* VisionBridge - 多感官視覺描述平台
 *
 * 版面採「舞台」形式：一次只專注一件事，描述以文章規格排版。
 * 主要使用情境為對外展示與演講，因此以深色劇場感為預設；
 * 系統偏好淺色時切換為同版面的淺色主題。
 */

/* ==========================================================================
   1. 設計語彙
   ========================================================================== */

:root {
  --bg: #0d0d10;
  --bg-glow: rgba(200, 162, 106, 0.07);
  --surface: #16161b;
  --surface-2: #1c1c22;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);

  --ink: #f2f0ec;
  --muted: #a8a49e;
  /* 最淡的一階仍須與底色維持 AA 對比（圖說、字數、頁尾都用它） */
  --faint: #8d8881;

  /* 金色作為唯一強調色，用量克制 */
  --gold: #c8a26a;
  --gold-hi: #dcb87f;
  --gold-soft: rgba(200, 162, 106, 0.13);
  --gold-ink: #17150f;

  --danger: #f08a7d;
  --danger-soft: rgba(240, 138, 125, 0.12);
  --ok: #7fc9a0;

  --shadow-lift: 0 20px 50px -12px rgba(0, 0, 0, 0.8);
  --shadow-art: 0 30px 70px -20px rgba(0, 0, 0, 0.75);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-full: 999px;

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --stage-width: 780px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #faf8f5;
    --bg-glow: rgba(176, 132, 66, 0.08);
    --surface: #ffffff;
    --surface-2: #f4f1ec;
    --line: rgba(26, 22, 16, 0.11);
    --line-strong: rgba(26, 22, 16, 0.2);

    --ink: #1c1a17;
    --muted: #5d574e;
    --faint: #6e675c;

    --gold: #8a6220;
    --gold-hi: #6f4e19;
    --gold-soft: rgba(138, 98, 32, 0.1);
    --gold-ink: #ffffff;

    --danger: #b4372a;
    --danger-soft: rgba(180, 55, 42, 0.08);
    --ok: #2c7a55;

    --shadow-lift: 0 18px 40px -14px rgba(60, 45, 25, 0.28);
    --shadow-art: 0 24px 55px -18px rgba(60, 45, 25, 0.32);
  }
}

/* ==========================================================================
   2. 基礎
   ========================================================================== */

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans TC', 'WenQuanYi Zen Hei', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg);
  background-image: radial-gradient(ellipse 1000px 600px at 50% -10%, var(--bg-glow), transparent 65%);
  background-repeat: no-repeat;
  color: var(--ink);
  line-height: 1.7;
  font-size: 16px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--gold);
  text-underline-offset: 2px;
}

button,
input,
textarea,
label {
  font-family: inherit;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

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

.skip-link {
  position: absolute;
  top: 0;
  left: 50%;
  z-index: 200;
  transform: translate(-50%, -130%);
  padding: 12px 20px;
  border-radius: 0 0 var(--r-sm) var(--r-sm);
  background-color: var(--gold);
  color: var(--gold-ink);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 0.18s var(--ease);
}

.skip-link:focus {
  transform: translate(-50%, 0);
}

/* ==========================================================================
   3. 頂列
   ========================================================================== */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px;
  position: relative;
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-mark svg {
  display: block;
  width: 17px;
  height: 17px;
  stroke: var(--gold);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background-color: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
}

.model-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--r-full);
  background-color: var(--faint);
  flex-shrink: 0;
}

.model-chip.ready .model-dot {
  background-color: var(--ok);
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background-color: var(--surface);
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}

.ghost-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.ghost-btn svg {
  width: 13px;
  height: 13px;
}

/* ==========================================================================
   4. 進度軌道
   ========================================================================== */

.rail {
  position: fixed;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 20;
}

.rail ol {
  display: flex;
  flex-direction: column;
  gap: 16px;
  list-style: none;
}

.rail-step {
  display: flex;
  align-items: center;
  gap: 11px;
  color: var(--faint);
  font-size: 11.5px;
  letter-spacing: 0.04em;
  transition: color 0.25s var(--ease);
}

.rail-step i {
  width: 7px;
  height: 7px;
  border-radius: var(--r-full);
  background-color: var(--line-strong);
  flex-shrink: 0;
  transition: background-color 0.25s var(--ease), box-shadow 0.25s var(--ease);
}

.rail-step.done i {
  background-color: var(--gold);
  opacity: 0.5;
}

.rail-step.now {
  color: var(--ink);
}

.rail-step.now i {
  background-color: var(--gold);
  opacity: 1;
  box-shadow: 0 0 0 4px var(--gold-soft);
}

/* 空間不足時隱藏軌道，避免與內容相撞 */
@media (max-width: 1180px) {
  .rail { display: none; }
}

/* ==========================================================================
   5. 舞台
   ========================================================================== */

.stage {
  max-width: var(--stage-width);
  margin: 0 auto;
  padding: 8px 32px 160px;
  text-align: center;
}

.stage:focus {
  outline: none;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 15px;
  margin-bottom: 26px;
  border: 1px solid var(--gold-soft);
  border-radius: var(--r-full);
  background-color: var(--gold-soft);
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.05em;
}

.art {
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow-art);
  border: 1px solid var(--line);
  background-color: var(--surface);
}

.art img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 62vh;
  object-fit: contain;
  background-color: var(--surface-2);
}

.art-caption {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.03em;
}

.art-actions {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}

/* 已有描述後，圖片讓出空間，使圖與描述能同屏並存——
   演講時不必當場捲動就能同時呈現作品與生成結果。 */
.has-result .art {
  /* 讓外框貼合縮小後的圖片，避免左右出現空白色塊 */
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
}

.has-result .art img {
  width: auto;
  max-width: 100%;
  max-height: 34vh;
}

.has-result .eyebrow {
  margin-bottom: 18px;
  font-size: 11.5px;
}

.has-result .art-actions {
  margin-top: 14px;
}

/* 生成後主要動作移交給底部控制列，此處降為次要 */
.has-result .art-actions .pill-btn {
  height: 34px;
  padding: 0 15px;
  font-size: 13px;
  background-color: transparent;
  border-color: var(--line);
  color: var(--muted);
  font-weight: 500;
}

.has-result .art-actions .pill-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
}

.has-result .reading {
  margin-top: 30px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.file-input:focus-visible + .pill-btn,
.file-input:focus-visible ~ label.pill-btn {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

/* ==========================================================================
   6. 按鈕
   ========================================================================== */

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 20px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  background-color: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease),
              color 0.18s var(--ease), transform 0.12s var(--ease);
}

.pill-btn:hover:not(:disabled) {
  border-color: var(--gold);
  color: var(--gold);
  transform: translateY(-1px);
}

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

.pill-btn.primary:hover:not(:disabled) {
  background-color: var(--gold-hi);
  border-color: var(--gold-hi);
  color: var(--gold-ink);
}

.pill-btn svg {
  width: 14px;
  height: 14px;
}

.pill-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

.block-btn {
  display: block;
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border: 1px solid var(--gold);
  border-radius: var(--r-sm);
  background-color: var(--gold);
  color: var(--gold-ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.18s var(--ease), opacity 0.18s var(--ease);
}

.block-btn:hover:not(:disabled) {
  background-color: var(--gold-hi);
  border-color: var(--gold-hi);
}

.block-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.text-btn {
  border: 0;
  background: none;
  color: var(--gold);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 4px;
}

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

.close-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background-color: transparent;
  color: var(--muted);
  cursor: pointer;
}

.close-btn:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.close-btn svg {
  width: 15px;
  height: 15px;
}

/* ==========================================================================
   7. 閱讀區
   ========================================================================== */

.reading {
  margin-top: 52px;
  text-align: left;
}

.reading-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 16px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--line);
}

.reading-label {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--ink);
}

.reading-label:focus {
  outline: none;
}

.reading-meta {
  font-size: 11.5px;
  color: var(--faint);
  white-space: nowrap;
}

/* 描述是產品的價值所在：字級、行距與字距都以「閱讀」為前提 */
.prose {
  font-size: 19px;
  line-height: 2.15;
  letter-spacing: 0.015em;
  color: var(--ink);
  white-space: pre-wrap;
  overflow-wrap: break-word;
  min-height: 120px;
}

.prose .typewriter-cursor {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  background-color: var(--gold);
  animation: blink 1.05s steps(2, start) infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 載入狀態 */
.loading {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--muted);
  font-size: 15px;
  letter-spacing: 0.02em;
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--gold);
  border-radius: var(--r-full);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-message {
  padding: 16px 18px;
  border-radius: var(--r-md);
  background-color: var(--danger-soft);
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 15px;
  line-height: 1.8;
}

.error-tips {
  margin-top: 12px;
  padding: 14px 18px;
  border-radius: var(--r-md);
  background-color: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.8;
}

/* ==========================================================================
   8. 底部控制列
   ========================================================================== */

.dock {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px;
  max-width: calc(100vw - 32px);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background-color: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(18px) saturate(180%);
  -webkit-backdrop-filter: blur(18px) saturate(180%);
  box-shadow: var(--shadow-lift);
}

@supports not (background-color: color-mix(in srgb, red 50%, transparent)) {
  .dock { background-color: var(--surface); }
}

.dock-play {
  width: 42px;
  height: 42px;
  border-radius: var(--r-full);
  border: 0;
  background-color: var(--gold);
  color: var(--gold-ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background-color 0.18s var(--ease);
}

.dock-play:hover {
  background-color: var(--gold-hi);
}

.dock-play svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
  stroke: none;
  grid-area: 1 / 1;
}

.dock-play .ico-stop { display: none; }
.dock-play.speaking .ico-play { display: none; }
.dock-play.speaking .ico-stop { display: block; }

.dock-sep {
  width: 1px;
  height: 22px;
  background-color: var(--line);
  margin: 0 3px;
  flex-shrink: 0;
}

.dock-variants {
  display: flex;
  gap: 2px;
  /* 版本 chips 會隨生成次數增加：超寬時水平捲動，不擠壓播放鈕 */
  overflow-x: auto;
  max-width: min(58vw, 560px);
  scrollbar-width: thin;
}

.dock-variants .dock-btn {
  flex: 0 0 auto;
}

.dock-btn {
  height: 38px;
  padding: 0 15px;
  border: 0;
  border-radius: var(--r-full);
  background: none;
  color: var(--muted);
  font-size: 13.5px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background-color 0.18s var(--ease), color 0.18s var(--ease);
}

.dock-btn:hover:not(:disabled) {
  color: var(--ink);
}

.dock-btn[aria-pressed="true"] {
  background-color: var(--gold-soft);
  color: var(--gold);
  font-weight: 600;
}

.dock-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.dock-btn svg {
  width: 14px;
  height: 14px;
}

/* ==========================================================================
   9. 面板（設定 / 調整）
   ========================================================================== */

.panel {
  position: fixed;
  right: 20px;
  bottom: 84px;
  z-index: 60;
  width: min(400px, calc(100vw - 40px));
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background-color: var(--surface);
  box-shadow: var(--shadow-lift);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.panel-head h2 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.panel-body {
  padding: 18px;
  overflow-y: auto;
  /* flex 子元素預設不會縮到內容高度以下，沒有 min-height: 0 就不會出現捲動，
     內容會被 .panel 的 overflow: hidden 直接切掉（手機上主要按鈕曾因此按不到）。 */
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}

/* 面板的主要動作固定在底部，捲動時永遠看得到 */
.panel-foot {
  flex-shrink: 0;
  padding: 14px 18px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background-color: var(--surface);
}

.panel-foot .block-btn {
  margin-top: 0;
}

.panel-foot .profile-note {
  margin: 0 0 10px;
}

.field + .field {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.field-head label,
.field-label {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
}

.field-hint {
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
  margin-bottom: 12px;
}

textarea,
input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background-color: var(--surface-2);
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.7;
  transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease);
}

textarea {
  resize: vertical;
  min-height: 96px;
}

textarea::placeholder,
input::placeholder {
  color: var(--faint);
}

textarea:focus,
input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-soft);
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.btn-row .pill-btn {
  flex: 1 1 auto;
  min-width: 84px;
  height: 38px;
  padding: 0 14px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-full);
  background-color: transparent;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  transition: border-color 0.18s var(--ease), color 0.18s var(--ease),
              background-color 0.18s var(--ease);
}

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

.chip[aria-pressed="true"] {
  background-color: var(--gold);
  border-color: var(--gold);
  color: var(--gold-ink);
  font-weight: 600;
}

.profile-note {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  border-left: 2px solid var(--gold);
  background-color: var(--surface-2);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.75;
}

.status {
  margin-top: 14px;
  padding: 11px 13px;
  border-radius: var(--r-sm);
  background-color: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.7;
}

.status.ok {
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
  color: var(--ok);
}

.status.warn {
  border-color: color-mix(in srgb, var(--gold) 45%, transparent);
  color: var(--gold);
}

/* 面板開啟時的遮罩 */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background-color: rgba(0, 0, 0, 0.45);
}

/* ==========================================================================
   10. 頁尾
   ========================================================================== */

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 28px 32px 32px;
  color: var(--faint);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.footer a {
  color: var(--faint);
  text-decoration: none;
}

.footer a:hover {
  color: var(--gold);
}

/* ==========================================================================
   11. 觸控與手機
   --------------------------------------------------------------------------
   手機是本平台的重要使用情境：使用者站在作品前、單手持機、以「聽」為主。
   因此控制項集中於拇指可及的下緣，面板改為由下而上的抽屜，
   並保留 iOS 安全區域，避免與home indicator重疊。
   ========================================================================== */

/* 拍照入口僅在觸控裝置顯示（桌機沒有相機或體驗不佳）。
   輸入元素也必須一併移除：若只隱藏 label，桌機上會留下一個
   沒有可存取名稱的表單控制項在無障礙樹中。 */
.touch-only {
  display: none;
}

.touch-only-input {
  display: none;
}

@media (pointer: coarse) {
  .touch-only {
    display: inline-flex;
  }

  .touch-only-input {
    display: block;
  }

  /* 觸控目標至少 44px，符合 WCAG 2.5.5 與行動裝置操作慣例 */
  .pill-btn,
  .dock-btn,
  .chip,
  .close-btn,
  .ghost-btn,
  .block-btn {
    min-height: 44px;
  }

  /* 「原始」等兩字按鈕寬度僅 43px，補足最小寬度 */
  .dock-btn {
    min-width: 44px;
  }

  .close-btn {
    width: 44px;
  }

  .text-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  /* 頁尾連結原本僅 20px 高，指尖很難點中 */
  .footer a {
    display: inline-block;
    padding: 12px 4px;
    margin: -12px 0;
  }
}

@media (max-width: 768px) {
  /* 手機上單手持機、視距較遠：說明文字放大一階（拿來讀的，不是裝飾） */
  .field-hint { font-size: 13.5px; }
  .art-caption { font-size: 13px; }

  /* --- 頂列：精簡為品牌 + 設定，狀態改以設定鍵上的圓點呈現 --- */
  .topbar {
    padding: 12px 16px;
  }

  .model-chip {
    display: none;
  }

  .ghost-btn::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: var(--r-full);
    background-color: var(--faint);
    flex-shrink: 0;
  }

  .key-ready .ghost-btn::before {
    background-color: var(--ok);
  }

  /* --- 舞台：以 dvh 為準，避免瀏覽器工具列伸縮造成版面跳動 --- */
  .stage {
    padding: 4px 16px 132px;
    /* 底部預留控制列高度與安全區域 */
    padding-bottom: calc(132px + env(safe-area-inset-bottom, 0px));
  }

  .eyebrow {
    margin-bottom: 18px;
    padding: 5px 13px;
    font-size: 13px;   /* 操作指示是拿來讀的；11.5px 在手機視距下太小 */
  }

  .art img {
    max-height: 44vh;
    max-height: 44dvh;
  }

  /* 生成描述後，圖片收為縮圖列。
     手機螢幕高度有限，若維持大圖，描述只剩兩三行就被控制列蓋住；
     掃描後真正要讀（或聽）的是描述，圖片留一個確認用的縮圖即可。 */
  .has-result .art {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px;
    border-radius: var(--r-md);
    text-align: left;
    box-shadow: none;
  }

  .has-result .art img {
    width: 52px;
    height: 52px;
    max-height: none;
    object-fit: cover;
    border-radius: var(--r-sm);
    flex-shrink: 0;
  }

  .has-result .art-caption {
    flex: 1;
    min-width: 0;
    padding: 0;
    border-top: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 已有結果時前言標籤資訊量低，讓位給描述 */
  .has-result .eyebrow {
    display: none;
  }

  .art-actions {
    gap: 8px;
    margin-top: 16px;
  }

  .has-result .art-actions {
    margin-top: 10px;
  }

  /* --- 閱讀：行寬變窄，行距略收，維持可讀性 --- */
  .reading {
    margin-top: 32px;
  }

  .has-result .reading {
    margin-top: 24px;
  }

  .prose {
    font-size: 17.5px;
    line-height: 2;
  }

  /* --- 控制列：橫跨底部、朗讀鍵放大置左，拇指最易觸及 --- */
  .dock {
    left: 10px;
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    transform: none;
    max-width: none;
    gap: 4px;
    padding: 8px;
    border-radius: var(--r-lg);
    /* 控制列橫跨整個寬度，提高不透明度避免下方文字透出干擾閱讀 */
    background-color: color-mix(in srgb, var(--surface) 97%, transparent);
  }

  .dock-play {
    width: 48px;
    height: 48px;
  }

  .dock-play svg {
    width: 17px;
    height: 17px;
  }

  .dock-variants {
    flex: 1;
    justify-content: center;
  }

  .dock-btn {
    padding: 0 12px;
    font-size: 13px;
  }

  /* --- 面板：改為底部抽屜，貼齊下緣、單手可及 --- */
  .panel {
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    transform: none;
    width: auto;
    max-height: 86vh;
    max-height: 86dvh;
    border-width: 1px 0 0;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
  }

  /* 抽屜握把：暗示可由下緣拉出 */
  .panel-head {
    position: relative;
    padding-top: 22px;
  }

  .panel-head::before {
    content: '';
    position: absolute;
    top: 9px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: var(--r-full);
    background-color: var(--line-strong);
  }

  .panel-body {
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .footer {
    padding: 20px 16px 24px;
    font-size: 11.5px;
  }
}

/* 窄機身：控制列文字再收斂，確保單行不換行 */
@media (max-width: 400px) {
  .dock {
    gap: 2px;
    padding: 7px;
  }

  .dock-btn {
    padding: 0 9px;
    font-size: 12.5px;
  }

  .dock-sep {
    display: none;
  }

  .dock-play {
    width: 44px;
    height: 44px;
  }
}

/* 橫向或矮螢幕：壓縮圖片，確保描述仍在可視範圍內 */
@media (max-height: 560px) and (orientation: landscape) {
  .art img {
    max-height: 52vh;
    max-height: 52dvh;
  }

  .has-result .art img {
    max-height: 34vh;
    max-height: 34dvh;
  }

  .eyebrow {
    display: none;
  }

  .stage {
    padding-top: 0;
  }
}

/* 窄機身且已有結果時，次要動作收為純圖示以維持單行；
   文字僅在視覺上隱藏，螢幕閱讀器仍能取得按鈕名稱。 */
@media (max-width: 400px) {
  .has-result .secondary-action .btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }

  .has-result .secondary-action {
    padding: 0 16px;
  }
}

/* ==========================================================================
   16. 大螢幕版面
   手機版是「單欄舞台」，直接放到桌機會變成中間一條窄柱、兩側大量留白，
   而策展與撰稿工作主要在桌機進行。以下僅在大螢幕改變版面配置，
   不影響手機與既有互動。
   ========================================================================== */

/* 進度軌道：由左側浮動改為頂部水平排列。
   原先固定在畫面左緣、垂直居中，與內容沒有視覺連結，
   且寬度不足 1180px 時整條隱藏，資訊直接消失。 */
@media (min-width: 769px) {
  .rail {
    position: static;
    left: auto;
    top: auto;
    transform: none;
    display: flex;
    justify-content: center;
    padding: 2px 32px 0;
  }

  .rail ol {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0;
  }

  .rail-step {
    gap: 8px;
  }

  /* 步驟之間的連接線，讓流程方向明確 */
  .rail-step:not(:last-child)::after {
    content: '';
    width: 32px;
    height: 1px;
    margin: 0 14px;
    background-color: var(--line-strong);
    opacity: 0.65;
  }
}

/* 生成描述後改為雙欄：左側作品、右側描述，兩者同屏並存不需捲動。
   生成前維持單欄置中的舞台感。 */
@media (min-width: 1100px) {
  .has-result .stage {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    gap: 16px 44px;
    align-items: start;
    max-width: 1180px;
    /* 撐滿首屏，讓頁尾落在視窗之外：主畫面只留作品、描述與控制列 */
    min-height: calc(100vh - 108px);
    padding-bottom: 132px;
    text-align: left;
  }

  .has-result .eyebrow {
    grid-column: 1 / -1;
    justify-self: center;
  }

  .has-result .art {
    grid-column: 1;
    grid-row: 2;
    width: 100%;
    margin: 0;
  }

  /* 有橫向空間可用，作品不必再壓到 34vh */
  .has-result .art img {
    width: 100%;
    max-height: 54vh;
    object-fit: contain;
  }

  .has-result .art-actions {
    grid-column: 1;
    grid-row: 3;
    justify-content: flex-start;
    margin-top: 16px;
  }

  .has-result .reading {
    grid-column: 2;
    grid-row: 2 / span 2;
    margin-top: 0;
  }

  /* 限制行寬，長描述在寬螢幕上仍好讀 */
  .has-result .prose {
    max-width: 34em;
  }
}

/* 底部控制列是固定定位，內容較短時會蓋住頁尾。
   控制列出現後（body.has-result）為頁尾保留讓位空間。 */
.has-result .footer {
  padding-bottom: 104px;
}

/* ==========================================================================
   17. 工作坊支援：描述動作列與我的紀錄
   ========================================================================== */

.reading-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 18px;
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* 明確告知送出後照片會被講師看到——照片預設不離開裝置，
   這是唯一會上傳的情況，必須在按下之前就看得到。 */
.action-note {
  flex: 1 1 100%;
  margin: 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.7;
}

.action-status {
  flex: 1 1 100%;
  min-height: 1.3em;
  color: var(--muted);
  font-size: 12.5px;
  letter-spacing: 0.02em;
}

/* 暱稱設在設定面板，只需填一次；不用跳窗，
   部分手機瀏覽器會擋掉 prompt 而造成靜默失敗。 */
#nicknameInput {
  width: 100%;
  box-sizing: border-box;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background-color: transparent;
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
}

#nicknameInput:focus {
  outline: none;
  border-color: var(--gold);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 4px 0 18px;
}

.history-item {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background-color: var(--surface-soft, rgba(0, 0, 0, 0.02));
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  color: var(--faint);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.history-text {
  margin: 0;
  color: var(--ink);
  font-size: 13.5px;
  line-height: 1.85;
  /* 清單以摘要呈現，避免長描述把面板撐得難以瀏覽 */
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ===== 作品資料（館方詮釋資料）=====
   預設收合，維持「舞台一次專注一件事」的版面；展開後才佔空間。
   聚焦樣式沿用全域的 :focus-visible，此處不另外覆寫。 */
.meta-block {
  width: min(100%, 720px);
  margin: 4px auto 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background-color: var(--surface);
}

.meta-block > summary {
  padding: 12px 16px;
  min-height: 44px;           /* 單手觸控目標 */
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  list-style: none;
  border-radius: var(--r-md);
}

.meta-block > summary::-webkit-details-marker { display: none; }

.meta-block > summary::before {
  content: '';
  width: 7px;
  height: 7px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform .18s ease;
  flex-shrink: 0;
}

.meta-block[open] > summary::before { transform: rotate(45deg); }

.meta-block .field-hint { margin: 0 16px 10px; }

.meta-block textarea {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background-color: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
}

.meta-block textarea:focus {
  outline: none;
  border-color: var(--gold);
}

.meta-count {
  margin: 6px 16px 14px;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}

@media (prefers-reduced-motion: reduce) {
  .meta-block > summary::before { transition: none; }
}

/* ===== 準確性約束開關（產出條件面板內的對照用控制） ===== */
.constrain-field { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 4px; }

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  /* 單手觸控目標 */
  min-height: 44px;
}

/* 覆蓋整個 label 而非縮成 0×0：0 尺寸的 input 沒有實際點擊區域，
   只能靠 label 代點，自動化工具也判定為不可操作。 */
.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch { position: relative; }

.switch-track {
  position: relative;
  flex: none;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background-color: var(--surface-2);
  border: 1px solid var(--line-strong);
  transition: background-color .18s ease, border-color .18s ease;
}

.switch-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: var(--muted);
  transition: transform .18s ease, background-color .18s ease;
}

.switch input:checked + .switch-track {
  background-color: var(--gold-soft);
  border-color: var(--gold);
}

.switch input:checked + .switch-track::after {
  transform: translateX(20px);
  background-color: var(--gold);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}

.switch-text { font-size: 14px; color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  .switch-track, .switch-track::after { transition: none; }
}

/* ==========================================================================
   版本對照與伺服器語音
   ========================================================================== */

.compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 32px;
}

.compare-col {
  min-width: 0;
}

.compare-col h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--gold);
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.compare-count {
  font-size: 12px;
  font-weight: 400;
  color: var(--faint);
}

/* 比 .prose 的 19px 略收一階：兩欄並排時單欄較窄，17px 行長較合理 */
.compare-text {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  font-size: 17px;
  line-height: 2;
  letter-spacing: 0.015em;
  color: var(--ink);
}

.compare-text mark.diff {
  background-color: var(--gold-soft);
  color: var(--gold-hi);
  border-radius: 3px;
  padding: 0 1px;
}

/* 對照側的版本 chip：金色描邊，與基準（實底壓下）區隔 */
.dock-btn.compare-other {
  box-shadow: inset 0 0 0 1.5px var(--gold);
  color: var(--gold);
}

@media (max-width: 760px) {
  .compare {
    grid-template-columns: 1fr;
    gap: 22px;
  }
}

/* 朗讀按鈕等待伺服器合成語音時的律動 */
.dock-play.loading {
  animation: tts-wait 1s ease-in-out infinite;
}

@keyframes tts-wait {
  50% { opacity: 0.45; }
}

@media (prefers-reduced-motion: reduce) {
  .dock-play.loading {
    animation: none;
    opacity: 0.7;
  }
}
