:root {
  --ink: #12100f;
  --charcoal: #1b1816;
  --panel: #24201d;
  --sheet: #eee3d4;
  --sheet-ink: #231a14;
  --line: #403832;
  --muted: #b7a89a;
  --accent: #f07b3a;
  --accent-strong: #ff9657;
  --danger: #d95b4a;
  --ok: #7fad74;
  --touch: 44px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: #f7eee4;
  background: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, textarea {
  font: inherit;
}

button {
  min-height: var(--touch);
  border: 1px solid #5b4b40;
  background: #302923;
  color: #fff5ea;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-areas:
    "top"
    "overview"
    "rail"
    "main";
  grid-template-rows: auto auto auto 1fr;
}

.topbar {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: rgba(18, 16, 15, .96);
  border-bottom: 1px solid var(--line);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; line-height: 1.15; }
h2 { font-size: 24px; line-height: 1.15; }
h3 { font-size: 15px; line-height: 1.2; color: #fff1e3; }
.eyebrow { color: var(--accent-strong); font-size: 12px; text-transform: uppercase; letter-spacing: 0; margin-bottom: 4px; }

.icon-btn {
  width: var(--touch);
  padding: 0;
  font-size: 24px;
}

.overview {
  grid-area: overview;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #171412;
}

.progress-strip {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
}

.progress-strip span {
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

#sourceOutline {
  margin: 0;
  color: #d9cabc;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
}

.scene-rail {
  grid-area: rail;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(190px, 1fr);
  overflow-x: auto;
  gap: 1px;
  border-bottom: 1px solid var(--line);
  background: var(--line);
}

.scene-tab {
  min-height: 88px;
  text-align: left;
  padding: 10px;
  background: var(--charcoal);
  border: 0;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 10px;
  align-items: center;
}

.scene-tab.active { background: #2b241f; box-shadow: inset 0 -3px 0 var(--accent); }
.scene-thumb {
  width: 42px;
  aspect-ratio: 9 / 16;
  background: #0d0b0a;
  border: 1px solid #4c4038;
  object-fit: cover;
}
.scene-tab strong { display: block; font-size: 14px; margin-bottom: 4px; }
.scene-tab span { display: block; color: var(--muted); font-size: 12px; line-height: 1.25; }

.workspace {
  grid-area: main;
  display: grid;
  gap: 0;
}

.frame-column {
  padding: 16px;
  background: #161311;
  border-bottom: 1px solid var(--line);
}

.viewport {
  width: min(72vw, 360px);
  max-height: 68vh;
  aspect-ratio: 9 / 16;
  margin: 0 auto;
  background: #080706;
  border: 1px solid #5a4b42;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.viewport img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.empty-frame {
  color: #6d5b50;
  font-size: 40px;
  font-weight: 700;
}

.frame-actions {
  display: grid;
  gap: 8px;
  margin: 12px auto 0;
  width: min(72vw, 360px);
}

#grokReason { color: var(--muted); font-size: 12px; line-height: 1.35; }

.asset-list {
  width: min(72vw, 360px);
  margin: 14px auto 0;
  display: grid;
  gap: 8px;
}

.asset-row, .version-row, .comment-row, .job-row, .canon-box {
  border: 1px solid var(--line);
  background: var(--panel);
  padding: 10px;
}

.asset-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.asset-row small, .job-row small, .version-row small, .comment-row small {
  color: var(--muted);
}

.status-actions { display: flex; gap: 6px; }
.status-actions button { min-height: 36px; padding: 0 9px; }

.scene-sheet {
  background: var(--sheet);
  color: var(--sheet-ink);
  padding: 18px 16px 28px;
}

.scene-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid #cfbfaa;
}

.scene-head .eyebrow { color: #9d4b1e; }

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

.reaction-group button {
  width: var(--touch);
  padding: 0;
  background: #fff8ef;
  color: var(--sheet-ink);
  border-color: #ccb8a2;
  font-size: 22px;
}

.reaction-group button.active {
  color: #fff;
  background: var(--accent);
  border-color: #c75e27;
}

.source-fragment {
  margin: 16px 0;
  padding: 12px;
  background: #fff8ef;
  border-left: 3px solid var(--accent);
}

.source-fragment span {
  color: #8e6a4f;
  font-size: 12px;
  text-transform: uppercase;
}

.source-fragment p { margin-top: 5px; line-height: 1.45; }

.fields-grid {
  display: grid;
  gap: 12px;
}

.field-block {
  padding-bottom: 12px;
  border-bottom: 1px solid #d2c1ad;
}

.field-block h3 {
  color: #5f3820;
  margin-bottom: 6px;
}

.field-block p {
  line-height: 1.55;
  font-size: 15px;
}

.side-panels {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.side-panels h3, .comments h3, .versions h3 { color: #382317; margin-bottom: 8px; }

.canon-box {
  background: #f8ecdc;
  border-color: #d7c2aa;
  color: var(--sheet-ink);
  display: grid;
  gap: 8px;
}

.canon-box img {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  background: #17120f;
}

.comments, .versions { margin-top: 20px; }
#commentsList, #versionsList, #jobsList { display: grid; gap: 8px; }

.comment-row, .version-row {
  background: #fbf0e2;
  border-color: #d7c2aa;
  color: var(--sheet-ink);
}

textarea {
  width: 100%;
  min-height: 104px;
  resize: vertical;
  padding: 12px;
  margin-top: 10px;
  border: 1px solid #cbb59d;
  background: #fffaf4;
  color: var(--sheet-ink);
}

.composer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.composer-actions button, .frame-actions button {
  background: var(--accent);
  border-color: #b95020;
  color: #1d110b;
  font-weight: 700;
}

.version-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.version-row button {
  background: #fff8ef;
  color: var(--sheet-ink);
  border-color: #ccb8a2;
  padding: 0 12px;
}

.job-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(100vw, 420px);
  transform: translateX(100%);
  transition: transform .18s ease;
  z-index: 10;
  background: #181411;
  border-left: 1px solid var(--line);
  padding: 14px;
  overflow-y: auto;
}

.job-drawer.open { transform: translateX(0); }

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

.job-row {
  display: grid;
  gap: 6px;
}

.job-row.failed { border-color: var(--danger); }
.job-row.succeeded { border-color: var(--ok); }
.job-row.running, .job-row.queued { border-color: var(--accent); }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  min-height: var(--touch);
  padding: 12px;
  background: #2b241f;
  border: 1px solid var(--accent);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity .16s ease, transform .16s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: 300px minmax(0, 1fr);
    grid-template-areas:
      "top top"
      "overview main"
      "rail main";
    grid-template-rows: auto auto 1fr;
  }

  .overview { border-right: 1px solid var(--line); }

  .scene-rail {
    grid-auto-flow: row;
    grid-auto-rows: 104px;
    grid-auto-columns: unset;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .workspace {
    grid-template-columns: minmax(330px, 38vw) minmax(0, 1fr);
    min-height: calc(100vh - 73px);
  }

  .frame-column {
    border-right: 1px solid var(--line);
    border-bottom: 0;
    position: sticky;
    top: 73px;
    height: calc(100vh - 73px);
    overflow-y: auto;
  }

  .scene-sheet {
    padding: 28px clamp(24px, 4vw, 52px) 52px;
  }

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

  .field-block:first-child, .field-block:nth-child(2), .field-block:nth-child(6) {
    grid-column: span 2;
  }

  .side-panels {
    grid-template-columns: 1fr 1fr;
  }
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 75% 15%, rgba(246, 119, 48, .12), transparent 32rem),
    #100e0c;
}

.login-card {
  width: min(100%, 420px);
  padding: clamp(26px, 7vw, 42px);
  border: 1px solid var(--line);
  background: #1a1613;
  box-shadow: 0 30px 90px rgba(0, 0, 0, .42);
}

.login-card h1 {
  margin: 8px 0 12px;
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1;
}

.login-note {
  margin: 0 0 28px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  font-weight: 700;
}

.login-form input[type="password"] {
  min-height: 52px;
  width: 100%;
  padding: 0 14px;
  border: 1px solid #4a4038;
  border-radius: 0;
  background: #100e0c;
  color: var(--text);
  font: inherit;
}

.login-form input[type="password"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.login-form button {
  margin-top: 8px;
  min-height: 52px;
}

.login-error {
  margin: 2px 0;
  color: #ff8f86;
  font-weight: 700;
}
