:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181c20;
  --panel-strong: #20262b;
  --text: #f4f0e8;
  --muted: #aeb6bc;
  --line: #374049;
  --accent: #f3b33d;
  --accent-strong: #ffcc5c;
  --green: #7ed56f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(126, 213, 111, 0.16), transparent 28rem),
    linear-gradient(135deg, #101214 0%, #171b1e 52%, #241b16 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
}

.control-panel,
.caption-panel {
  background: rgba(24, 28, 32, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 20px;
}

.control-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.8fr) minmax(320px, 1.4fr);
  gap: 18px;
  align-items: end;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 3vw, 3rem);
  line-height: 1;
  max-width: 560px;
}

h2 {
  margin-bottom: 14px;
  font-size: 1.1rem;
}

.job-form {
  display: grid;
  gap: 14px;
}

.url-field span,
.dragon-selector legend {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

input[type="url"] {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1012;
  color: var(--text);
  font: inherit;
  padding: 0 12px;
}

.dragon-selector {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.dragon-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.dragon-option {
  position: relative;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 68px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 0.88rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.dragon-option:hover {
  border-color: rgba(255, 204, 92, 0.58);
  background: #273038;
}

.dragon-option:has(input:checked) {
  border-color: var(--accent-strong);
  background: linear-gradient(135deg, rgba(255, 204, 92, 0.16), rgba(32, 38, 43, 0.96));
}

.dragon-option input {
  position: absolute;
  inset: 8px auto auto 8px;
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
}

.dragon-option img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  filter: drop-shadow(0 6px 8px rgba(0, 0, 0, 0.42));
}

.dragon-option span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.dragon-option strong,
.dragon-option small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dragon-option strong {
  font-size: 0.9rem;
}

.dragon-option small {
  color: var(--muted);
  font-size: 0.76rem;
}

button {
  justify-self: start;
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #1d1304;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 0 18px;
}

button:disabled {
  cursor: wait;
  filter: grayscale(0.7);
  opacity: 0.72;
}

.status-line {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}

.debug-steps {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
  max-height: 170px;
  overflow: auto;
  margin: 0;
  padding: 10px 10px 10px 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1012;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}

.debug-steps:empty {
  display: none;
}

.debug-steps li:last-child {
  color: var(--accent-strong);
}

.stage {
  position: relative;
  margin-top: 18px;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: #050607;
  aspect-ratio: 16 / 9;
  min-height: 360px;
}

.video-player {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  background: linear-gradient(135deg, rgba(32, 38, 43, 0.9), rgba(8, 10, 12, 0.94));
}

.empty-state.is-hidden {
  display: none;
}

.overlay-layer {
  pointer-events: none;
  position: absolute;
  inset: 0;
}

.dragon-stack {
  position: absolute;
  left: clamp(10px, 2.4vw, 28px);
  bottom: clamp(12px, 2vw, 24px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
  width: clamp(68px, 7vw, 96px);
  height: min(calc(100% - 32px), 420px);
}

.dragon-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  justify-content: center;
  align-items: center;
}

.stacked-dragon {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter:
    drop-shadow(0 0 8px color-mix(in srgb, var(--dragon-color), transparent 62%))
    drop-shadow(0 10px 14px rgba(0, 0, 0, 0.45));
}

.dragon-bubble {
  position: absolute;
  left: 110%;
  top: 50%;
  transform: translateY(-50%) scale(0.9);
  background: rgba(12, 15, 17, 0.95);
  border: 1px solid var(--dragon-color, rgba(255, 255, 255, 0.18));
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  width: max-content;
  max-width: clamp(180px, 50vw, 380px);
  font-size: clamp(0.85rem, 1.25vw, 1.05rem);
  line-height: 1.4;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1), transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.25s;
  z-index: 100;
  word-wrap: break-word;
  white-space: normal;
}

.dragon-bubble::before {
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  border-width: 6px;
  border-style: solid;
  border-color: transparent var(--dragon-color, rgba(255, 255, 255, 0.18)) transparent transparent;
}

.dragon-bubble::after {
  content: "";
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translateY(-50%);
  margin-right: -1px;
  border-width: 6px;
  border-style: solid;
  border-color: transparent rgba(12, 15, 17, 0.95) transparent transparent;
}

.dragon-bubble.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(-50%) scale(1);
}


.livestream-chat {
  position: absolute;
  right: clamp(10px, 2.4vw, 28px);
  bottom: clamp(12px, 2vw, 24px);
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: clamp(220px, 30vw, 380px);
  max-height: min(calc(100% - 32px), 420px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.chat-message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(12, 15, 17, 0.88);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(10px);
  animation: chatIn 0.2s ease-out;
}

.chat-message img {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 0 7px color-mix(in srgb, var(--dragon-color), transparent 50%));
}

.chat-meta {
  margin-bottom: 4px;
  color: var(--dragon-color);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.chat-message p {
  margin: 0;
  font-size: clamp(0.9rem, 1.4vw, 1.08rem);
  line-height: 1.35;
}

.caption-panel {
  margin-top: 18px;
}

.caption-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.caption-card {
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #121619;
  padding: 14px;
}

.caption-card h3 {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.9rem;
}

.caption-card p {
  margin-bottom: 0;
  color: var(--text);
  line-height: 1.45;
}

@media (max-width: 780px) {
  .shell {
    width: min(100vw - 20px, 640px);
    padding-top: 10px;
  }

  .control-panel {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .dragon-options,
  .caption-list {
    grid-template-columns: 1fr 1fr;
  }

  .stage {
    min-height: 420px;
    aspect-ratio: 9 / 12;
  }

  .dragon-stack {
    width: 62px;
    gap: 4px;
  }

  .stacked-dragon {
    width: 62px;
  }


  .chat-message {
    grid-template-columns: 30px minmax(0, 1fr);
    padding: 9px 10px;
  }

  .chat-message img {
    width: 30px;
    height: 30px;
  }
}

@media (max-width: 460px) {
  .dragon-options,
  .caption-list {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 1.6rem;
  }
}

/* Tabs Layout & Aesthetics */
.workspace-area {
  margin-top: 18px;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: 12px;
}

.tab-button {
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 6px 6px 0 0;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.tab-button::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 100%;
  height: 3px;
  background: transparent;
  border-radius: 2px;
  transform: scaleX(0);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-button:hover:not(:disabled) {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

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

.tab-button.active::after {
  background: var(--accent-strong);
  transform: scaleX(1);
}

.tab-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* Tab Panels */
.tab-panel {
  transition: opacity 0.3s ease;
}

/* Stage override to match panel layout */
.stage {
  margin-top: 0;
}

/* Frames Grid & Cards */
.frames-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  padding: 8px 0;
  animation: fadeIn 0.4s ease-out;
}

.frame-card {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  aspect-ratio: 16 / 9;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s ease, border-color 0.3s ease;
  cursor: zoom-in;
}

.frame-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
  border-color: var(--accent-strong);
}

.frame-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.frame-card span {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(16, 18, 20, 0.85);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: ui-monospace, monospace;
  font-weight: 600;
}

.empty-message {
  color: var(--muted);
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px 0;
  font-style: italic;
}

/* Analysis JSON View */
.analysis-code {
  margin: 0;
  background: #0d1012;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  overflow: auto;
  max-height: 480px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #aeb6bc;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.5);
  animation: fadeIn 0.4s ease-out;
}

/* Lightbox Modal */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(8, 10, 12, 0.94);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: zoom-out;
}

.lightbox.active {
  opacity: 1;
  pointer-events: all;
}

.lightbox img {
  max-width: 90%;
  max-height: 85%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.12);
  transform: scale(0.95);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.lightbox.active img {
  transform: scale(1);
}

/* Keyframes */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes chatOut {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(-8px);
  }
}

.chat-exit {
  animation: chatOut 0.28s ease-in forwards;
  pointer-events: none;
}
