:root {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: #26251f;
  background: #f5f1e8;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 8% 0%, rgba(198, 151, 88, 0.17), transparent 30%),
    radial-gradient(circle at 95% 12%, rgba(47, 93, 80, 0.09), transparent 26%),
    #f5f1e8;
}

button, textarea, input, select { font: inherit; }
button, select { color: inherit; }

.app-shell {
  width: min(1120px, calc(100% - 32px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 36px 20px 54px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
}

.eyebrow,
.card-kicker {
  margin: 0 0 5px;
  color: #987044;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.15em;
}

h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(29px, 4vw, 43px);
  line-height: 1;
  letter-spacing: -0.03em;
}

h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

h3 { margin: 0; font-size: 16px; }

.top-statuses {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 9px;
  padding-bottom: 3px;
}

.connection {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #77736a;
  font-size: 12px;
  line-height: 1;
}

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b56c61;
  box-shadow: 0 0 0 3px rgba(181, 108, 97, 0.12);
}

.connection.connected .connection-dot {
  background: #4f8a67;
  box-shadow: 0 0 0 3px rgba(79, 138, 103, 0.14);
}

.tabs {
  display: flex;
  width: fit-content;
  padding: 4px;
  border: 1px solid #d7cebf;
  border-radius: 12px;
  background: rgba(255, 254, 250, 0.64);
  box-shadow: 0 6px 18px rgba(75, 61, 42, 0.04);
}

.tab-button {
  min-height: 40px;
  padding: 8px 18px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #777166;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
}

.tab-button.active {
  background: #2f5d50;
  color: #fffdf8;
  box-shadow: 0 5px 13px rgba(47, 93, 80, 0.18);
}

.tab-panel { display: none; }
.tab-panel.active { display: grid; gap: 20px; }
.legacy-hidden-panel { display: none !important; }

.visual-mode-toggle {
  display: inline-flex;
  width: fit-content;
  padding: 4px;
  border: 1px solid #d7cebf;
  border-radius: 12px;
  background: rgba(255, 254, 250, 0.64);
  box-shadow: 0 6px 18px rgba(75, 61, 42, 0.04);
}

.visual-mode-button {
  min-width: 128px;
  min-height: 40px;
  padding: 8px 18px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #777166;
  cursor: pointer;
  font-size: 14px;
  font-weight: 650;
}

.visual-mode-button.active {
  background: #2f5d50;
  color: #fffdf8;
  box-shadow: 0 5px 13px rgba(47, 93, 80, 0.18);
}

.visual-pane { display: none; }
.visual-pane.active { display: grid; gap: 20px; }

.text-section { display: grid; gap: 10px; }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

label,
.field-label {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.field-label {
  display: block;
  margin: 16px 0 7px;
  font-family: inherit;
  font-size: 13px;
  letter-spacing: 0;
}

.counter {
  color: #8b867d;
  font-size: 11px;
}

textarea {
  width: 100%;
  min-height: 250px;
  resize: vertical;
  padding: 18px 19px;
  color: #2b2a25;
  background: rgba(255, 254, 250, 0.91);
  border: 1px solid #d9d1c4;
  border-radius: 14px;
  outline: none;
  line-height: 1.58;
  box-shadow: 0 9px 25px rgba(75, 61, 42, 0.05);
  transition: border-color 140ms ease, box-shadow 140ms ease, opacity 140ms ease;
}

.tts-textarea { min-height: 300px; }

textarea:focus,
.text-input:focus,
.select-input:focus {
  border-color: #a97840;
  box-shadow: 0 0 0 3px rgba(169, 120, 64, 0.12), 0 9px 25px rgba(75, 61, 42, 0.05);
}

textarea:disabled { opacity: 0.68; }
textarea::placeholder,
.text-input::placeholder { color: #aaa49a; }

.text-input,
.select-input {
  width: 100%;
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid #d6ccbd;
  border-radius: 10px;
  outline: none;
  background: rgba(255, 254, 250, 0.92);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.select-input { cursor: pointer; }
.select-input[size] { min-height: 238px; padding: 6px; }
.select-input[size] option { padding: 9px 8px; border-radius: 6px; }
.single-select { min-height: 43px; }

.section-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: 0;
  cursor: pointer;
  transition: background 130ms ease, transform 130ms ease, opacity 130ms ease;
}

button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: default; opacity: 0.43; }

.secondary-button,
.cancel-button,
.link-button {
  min-height: 39px;
  padding: 8px 15px;
  border: 1px solid #cec4b5;
  border-radius: 9px;
  color: #4e493f;
  background: rgba(255, 254, 250, 0.84);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.secondary-button:hover:not(:disabled),
.cancel-button:hover:not(:disabled),
.link-button:hover { background: #fffdf7; }

.full-width { width: 100%; margin-top: 12px; }

.text-button {
  padding: 8px 7px;
  color: #8a8276;
  background: transparent;
  font-size: 13px;
}

.text-button:hover:not(:disabled) { color: #5b554d; }
.danger-text { color: #9b5149; }

.action-area {
  display: flex;
  min-height: 82px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.primary-button {
  min-width: 245px;
  min-height: 54px;
  padding: 12px 30px;
  border-radius: 12px;
  color: #fffdf8;
  background: #2f5d50;
  font-size: 17px;
  font-weight: 680;
  letter-spacing: 0.01em;
  box-shadow: 0 9px 19px rgba(47, 93, 80, 0.19);
}

.primary-button:hover:not(:disabled),
.primary-small-button:hover:not(:disabled) { background: #274f44; }

.primary-small-button {
  min-height: 42px;
  padding: 9px 16px;
  border: 0;
  border-radius: 9px;
  color: #fffdf8;
  background: #2f5d50;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.cancel-button {
  color: #8a443c;
  border-color: #d9b9b3;
}

.message,
.inline-message {
  min-height: 0;
  margin: 0;
  font-size: 13px;
}

.message {
  flex-basis: 100%;
  text-align: center;
}

.inline-message { margin-top: 10px; }
.progress { color: #68645b; }
.warning { color: #9a651e; }
.error { color: #a13e36; white-space: pre-wrap; }

.provider-diagnostic {
  flex-basis: 100%;
  width: min(100%, 900px);
  margin: 2px auto 0;
  border: 1px solid #d8b8b2;
  border-radius: 12px;
  background: rgba(255, 249, 247, 0.88);
  text-align: left;
}

.provider-diagnostic summary {
  padding: 11px 14px;
  color: #873a33;
  font-size: 13px;
  font-weight: 750;
  cursor: pointer;
}

.provider-diagnostic pre {
  max-height: 420px;
  margin: 0;
  padding: 0 14px 14px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #4d302d;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.result-section textarea { min-height: 250px; }
.hidden { display: none !important; }

.settings-card {
  padding: 20px;
  border: 1px solid #d8cfc1;
  border-radius: 16px;
  background: rgba(255, 254, 250, 0.83);
  box-shadow: 0 10px 28px rgba(75, 61, 42, 0.055);
}

.card-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
}

.card-heading p:not(.card-kicker) {
  max-width: 720px;
  margin: 8px 0 0;
  color: #756f65;
  font-size: 13px;
  line-height: 1.55;
}

.compact-heading { align-items: center; margin-bottom: 14px; }

.api-key-card { padding: 24px; }
.api-key-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 18px; }

.voice-workspace { display: grid; gap: 20px; }

.account-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(130px, 1fr)) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  border: 1px solid #d8cfc1;
  border-radius: 13px;
  background: rgba(255, 254, 250, 0.72);
}

.account-strip > div:not(.account-actions) { display: grid; gap: 3px; }
.account-label { color: #8a847a; font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; }
.account-strip strong { font-size: 14px; }
.account-actions { display: flex; justify-content: flex-end; gap: 8px; }

.voice-control-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.8fr);
  gap: 16px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: 1px solid #d2c8b9;
  background: rgba(255, 254, 250, 0.8);
  font-size: 20px;
  line-height: 1;
}

.voice-library-launch-card {
  display: grid;
  align-content: start;
  gap: 12px;
}
.voice-library-launch-button {
  min-height: 74px;
  font-size: 18px;
}
.selected-voice-meta {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid #d8cfc1;
  border-radius: 11px;
  background: rgba(255, 254, 250, 0.72);
  color: #5f5a52;
  font-size: 12px;
  line-height: 1.45;
}
.field-help { margin: 7px 0 0; color: #827c72; font-size: 11px; line-height: 1.45; }

.slider-card { padding-bottom: 18px; }
.sliders-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 28px; }
.slider-field { display: grid; gap: 8px; font-family: inherit; font-size: 13px; }
.slider-field > span { display: flex; justify-content: space-between; align-items: center; }
.slider-field output { color: #8a6c47; font-variant-numeric: tabular-nums; }
.slider-field small { color: #8a847a; font-size: 11px; line-height: 1.35; }
.slider-field input[type="range"] { width: 100%; accent-color: #2f5d50; }

.toggle-field {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 22px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
}

.toggle-field > input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-visual {
  width: 42px;
  height: 24px;
  padding: 3px;
  border-radius: 999px;
  background: #c7c0b5;
  transition: background 140ms ease;
}
.toggle-visual::after {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.16);
  transition: transform 140ms ease;
}
.toggle-field input:checked + .toggle-visual { background: #2f5d50; }
.toggle-field input:checked + .toggle-visual::after { transform: translateX(18px); }
.toggle-field span:last-child { display: grid; gap: 2px; }
.toggle-field small { color: #8a847a; font-size: 11px; }

.voice-action-area { min-height: 96px; }
.audio-result-card { display: grid; gap: 14px; }
.final-audio { width: 100%; }

.library-dialog {
  width: min(960px, calc(100% - 24px));
  max-height: min(88vh, 880px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: #f7f3ea;
  box-shadow: 0 25px 80px rgba(37, 31, 23, 0.28);
}

.library-dialog::backdrop { background: rgba(31, 28, 24, 0.48); backdrop-filter: blur(3px); }
.dialog-shell { display: grid; grid-template-rows: auto auto auto minmax(160px, 1fr) auto; max-height: inherit; }
.dialog-heading { display: flex; justify-content: space-between; gap: 20px; padding: 22px 24px 16px; }
.dialog-heading p:not(.card-kicker) { margin: 7px 0 0; color: #777168; font-size: 13px; }
.dialog-close { width: 38px; height: 38px; border-radius: 50%; background: transparent; color: #756e64; font-size: 28px; line-height: 1; }
.dialog-close:hover { background: rgba(0, 0, 0, 0.05); }
.library-filters { display: grid; grid-template-columns: minmax(260px, 1.8fr) minmax(140px, 0.65fr) minmax(150px, 0.7fr) auto; gap: 8px; padding: 0 24px 14px; }
.library-dialog .inline-message { padding: 0 24px 10px; }
.library-results { overflow-y: auto; display: grid; gap: 10px; padding: 0 24px 18px; }
.library-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 0.42fr);
  gap: 16px;
  padding: 14px;
  border: 1px solid #ddd4c7;
  border-radius: 12px;
  background: rgba(255, 254, 250, 0.84);
}
.library-card-main { min-width: 0; }
.library-card-tags { margin: 5px 0; color: #9a7144; font-size: 11px; }
.library-card-description { margin: 0; color: #777168; font-size: 12px; line-height: 1.45; }
.library-card-actions { display: grid; align-content: center; gap: 8px; }
.library-card audio { width: 100%; height: 34px; }
.dialog-footer { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 14px 24px 20px; border-top: 1px solid #ded6ca; }
.empty-state { margin: 30px auto; color: #898278; font-size: 13px; }

@media (max-width: 820px) {
  .voice-control-grid { grid-template-columns: 1fr; }
  .library-filters { grid-template-columns: 1fr 1fr; }
  .library-filters .primary-small-button { grid-column: span 2; }
  .library-card { grid-template-columns: 1fr; }
  .account-strip { grid-template-columns: repeat(3, 1fr); }
  .account-actions { grid-column: 1 / -1; justify-content: flex-start; }
}

@media (max-width: 650px) {
  .app-shell { width: min(100% - 20px, 1120px); padding: 24px 5px 36px; }
  .topbar { align-items: flex-start; flex-direction: column; gap: 14px; }
  .top-statuses { align-items: flex-start; }
  .tabs { width: 100%; }
  .tab-button { flex: 1; padding-inline: 10px; }
  textarea, .result-section textarea { min-height: 220px; }
  .primary-button { width: 100%; }
  .section-actions { justify-content: stretch; }
  .section-actions .secondary-button,
  .section-actions .link-button { flex: 1; }
  .api-key-row { grid-template-columns: 1fr; }
  .sliders-grid { grid-template-columns: 1fr; }
  .account-strip { grid-template-columns: 1fr 1fr; }
  .account-actions { grid-column: 1 / -1; }
  .library-filters { grid-template-columns: 1fr; }
  .library-filters .primary-small-button { grid-column: auto; }
  .dialog-heading { padding-inline: 16px; }
  .library-filters,
  .library-results { padding-inline: 16px; }
}

.library-filters-search-only { grid-template-columns: minmax(260px, 1fr) auto; }
@media (max-width: 760px) { .library-filters-search-only { grid-template-columns: 1fr; } }

.library-token-card code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(47, 93, 80, 0.08);
  color: #345f53;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}
.library-token-help { margin-top: 10px; }
.library-token-connected {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
  padding: 14px 15px;
  border: 1px solid rgba(79, 138, 103, 0.35);
  border-radius: 12px;
  background: rgba(79, 138, 103, 0.08);
}
.library-token-success {
  margin: 0;
  color: #35674f;
  font-size: 13px;
  line-height: 1.45;
}
.library-token-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.voice-library-launch-button:disabled {
  cursor: not-allowed;
  background: #99aaa3;
  opacity: 0.8;
}
@media (max-width: 650px) {
  .library-token-connected { align-items: stretch; flex-direction: column; }
  .library-token-actions { flex-wrap: wrap; }
}

/* v22: English master script + localized channel script */
.localization-settings {
  display: grid;
  grid-template-columns: minmax(230px, 0.42fr) minmax(0, 1fr);
  gap: 18px;
  align-items: end;
  padding: 16px 18px;
  border: 1px solid #d8cfc1;
  border-radius: 13px;
  background: rgba(255, 254, 250, 0.68);
}

.language-field { min-width: 0; }
.language-field .field-label { margin: 0 0 7px; }
.localization-help { margin: 0 0 4px; max-width: 720px; }

.english-result-section,
.localized-result-section {
  padding: 18px;
  border: 1px solid #ddd4c7;
  border-radius: 16px;
  background: rgba(255, 254, 250, 0.43);
}

.localized-result-section {
  border-color: rgba(47, 93, 80, 0.34);
  background: rgba(239, 247, 242, 0.42);
}

@media (max-width: 720px) {
  .localization-settings { grid-template-columns: 1fr; align-items: start; }
}

/* v24: selectable local/cloud text engine */
.rewrite-engine-grid {
  grid-template-columns: minmax(220px, 0.8fr) minmax(240px, 0.9fr) minmax(0, 1.3fr);
}
.google-key-card {
  padding: 18px;
}
.google-key-card h2 {
  font-size: 19px;
}
.google-key-card .api-key-row {
  margin-top: 12px;
}
.claude-card code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(47, 93, 80, 0.08);
  color: #345f53;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}
.claude-status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
  padding: 13px 14px;
  border: 1px solid rgba(79, 138, 103, 0.30);
  border-radius: 12px;
  background: rgba(79, 138, 103, 0.07);
}
.claude-status-row .library-token-success.error { color: #a13e36; }
@media (max-width: 650px) {
  .claude-status-row { align-items: stretch; flex-direction: column; }
}
@media (max-width: 900px) {
  .rewrite-engine-grid { grid-template-columns: 1fr 1fr; }
  .rewrite-engine-grid .localization-help { grid-column: 1 / -1; }
}
@media (max-width: 650px) {
  .rewrite-engine-grid { grid-template-columns: 1fr; }
  .rewrite-engine-grid .localization-help { grid-column: auto; }
}

/* v50: integrated Google Cloud image generation */
.photo-textarea { min-height: 320px; }
.photo-cloud-grid,
.photo-controls-grid,
.photo-regenerate-grid {
  display: grid;
  gap: 16px;
}
.photo-cloud-grid { grid-template-columns: minmax(0, 1fr) minmax(180px, 0.34fr); }
.photo-cloud-actions { margin-top: 14px; }
.photo-controls-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; }
.photo-toggle-field { min-height: 78px; margin-top: 0; }
.photo-regenerate-grid { grid-template-columns: minmax(150px, 0.25fr) minmax(0, 1fr); align-items: start; }
.compact-textarea { min-height: 112px; padding: 13px 14px; }
.photo-result-card {
  border-color: rgba(47, 93, 80, 0.34);
  background: rgba(239, 247, 242, 0.5);
}
.photo-action-area { min-height: 104px; }
.photo-cloud-card code,
.photo-result-card code,
.photo-regenerate-card code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(47, 93, 80, 0.08);
  color: #345f53;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.92em;
}
@media (max-width: 760px) {
  .photo-cloud-grid,
  .photo-controls-grid,
  .photo-regenerate-grid { grid-template-columns: 1fr; }
}
@media (max-width: 650px) {
  .tabs { overflow-x: auto; }
  .tab-button { min-width: max-content; }
}

/* v51: FFmpeg automatic montage */
.montage-input-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.montage-upload-card {
  display: grid;
  gap: 10px;
  min-height: 142px;
  padding: 15px;
  border: 1px solid #ddd4c7;
  border-radius: 14px;
  background: rgba(255, 254, 250, 0.64);
}

.montage-upload-card > strong,
.montage-upload-heading > strong {
  font-size: 14px;
}

.montage-upload-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.montage-upload-card small,
.montage-volume-field small {
  color: #837d72;
  font-size: 11px;
  line-height: 1.45;
}

.mini-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 650;
  color: #496c60;
  cursor: pointer;
}

.mini-toggle input { accent-color: #2f5d50; }

.file-input {
  width: 100%;
  min-height: 42px;
  padding: 7px 8px;
  border: 1px solid #d8cfc1;
  border-radius: 10px;
  background: #fffdf9;
  color: #666056;
  font-size: 12px;
}

.file-input::file-selector-button {
  margin-right: 9px;
  padding: 7px 10px;
  border: 0;
  border-radius: 7px;
  background: #e8e0d4;
  color: #514c43;
  cursor: pointer;
  font-weight: 650;
}

.montage-script { min-height: 210px; }

.montage-presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 11px;
}

.montage-presets > div {
  display: grid;
  gap: 5px;
  padding: 13px 14px;
  border: 1px solid #ddd4c7;
  border-radius: 12px;
  background: rgba(255, 254, 250, 0.55);
}

.montage-presets span {
  color: #8b867d;
  font-size: 11px;
}

.montage-presets strong {
  font-size: 13px;
  color: #345f53;
}

.montage-volume-field {
  margin-top: 16px;
}

.montage-action-area { min-height: 132px; }

.montage-progress-track {
  width: min(620px, 100%);
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(47, 93, 80, 0.12);
}

.montage-progress-track span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #2f5d50;
  transition: width 180ms linear;
}

.montage-result-card {
  border-color: rgba(47, 93, 80, 0.34);
  background: rgba(239, 247, 242, 0.5);
}

.montage-preview {
  width: 100%;
  max-height: 610px;
  border-radius: 14px;
  background: #171713;
  box-shadow: 0 10px 28px rgba(42, 39, 31, 0.12);
}

@media (max-width: 860px) {
  .montage-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .montage-input-grid { grid-template-columns: 1fr; }
  .montage-upload-heading { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 520px) {
  .montage-presets { grid-template-columns: 1fr; }
}

/* v60: selectable centered zoom */
.montage-zoom-preset { align-items: stretch !important; gap: 8px; }
.montage-zoom-preset label { color: #8d877d; font-size: 0.9rem; }
.montage-zoom-select { width: 100%; min-height: 38px; padding: 7px 34px 7px 10px; font-weight: 700; color: #2f5d50; background-color: rgba(255,255,255,0.62); }

.montage-subtitle-toggle { align-items: center !important; gap: 10px; }
.montage-subtitle-toggle .mini-toggle { margin-top: 2px; }
.montage-subtitle-control { align-items: stretch !important; gap: 8px; }
.montage-subtitle-control label { color: #8d877d; font-size: 0.9rem; }
.montage-subtitle-help { margin-top: 14px; }


/* v0.39: manual recovery for incomplete video batches */
.video-result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.video-result-actions .secondary-button,
.video-result-actions .primary-small-button {
  white-space: nowrap;
}

@media (max-height: 820px) {
  .video-result-actions {
    gap: 6px;
  }
  .video-result-actions .secondary-button,
  .video-result-actions .primary-small-button {
    min-height: 34px;
    padding: 7px 12px;
  }
}

/* ----------------------------- Packaging tab ----------------------------- */
body:has(#packagingTab.active) {
  overflow: hidden;
}

.app-shell:has(#packagingTab.active) {
  height: 100dvh;
  min-height: 0;
  padding-bottom: 10px;
  overflow: hidden;
}

#packagingTab.tab-panel.active {
  display: block;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.packaging-workspace-shell {
  height: 100%;
  min-height: 0;
  padding: 12px;
  overflow: hidden;
}

.packaging-workspace-grid {
  display: grid;
  grid-template-columns: minmax(470px, .9fr) minmax(760px, 1.45fr);
  gap: 14px;
  height: 100%;
  min-height: 0;
}

.packaging-source-card,
.packaging-results-pane {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--border-color, #e1d8cb);
  border-radius: 18px;
  background: rgba(255, 254, 250, .72);
}

/* Left side deliberately mirrors the large Original Script card. */
.packaging-source-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 15px;
  overflow: hidden;
}

.packaging-pane-heading,
.packaging-result-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.packaging-pane-heading h2,
.packaging-result-heading h2 {
  margin: 0;
  font-size: 22px;
}

.packaging-pane-heading .card-kicker,
.packaging-result-heading .card-kicker {
  margin-bottom: 3px;
}

.packaging-source-textarea {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  padding: 16px 17px;
  border-radius: 14px;
  line-height: 1.52;
  overflow: auto;
}

.packaging-source-controls {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, .78fr) minmax(0, 1.05fr);
  gap: 7px;
  align-items: end;
}

.packaging-source-controls .secondary-button {
  width: 100%;
  min-height: 38px;
  padding: 6px 10px;
  line-height: 1.1;
  font-size: 12px;
}

.packaging-style-control {
  display: block;
  min-width: 0;
}

.packaging-style-control .select-input {
  width: 100%;
  min-height: 38px;
  height: 38px;
  padding: 6px 32px 6px 10px;
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
}

.packaging-source-action {
  display: grid;
  justify-items: center;
  gap: 4px;
  min-width: 0;
}

.packaging-generate-button {
  width: min(68%, 360px);
  min-height: 42px;
  padding: 8px 16px;
  font-size: 14px;
}

.packaging-source-action .cancel-button {
  min-height: 32px;
  padding: 5px 11px;
  font-size: 12px;
}

.packaging-source-action .message {
  width: 100%;
  max-height: 72px;
  margin: 0;
  overflow: auto;
  text-align: center;
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.packaging-source-meta {
  display: none !important;
}

.packaging-results-pane {
  padding: 12px;
  overflow: hidden;
}

.packaging-empty-state {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 0;
  padding: 24px;
  text-align: center;
  color: #8a8176;
}

.packaging-empty-state h2 {
  margin: 0 0 7px;
  font-size: 25px;
}

.packaging-empty-state p:not(.card-kicker) {
  margin: 0;
}

.packaging-result-workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  height: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  overflow: hidden;
}

.packaging-result-heading {
  align-items: center;
}

.packaging-result-heading .counter {
  flex: 0 0 auto;
  font-size: 10px;
}

.packaging-section-label {
  margin-bottom: 7px;
  font-size: 13px;
  font-weight: 800;
}

/* Give thumbnails every possible pixel in the right pane. */
.packaging-thumb-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.packaging-thumb-card {
  min-width: 0;
  display: grid;
  gap: 6px;
  padding: 7px;
  border: 1px solid var(--border-color, #e1d8cb);
  border-radius: 14px;
  background: rgba(255,255,255,.56);
}

.packaging-thumb-card img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  border-radius: 10px;
  background: rgba(0,0,0,.08);
}

.packaging-thumb-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.packaging-thumb-actions .counter {
  font-size: 9px;
}

.packaging-thumb-actions .link-button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 9px;
}

.packaging-result-details {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(250px, .75fr);
  gap: 10px;
  min-height: 0;
  overflow: hidden;
}

.packaging-copy-card {
  min-width: 0;
  min-height: 0;
  padding: 10px;
  border: 1px solid var(--border-color, #e1d8cb);
  border-radius: 14px;
  background: rgba(255,255,255,.5);
  overflow: hidden;
}

.packaging-titles-card {
  display: grid;
  grid-template-rows: auto minmax(0,1fr);
}

.packaging-text-stack {
  display: grid;
  grid-template-rows: minmax(0, 1.25fr) minmax(0, .75fr);
  gap: 10px;
  min-height: 0;
}

.packaging-text-stack .packaging-copy-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.packaging-copy-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.packaging-copy-head h3 {
  font-size: 14px;
}

.packaging-copy-head .secondary-button,
.packaging-title-copy-button {
  min-height: 29px;
  padding: 5px 8px;
  font-size: 9px;
}

.packaging-titles-list {
  min-height: 0;
  margin: 0;
  padding: 0 0 0 20px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 5px;
}

.packaging-title-item {
  min-width: 0;
  padding: 5px 0 6px;
  border-bottom: 1px solid rgba(130,116,94,.1);
}

.packaging-title-copy {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 7px;
  align-items: start;
}

.packaging-title-original {
  font-size: 11px;
  line-height: 1.28;
  font-weight: 700;
}

.packaging-title-translation {
  margin-top: 2px;
  color: #7e766b;
  font-size: 9.5px;
  line-height: 1.25;
}

.packaging-output-textarea {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 10px;
  line-height: 1.35;
  overflow: auto;
}

.packaging-tags-output {
  min-height: 0;
}

@media (max-width: 1250px) {
  body:has(#packagingTab.active) {
    overflow: auto;
  }

  .app-shell:has(#packagingTab.active) {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  #packagingTab.tab-panel.active {
    overflow: visible;
  }

  .packaging-workspace-shell {
    height: auto;
    overflow: visible;
  }

  .packaging-workspace-grid {
    grid-template-columns: 1fr;
    height: auto;
  }

  .packaging-source-card,
  .packaging-results-pane {
    min-height: 680px;
  }
}

@media (max-width: 760px) {
  .packaging-source-controls,
  .packaging-result-details,
  .packaging-thumb-grid {
    grid-template-columns: 1fr;
  }

  .packaging-generate-button {
    width: 100%;
  }
}


/* v16 compact source footer */
.packaging-source-controls { margin-top: 0; }
.packaging-source-action { margin-top: 1px; }
.packaging-source-action .message:empty { display:none; }
.packaging-source-action .cancel-button.hidden { display:none !important; }


/* AUTOTUBE_PACKAGING_RESULT_READABILITY_V17_BEGIN */
.packaging-thumb-image-button {
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: zoom-in;
  overflow: hidden;
}

.packaging-thumb-image-button img {
  transition: transform 140ms ease;
}

.packaging-thumb-image-button:hover img {
  transform: none;
}

.packaging-thumb-action-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.packaging-thumb-actions .packaging-fullscreen-button,
.packaging-thumb-actions .packaging-download-button {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 34px !important;
  padding: 7px 14px !important;
  border: 0 !important;
  border-radius: 11px !important;
  background: #080808 !important;
  color: #f3e8d8 !important;
  font-size: 10px !important;
  line-height: 1 !important;
  font-weight: 800 !important;
  letter-spacing: -0.01em !important;
  white-space: nowrap !important;
  text-decoration: none !important;
  opacity: 1 !important;
  visibility: visible !important;
  box-shadow: 0 8px 20px rgba(0,0,0,.16) !important;
  cursor: pointer !important;
}


.packaging-thumb-actions .packaging-download-button:hover {
  background: #1b1b1b !important;
  color: #fff5e7 !important;
  transform: translateY(-1px);
}

.packaging-result-details {
  grid-template-columns: minmax(0, 1.45fr) minmax(230px, .55fr);
}

.packaging-titles-list {
  overflow-x: hidden;
}

.packaging-title-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
  min-width: 0;
  width: 100%;
  padding: 7px 0 8px;
}

.packaging-title-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  width: 100%;
}

.packaging-title-original,
.packaging-title-translation {
  display: block;
  width: 100%;
  max-width: none;
  overflow: visible;
  text-overflow: clip;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

.packaging-title-original {
  color: #171717;
  font-size: 11.5px;
  line-height: 1.34;
  font-weight: 800;
}

.packaging-title-translation {
  margin-top: 1px;
  color: #9b5f16;
  font-size: 10.5px;
  line-height: 1.32;
  font-weight: 700;
}

.packaging-title-copy-button {
  flex: 0 0 auto;
  align-self: start;
  white-space: nowrap;
}

.packaging-preview-dialog {
  width: 100vw;
  max-width: none;
  height: 100vh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: rgba(8,8,9,.96);
  overflow: hidden;
}

.packaging-preview-dialog::backdrop {
  background: rgba(0,0,0,.88);
}

.packaging-preview-dialog-shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
}

.packaging-preview-dialog-shell img {
  display: block;
  width: auto;
  height: auto;
  max-width: calc(100vw - 56px);
  max-height: calc(100vh - 56px);
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
}

.packaging-preview-close {
  position: fixed;
  z-index: 2;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 12px;
  background: rgba(20,20,21,.8);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  backdrop-filter: blur(8px);
}

@media (max-width: 1250px) {
  .packaging-thumb-action-buttons {
    gap: 4px;
  }
  .packaging-thumb-actions .packaging-fullscreen-button,
  .packaging-thumb-actions .packaging-download-button {
    padding: 6px 7px;
    font-size: 8.5px;
  }
}
/* AUTOTUBE_PACKAGING_RESULT_READABILITY_V17_END */


/* AUTOTUBE_CHANNEL_THUMBNAIL_STYLES_V1 */
.thumbnail-style-dialog{border:1px solid rgba(255,255,255,.14);background:#191b20;color:#f4f4f5;border-radius:18px;padding:0;width:min(440px,calc(100vw - 32px));box-shadow:0 20px 70px rgba(0,0,0,.55)}
.thumbnail-style-dialog::backdrop{background:rgba(0,0,0,.68);backdrop-filter:blur(4px)}
.thumbnail-style-form{display:flex;flex-direction:column;gap:12px;padding:24px}
.thumbnail-style-top{display:flex;align-items:center;justify-content:space-between;gap:16px}
.thumbnail-style-top h3{font-size:20px;font-weight:700;line-height:1.25;margin:0}
.thumbnail-style-top button{border:0;background:transparent;color:inherit;font-size:26px;cursor:pointer}
.thumbnail-style-form p{color:#a7a7af;font-size:13px;line-height:1.5;margin:0 0 8px}
.thumbnail-style-form label{font-weight:600;font-size:13px}
.thumbnail-style-form input{width:100%;box-sizing:border-box;background:#101115;color:#f3f4f6;border:1px solid #464650;border-radius:10px;padding:11px 12px;font:inherit;min-height:43px}
.thumbnail-style-form input:focus{outline:2px solid #d75356;outline-offset:1px}
.thumbnail-style-form .primary-button{width:100%;margin-top:5px}
.thumbnail-style-message{font-size:13px;line-height:1.4;min-height:0;color:#a7a7af}
