/* Design tokens mirror SparkAsk (Apple/iOS aesthetic): light-first, muted
   terracotta accent, hairline borders, soft shadows. Same var names as before
   so every component picks up the new look automatically. */
:root {
  color-scheme: light dark;
  --bg: #f5f5f7;
  --bg-2: #ebebef;
  --card: #ffffff;
  --card-2: #ebebef;
  --line: rgba(0,0,0,.08);
  --line-strong: rgba(0,0,0,.14);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --accent: #c87850;
  --accent-2: #b46a45;
  --accent-soft: rgba(200,120,80,.10);
  --accent-fg: #ffffff;
  --user-bubble: #ebebef;
  --user-bubble-text: #1d1d1f;
  --green: #1d9e75;
  --red: #d70015;
  --blue: #006edc;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow: 0 8px 28px rgba(0,0,0,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a0a0d;
    --bg-2: #131316;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --line: rgba(255,255,255,.08);
    --line-strong: rgba(255,255,255,.16);
    --text: #f5f5f7;
    --muted: #98989d;
    --accent: #e08a64;
    --accent-2: #ed9974;
    --accent-soft: rgba(224,138,100,.16);
    --accent-fg: #1c1c1e;
    --user-bubble: #2c2c2e;
    --user-bubble-text: #f5f5f7;
    --green: #34d399;
    --red: #ff453a;
    --blue: #64a4ff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow: 0 8px 28px rgba(0,0,0,.5);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "PingFang TC", "PingFang SC", "Noto Sans TC", system-ui, sans-serif;
  /* Warm ambient background — subtle terracotta light wash, no loud gradients.
     Layered radial pools at the top + a soft warm haze, sitting over the base bg.
     Apple HIG: depth without distraction. */
  background:
    radial-gradient(110% 50% at 50% -10%, rgba(232, 150, 113, 0.14), transparent 55%),
    radial-gradient(70% 40% at 100% 20%, rgba(180, 106, 69, 0.07), transparent 60%),
    radial-gradient(60% 40% at 0% 30%, rgba(232, 150, 113, 0.06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px clamp(16px, 5vw, 48px);
  padding-top: calc(18px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand .spark { font-size: 30px; filter: drop-shadow(0 0 12px rgba(255,176,32,.5)); flex-shrink: 0; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .3px; white-space: nowrap; }
.tagline { margin: 0; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.status-cluster { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.icon-btn {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  width: 38px; height: 38px; border-radius: 12px; cursor: pointer; font-size: 17px;
}
.icon-btn:hover { background: var(--card-2); }

main {
  max-width: 860px; margin: 0 auto; padding: 24px clamp(16px,5vw,48px) 60px;
  display: grid; gap: 20px; align-content: start;
}
/* Grid items default to min-width:auto (won't shrink below their content's
   intrinsic min-content size) — one unwrappable long string anywhere inside
   a grid child was enough to hold the WHOLE page open to that width on
   narrow phones, overflowing the viewport horizontally. min-width:0 lets
   these actually shrink to fit. This cascades through every grid nesting
   level in this layout (main -> #view-transcribe -> .card sections), so
   apply it broadly rather than just at the top. */
main > *, #view-transcribe > *, .card { min-width: 0; }
#view-transcribe { display: grid; gap: 20px; min-width: 0; }
/* Wide screens: two columns — capture form + history side by side. */
@media (min-width: 1040px) {
  main { max-width: 1180px; }
  #view-transcribe {
    align-items: start;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  }
  #capture { grid-column: 1; }
  #history {
    grid-column: 2; position: sticky; top: 92px;
    max-height: calc(100vh - 112px); overflow: auto;
  }
}
/* Very large screens: cap the line length so it never feels stretched. */
@media (min-width: 1500px) { main { max-width: 1320px; } }

/* Top-level tabs — iOS segmented control */
.main-tabs { display: flex; gap: 4px; background: var(--bg-2); padding: 4px; border-radius: 14px; }
.main-tab {
  flex: 1 1 0; min-width: 0; padding: 9px 10px; border-radius: 10px; border: none;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: 14px; font-weight: 600; letter-spacing: -0.005em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .15s ease, color .15s ease;
}
.main-tab:hover { color: var(--text); }
.main-tab.active { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }
@media (max-width: 640px) { .main-tab { font-size: 12.5px; padding: 8px 6px; } }
@media (min-width: 1040px) { .main-tabs { max-width: 420px; } }

/* Chat (問答 + 對話) — SparkAsk-style */
.chat-card { display: flex; flex-direction: column; }
.chat-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-job { width: auto; min-width: 0; flex: 1 1 200px; max-width: 100%; padding: 9px 30px 9px 11px; }
.chat-toolbar .model-sel { margin: 0; flex: 0 0 auto; margin-left: auto; }
.chat-model { width: auto !important; margin-top: 0; padding: 8px 28px 8px 11px; font-size: 13px; border-radius: 10px; background-position: right 9px center; max-width: 42vw; }
.chat-toolbar .model-sel { display: inline-flex; margin: 0; }
.chat-toolbar .model-sel:first-of-type { margin-left: auto; }
.lang-sel { display: inline-block; }
.chat-messages { display: flex; flex-direction: column; gap: 16px; margin: 14px 0; min-height: 80px; max-height: 62vh; overflow-y: auto; padding-right: 2px; }
@media (min-width: 1040px) { #ask .chat-messages { max-height: calc(100vh - 320px); } }
.chat-empty { padding: 28px 6px; text-align: center; }
.chat-msg { display: flex; flex-direction: column; max-width: 90%; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-msg.ai { align-self: flex-start; align-items: flex-start; }
.chat-bubble { padding: 12px 16px; border-radius: 16px; font-size: 15.5px; line-height: 1.7; word-break: break-word; }
.chat-msg.user .chat-bubble { background: var(--user-bubble); color: var(--user-bubble-text); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.chat-msg.ai .chat-bubble { background: var(--bg-2); border: 1px solid var(--line); color: var(--text); border-bottom-left-radius: 5px; }
.chat-by { display: block; font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.chat-actions { margin-top: 4px; padding-left: 4px; }
.chat-copy { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 7px; }
.chat-copy:hover { background: var(--card-2); color: var(--text); }
.chat-caret { display: inline-block; width: 7px; height: 1.05em; background: var(--accent-2); vertical-align: text-bottom; margin-left: 2px; border-radius: 1px; animation: blink 1s steps(2) infinite; }
/* markdown inside answers */
.chat-bubble p { margin: 0 0 9px; } .chat-bubble p:last-child { margin-bottom: 0; }
.chat-bubble ul, .chat-bubble ol { margin: 7px 0 9px; padding-left: 22px; }
.chat-bubble li { margin: 3px 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3, .chat-bubble h4 { margin: 12px 0 7px; line-height: 1.35; }
.chat-bubble h1 { font-size: 18px; } .chat-bubble h2 { font-size: 17px; } .chat-bubble h3 { font-size: 16px; } .chat-bubble h4 { font-size: 15.5px; }
.chat-bubble strong { font-weight: 700; }
.chat-bubble a { color: var(--blue); }
.chat-bubble code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; font-size: 13.5px; }
.chat-bubble pre { background: var(--card-2); padding: 12px 14px; border-radius: 11px; overflow-x: auto; margin: 8px 0; }
.chat-bubble pre code { background: none; padding: 0; }
.chat-bubble blockquote { border-left: 3px solid var(--line); margin: 8px 0; padding: 2px 0 2px 12px; color: var(--muted); }
.chat-bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.chat-bubble th, .chat-bubble td { border: 1px solid var(--line); padding: 5px 10px; }
.chat-composer { display: flex; gap: 10px; align-items: flex-end; margin-top: 4px; }
.chat-composer textarea { flex: 1; min-height: 46px; max-height: 180px; resize: vertical; }
.chat-composer .chat-send { flex: 0 0 auto; }
.chat-mic { flex: 0 0 auto; align-self: flex-end; }
.chat-mic.listening { color: var(--red); border-color: color-mix(in srgb, var(--red) 50%, transparent); animation: pulse-mic 1.2s infinite; }
@keyframes pulse-mic { 0%,100% { box-shadow: 0 0 0 0 rgba(248,113,113,.45); } 50% { box-shadow: 0 0 0 7px rgba(248,113,113,0); } }
.chat-actions { display: flex; gap: 2px; }
.chat-speak { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 7px; }
.chat-speak:hover { background: var(--card-2); color: var(--text); }
.chat-speak.speaking { color: var(--accent-2); }
.ask-err { color: var(--red); font-size: 14px; }
.chat-retry { background: none; border: 1px solid var(--line); color: var(--text); cursor: pointer; font-size: 13px; padding: 4px 12px; border-radius: 8px; }
.chat-retry:hover { background: var(--card-2); }

/* chat toolbar selects + session sidebar (shared by 問答 + 對話) */
.chat-model, .chat-persona { width: auto !important; margin-top: 0; padding: 8px 28px 8px 11px; font-size: 13px; border-radius: 10px; background-position: right 9px center; max-width: 42vw; }
.chat-new { flex: 0 0 auto; padding: 8px 12px; }
@media (min-width: 1040px) { #chat .chat-messages, #ask .chat-messages { max-height: calc(100vh - 320px); } }
.chat-layout { display: flex; gap: 16px; align-items: stretch; }
.chat-sidebar { flex: 0 0 220px; width: 220px; display: flex; flex-direction: column; gap: 9px; border-right: 1px solid var(--line); padding-right: 14px; }
.chat-sidebar .chat-new { width: 100%; }
.chat-search { width: 100%; margin-top: 0; padding: 9px 12px; }
.chat-sessions { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; max-height: 56vh; }
.chat-sess { display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px; cursor: pointer; color: var(--text); }
.chat-sess:hover { background: var(--bg-2); }
.chat-sess.active { background: var(--card-2); border: 1px solid var(--line); }
.chat-sess-title { flex: 1; min-width: 0; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sess-del { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 6px; border-radius: 6px; opacity: 0; flex: 0 0 auto; }
.chat-sess:hover .chat-sess-del, .chat-sess.active .chat-sess-del { opacity: 1; }
.chat-sess-del:hover { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.chat-sess-empty { padding: 14px 8px; font-size: 13px; list-style: none; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-hist-btn { display: none; }
.chat-export { flex: 0 0 auto; }
@media (max-width: 760px) { .chat-hist-btn { display: inline-grid; place-items: center; flex: 0 0 auto; } }

/* ============ Full-screen native 對話 chat (body.chat-mode) ============ */
/* The chat owns the whole viewport: header on top, the chat fills the rest, the
   composer is pinned and only the messages scroll. Flexbox = no magic heights. */
body.chat-mode { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.chat-mode > .topbar { position: static; flex: 0 0 auto; }
body.chat-mode > .foot { display: none; }
body.chat-mode > main { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column;
  max-width: none; margin: 0; width: 100%; padding: 8px clamp(8px, 3vw, 22px) 8px; gap: 8px; }
body.chat-mode #backends { display: none; }
body.chat-mode .main-tabs { flex: 0 0 auto; max-width: none; }
body.chat-mode #view-chat { flex: 1 1 auto; min-height: 0; display: flex; }
body.chat-mode #chat.chat-card { flex: 1 1 auto; min-height: 0; display: flex; padding: 0; overflow: hidden; }
body.chat-mode .chat-layout { flex: 1; min-height: 0; height: 100%; gap: 0; align-items: stretch; }
body.chat-mode .chat-sidebar { height: auto; min-height: 0; padding: 14px 12px; border-right: 1px solid var(--line); }
body.chat-mode .chat-sessions { flex: 1 1 auto; min-height: 0; max-height: none; }
body.chat-mode .chat-main { height: 100%; min-height: 0; padding: 12px clamp(10px, 2.5vw, 20px); }
body.chat-mode .chat-toolbar { flex: 0 0 auto; padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
body.chat-mode .chat-messages { flex: 1 1 auto; min-height: 0; max-height: none; margin: 10px 0; }
body.chat-mode .chat-composer { flex: 0 0 auto; }
/* desktop: roomy two-pane, capped width so lines don't stretch on huge monitors */
@media (min-width: 1040px) {
  body.chat-mode > main { max-width: 1280px; }
  body.chat-mode .chat-sidebar { flex: 0 0 250px; width: 250px; }
}
/* mobile: chat fills; sidebar is a slide-in drawer over everything */
@media (max-width: 760px) {
  body.chat-mode > main { padding: 6px 8px; }
  body.chat-mode .chat-main { padding: 10px 10px 8px; width: 100%; }
  body.chat-mode .chat-sidebar {
    position: fixed; z-index: 30; top: 0; left: 0; bottom: 0; width: 82%; max-width: 300px; height: 100dvh;
    background: var(--card); border-right: 1px solid var(--line); border-radius: 0; padding: 16px 14px;
    box-shadow: var(--shadow); transform: translateX(-104%); transition: transform .22s ease;
  }
  body.chat-mode #chat.show-sidebar .chat-sidebar { transform: none; }
  body.chat-mode #chat.show-sidebar::before {
    content: ""; position: fixed; inset: 0; z-index: 29; background: rgba(0,0,0,.4);
  }
}

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 14px; font-size: 17px; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 10px 0 0; }
.settings-sep { border: none; border-top: 1px solid var(--line); margin: 18px 0 14px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input[type=text], input[type=url], input[type=password], input[type=date], textarea, select {
  width: 100%; margin-top: 6px; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text);
  font-size: 15px; font-family: inherit;
}
select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%239aa3b8' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 34px; }
textarea { resize: vertical; min-height: 44px; line-height: 1.5; }
label.full { display: block; margin-top: 4px; }
#presetDesc { display: block; margin-top: 6px; }
.file-import { display: inline-flex; align-items: center; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); border-color: transparent; }

.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn {
  border: none; border-radius: 12px; padding: 11px 18px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform .05s ease, filter .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-ghost:hover { background: var(--card-2); }

.pill { font-size: 12px; padding: 5px 11px; border-radius: 999px; font-weight: 600; white-space: nowrap; }

@media (max-width: 640px) {
  .topbar { padding-left: 14px; padding-right: 14px; gap: 8px; }
  .brand { gap: 10px; }
  .brand .spark { font-size: 25px; }
  .brand h1 { font-size: 17px; }
  .tagline { display: none; }
  .pill { font-size: 10.5px; padding: 4px 9px; }
  .lang-sel { font-size: 12px !important; padding: 6px 24px 6px 9px !important; }
  .icon-btn { width: 34px; height: 34px; }
}
/* Phones: collapse the connection pill to a status dot (colour = state). */
@media (max-width: 480px) {
  #conn { font-size: 0; width: 12px; height: 12px; min-width: 12px; padding: 0;
    border: none; border-radius: 50%; }
  #conn.pill-ok { background: var(--green); }
  #conn.pill-bad { background: var(--red); }
  #conn.pill-muted { background: var(--muted); }
}
.pill-muted { background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.pill-ok { background: color-mix(in srgb, var(--green) 22%, transparent); color: var(--green); }
.pill-bad { background: color-mix(in srgb, var(--red) 20%, transparent); color: var(--red); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 34px; border: 2px dashed var(--line-strong); border-radius: 14px; cursor: pointer;
  text-align: center; color: var(--text);
}
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 30px; }

/* Reference-photo attachment: secondary, smaller dropzone below the audio one. */
.attach-zone {
  display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 10px;
  padding: 14px; margin-top: 10px;
  border: 1.5px dashed var(--line); border-radius: 12px;
  cursor: pointer; color: var(--muted);
  text-align: center; font-size: 13.5px;
  background: rgba(0, 0, 0, 0.02);
}
.attach-zone:hover { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.attach-icon { font-size: 18px; }
.attach-thumbs {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 10px;
}
.attach-thumb {
  position: relative;
  width: 64px; height: 64px;
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--line);
  background: var(--card);
}
.attach-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.attach-thumb .attach-rm {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; line-height: 16px;
  border-radius: 50%; background: rgba(0,0,0,0.55); color: #fff;
  font-size: 11px; text-align: center; cursor: pointer;
  border: 0;
}
.attach-thumb .attach-rm:hover { background: rgba(0,0,0,0.8); }
.attach-thumb.saved { box-shadow: 0 0 0 2px #2ea25b; }
.attach-thumb .attach-ok {
  position: absolute; bottom: 2px; left: 2px;
  width: 18px; height: 18px; line-height: 18px;
  border-radius: 50%; background: #2ea25b; color: #fff;
  font-size: 11px; text-align: center;
}

/* Resume-after-quit banner: shows on app load when localStorage has an
   unfinalized upload session and the server still has those parts on disk. */
.resume-banner {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 12px; color: var(--text);
  font-size: 13.5px;
}
.resume-banner .rb-text { flex: 1; line-height: 1.45; }
.resume-banner .rb-actions { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.resume-banner button {
  padding: 7px 12px; border-radius: 8px; border: 0;
  background: var(--accent); color: #fff; font-size: 13px;
  cursor: pointer; white-space: nowrap;
}
.resume-banner button.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--line);
}
.resume-banner button:disabled { opacity: 0.5; cursor: default; }

/* Q&A history list under the chat composer — mirrors the SparkAsk chat
   sidebar pattern but inline (per-transcript scoped list). */
.ask-history {
  margin-top: 14px; padding-top: 12px;
  border-top: 1px solid var(--line);
}
.ask-history-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12.5px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.06em;
}
.ask-history-title { font-weight: 600; }
.ask-new-btn {
  background: transparent; border: 1px solid var(--line);
  color: var(--text); font-size: 12px;
  padding: 4px 10px; border-radius: 999px;
  cursor: pointer; text-transform: none; letter-spacing: 0;
}
.ask-new-btn:hover { border-color: var(--accent); color: var(--accent); }

.ask-sessions { list-style: none; padding: 0; margin: 0; }
.ask-sess {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center; gap: 8px;
  padding: 9px 10px; margin-bottom: 6px;
  border-radius: 9px;
  background: var(--card-2, rgba(0,0,0,0.02));
  cursor: pointer;
  transition: background 0.12s;
}
.ask-sess:hover { background: var(--accent-soft); }
.ask-sess.active {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.ask-sess-title {
  font-size: 13.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ask-sess-meta {
  font-size: 11.5px; white-space: nowrap;
}
.ask-sess-del {
  background: transparent; border: 0; color: var(--muted);
  width: 22px; height: 22px; line-height: 18px;
  border-radius: 50%; cursor: pointer;
  font-size: 13px; padding: 0;
}
.ask-sess-del:hover { background: rgba(192, 0, 0, 0.1); color: #c00; }
.ask-sess-empty {
  padding: 12px; text-align: center;
  font-size: 12.5px; color: var(--muted);
}

.check-row { display: flex; align-items: center; gap: 9px; margin: 12px 0 2px; cursor: pointer; color: var(--text); font-size: 13.5px; }
.check-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent-2); flex: 0 0 auto; margin: 0; cursor: pointer; }
.check-row span { line-height: 1.35; }

.meta-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin: 20px 0 8px; }
.meta-grid.two { grid-template-columns: 1fr 1fr; }
.meta-grid label { margin-bottom: 0; }
@media (max-width: 620px) { .meta-grid, .meta-grid.two { grid-template-columns: 1fr; } }

.lang-sel {
  width: auto !important; margin-top: 0 !important; padding: 7px 28px 7px 11px !important;
  font-size: 13px !important; border-radius: 10px !important; background-position: right 9px center !important;
}

.progress { height: 8px; background: var(--bg-2); border-radius: 999px; overflow: hidden; margin-top: 14px; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s ease; }

.jobs-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.jobs-head h2 { margin: 0; }
.notice {
  display: flex; align-items: flex-start; gap: 10px;
  background: color-mix(in srgb, var(--green) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--green) 40%, transparent);
  color: var(--text); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px;
  font-size: 14px; line-height: 1.5;
}
.notice::before { content: "✓"; color: var(--green); font-weight: 700; }

.jobs { display: grid; gap: 12px; }
.job {
  min-width: 0; /* same grid-item min-width:auto overflow fix as main/#view-transcribe/.card */
  border: 1px solid var(--line); border-radius: 14px; padding: 15px; background: var(--bg-2);
}
.job-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.job-title { font-weight: 700; font-size: 15px; }
.job-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.job-state { font-size: 12px; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.s-done { background: color-mix(in srgb,var(--green) 22%,transparent); color: var(--green); }
.s-error { background: color-mix(in srgb,var(--red) 20%,transparent); color: var(--red); }
.s-run { background: color-mix(in srgb,var(--blue) 20%,transparent); color: var(--blue); }
.job .progress { margin-top: 12px; }
.job-actions { margin-top: 12px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.job-del { margin-left: auto; color: var(--muted); padding: 8px 12px; }
.job-del:hover { color: var(--red); border-color: color-mix(in srgb, var(--red) 45%, transparent); }

.jobs-toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.jobs-toolbar .job-search { flex: 1 1 150px; min-width: 0; }
.jobs-toolbar select { width: auto; min-width: 0; flex: 0 0 auto; padding: 9px 30px 9px 11px; }
.jobs-toolbar #clearDone { flex: 0 0 auto; }
.jobs-pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }
.jobs-pager .btn { padding: 6px 16px; font-size: 18px; line-height: 1; }
.jobs-pager .btn:disabled { opacity: .35; cursor: default; }

.spinner { width: 24px; height: 24px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.jobs-loading { display: flex; justify-content: center; padding: 22px; }

.offline-banner {
  display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text);
  background: color-mix(in srgb, var(--red) 13%, transparent);
  border: 1px solid color-mix(in srgb, var(--red) 40%, transparent);
  border-radius: 12px; padding: 11px 14px;
}
.offline-banner::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--red); flex: 0 0 auto; animation: blink 1.2s infinite; }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* AI backend availability indicator */
.backends {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 9px 14px;
}
.backends-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.backends-chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.bchip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600;
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-2); color: var(--muted); white-space: nowrap;
}
.bchip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: 0 0 auto; }
.bchip.up { color: var(--green); border-color: color-mix(in srgb, var(--green) 40%, transparent); }
.bchip.up::before { background: var(--green); }
.bchip.down { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.bchip.down::before { background: var(--red); }
.bchip.checking::before { animation: blink 1.1s infinite; }
.backends-refresh {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 30px; height: 30px; border-radius: 9px; cursor: pointer;
  flex: 0 0 auto; display: inline-grid; place-items: center; padding: 0;
}
.backends-refresh:hover { background: var(--card-2); color: var(--text); }
.backends-refresh .bicon { display: block; transform-origin: 50% 50%; }
/* spin the icon (not the button) so a clean, centred rotation — no wobble */
.backends-refresh.spinning .bicon { animation: spin .8s linear infinite; }
.backends-refresh:disabled { opacity: .6; cursor: default; }

/* Job re-calibrate control */
.recal-group { display: inline-flex; align-items: center; gap: 6px; }
.recal-pick {
  width: auto !important; margin-top: 0 !important; padding: 8px 26px 8px 10px !important;
  font-size: 13px !important; border-radius: 10px !important; background-position: right 8px center !important;
}
.job-recal { padding: 8px 12px; }
.ai-badge.recalc { opacity: .6; }

.select-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; }
.select-bar .sel-all { display: inline-flex; align-items: center; gap: 7px; margin: 0; font-size: 14px; color: var(--text); cursor: pointer; }
.select-bar .sel-actions { margin-left: auto; display: flex; gap: 8px; }
.select-bar input[type=checkbox], .job-check { width: 18px; height: 18px; accent-color: var(--accent-2); cursor: pointer; }
#selectBtn.active { border-color: var(--accent); color: var(--accent); }
.job.selected { outline: 2px solid var(--accent); outline-offset: -1px; }
.job-check { margin-right: 10px; flex: 0 0 auto; }
.job-actions a { text-decoration: none; }
.ai-badge { font-size: 11px; color: var(--accent); border: 1px solid color-mix(in srgb,var(--accent) 40%,transparent); padding: 2px 8px; border-radius: 999px; }
.job-log { margin-top: 10px; font-size: 11.5px; color: var(--muted); white-space: pre-wrap; max-height: 0; overflow: hidden; transition: max-height .25s ease; }
.job-log.open { max-height: 240px; overflow: auto; }
.log-toggle { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0; margin-top: 8px; }

.foot { text-align: center; padding: 24px; font-size: 12px; }

.toasts {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px;
  align-items: center; z-index: 200; pointer-events: none; max-width: 92vw;
}
.toast {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--shadow); border-radius: 12px; padding: 11px 16px;
  font-size: 14px; line-height: 1.45; text-align: center; max-width: 92vw;
  transition: opacity .25s ease; animation: toastIn .25s ease;
}
.toast.ok { border-color: color-mix(in srgb, var(--green) 50%, transparent); }
.toast.err { border-color: color-mix(in srgb, var(--red) 50%, transparent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ============== Spark — iOS-style hub navigation ============== */

/* Better iOS feel: no rubber-band, no tap highlight, large tap targets. */
html, body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: contain; }
button, a { -webkit-tap-highlight-color: transparent; }

/* The navbar shows on pushed sub-views only (轉錄 / 問答). Sticky, blurred,
   safe-area-aware. Hidden on Home (which uses the large-title hero instead). */
.navbar {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  gap: 8px;
  padding: 6px clamp(12px, 4vw, 22px);
  padding-top: calc(8px + env(safe-area-inset-top));
  min-height: calc(44px + env(safe-area-inset-top));
  /* iOS 26 Liquid Glass: heavy saturation + blur on a translucent surface, with
     an inner highlight for the light-bending edge. */
  background: rgba(245, 245, 247, 0.72);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
@media (prefers-color-scheme: dark) {
  .navbar { background: rgba(28, 28, 30, 0.72); border-bottom-color: rgba(255,255,255,0.06); box-shadow: inset 0 1px 0 rgba(255,255,255,0.05); }
}
.navbar[hidden] { display: none; }
.navbar-back {
  justify-self: start; display: inline-flex; align-items: center; gap: 2px;
  background: none; border: none; color: var(--accent);
  font-size: 16px; font-weight: 500; cursor: pointer;
  padding: 8px 4px; margin-left: -4px;
  letter-spacing: -0.01em;
}
.navbar-back:active { opacity: .55; }
.navbar-back svg { transform: translateY(0); flex-shrink: 0; }
.navbar-title {
  margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -0.01em;
  color: var(--text); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.navbar-actions { justify-self: end; display: inline-flex; align-items: center; gap: 8px; }

/* On sub-views the navbar replaces the old topbar — give main the right padding. */
body.on-sub > main { padding-top: 14px; }

/* ============== Home (the launcher) ============== */
/* [hidden] must beat .view-home's display: flex */
[hidden] { display: none !important; }
/* Global safe-area: keep ALL content (backends strip, etc.) below the notch.
   The navbar handles its own inset on sub-views, so a no-op there. */
body { padding-top: env(safe-area-inset-top); }
body.on-sub { padding-top: 0; }  /* navbar already adds the inset */

#view-home.view-home {
  display: flex; flex-direction: column; gap: 18px;
  padding-top: 8px;
}
.home-hero {
  position: relative; text-align: center;
  padding: 36px 8px 14px;
}
/* Free-floating sparkle glyph — bigger, with a richer iOS-26-style multi-layer
   halo (drop-shadow + glow). NOT the rounded-rect app icon (that's 對話's
   identity). Gentle breathing animation conveys "alive". */
.home-mark {
  width: 64px; height: 64px;
  filter:
    drop-shadow(0 0 22px rgba(200, 120, 80, 0.42))
    drop-shadow(0 14px 30px rgba(200, 120, 80, 0.22));
  animation: sparkBreathe 5s ease-in-out infinite;
}
@keyframes sparkBreathe {
  0%, 100% { transform: scale(1) rotate(0); }
  50% { transform: scale(1.06) rotate(2deg); }
}
@media (prefers-reduced-motion: reduce) { .home-mark { animation: none; } }
/* Large iOS-style title with a subtle terracotta tint at the bottom for warmth. */
.home-title {
  margin: 14px 0 6px;
  font-size: clamp(42px, 9vw, 52px);
  font-weight: 700; letter-spacing: -0.035em;
  line-height: 1.05;
  background: linear-gradient(180deg, var(--text) 0%, var(--text) 60%, color-mix(in srgb, var(--text) 75%, var(--accent) 25%) 100%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
}
.home-sub { margin: 0; color: var(--muted); font-size: 15.5px; letter-spacing: -0.005em; }
/* Top-right action row — segmented language control + Liquid Glass settings gear. */
.home-actions {
  position: absolute; top: 4px; right: 0;
  display: flex; align-items: center; gap: 8px;
}
/* iOS-style segmented control — 3 segments (繁/简/EN) in a glass capsule. */
.lang-toggle {
  display: inline-flex; padding: 3px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 12px;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  gap: 1px;
}
.lt-btn {
  background: transparent; border: none; cursor: pointer;
  min-width: 30px; height: 28px; padding: 0 8px;
  border-radius: 9px;
  color: var(--muted); font-size: 13px; font-weight: 600; letter-spacing: -0.005em;
  font-family: inherit;
  transition: background-color .15s ease, color .15s ease;
}
.lt-btn:hover { color: var(--text); }
.lt-btn.active {
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.04);
}
@media (prefers-color-scheme: dark) {
  .lang-toggle { background: rgba(44, 44, 46, 0.55); border-color: rgba(255,255,255,0.10); box-shadow: 0 4px 14px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.06); }
  .lt-btn.active { background: rgba(72, 72, 74, 0.95); box-shadow: 0 1px 2px rgba(0,0,0,0.3); }
}

/* Settings gear — pure Liquid Glass capsule (translucent + saturated blur). */
.home-settings {
  width: 40px; height: 40px; border-radius: 14px;
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.75);
  color: var(--muted);
  display: inline-grid; place-items: center; cursor: pointer;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  transition: transform .12s ease, color .15s ease;
}
.home-settings:hover { color: var(--text); }
.home-settings:active { transform: scale(0.94); }
@media (prefers-color-scheme: dark) {
  .home-settings { background: rgba(44, 44, 46, 0.55); border-color: rgba(255,255,255,0.10); box-shadow: 0 4px 14px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.06); }
}

/* On Home: tuck the AI 校準後端 strip BELOW the cards (it's a status surface,
   not the focus) and hide the footer (transcribe-specific copy). */
body.on-home > main > #backends { order: 99; margin-top: 8px; opacity: .85; }
body.on-home > .foot { display: none; }
body.on-home > main { display: flex; flex-direction: column; }

/* Card list — large, thumb-friendly, glass surfaces over the ambient gradient. */
.home-cards {
  list-style: none; margin: 4px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 12px;
}
.home-card {
  display: flex; align-items: center; gap: 14px; width: 100%;
  padding: 17px 16px;
  /* Liquid Glass card: translucent white over the warm gradient, edge highlight,
     soft drop shadow. */
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 22px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.03),
    0 10px 26px rgba(60, 35, 20, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
  cursor: pointer; text-align: left; color: inherit; text-decoration: none;
  /* Spring transition on tap. */
  transition: transform .18s cubic-bezier(0.34, 1.56, 0.64, 1),
              box-shadow .15s ease, background-color .15s ease;
}
.home-card:hover {
  background: rgba(255, 255, 255, 0.85);
  box-shadow:
    0 2px 4px rgba(0, 0, 0, 0.04),
    0 14px 36px rgba(60, 35, 20, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
.home-card:active { transform: scale(0.97); }
@media (prefers-color-scheme: dark) {
  .home-card { background: rgba(44, 44, 46, 0.62); border-color: rgba(255,255,255,0.08); box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 26px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,0.06); }
  .home-card:hover { background: rgba(56, 56, 58, 0.72); }
}
.home-card-icon {
  flex: 0 0 auto; width: 54px; height: 54px;
  border-radius: 16px;
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  /* Subtle inner highlight to match the glass language. */
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
  transition: transform .2s cubic-bezier(.26,1.4,.6,1);
}
/* Per-function icon tints — mirrors the games landing so the cards are
   instantly scannable by colour instead of a uniform terracotta wash. */
.home-card-icon.tint-transcribe { background: rgba(200,120,80,0.16);  color: #c87850; }
.home-card-icon.tint-ask        { background: rgba(0,110,220,0.14);   color: #2b7fd4; }
.home-card-icon.tint-chat       { background: rgba(232,150,113,0.18); color: #c87850; }
.home-card-icon.tint-ppt        { background: rgba(140,110,200,0.16); color: #7659c0; }
.home-card-icon.tint-live       { background: rgba(0,160,190,0.16);   color: #0d8fa8; }
.home-card-icon.tint-slides     { background: rgba(224,122,63,0.16);  color: #d1702f; }
.home-card-icon.tint-game       { background: rgba(46,162,91,0.16);   color: #2a9c5c; }
@media (prefers-color-scheme: dark) {
  .home-card-icon.tint-transcribe { color: #f2a684; }
  .home-card-icon.tint-ask        { color: #7db4ee; }
  .home-card-icon.tint-chat       { color: #f2a684; }
  .home-card-icon.tint-ppt        { color: #b8a0ea; }
  .home-card-icon.tint-live       { color: #5fd0e6; }
  .home-card-icon.tint-slides     { color: #f0a06a; }
  .home-card-icon.tint-game       { color: #7ed3a2; }
}
/* Hover: icon tile blooms + chevron slides in, matching the games cards. */
.home-card:hover .home-card-icon { transform: scale(1.06) rotate(-3deg); }
.home-card:hover .home-card-chevron { color: var(--accent); transform: translateX(3px); }
.home-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.home-card-icon img { width: 54px; height: 54px; border-radius: 16px; display: block; }
.home-card-icon-spark { background: transparent; padding: 0; box-shadow: none; }
.home-card-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.home-card-text strong {
  font-size: 17px; font-weight: 600; color: var(--text); letter-spacing: -0.012em;
}
.home-card-text em {
  font-style: normal; font-size: 13.5px; color: var(--muted); letter-spacing: -0.005em;
}
.home-card-chevron {
  flex: 0 0 auto; color: var(--muted); display: inline-grid; place-items: center;
  transition: color .16s ease, transform .16s ease;
}

/* ── one-time entrance choreography (initial load only) ─────────────────
   Gated on body.booting so it plays once on first paint and NOT every time
   the user navigates back to Home from a sub-view (app.js removes .booting
   after the run). Hero + each card fade + rise, staggered. */
@keyframes home-rise {
  from { opacity: 0; transform: translateY(15px); }
  to   { opacity: 1; transform: translateY(0); }
}
body.booting .home-hero,
body.booting .home-cards li {
  animation: home-rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) backwards;
}
body.booting .home-hero          { animation-delay: 0.02s; }
body.booting .home-cards li:nth-child(1) { animation-delay: 0.10s; }
body.booting .home-cards li:nth-child(2) { animation-delay: 0.16s; }
body.booting .home-cards li:nth-child(3) { animation-delay: 0.22s; }
body.booting .home-cards li:nth-child(4) { animation-delay: 0.28s; }
body.booting .home-cards li:nth-child(5) { animation-delay: 0.34s; }
@media (prefers-reduced-motion: reduce) {
  body.booting .home-hero, body.booting .home-cards li { animation: none !important; }
}

/* Backends status — refined glass capsule on Home. */
body.on-home > main > #backends {
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: saturate(160%) blur(16px);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 18px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
@media (prefers-color-scheme: dark) {
  body.on-home > main > #backends { background: rgba(44,44,46,0.5); border-color: rgba(255,255,255,0.06); }
}

@media (min-width: 720px) {
  #view-home.view-home { max-width: 620px; margin: 0 auto; }
}

/* ============== 投影片 (Spark-PPT browser) ============== */
.ppt-list { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.ppt-card {
  display: flex; flex-direction: column; gap: 8px;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.85);
  border-radius: 18px;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.03),
    0 8px 22px rgba(60, 35, 20, 0.06),
    inset 0 1px 0 rgba(255, 255, 255, 0.7);
}
@media (prefers-color-scheme: dark) {
  .ppt-card { background: rgba(44, 44, 46, 0.62); border-color: rgba(255,255,255,0.08); box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 22px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,0.06); }
}
.ppt-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ppt-card-title { font-size: 16.5px; font-weight: 600; color: var(--text); letter-spacing: -0.01em; }
.ppt-card-meta { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ppt-card-notes { font-size: 13.5px; line-height: 1.55; }
.ppt-card-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.ppt-dl { text-decoration: none; padding: 9px 14px; font-size: 14px; }
.ppt-build { padding: 9px 14px; font-size: 14px; }

/* Top row: hint + 新建 button */
.ppt-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.ppt-top .hint { margin: 0; flex: 1; }
.ppt-top .btn { flex: 0 0 auto; }
@media (max-width: 560px) {
  .ppt-top { flex-direction: column; align-items: stretch; }
}

/* New-project form */
.ppt-form { display: flex; flex-direction: column; gap: 14px; padding: 16px; margin-bottom: 16px;
  background: rgba(255, 255, 255, 0.5); border: 1px solid var(--line); border-radius: 16px;
  backdrop-filter: blur(12px); }
@media (prefers-color-scheme: dark) { .ppt-form { background: rgba(44,44,46,0.5); } }
.ppt-form-row { display: flex; gap: 10px; flex-wrap: wrap; }
.ppt-form-field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 180px; min-width: 0; }
.ppt-form-field.full { flex-basis: 100%; }
.ppt-form-field > span { font-size: 13px; color: var(--muted); }
.ppt-form-field input, .ppt-form-field select, .ppt-form-field textarea { margin: 0; width: 100%; }
.ppt-form-songs { display: flex; flex-direction: column; gap: 12px; }
.ppt-form-song { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.ppt-form-song-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.ppt-form-song-rm { font-size: 12.5px; padding: 4px 10px; color: var(--muted); }
.ppt-form-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.ppt-form-actions .btn-primary { margin-left: auto; }
.ppt-form-msg { margin: 0; font-size: 13.5px; min-height: 1.2em; }

/* Per-project revise (追問調整) */
.ppt-revise { margin-top: 8px; }
.ppt-revise > summary { font-size: 13.5px; color: var(--accent); cursor: pointer; list-style: none; padding: 4px 0; }
.ppt-revise > summary::-webkit-details-marker { display: none; }
.ppt-revise[open] > summary { margin-bottom: 8px; }
.ppt-revise-input { width: 100%; margin: 0; }
.ppt-revise-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.ppt-revise-status { font-size: 13px; }

/* PDF auto-fill entry inside the new-project form */
.ppt-extract { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px;
  background: var(--accent-soft); border-radius: 12px; }
.ppt-extract-btn { margin: 0; cursor: pointer; padding: 8px 14px; font-size: 14px; }
.ppt-extract-hint { font-size: 12.5px; flex: 1 1 200px; }
.ppt-extract-msg { font-size: 12.5px; }

/* Smaller project-card action buttons so 5 of them fit nicely */
.ppt-card-actions .btn-ghost { padding: 7px 12px; font-size: 13px; }
.ppt-polish, .ppt-autobg, .ppt-rollback { white-space: nowrap; }
.ppt-rollback { color: var(--muted); }

/* Backgrounds thumbnail strip — visual QA without opening the .pptx */
.ppt-card-bgs { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0;
  -webkit-overflow-scrolling: touch; }
.ppt-card-bg { flex: 0 0 auto; width: 76px; height: 43px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line); background: var(--bg-2); }

/* ============== Spark Jump (game view) ============== */
/* AI status strip + footer are transcription-page furniture — hide them while playing. */
body.on-game > main > #backends, body.on-game > .foot { display: none; }

/* Full-bleed: navbar at top, canvas fills the rest of the viewport. iOS PWA feel. */
body.on-game { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
body.on-game > .topbar, body.on-game > .navbar { flex: 0 0 auto; }
body.on-game > main {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  padding: 0 8px;
  max-width: none; margin: 0; width: 100%;
}
body.on-game #view-game { flex: 1 1 auto; min-height: 0; display: flex; }

.game-wrap {
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column; align-items: stretch;
  gap: 8px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
  width: 100%;
}
.game-canvas {
  flex: 1 1 auto; min-height: 200px;
  display: block; width: 100%;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 8px 22px rgba(60, 35, 20, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  cursor: pointer;
}
.game-hint { margin: 0; text-align: center; font-size: 13px; color: var(--muted); flex: 0 0 auto; }
@media (prefers-color-scheme: dark) {
  .game-canvas { box-shadow: 0 8px 22px rgba(0,0,0,0.4), inset 0 1px 0 rgba(255,255,255,0.05); }
}


/* ---- Direct (BYOK) transcription result overlay -------------------------- */
.dr-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; width: 100%; height: 100%;
  z-index: 200; display: flex;
  align-items: flex-start; justify-content: center; padding: 24px 16px;
  background: rgba(0,0,0,.45); backdrop-filter: blur(3px); overflow-y: auto;
}
.dr-overlay.hidden { display: none; }
.dr-card {
  width: 100%; max-width: 720px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 24px 60px rgba(0,0,0,.28); padding: 20px 22px 22px;
}
.dr-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dr-title { margin: 0; font-size: 20px; }
.dr-body {
  margin: 14px 0 18px; max-height: 56vh; overflow-y: auto;
  padding-right: 6px; line-height: 1.7;
}
.dr-body h3 {
  margin: 18px 0 6px; font-size: 15px; font-weight: 700;
  color: var(--accent-2); letter-spacing: .01em;
}
.dr-body h3:first-child { margin-top: 0; }
.dr-body p { margin: 0 0 10px; white-space: pre-wrap; }
.dr-actions { display: flex; flex-wrap: wrap; gap: 10px; }
@media (max-width: 480px) {
  .dr-actions .btn { flex: 1 1 auto; }
}


/* ── Spark Slides ───────────────────────────────────────────────────────
   The deck preview is the whole point of this view: the pastor's complaint
   was that he cannot tell how a talk will look until he has built it. So the
   slides are shown at real 16:9 proportions with the same restraint the PPTX
   applies — big type, one idea, generous margins — and each one is editable
   in place, because catching a clumsy headline here costs seconds and
   catching it in PowerPoint costs the evening. */
.sl-form { display: grid; gap: 12px; }
.sl-form textarea {
  min-height: 240px; font: inherit; line-height: 1.65; resize: vertical;
}
.sl-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.sl-row > label { display: grid; gap: 4px; flex: 1 1 160px; min-width: 0; }
.sl-est { color: var(--muted); font-size: 13px; }

.sl-deck { display: grid; gap: 18px; margin-top: 18px; }
.sl-slide {
  position: relative; aspect-ratio: 16 / 9; background: #fff; color: #1a1a1a;
  border: 1px solid rgba(0,0,0,.12); border-radius: 10px;
  padding: 6.5% 8%; display: flex; flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,.07); overflow: hidden;
  container-type: inline-size;
}
/* Type sized in container units so the preview scales exactly like the real
   slide does on a projector, instead of only looking right at one width. */
.sl-slide .h  { font-size: 5.2cqw; font-weight: 700; line-height: 1.25; }
.sl-slide .b  { font-size: 2.6cqw; line-height: 1.45; margin-top: .6em; color: #333; }
.sl-slide .rf { font-size: 1.9cqw; color: #6b6b6b; margin-top: auto; }
.sl-slide .rule { width: 12%; height: .5cqw; background: #e07a3f; margin: .9em 0; }
.sl-slide.is-statement { justify-content: center; text-align: center; }
.sl-slide.is-statement .h { font-size: 6cqw; }
.sl-slide.is-scripture { justify-content: center; border-left: .8cqw solid #e07a3f; }
.sl-slide.is-scripture .h { font-size: 4cqw; font-weight: 400; line-height: 1.5; }
.sl-slide.is-section { justify-content: center; }
.sl-slide.is-title   { justify-content: center; }
.sl-slide.is-title .h { font-size: 6.4cqw; }
.sl-slide img { max-height: 55%; object-fit: contain; align-self: flex-start; margin-top: .8em; }
.sl-slide.is-question { flex-direction: row; align-items: center; gap: 4%; }
.sl-slide.is-question img { max-height: 70%; max-width: 30%; margin: 0; }

.sl-meta {
  display: flex; justify-content: space-between; align-items: center;
  gap: 10px; margin-top: 6px; font-size: 12px; color: var(--muted);
}
.sl-meta .layout { text-transform: uppercase; letter-spacing: .08em; }
.sl-edit { width: 100%; font: inherit; margin-top: 6px; }
.sl-notes { font-size: 12px; color: var(--muted); line-height: 1.5; margin-top: 4px; }
@media (prefers-color-scheme: dark) {
  .sl-slide { border-color: rgba(255,255,255,.14); }
}
