.studio-layout {
  display: grid;
  grid-template-columns: minmax(360px, 420px) minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.studio-compose {
  position: sticky;
  top: 18px;
  min-width: 0;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 12px 34px rgba(20, 38, 54, 0.07);
}

.studio-compose-head,
.studio-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.studio-compose-head h2,
.studio-section-head h3 {
  margin: 3px 0 0;
}

.studio-fieldset {
  min-width: 0;
  margin: 21px 0 0;
  padding: 0;
  border: 0;
}

.studio-fieldset legend,
.studio-label,
.studio-label > span:first-child {
  color: #354052;
  font-size: 12px;
  font-weight: 750;
}

.mode-tabs,
.output-mode {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  margin-top: 8px;
  padding: 4px;
  border: 1px solid oklch(90% 0.01 165);
  border-radius: 10px;
  background: oklch(96.5% 0.008 165);
}

.mode-tabs button,
.output-mode button {
  min-width: 0;
  padding: 9px 5px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.mode-tabs button:hover,
.output-mode button:hover {
  color: var(--ink);
}

.mode-tabs button.active,
.output-mode button.active {
  background: var(--paper);
  color: var(--green-dark);
  box-shadow: 0 1px 5px rgba(20, 38, 54, 0.12);
}

.field-help {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.studio-label {
  display: grid;
  gap: 7px;
  margin: 15px 0;
}

.studio-label small {
  color: var(--muted);
  font-weight: 450;
  line-height: 1.5;
}

.studio-label > span small {
  margin-left: 4px;
  color: var(--green);
}

.studio-label textarea,
.studio-label select,
.studio-label input,
.asset-url-row input,
.asset-url-row select {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid #dce2e8;
  border-radius: 9px;
  outline: none;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
}

.studio-label textarea {
  resize: vertical;
  line-height: 1.6;
}

.studio-label textarea:focus,
.studio-label select:focus,
.studio-label input:focus,
.asset-url-row input:focus,
.asset-url-row select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(8, 125, 104, 0.1);
}

.studio-form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr) minmax(76px, 0.65fr);
  gap: 9px;
}

.asset-slot {
  margin: 15px 0;
}

.asset-slot-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

.asset-slot-head strong {
  font-size: 12px;
}

.asset-slot-head small {
  color: var(--muted);
  font-size: 10px;
}

.studio-upload-zone {
  display: grid;
  width: 100%;
  min-height: 94px;
  place-content: center;
  padding: 13px;
  border: 1px dashed #aebebc;
  border-radius: 11px;
  background: oklch(98.2% 0.008 165);
  color: #53636b;
  text-align: center;
  transition: background 180ms ease-out, border-color 180ms ease-out;
}

.studio-upload-zone:hover,
.studio-upload-zone:focus-visible {
  border-color: var(--green);
  outline: 0;
  background: oklch(96.5% 0.02 165);
}

.studio-upload-zone > span {
  color: var(--green);
  font-size: 22px;
}

.studio-upload-zone strong {
  margin-top: 4px;
  font-size: 12px;
}

.studio-upload-zone small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 9px;
}

.studio-selected-list {
  display: grid;
  gap: 7px;
}

.selected-asset {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 7px;
  border: 1px solid #dfe6e5;
  border-radius: 10px;
  background: var(--paper);
}

.selected-asset img,
.selected-asset video,
.selected-asset .asset-kind-icon {
  width: 46px;
  height: 40px;
  border-radius: 7px;
  object-fit: cover;
  background: #eaf0ef;
}

.asset-kind-icon {
  display: grid;
  place-items: center;
  color: var(--green);
  font-size: 17px;
}

.selected-asset div {
  min-width: 0;
}

.selected-asset strong,
.recent-asset strong {
  display: block;
  overflow: hidden;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-asset small,
.recent-asset small {
  color: var(--muted);
  font-size: 9px;
}

.asset-remove {
  width: 27px;
  height: 27px;
  border: 0;
  border-radius: 50%;
  background: #f0f3f3;
  color: #718088;
  font-size: 15px;
}

.asset-remove:hover {
  background: #fae8e8;
  color: #a83e3e;
}

.output-fieldset {
  padding-top: 17px;
  border-top: 1px solid var(--line);
}

.output-mode {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.studio-switches {
  margin-top: 18px;
  border-top: 1px solid var(--line);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  padding: 13px 0;
  border-bottom: 1px solid #edf0f2;
  cursor: pointer;
}

.switch-row > span {
  display: grid;
  gap: 3px;
}

.switch-row strong {
  font-size: 12px;
}

.switch-row small {
  color: var(--muted);
  font-size: 9px;
}

.switch-row input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-row i {
  position: relative;
  flex: 0 0 auto;
  width: 38px;
  height: 22px;
  border-radius: 99px;
  background: #cdd5d9;
  transition: background 180ms ease-out;
}

.switch-row i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 1px 4px rgba(20, 38, 54, 0.2);
  content: "";
  transition: transform 180ms ease-out;
}

.switch-row input:checked + i {
  background: var(--green);
}

.switch-row input:checked + i::after {
  transform: translateX(16px);
}

.switch-row input:focus-visible + i {
  box-shadow: 0 0 0 3px rgba(8, 125, 104, 0.17);
}

.studio-advanced {
  margin: 13px 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.studio-advanced summary {
  color: #536070;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}

.check-row {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 12px;
  font-size: 11px;
}

.check-row input {
  margin-top: 2px;
  accent-color: var(--green);
}

.check-row span {
  display: grid;
  gap: 2px;
}

.check-row small {
  color: var(--muted);
  font-size: 9px;
}

.studio-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.studio-stage {
  display: grid;
  min-width: 0;
  gap: 18px;
}

.studio-shelf,
.studio-output {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--paper);
}

.studio-section-head > small {
  color: var(--muted);
  font-size: 10px;
}

.asset-url-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr) auto;
  gap: 8px;
  margin: 17px 0 14px;
}

.asset-url-row input,
.asset-url-row select {
  padding: 9px 10px;
}

.studio-recent-assets {
  display: flex;
  gap: 9px;
  min-height: 75px;
  overflow: auto;
  padding-bottom: 3px;
}

.recent-asset {
  display: grid;
  grid-template-columns: 52px minmax(90px, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 185px;
  max-width: 230px;
  padding: 7px;
  border: 1px solid #e1e6e8;
  border-radius: 10px;
  background: #fbfcfc;
  cursor: pointer;
}

.recent-asset:hover {
  border-color: #9ec5bd;
  background: #f4faf8;
}

.recent-asset img,
.recent-asset video,
.recent-asset .asset-kind-icon {
  width: 52px;
  height: 48px;
  border-radius: 7px;
  object-fit: cover;
  background: #e9efef;
}

.recent-asset .asset-meta {
  min-width: 0;
}

.recent-asset .asset-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.recent-asset button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--green);
  font-size: 9px;
  font-weight: 750;
}

.studio-output {
  min-height: 500px;
}

.studio-empty {
  display: grid;
  min-height: 405px;
  place-content: center;
  padding: 35px;
  color: var(--muted);
  text-align: center;
}

.studio-empty > span {
  display: grid;
  width: 60px;
  height: 60px;
  place-items: center;
  margin: 0 auto 13px;
  border-radius: 50%;
  background: #e9f5f1;
  color: var(--green);
  font-size: 25px;
}

.studio-empty h3 {
  margin: 0 0 7px;
  color: var(--ink);
}

.studio-empty p {
  max-width: 520px;
  margin: 0;
  font-size: 12px;
  line-height: 1.7;
}

.studio-result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
}

.studio-result-head h2 {
  margin: 3px 0 6px;
  font-size: 21px;
}

.studio-result-head p {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
}

.studio-result-video {
  width: 100%;
  max-height: 540px;
  aspect-ratio: 16 / 9;
  margin-top: 16px;
  border-radius: 12px;
  background: #0c151b;
  object-fit: contain;
}

.studio-progress-visual {
  display: grid;
  min-height: 310px;
  place-content: center;
  margin-top: 16px;
  border-radius: 12px;
  text-align: center;
}

.studio-progress-visual span {
  font-size: 33px;
}

.studio-progress-visual h3 {
  margin: 12px 0 6px;
}

.studio-progress-visual p {
  margin: 0;
  font-size: 11px;
}

.studio-usage {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 9px;
  margin-top: 12px;
}

.studio-usage > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfc;
}

.studio-usage small {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 9px;
}

.studio-usage strong {
  font-size: 17px;
}

.studio-result-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 13px;
}

.studio-result-actions p {
  margin: 0;
  color: var(--muted);
  font-size: 10px;
}

.studio-history-panel {
  margin-bottom: 24px;
}

.studio-history-panel table {
  min-width: 780px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.studio-result-actions a {
  background: var(--green);
  color: #fcfdfd;
  border-radius: 9px;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 750;
}

.studio-result-actions a:hover {
  background: var(--green-dark);
}

/* Keep the creation flow calm and compact without hiding the final action. */
textarea,
button,
input,
select {
  font: inherit;
}

:where(button, a, input, select, textarea, summary):focus-visible {
  outline: 3px solid rgba(16, 138, 115, 0.28);
  outline-offset: 2px;
}

.studio-account-state {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.studio-free-note,
.studio-balance {
  min-width: 72px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  text-align: right;
}

.studio-free-note {
  border-color: rgba(16, 138, 115, 0.22);
  background: var(--mint);
  color: var(--green-dark);
}

.studio-free-note strong,
.studio-balance strong {
  display: block;
  font-size: 18px;
  line-height: 1;
}

.studio-free-note span,
.studio-balance span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
}

.studio-free-note[hidden] {
  display: none;
}

.studio-cost-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin: 15px 0 10px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.studio-cost-bar > span:last-child {
  text-align: left;
}

.studio-cost-bar strong {
  color: var(--ink);
  font-size: 15px;
}

.studio-result-actions,
.studio-result-actions > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.studio-result-actions .secondary,
.studio-result-actions a {
  min-height: 38px;
}

.studio-shelf,
.studio-output,
.studio-history-panel {
  min-width: 0;
}

.field-help,
.studio-label small,
.switch-row small,
.check-row small {
  font-size: 11px;
  line-height: 1.5;
}

@media (min-width: 981px) {
  .topbar {
    min-height: 70px;
    margin-bottom: 22px;
  }

  .studio-compose {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 38px);
    overflow: hidden;
  }

  .studio-compose form {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-height: 0;
  }

  .studio-form-scroll {
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
    scrollbar-gutter: stable;
  }

  .studio-action-dock {
    flex: 0 0 auto;
    margin-top: 0;
    padding-top: 12px;
    border-top: 1px solid var(--line);
    background: var(--paper);
  }
}

@media (max-width: 760px) {
  #page-studio.active {
    padding-bottom: 132px;
  }

  #page-studio.active .studio-action-dock {
    position: fixed;
    z-index: 40;
    right: 12px;
    bottom: 0;
    left: 12px;
    margin: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 14px 14px 0 0;
    background: rgba(255, 255, 255, 0.97);
    box-shadow: 0 -12px 32px rgba(13, 38, 51, 0.12);
    backdrop-filter: blur(12px);
  }

  .studio-cost-bar {
    gap: 8px;
    font-size: 11px;
  }

  .studio-compose-head {
    align-items: flex-start;
  }

  .studio-account-state {
    flex-direction: column;
  }

  .studio-free-note,
  .studio-balance {
    min-width: 66px;
    padding: 7px 9px;
  }

  .studio-result-actions,
  .studio-result-actions > div {
    align-items: stretch;
  }

  .studio-result-actions .secondary,
  .studio-result-actions a {
    flex: 1 1 132px;
    text-align: center;
  }

  .studio-history-panel .table-wrap {
    max-width: 100%;
  }
}

@media (max-width: 1280px) {
  .studio-layout {
    grid-template-columns: 350px minmax(0, 1fr);
  }

  .studio-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .studio-form-grid .studio-label:first-child {
    grid-column: 1 / -1;
  }

  .studio-usage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }

  .studio-compose {
    position: static;
  }

  .studio-form-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .studio-form-grid .studio-label:first-child {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .studio-compose,
  .studio-shelf,
  .studio-output {
    padding: 16px;
  }

  .mode-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .studio-form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .studio-form-grid .studio-label:first-child {
    grid-column: 1 / -1;
  }

  .asset-url-row {
    grid-template-columns: 1fr;
  }

  .studio-section-head {
    align-items: flex-start;
  }

  .studio-section-head > small {
    max-width: 100px;
    text-align: right;
  }

  .studio-usage {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 430px) {
  .studio-form-grid,
  .studio-usage {
    grid-template-columns: 1fr;
  }

  .studio-form-grid .studio-label:first-child {
    grid-column: auto;
  }
}
