@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/IBMPlexSans-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/IBMPlexSans-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
  font-weight: 560;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Sans";
  src: url("/static/fonts/IBMPlexSans-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0c0c0c;
  --surface: #161616;
  --text: #ececec;
  --text-dim: #9a9a9a;
  --accent: #c9a227;
  --border: #2a2a2a;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
}

[data-theme="light"] {
  --bg: #f3f2ef;
  --surface: #ffffff;
  --text: #161616;
  --text-dim: #6d6d68;
  --accent: #9a6b12;
  --border: #e2e0db;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }
body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "IBM Plex Sans", "Noto Sans", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.01em;
  -webkit-tap-highlight-color: transparent;
  text-wrap: pretty;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
}
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: default; }
textarea, input, select { border-radius: 0; }
input, select, textarea { font-size: 16px; }
@media (min-width: 768px) {
  input, select, textarea { font-size: 14px; }
}

::placeholder {
  color: var(--text-dim);
  opacity: 1;
}

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

h1, h2, strong { font-weight: 560; letter-spacing: -0.02em; }
h1 { font-size: 28px; line-height: 1.2; margin: 0 0 16px; text-wrap: balance; }
h2 { font-size: 20px; line-height: 1.25; margin: 0; text-wrap: balance; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* Login: quiet, no hero, no marketing */
.login {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-form {
  width: 100%;
  max-width: 360px;
}
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  color: var(--text-dim);
  font-size: 12px;
}
.login-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--surface);
}
.login-form button[type="submit"] {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
  font-weight: 560;
}
[data-theme="light"] .login-form button[type="submit"] { color: #fff; }
.form-error { color: #c4473a; font-size: 14px; margin: 0 0 12px; }

/* App shell */
.app {
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: auto 1fr auto auto;
  grid-template-areas:
    "top top"
    "rail main"
    "rail scene"
    "rail bar";
}
.app.rail-collapsed {
  grid-template-columns: 0 1fr;
}
.app.rail-collapsed .rail { display: none; }

.top {
  grid-area: top;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  min-width: 0;
}
.brand {
  font-size: 16px;
  font-weight: 560;
  flex-shrink: 0;
}
.balance {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}
.top-actions { display: flex; gap: 4px; flex-shrink: 0; margin-left: auto; }

.text-btn, .icon-btn {
  background: transparent;
  border: 0;
  height: 36px;
  padding: 0 12px;
  color: var(--text-dim);
  font-size: 14px;
}
.icon-btn { width: 36px; padding: 0; display: grid; place-items: center; flex-shrink: 0; }
@media (hover: hover) and (pointer: fine) {
  .text-btn:hover, .icon-btn:hover { color: var(--text); }
  .text-btn:active, .icon-btn:active, .generate:active, .chip:active { transform: scale(0.97); }
}
.text-btn, .icon-btn, .generate, .chip, .mode, .asset-card, .clip {
  transition: transform 140ms var(--ease-out), opacity 140ms var(--ease-out), color 140ms var(--ease-out), background-color 140ms var(--ease-out), border-color 140ms var(--ease-out);
}

.rail {
  grid-area: rail;
  border-right: 1px solid var(--border);
  background: var(--bg);
  overflow: auto;
  min-width: 0;
}
.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 8px 16px;
  color: var(--text-dim);
  font-size: 12px;
}
.project-list { list-style: none; margin: 0; padding: 0 8px 16px; }
.project-list li button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  padding: 10px 8px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}
.project-list li button.active { color: var(--text); background: var(--surface); }

.main {
  grid-area: main;
  min-width: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
}
.main-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px 0;
}
.project-title {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  padding: 0;
  border: 0;
  background: transparent;
  font-size: 20px;
  font-weight: 560;
  letter-spacing: -0.02em;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  padding: 16px;
}
.asset-card {
  position: relative;
  aspect-ratio: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  padding: 0;
  display: block;
  width: 100%;
  min-width: 0;
}
.asset-card img, .asset-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.asset-card .ph {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 12px;
  text-align: center;
}
.asset-card .st {
  position: absolute;
  left: 8px;
  bottom: 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  padding: 4px 8px;
}
.asset-card .st.err { color: #c4473a; }
.asset-card .st.wait { color: var(--text-dim); }

.empty {
  margin: 48px 16px;
  color: var(--text-dim);
  max-width: 720px;
  font-size: 14px;
}

/* Scene timeline */
.scene {
  grid-area: scene;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 12px 16px 8px;
}
.scene-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.scene-head strong { font-size: 14px; }
.timeline {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
}
.clip {
  flex: 0 0 160px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px;
  min-width: 0;
}
.clip img, .clip video {
  width: 100%;
  height: 80px;
  object-fit: cover;
  display: block;
  margin-bottom: 8px;
}
.clip .clip-tools {
  display: flex;
  gap: 4px;
  align-items: center;
}
.clip input {
  width: 56px;
  height: 28px;
  padding: 0 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.scene-player {
  width: 100%;
  max-height: 200px;
  margin-top: 8px;
  background: #000;
}

/* Prompt bar, Flow-like bottom dock */
.promptbar {
  grid-area: bar;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modes {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.mode {
  height: 32px;
  padding: 0 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  touch-action: manipulation;
}
.mode[aria-selected="true"] {
  color: var(--bg);
  background: var(--text);
  border-color: var(--text);
}
.refs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.ref-slot, .ref-add {
  width: 64px;
  height: 64px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
  font-size: 12px;
  color: var(--text-dim);
  text-align: center;
  flex-shrink: 0;
}
.ref-slot img { width: 100%; height: 100%; object-fit: cover; }
.ref-slot .x {
  position: absolute;
  /* keep simple: overlay via button after img handled in js */
}
#prompt {
  width: 100%;
  min-height: 56px;
  max-height: 160px;
  resize: vertical;
  padding: 12px;
  background: var(--surface);
  line-height: 1.45;
  border-color: var(--border);
}
.prompt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.prompt-row select {
  height: 36px;
  padding: 0 8px;
  max-width: 240px;
  min-width: 0;
}
.count-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}
#variants {
  width: 56px;
  height: 36px;
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.cost {
  margin: 0 auto 0 0;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 0;
  overflow-wrap: anywhere;
}
.generate {
  height: 36px;
  padding: 0 20px;
  background: var(--accent);
  color: #111;
  border-color: var(--accent);
  font-weight: 560;
  flex-shrink: 0;
  margin-left: auto;
  touch-action: manipulation;
}
[data-theme="light"] .generate { color: #fff; }

/* Sheets */
.sheet {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  display: grid;
  place-items: end center;
  z-index: 20;
  padding: 0;
}
.sheet-card {
  width: min(520px, 100%);
  max-height: min(88dvh, 800px);
  overflow: auto;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
}
.sheet-card.wide { width: min(880px, 100%); }
.sheet-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 16px;
}
.sheet-fields {
  display: grid;
  gap: 16px;
}
.sheet-fields label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.sheet-fields input, .sheet-fields select {
  height: 40px;
  padding: 0 12px;
}
.lb-media { background: var(--surface); margin-bottom: 16px; }
.lb-media img, .lb-media video, .lb-media audio {
  display: block;
  width: 100%;
  max-height: 56dvh;
  object-fit: contain;
  background: #000;
}
.lb-meta {
  color: var(--text-dim);
  font-size: 14px;
  margin: 0 0 16px;
  max-width: 720px;
  overflow-wrap: anywhere;
}
.lb-actions, .scene-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.admin-body table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}
.admin-body th, .admin-body td {
  text-align: right;
  border-bottom: 1px solid var(--border);
  padding: 8px 8px;
  vertical-align: top;
}
.admin-body th:first-child, .admin-body td:first-child { text-align: left; }
.admin-body input {
  width: 72px;
  height: 32px;
  padding: 0 8px;
  text-align: right;
}

@media (max-width: 767px) {
  .top {
    display: grid;
    grid-template-columns: 36px minmax(0, 1fr) auto;
    align-items: center;
    row-gap: 8px;
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
  .rail-toggle { grid-column: 1; grid-row: 1; }
  .brand { grid-column: 2; grid-row: 1; }
  .top-actions { grid-column: 3; grid-row: 1; margin: 0; }
  .balance { grid-column: 1 / -1; grid-row: 2; white-space: normal; overflow: visible; }
  .count-label { font-size: 12px; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas:
      "top"
      "main"
      "scene"
      "bar";
  }
  .top, .main, .scene, .promptbar { min-width: 0; }

  .rail {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 240px;
    z-index: 10;
    display: block;
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 220ms var(--ease-drawer);
    pointer-events: none;
    visibility: visible;
  }
  .app.rail-open .rail {
    transform: translateX(0);
    pointer-events: auto;
  }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: 12px; gap: 8px; }
  .balance { font-size: 12px; white-space: normal; }
  .prompt-row select { max-width: 100%; flex: 1 1 140px; }
  .cost { flex: 1 1 100%; margin: 0; }
  .generate { width: 100%; margin: 0; height: 44px; }
  .project-title { font-size: 16px; }
  h1 { font-size: 28px; }
}


/* Motion — Emil Kowalski: transform/opacity, ease-out, <300ms UI, reduced-motion */
.login {
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
}
.login.is-leaving {
  opacity: 0;
  transform: scale(0.98);
  pointer-events: none;
}
.app {
  opacity: 1;
}
.app.is-entering {
  opacity: 0;
}
.app.is-ready {
  opacity: 1;
  transition: opacity 220ms var(--ease-out);
}
.promptbar {
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out);
}
.app.is-entering .promptbar {
  opacity: 0;
  transform: translateY(8px);
}
#model, #aspect, .count-label {
  transition: opacity 180ms var(--ease-out);
}
#model.is-refreshing, #aspect.is-refreshing {
  opacity: 0.55;
}

.asset-card {
  animation: card-in 220ms var(--ease-out) backwards;
  transition: transform 180ms var(--ease-out);
  animation-delay: calc(var(--stagger, 0) * 40ms);
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (hover: hover) and (pointer: fine) {
  .asset-card:hover { transform: translateY(-2px); }
}

.st.wait {
  overflow: hidden;
}
.st.wait::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text) 22%, transparent), transparent);
  transform: translateX(-100%);
  animation: shimmer 1.4s linear infinite;
  pointer-events: none;
}
@keyframes shimmer {
  to { transform: translateX(100%); }
}

.sheet {
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease-out);
}
.sheet.is-open {
  opacity: 1;
  pointer-events: auto;
}
.sheet .sheet-card {
  transform: translateY(16px) scale(0.97);
  opacity: 0;
  transition: transform 220ms var(--ease-drawer), opacity 200ms var(--ease-out);
}
.sheet.is-open .sheet-card {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.scene {
  transition: opacity 200ms var(--ease-out), transform 220ms var(--ease-drawer);
  transform: translateY(8px);
  opacity: 0;
  pointer-events: none;
}
.scene.is-open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  width: min(360px, calc(100% - 32px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 16px;
  font-size: 14px;
  line-height: 1.45;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 220ms var(--ease-out), transform 220ms var(--ease-out);
}
.toast.is-out {
  opacity: 0;
  transform: translateY(12px);
}
.toast.is-error { color: #c4473a; }

@media (prefers-reduced-motion: reduce) {
  .login, .app, .app.is-ready, .sheet, .sheet .sheet-card, .scene, .toast, .rail, .asset-card,
  .text-btn, .icon-btn, .generate, .chip, .mode, .clip {
    transition-property: opacity;
    animation: none !important;
    transform: none !important;
  }
  .st.wait::after { animation: none !important; }
  .login.is-leaving, .toast.is-out { opacity: 0; }
  .sheet:not(.is-open), .scene:not(.is-open) { opacity: 0; }
}
