.workspace {
  order: 2;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(18rem, 0.82fr) minmax(0, 1.18fr);
  gap: 1rem;
  align-items: start;
  min-width: 0;
  scroll-margin-top: 5.5rem;
  animation: fadeUp 560ms ease 80ms both;
}

body[data-auth="signed-in"] .workspace {
  margin-top: 1rem;
}

body[data-auth="signed-in"] .input-panel {
  top: 5.25rem;
}

.guest-workspace-gate {
  order: 3;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(18rem, 1.1fr);
  gap: 1rem;
  align-items: stretch;
  min-width: 0;
  margin-top: 0.25rem;
  animation: fadeUp 560ms ease 140ms both;
}

.gate-copy,
.workspace-preview {
  min-width: 0;
  min-height: 22rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.92);
}

.gate-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: clamp(1.2rem, 4vw, 2rem);
}

.gate-copy h2 {
  font-size: clamp(2rem, 5vw, 3.3rem);
}

.gate-copy p {
  color: var(--text-secondary);
}

.gate-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.workspace-preview {
  position: relative;
  overflow: hidden;
  padding: 1rem;
}

.workspace-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  height: 10rem;
  opacity: 0.7;
  background: linear-gradient(90deg, transparent, rgba(202, 255, 51, 0.16), transparent);
}

.preview-bar {
  position: relative;
  display: flex;
  gap: 0.5rem;
  padding: 0 0 1rem;
  border-bottom: 1px solid var(--bg-border);
}

.preview-bar span {
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 999px;
  background: var(--bg-border);
}

.preview-bar span:first-child {
  background: var(--accent);
  box-shadow: 0 0 18px var(--accent-glow);
}

.preview-grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.preview-grid div {
  min-height: 16.5rem;
  padding: 1rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: rgba(26, 26, 26, 0.86);
}

.preview-grid strong {
  display: block;
  margin-bottom: 2rem;
  color: var(--accent);
  font-family: var(--font-display);
}

.preview-grid p {
  margin-bottom: 0.75rem;
  padding: 0.7rem;
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  color: var(--text-secondary);
  background: var(--bg-surface);
}

.input-panel,
.output-panel {
  min-width: 0;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.92);
}

.input-panel {
  position: sticky;
  top: 5.5rem;
  display: grid;
  gap: 0.95rem;
  padding: 1rem;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.panel-heading h2 {
  margin-bottom: 0;
  font-size: 1.55rem;
}

.cost-badge {
  flex: 0 0 auto;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--bg-border);
  border-radius: 999px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
}

.url-row {
  position: relative;
}

.url-valid {
  position: absolute;
  top: 50%;
  right: 0.7rem;
  transform: translateY(-50%);
  color: var(--success);
  font-family: var(--font-output);
  font-size: 0.78rem;
}

.notice {
  margin-bottom: 1rem;
  padding: 0.85rem;
  border: 1px solid rgba(245, 158, 11, 0.45);
  border-radius: 8px;
  background: rgba(245, 158, 11, 0.08);
  color: var(--text-secondary);
}

.choice-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-group legend {
  margin-bottom: 0.65rem;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.format-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.format-choice {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
  min-height: 3.25rem;
  padding: 0.55rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 700;
  transition: transform 160ms ease, border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.format-choice span:last-child {
  min-width: 0;
  overflow-wrap: anywhere;
}

.format-choice:hover {
  border-color: rgba(202, 255, 51, 0.45);
  background: rgba(202, 255, 51, 0.06);
  color: var(--text-primary);
}

.format-choice input,
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.format-choice:has(input:checked) {
  border-color: var(--accent);
  background: rgba(202, 255, 51, 0.12);
  color: var(--text-primary);
  box-shadow: 0 0 20px var(--accent-glow);
}

.format-choice:active {
  transform: scale(0.97);
}

.choice-icon {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--accent);
  font-family: var(--font-output);
  font-size: 0.8rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 0.25rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-elevated);
}

.segmented label {
  position: relative;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 2.5rem;
  border-radius: 6px;
  color: var(--text-secondary);
  font-weight: 700;
}

.segmented input:checked + span {
  background: var(--accent);
  color: var(--text-on-accent);
}

.draft-select-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.unroll-button {
  position: relative;
  width: 100%;
  min-height: 3.7rem;
  overflow: hidden;
  font-family: var(--font-display);
  text-transform: uppercase;
}

.unroll-button.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.42), transparent);
  animation: shimmer 1s linear infinite;
}

.output-panel {
  min-height: 37.5rem;
  padding: 1rem;
}

.output-empty {
  display: grid;
  place-content: center;
  min-height: 33.5rem;
  border: 1px dashed var(--bg-border);
  border-radius: 8px;
  color: var(--text-secondary);
  text-align: center;
}

.output-empty h2 {
  font-size: 1.8rem;
}

.output-loading {
  display: grid;
  gap: 1rem;
  padding: 1rem;
}

.skeleton-line,
.skeleton-card {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: var(--bg-elevated);
}

.skeleton-line {
  width: 62%;
  height: 1.25rem;
}

.skeleton-line.wide {
  width: 86%;
}

.skeleton-card {
  height: 8rem;
}

.skeleton-card.short {
  height: 5.5rem;
}

.skeleton-line::after,
.skeleton-card::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  animation: shimmer 1.1s linear infinite;
}

.result-tabs {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.tab-button {
  min-height: 2.5rem;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-weight: 700;
}

.tab-button.active {
  border-color: var(--accent);
  color: var(--accent);
}

.result-card {
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-surface);
  animation: riseIn 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--bg-border);
}

.result-header h3 {
  margin: 0;
}

.result-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.output-blocks {
  display: grid;
  gap: 0.85rem;
  padding: 1rem;
}

.output-block {
  position: relative;
  padding: 1rem;
  border: 1px solid var(--bg-border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-output);
  white-space: pre-wrap;
  word-break: break-word;
  animation: riseIn 420ms cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.output-block .copy-one {
  margin-top: 0.85rem;
}

.video-meta {
  display: grid;
  grid-template-columns: 5.5rem minmax(0, 1fr);
  gap: 0.8rem;
  padding: 0 1rem 1rem;
  color: var(--text-secondary);
}

.video-meta img {
  width: 5.5rem;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  object-fit: cover;
}

.video-meta strong {
  display: block;
  color: var(--text-primary);
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.history-tabs {
  display: inline-flex;
  gap: 0.35rem;
  margin-bottom: 1rem;
  padding: 0.25rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-surface);
}

.history-tabs button {
  min-height: 2.45rem;
  padding: 0.45rem 0.9rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-weight: 800;
}

.history-tabs button.active {
  background: var(--accent);
  color: var(--text-on-accent);
}

.history-card,
.empty-history {
  min-height: 19rem;
  padding: 1rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-surface);
}

.history-card {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.history-card img {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  object-fit: cover;
}

.history-loading {
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  min-height: 22rem;
  padding: 2rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-surface);
  text-align: center;
}

.history-loading span {
  width: 2.75rem;
  height: 2.75rem;
  border: 3px solid rgba(202, 255, 51, 0.18);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.85s linear infinite;
}

.history-loading p {
  margin: 0.8rem 0 0;
  color: var(--text-secondary);
  font-weight: 700;
}

.history-source-preview {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  background:
    linear-gradient(135deg, rgba(202, 255, 51, 0.12), transparent),
    #151515;
  color: var(--accent);
  font-family: var(--font-output);
  font-size: 2.35rem;
  font-weight: 800;
}

.history-card p,
.empty-history p,
.history-card small {
  color: var(--text-secondary);
}

.history-card small {
  display: -webkit-box;
  overflow: hidden;
  font-size: 0.9rem;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.history-card .badge {
  display: inline-flex;
  align-self: flex-start;
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  background: rgba(202, 255, 51, 0.12);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
}

.history-card .card-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: auto;
}

.output-modal {
  width: min(100%, 56rem);
}

.output-modal pre {
  max-height: 65vh;
  overflow: auto;
  padding: 1rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  font-family: var(--font-output);
  white-space: pre-wrap;
}

.video-chat-layout {
  display: grid;
  grid-template-columns: minmax(20rem, 0.75fr) minmax(0, 1.25fr);
  gap: 1rem;
  align-items: stretch;
  min-width: 0;
}

.video-chat-copy,
.video-chat-card {
  min-width: 0;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.92);
}

.video-chat-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: 30rem;
  padding: clamp(1.2rem, 4vw, 2rem);
  animation: riseIn 420ms ease both;
}

.video-chat-copy h2 {
  font-size: clamp(2rem, 5vw, 3.35rem);
}

.video-chat-copy p {
  color: var(--text-secondary);
  font-size: 1.05rem;
}

.chat-feature-list {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.chat-feature-list span {
  padding: 0.42rem 0.62rem;
  border: 1px solid rgba(202, 255, 51, 0.2);
  border-radius: 999px;
  background: rgba(202, 255, 51, 0.06);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
}

.video-chat-card {
  position: relative;
  display: grid;
  gap: 1rem;
  min-height: 30rem;
  padding: 1rem;
  overflow: hidden;
  animation: riseIn 420ms ease 80ms both;
}

.video-chat-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 7rem;
  opacity: 0.7;
  background: linear-gradient(90deg, transparent, rgba(202, 255, 51, 0.12), transparent);
  pointer-events: none;
}

.chat-card-top,
.chat-prepare-form,
.chat-ready,
.chat-messages,
.chat-question-form {
  position: relative;
  z-index: 1;
}

.chat-card-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}

.chat-card-top h3 {
  margin: 0;
  font-size: 1.45rem;
}

.chat-url-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.6rem;
}

.chat-ready {
  display: grid;
  grid-template-columns: 6rem minmax(0, 1fr);
  gap: 0.8rem;
  align-items: center;
  padding: 0.75rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: rgba(26, 26, 26, 0.84);
}

.chat-ready img {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--bg-border);
  border-radius: 6px;
  object-fit: cover;
}

.chat-ready strong,
.chat-ready span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-ready span {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.chat-messages {
  display: grid;
  align-content: start;
  gap: 0.75rem;
  min-height: 14rem;
  max-height: 26rem;
  overflow: auto;
  padding: 0.85rem;
  border: 1px dashed var(--bg-border);
  border-radius: 8px;
  background: rgba(10, 10, 10, 0.38);
}

.chat-empty {
  align-self: center;
  justify-self: center;
  max-width: 28rem;
  color: var(--text-secondary);
  text-align: center;
}

.chat-empty span {
  color: var(--accent);
  font-weight: 800;
}

.chat-message {
  max-width: 88%;
  padding: 0.8rem;
  border: 1px solid var(--bg-border);
  border-radius: 8px;
  background: var(--bg-elevated);
  color: var(--text-primary);
  white-space: pre-wrap;
  animation: riseIn 240ms ease both;
}

.chat-message.user {
  justify-self: end;
  border-color: rgba(202, 255, 51, 0.38);
  background: rgba(202, 255, 51, 0.1);
}

.chat-message.assistant {
  justify-self: start;
  font-family: var(--font-output);
  font-size: 0.92rem;
}

.chat-question-form {
  display: grid;
  gap: 0.65rem;
}

.chat-lock {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2rem;
  background: rgba(10, 10, 10, 0.82);
  backdrop-filter: blur(8px);
}

body[data-auth="signed-in"] .chat-lock {
  display: none;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .workspace,
  .guest-workspace-gate {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }

  .output-panel,
  .output-empty {
    min-height: 24rem;
  }

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

  .video-chat-layout {
    grid-template-columns: 1fr;
  }

  .video-chat-copy,
  .video-chat-card {
    min-height: auto;
  }
}

@media (max-width: 860px) {
  .workspace,
  .draft-layout,
  .history-main,
  .studio-main {
    padding-inline: 0;
  }

  .input-panel,
  .output-panel,
  .draft-panel,
  .history-panel,
  .studio-panel {
    padding: 1rem;
  }

  .format-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .format-option,
  .draft-format-option {
    padding: 0.6rem;
    font-size: 0.85rem;
  }

  .input-panel select,
  .input-panel input[type="text"],
  .input-panel input[type="url"],
  .draft-panel select,
  .draft-panel input[type="text"],
  .draft-panel input[type="url"] {
    font-size: 16px;
  }
}

@media (max-width: 620px) {
  .format-grid,
  .draft-select-grid,
  .history-grid,
  .preview-grid {
    grid-template-columns: 1fr;
  }

  .result-header,
  .video-meta {
    grid-template-columns: 1fr;
  }

  .result-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .video-meta img {
    width: 100%;
  }

  .chat-card-top,
  .chat-url-row,
  .chat-ready {
    grid-template-columns: 1fr;
  }

  .chat-card-top {
    flex-direction: column;
  }

  .gate-actions,
  .chat-lock .gate-actions {
    flex-direction: column;
  }

  .gate-actions > *,
  .chat-lock .gate-actions > * {
    width: 100%;
  }

  .chat-message {
    max-width: 100%;
  }
}
