:root {
  color-scheme: light;
  --bg: #f3f1e9;
  --panel: #fff7eb;
  --ink: #1c1b18;
  --muted: #5c564d;
  --accent: #d46b2b;
  --accent-dark: #9c4a1d;
  --stroke: #e1d6c7;
  --shadow: rgba(28, 27, 24, 0.12);
  --glow: rgba(212, 107, 43, 0.25);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Fira Sans", "Trebuchet MS", "Lucida Grande", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, rgba(212, 107, 43, 0.2), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(61, 106, 167, 0.18), transparent 40%),
    radial-gradient(circle at 50% 90%, rgba(32, 130, 96, 0.18), transparent 45%),
    var(--bg);
  min-height: 100vh;
}

body::before,
body::after {
  content: "";
  position: fixed;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: linear-gradient(140deg, rgba(212, 107, 43, 0.2), rgba(61, 106, 167, 0.2));
  filter: blur(0);
  opacity: 0.3;
  z-index: 0;
  animation: float 12s ease-in-out infinite;
}

body::before {
  top: -80px;
  left: -60px;
}

body::after {
  bottom: -100px;
  right: -40px;
  animation-delay: -5s;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0) translateX(0);
  }
  50% {
    transform: translateY(18px) translateX(12px);
  }
}

.app {
  position: relative;
  z-index: 1;
  padding: 32px 28px 48px;
  max-width: 1480px;
  margin: 0 auto;
}

.app-container {
  display: flex;
  gap: 20px;
}

/* Sidebar */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 20px 40px var(--shadow);
  animation: rise 0.45s ease-out;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
  position: sticky;
  top: 20px;
  align-self: flex-start;
  transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease;
}

.sidebar.collapsed {
  width: 48px;
  min-width: 48px;
  padding: 12px;
}

.sidebar.collapsed .sidebar-header h2,
.sidebar.collapsed .sidebar-actions,
.sidebar.collapsed .thread-list {
  display: none;
}

.sidebar.collapsed .sidebar-header {
  justify-content: center;
}

.sidebar.collapsed #sidebarToggle {
  transform: rotate(180deg);
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 16px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  border-radius: 8px;
}

.sidebar-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.sidebar-tab {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--stroke);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.2s ease;
}

.sidebar-tab:hover {
  border-color: var(--accent);
  color: var(--ink);
}

.sidebar-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.sidebar.collapsed .sidebar-tabs {
  display: none;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.sidebar-actions button:first-child {
  flex: 1;
}

.thread-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thread-list .empty-state {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 20px 10px;
}

.thread-card {
  background: white;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.thread-card:hover {
  border-color: var(--accent);
}

.thread-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--glow);
}

.thread-card-details {
  display: none;
}

.thread-card.active .thread-card-details {
  display: block;
}

.thread-card-thumbnail {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 8px;
  object-fit: cover;
  max-height: 160px;
}

.thread-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.thread-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.thread-card-status {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--stroke);
  color: var(--muted);
}

.thread-card-status.active {
  background: rgba(212, 107, 43, 0.15);
  color: var(--accent-dark);
}

.thread-card-status.completed {
  background: rgba(32, 130, 96, 0.15);
  color: #166534;
}

.thread-card-status.published {
  background: rgba(61, 106, 167, 0.15);
  color: #1e4e8c;
}

.thread-card-author {
  font-weight: 500;
  color: var(--ink);
}

.thread-card-plot {
  font-size: 11px;
  color: var(--muted);
  margin: 6px 0 0;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.thread-card-meta {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  display: flex;
  justify-content: space-between;
}

.thread-card-actions {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--stroke);
}

.thread-card-actions button {
  flex: 1;
  padding: 4px 8px;
  font-size: 10px;
  border-radius: 6px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  margin-bottom: 28px;
  animation: rise 0.5s ease-out;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 11px;
  color: var(--accent-dark);
}

h1 {
  margin: 0 0 8px;
  font-size: 34px;
  line-height: 1.1;
}

h2 {
  margin: 0 0 12px;
  font-size: 18px;
  letter-spacing: 0.02em;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  max-width: 520px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 10px 30px var(--shadow);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #bbb;
  box-shadow: 0 0 8px transparent;
}

.status-dot.active {
  background: var(--accent);
  box-shadow: 0 0 10px var(--glow);
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr);
  gap: 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 40px var(--shadow);
  animation: rise 0.45s ease-out;
}

.controls {
  position: sticky;
  top: 20px;
  align-self: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--muted);
}

.field input,
.field textarea,
.field select {
  font-family: "Fira Sans", "Trebuchet MS", "Lucida Grande", sans-serif;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  background: #fffdf8;
  transition: border 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 107, 43, 0.15);
}

.row {
  display: flex;
  gap: 8px;
}

.row input {
  flex: 1;
}

.pill-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: #fffdf8;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.pill input {
  accent-color: var(--accent);
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}

.checkbox input {
  accent-color: var(--accent);
}

.divider {
  height: 1px;
  background: var(--stroke);
  margin: 18px 0;
}

.button-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

button {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 12px 20px rgba(212, 107, 43, 0.22);
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(1px);
}

button.ghost {
  background: transparent;
  color: var(--accent-dark);
  border: 1px solid var(--stroke);
  box-shadow: none;
}

.resume {
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.resume summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 8px;
}

.output .section {
  margin-bottom: 26px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.hint {
  font-size: 12px;
  color: var(--muted);
}

.scene-viewer.empty,
.state-overview.empty,
.image-grid.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
  border: 1px dashed var(--stroke);
  border-radius: 12px;
}

.scene-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.scene-tab {
  border: 1px solid var(--stroke);
  background: #fffdf8;
  color: var(--muted);
  font-size: 11px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: none;
}

.scene-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.scene-viewer {
  background: #fffdf8;
  border: 1px solid var(--stroke);
  border-radius: 16px;
  padding: 14px;
  height: 360px;
  overflow-y: auto;
  box-shadow: 0 10px 24px rgba(28, 27, 24, 0.08);
  animation: rise 0.35s ease-out;
}

.scene-viewer h3 {
  margin: 0 0 8px;
  font-size: 16px;
}

.scene-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

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

.panel-item {
  background: white;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px;
}

.panel-item pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  font-family: "Fira Mono", "Consolas", "Courier New", monospace;
  font-size: 12px;
  color: var(--ink);
}

.screenplay-text {
  background: white;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 14px;
  margin: 10px 0 0;
  white-space: pre-wrap;
  font-family: "Fira Mono", "Consolas", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink);
}

.state-overview {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.state-card {
  background: white;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 10px;
  font-size: 12px;
}

.state-card span {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
}

.character-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.character-card {
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 10px;
  background: white;
}

.character-card img {
  width: 100%;
  border-radius: 10px;
  margin-top: 8px;
}

.raw summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--accent-dark);
  margin-bottom: 8px;
}

.code-block {
  background: #11110f;
  color: #f1eae1;
  padding: 12px;
  border-radius: 12px;
  font-size: 12px;
  overflow-x: auto;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.image-card {
  background: white;
  border: 2px solid var(--stroke);
  border-radius: 14px;
  padding: 10px;
  cursor: pointer;
  position: relative;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.image-card:hover {
  border-color: var(--accent);
}

.image-card.thumbnail-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(212, 107, 43, 0.25);
}

.image-card.thumbnail-selected::after {
  content: "Thumbnail";
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
}

.image-card img {
  width: 100%;
  border-radius: 10px;
  display: block;
}

.image-card .meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

.video-grid.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
  border: 1px dashed var(--stroke);
  border-radius: 12px;
}

.video-card {
  background: white;
  border: 1px solid var(--stroke);
  border-radius: 14px;
  padding: 10px;
  overflow: hidden;
}

.video-card video {
  width: 100%;
  max-height: 70vh;
  border-radius: 10px;
  display: block;
  background: #11110f;
}

.video-card .meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.event-log {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.event-log li {
  padding: 8px 10px;
  border-radius: 10px;
  background: #fffdf8;
  border: 1px solid var(--stroke);
}

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

.hidden {
  display: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(212, 107, 43, 0.2), transparent 45%),
    radial-gradient(circle at 80% 10%, rgba(61, 106, 167, 0.18), transparent 40%),
    radial-gradient(circle at 50% 90%, rgba(32, 130, 96, 0.18), transparent 45%),
    var(--bg);
  z-index: 1000;
}

.login-card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 24px;
  padding: 40px 48px;
  text-align: center;
  box-shadow: 0 30px 60px var(--shadow);
  animation: rise 0.5s ease-out;
  max-width: 400px;
}

.login-card h1 {
  margin-bottom: 12px;
}

.login-subtitle {
  color: var(--muted);
  margin-bottom: 28px;
}

.login-error {
  color: #c53030;
  font-size: 13px;
  margin-top: 16px;
  min-height: 20px;
}

#googleSignInBtn {
  display: flex;
  justify-content: center;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  font-size: 13px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
}

.user-info button {
  padding: 6px 12px;
  font-size: 12px;
}

/* Timeline */
.timeline {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
}

.timeline.empty {
  color: var(--muted);
  font-size: 13px;
  padding: 12px;
  border: 1px dashed var(--stroke);
  border-radius: 12px;
}

.timeline-event {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  background: white;
  border: 1px solid var(--stroke);
  border-radius: 12px;
  font-size: 12px;
}

.timeline-event-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--stroke);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.timeline-event-icon.scene {
  background: rgba(61, 106, 167, 0.15);
}

.timeline-event-icon.character {
  background: rgba(32, 130, 96, 0.15);
}

.timeline-event-icon.complete {
  background: rgba(212, 107, 43, 0.15);
}

.timeline-event-content {
  flex: 1;
  min-width: 0;
}

.timeline-event-type {
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
}

.timeline-event-time {
  color: var(--muted);
  font-size: 10px;
}

.timeline-event-details {
  color: var(--muted);
  margin-top: 4px;
  font-size: 11px;
}

@media (max-width: 1100px) {
  .app-container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    max-height: none;
    position: static;
  }

  .sidebar.collapsed {
    width: 100%;
    min-width: 100%;
  }
}

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

  .controls {
    position: static;
  }

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

  .scene-viewer {
    height: 300px;
  }
}

/* Player Mode */
.play-btn {
  margin-left: auto;
  padding: 6px 12px;
  font-size: 12px;
}

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.player-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
  box-shadow: none;
  padding: 0;
}

.player-close:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: none;
}

.player-counter {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  background: rgba(0, 0, 0, 0.5);
  border-radius: 999px;
}

.player-content {
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-content img {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.player-content video {
  max-width: 90vw;
  max-height: 85vh;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  background: #000;
}

.player-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  font-size: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, opacity 0.2s ease;
  box-shadow: none;
  padding: 0;
}

.player-nav:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-50%);
}

.player-nav:disabled {
  opacity: 0.3;
  cursor: default;
}

.player-nav:disabled:hover {
  background: rgba(255, 255, 255, 0.1);
}

.player-prev {
  left: 20px;
}

.player-next {
  right: 20px;
}
