:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  color: #171c1d;
  background: #eef2f1;
  line-height: 1.5;
  --accent: #0b7a70;
  --accent-soft: #d9f0ec;
  --border: #d5dddc;
  --muted: #5f6c6e;
  --panel: #fff;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; max-width: 100%; overflow-x: hidden; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; border: 1px solid var(--border); background: #fff; border-radius: 10px; padding: 10px 16px; color: inherit; font-weight: 650; }
button:disabled { cursor: not-allowed; opacity: .5; }
button:hover:not(:disabled) { background: #f3f7f6; }
[hidden] { display: none !important; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid #7fd0c6; outline-offset: 2px; }
a { color: var(--accent); }
h1, h2, p { margin: 0; }
h1 { font-size: 26px; letter-spacing: -0.03em; }
h2 { font-size: 15px; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 18px;
  min-height: 64px; padding: 10px 22px;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; font-weight: 780; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #142422; color: #fff; font-size: 12px; }
.brand-light { font-weight: 500; color: var(--muted); }
.top-nav { display: flex; gap: 6px; flex: 1; min-width: 0; }
.nav-button { border: 0; background: transparent; font-weight: 600; padding: 8px 12px; display: inline-flex; gap: 8px; align-items: center; }
.nav-button.active { background: var(--accent-soft); color: #0a5f58; }
.nav-button span { font-size: 11px; min-width: 18px; text-align: center; color: var(--muted); }
.account-controls { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.connection { font-size: 12px; color: #8a5d18; padding: 5px 9px; background: #fff6df; border-radius: 999px; }
.connection[data-ready=true] { background: #e4f5ef; color: #076d55; }
.quiet { border-color: transparent; background: transparent; font-weight: 550; color: var(--muted); }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: #08665e; }
.secondary { background: #fff; }
.full-width { width: 100%; }

main { padding: 24px; }
.view { max-width: 1280px; margin: 0 auto; }
.kicker { font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.lede { color: var(--muted); font-size: 14px; margin-top: 6px; max-width: 36em; }
.page-heading { display: flex; justify-content: space-between; gap: 16px; align-items: end; margin-bottom: 22px; }

.studio-layout { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); gap: 22px; align-items: start; }
.stage, .composer { background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 22px; }
.stage-top { display: flex; justify-content: space-between; gap: 12px; align-items: start; margin-bottom: 16px; }
.composer > div:first-child { margin-bottom: 16px; }

.source-panel { margin-bottom: 16px; }
.preview-panel { border: 1px solid var(--border); border-radius: 16px; overflow: hidden; background: #f7fafa; }
.preview-header { display: flex; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: #fff; }
.preview-header span { font-size: 12px; color: var(--muted); }
.preview-surface { display: grid; place-items: center; min-height: 360px; padding: 18px; background: radial-gradient(circle at top, #e7eeec, #d7dfdd); }
.preview-frame { position: relative; width: min(100%, 280px); aspect-ratio: 9/16; overflow: hidden; border-radius: 14px; background: #cfd8d5; display: grid; place-items: center; box-shadow: 0 18px 40px #13201c22; }
.preview-frame.wide { width: 100%; max-width: 520px; aspect-ratio: 16/9; }
.preview-frame.square { aspect-ratio: 1/1; width: min(100%, 340px); }
.preview-frame img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #121918; }
.preview-frame:has(img:not([hidden])) { background: #121918; }
#preview-empty { display: grid; gap: 8px; text-align: center; color: #5c6c68; padding: 20px; font-size: 13px; }
#preview-empty strong { font-size: 15px; color: #24302e; }
#preview-busy { position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; align-content: center; gap: 8px; background: #121918d0; color: #fff; text-align: center; padding: 20px; }
.preview-details { display: flex; gap: 24px; margin: 0; padding: 12px 16px; background: #fff; font-size: 12px; }
.preview-details dt { color: var(--muted); }
.preview-details dd { margin: 3px 0 0; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; margin: 0 0 12px; background: #fff; }
.segmented label { position: relative; margin: 0; text-align: center; cursor: pointer; font-size: 13px; }
.segmented label + label { border-left: 1px solid var(--border); }
.segmented input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.segmented span { display: block; padding: 11px 8px; }
.segmented input:checked + span { background: var(--accent-soft); color: #0a5f58; font-weight: 750; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -3px; }

label { display: block; font-size: 13px; font-weight: 650; margin: 0 0 8px; }
input:not([type=radio]):not([type=file]):not([type=checkbox]), textarea, select {
  display: block; width: 100%; border: 1px solid #c8d2d1; border-radius: 12px; padding: 11px 12px; background: #fff; color: inherit;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.65; }
.optional { font-size: 11px; font-weight: 500; color: var(--muted); }
.label-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; margin-top: 16px; }
.label-row span { font-size: 12px; color: var(--muted); }
.field-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; }
.inline-error { font-size: 13px; color: #ac3027; background: #fff0ed; padding: 12px; border-radius: 10px; }
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 108px; padding: 18px; border: 1.5px dashed #9fb2ae; border-radius: 14px; background: #f4f8f7; cursor: pointer; position: relative;
}
.dropzone strong { font-size: 14px; }
.dropzone > span { font-size: 12px; color: var(--muted); margin-top: 6px; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone:hover, .dropzone.dragging { border-color: var(--accent); background: #eaf4f1; }
.file-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.generate-row { display: flex; gap: 12px; align-items: center; margin-top: 10px; }
.generate-row .field-note { margin: 0; }
#generate-image { min-height: 42px; flex: 0 0 auto; }
.image-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; margin: 10px 0; }
.thumb { padding: 0; overflow: hidden; aspect-ratio: 9/16; border-radius: 10px; background: #dce4e2; display: grid; place-items: center; font-size: 11px; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.is-active { outline: 3px solid var(--accent); }
.thumb.is-busy { opacity: .7; }
.image-actions { margin-top: 10px; display: flex; gap: 12px; align-items: center; }
.output-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-top: 16px; }
.duration-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 18px; }
.chip { padding: 7px 12px; border-radius: 999px; font-size: 12px; background: #f4f7f6; }
.chip.is-active { background: var(--accent-soft); color: #0a5f58; border-color: #b7ddd6; }
.choice-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.sound-panel { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.sound-panel > label { margin-top: 14px; }
.sound-tabs { margin: 0 0 10px; }
.audio-preview { white-space: pre-wrap; background: #f4f8f7; border-radius: 12px; padding: 12px; font-size: 12px; color: #365b54; margin: 12px 0 0; }
.form-footer { display: grid; gap: 10px; margin-top: 8px; }
.check-label { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; font-size: 13px; }
.check-label input[type=checkbox] { width: 16px; height: 16px; margin-top: 2px; accent-color: var(--accent); padding: 0; border: 0; }

.notice { background: #eef4f3; border-left: 3px solid #368e82; font-size: 13px; padding: 14px 16px; color: #365b54; margin-bottom: 18px; border-radius: 0 10px 10px 0; }
.settings-form { max-width: 640px; background: var(--panel); border: 1px solid var(--border); border-radius: 18px; padding: 22px; }
.settings-form + .api-access { margin-top: 18px; }
.api-docs { overflow: auto; background: #142422; color: #d9f0ec; border-radius: 12px; padding: 12px; font-size: 12px; line-height: 1.55; white-space: pre-wrap; }
.api-key-list { display: grid; gap: 8px; margin-top: 12px; }
.api-key-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; font-size: 13px; background: #f4f8f7; border-radius: 10px; padding: 10px 12px; }
.settings-form fieldset { border: 0; margin: 0 0 18px; padding: 0; }
.settings-actions { display: flex; gap: 10px; }
.empty-state { text-align: center; padding: 72px 20px; background: var(--panel); border: 1px dashed var(--border); border-radius: 18px; }
.empty-state p { color: var(--muted); margin: 8px 0 18px; }

.job { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px; margin-bottom: 14px; }
.job-head { display: flex; justify-content: space-between; gap: 12px; }
.job-meta, .job summary { font-size: 12px; color: var(--muted); }
.status { font-size: 12px; padding: 4px 10px; border-radius: 999px; background: #edf0f2; color: #526266; height: fit-content; }
.status.completed { background: #e3f4ed; color: #16704e; }
.status.failed { background: #ffedea; color: #a72f26; }
.job progress { width: 100%; height: 6px; accent-color: var(--accent); margin: 14px 0 6px; }
.job p { font-size: 13px; margin-top: 8px; overflow-wrap: anywhere; }
.job-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.job-actions a { display: inline-flex; align-items: center; border-radius: 10px; padding: 8px 14px; text-decoration: none; background: var(--accent); color: #fff; font-size: 13px; }
.job video { display: block; width: 100%; max-height: 480px; margin-top: 16px; background: #131a19; border-radius: 12px; }
.job-error { color: #a72f26; }
.job-prompt { color: var(--muted); white-space: pre-wrap; }
.job summary { cursor: pointer; margin-top: 12px; }

#toast { position: fixed; bottom: 20px; right: 20px; max-width: min(420px, calc(100vw - 32px)); background: #20312e; color: #fff; border-radius: 12px; padding: 12px 16px; z-index: 20; }
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: min(400px, calc(100vw - 32px)); color: inherit; }
dialog::backdrop { background: #14201b70; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
dialog label { margin-top: 12px; }
dialog .primary { margin-top: 18px; }

@media (max-width: 980px) {
  .studio-layout { grid-template-columns: 1fr; }
  .preview-surface { min-height: 320px; }
  .top-nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav-button { white-space: nowrap; flex: 0 0 auto; }
  .topbar { flex-wrap: wrap; }
}
@media (max-width: 600px) {
  main { padding: 14px; }
  h1 { font-size: 22px; }
  .brand-light { display: none; }
  .output-grid { grid-template-columns: 1fr; }
  .preview-frame { height: 240px; width: auto; aspect-ratio: 9/16; }
  .preview-frame.wide { width: 100%; height: auto; }
  .connection { max-width: 110px; }
}
@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

/* Use the official company artwork without cropping or recoloring. */
img.brand-mark { display:block; object-fit:contain; background:transparent; border-radius:0; }
