:root {
  --bg: #070a12;
  --bg-soft: #0c111c;
  --panel: #111827;
  --panel-strong: #151f2e;
  --text: #eef4ff;
  --muted: #8b98ad;
  --border: rgba(148, 163, 184, 0.2);
  --input: #0b1220;
  --primary: #14b8a6;
  --primary-dark: #0f766e;
  --accent: #f59e0b;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

:root[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-soft: #ecf1f8;
  --panel: #ffffff;
  --panel-strong: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.14);
  --input: #ffffff;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #d97706;
  --shadow: 0 20px 52px rgba(15, 23, 42, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 20% -10%, rgba(20, 184, 166, 0.18), transparent 32rem),
    linear-gradient(180deg, var(--bg), var(--bg-soft));
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
textarea:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(20, 184, 166, 0.35);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.24), rgba(59, 130, 246, 0.12));
  color: var(--primary);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p,
.panel-head p,
.chat-head p,
.empty-copy,
.empty-chat,
.video-meta .eyebrow {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.key-status,
.download-link,
.icon-button,
.chat-counter,
.meta-chips span {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.key-status.ready,
.chat-counter {
  border-color: rgba(20, 184, 166, 0.3);
  color: var(--primary);
}

.key-status.warn {
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--accent);
}

.icon-button {
  justify-content: center;
  width: 40px;
  color: var(--text);
}

.command-panel {
  display: grid;
  grid-template-columns: minmax(260px, 1.05fr) minmax(260px, 0.95fr) 138px 150px auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17, 24, 39, 0.72);
  box-shadow: var(--shadow);
  padding: 14px;
  backdrop-filter: blur(14px);
}

:root[data-theme="light"] .command-panel {
  background: rgba(255, 255, 255, 0.82);
}

.url-field span,
.title-field span,
.api-details summary {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

input[type="url"],
input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--input);
  color: var(--text);
  outline: none;
}

input[type="url"],
input[type="text"],
input[type="password"] {
  min-height: 46px;
  padding: 0 14px;
}

textarea {
  min-height: 104px;
  resize: vertical;
  padding: 13px 14px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: rgba(20, 184, 166, 0.75);
  box-shadow: 0 0 0 3px rgba(20, 184, 166, 0.16);
}

.primary,
.secondary,
.small,
.quick-prompts button,
.tab-button {
  min-height: 42px;
  border: 0;
  border-radius: 12px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0;
}

.primary {
  background: var(--primary);
  color: #041311;
}

.primary:hover {
  background: #2dd4bf;
}

.secondary,
.small,
.quick-prompts button,
.tab-button {
  border: 1px solid var(--border);
  background: rgba(148, 163, 184, 0.1);
  color: var(--text);
}

.api-details {
  min-width: 210px;
}

.api-details summary {
  cursor: pointer;
  list-style: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 14px;
  border: 1px solid rgba(20, 184, 166, 0.18);
  border-radius: 14px;
  background: rgba(20, 184, 166, 0.08);
  color: var(--primary);
  padding: 0 14px;
  font-size: 14px;
  font-weight: 800;
}

.history-panel {
  position: sticky;
  top: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(17, 24, 39, 0.72);
  box-shadow: var(--shadow);
  padding: 14px;
  max-height: calc(100vh - 32px);
  overflow: auto;
}

:root[data-theme="light"] .history-panel {
  background: rgba(255, 255, 255, 0.82);
}

.panel-head.compact {
  align-items: stretch;
  flex-direction: column;
  margin-bottom: 10px;
}

.panel-head.compact h2 {
  font-size: 18px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.history-item:hover {
  border-color: rgba(20, 184, 166, 0.34);
}

.history-item strong {
  display: block;
  overflow: hidden;
  font-size: 14px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.history-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.history-actions {
  display: flex;
  gap: 8px;
}

.history-actions button {
  flex: 1;
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.history-actions .danger {
  color: var(--danger);
}

.auth-dialog {
  width: min(420px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
}

.auth-dialog::backdrop {
  background: rgba(2, 6, 23, 0.68);
}

.auth-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.auth-dialog header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.auth-dialog label span,
#authDialogHint {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 3px solid rgba(20, 184, 166, 0.2);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(360px, 0.95fr);
  gap: 16px;
  align-items: start;
}

.split-layout.history-visible {
  grid-template-columns: minmax(300px, 0.48fr) minmax(0, 1.45fr) minmax(340px, 0.78fr);
}

.content-pane {
  display: grid;
  gap: 16px;
}

.player-card,
.analysis-card,
.chat-card {
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(17, 24, 39, 0.82);
  box-shadow: var(--shadow);
  overflow: hidden;
}

:root[data-theme="light"] .player-card,
:root[data-theme="light"] .analysis-card,
:root[data-theme="light"] .chat-card {
  background: rgba(255, 255, 255, 0.9);
}

.player-mount {
  aspect-ratio: 16 / 6.8;
  background: #000;
}

.youtube-iframe,
#youtubePlayer,
#youtubePlayer iframe {
  width: 100%;
  height: 100%;
  border: 0;
}

.empty-player {
  display: grid;
  height: 100%;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: #f8fafc;
  text-align: center;
  padding: 20px;
}

.play-glyph {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #041311;
  font-size: 24px;
}

.video-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.video-meta h2 {
  margin-top: 4px;
  font-size: 18px;
  line-height: 1.35;
}

.meta-chips {
  display: flex;
  gap: 8px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.tab-button.active {
  border-color: rgba(20, 184, 166, 0.35);
  background: rgba(20, 184, 166, 0.16);
  color: var(--primary);
}

.tab-panel {
  display: none;
  min-height: 420px;
  padding: 18px;
}

.tab-panel.active {
  display: block;
}

.panel-head,
.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-head h3,
.chat-head h2 {
  font-size: 20px;
  line-height: 1.2;
}

.rich-output,
.transcript-output,
.timeline-list,
.chat-messages {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(2, 6, 23, 0.28);
}

:root[data-theme="light"] .rich-output,
:root[data-theme="light"] .transcript-output,
:root[data-theme="light"] .timeline-list,
:root[data-theme="light"] .chat-messages {
  background: #f8fafc;
}

.rich-output,
.transcript-output {
  min-height: 300px;
  max-height: 58vh;
  overflow: auto;
  padding: 16px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.7;
  white-space: normal;
}

.rich-output h1,
.rich-output h2,
.chat-message h1,
.chat-message h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.rich-output p,
.chat-message p {
  margin: 0 0 10px;
}

.rich-output ul,
.chat-message ul {
  margin: 0 0 14px;
  padding-left: 20px;
}

.transcript-output p {
  margin: 0 0 10px;
}

.timestamp-chip {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  margin: 0 4px 2px 0;
  border: 1px solid rgba(245, 158, 11, 0.32);
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.13);
  color: var(--accent);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 900;
  vertical-align: baseline;
}

.timeline-list {
  display: grid;
  gap: 10px;
  max-height: 58vh;
  overflow: auto;
  padding: 12px;
}

.timeline-row {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  background: rgba(148, 163, 184, 0.08);
  color: var(--text);
  padding: 12px;
  text-align: left;
}

.timeline-row:hover {
  border-color: rgba(20, 184, 166, 0.34);
}

.timeline-row strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.timeline-row small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.chat-pane {
  position: sticky;
  top: 16px;
}

.chat-card {
  display: grid;
  grid-template-rows: auto auto minmax(320px, 1fr) auto auto;
  max-height: calc(100vh - 32px);
  padding: 16px;
}

.limit-notice {
  margin-bottom: 12px;
  border: 1px solid rgba(245, 158, 11, 0.24);
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.09);
  color: var(--accent);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.5;
}

.chat-messages {
  min-height: 320px;
  overflow: auto;
  padding: 12px;
}

.chat-message {
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.68);
  padding: 12px;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.65;
}

:root[data-theme="light"] .chat-message {
  background: #ffffff;
}

.user-message {
  border-color: rgba(20, 184, 166, 0.34);
  background: rgba(20, 184, 166, 0.12);
}

.chat-message header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.copy-message {
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
}

.stream-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--primary);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 0.35;
  }
  50% {
    opacity: 1;
  }
}

.quick-prompts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0;
}

.quick-prompts button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 12px;
}

.chat-actions {
  display: grid;
  grid-template-columns: 1fr 84px;
  gap: 10px;
}

@media (max-width: 1280px) {
  .command-panel,
  .split-layout,
  .split-layout.history-visible {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .history-panel,
  .chat-pane {
    position: static;
  }

  .history-panel,
  .chat-card {
    max-height: none;
  }

  .history-list {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .video-meta,
  .panel-head,
  .chat-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .meta-chips {
    flex-wrap: wrap;
  }

  .command-panel,
  .chat-actions,
  .quick-prompts {
    grid-template-columns: 1fr;
  }

  .tabs {
    grid-template-columns: 1fr;
  }

  .primary,
  .secondary,
  .small,
  .download-link,
  .icon-button {
    width: 100%;
    justify-content: center;
  }

  .rich-output,
  .transcript-output,
  .timeline-list {
    max-height: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
