:root {
  --bg: #121014;
  --panel: #1c1820;
  --text: #f2e9f0;
  --muted: #a898a6;
  --accent: #e85d75;
  --accent2: #c44d63;
  --border: #3a3038;
  --chip: #2a232c;
  --ok: #7dcea0;
  --err: #ff8a8a;
  --radius: 12px;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 10% -10%, #2a1520 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
}

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.top h1 {
  margin: 0.2rem 0;
  font-size: 1.5rem;
  letter-spacing: 0.02em;
}

.sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel {
  background: color-mix(in srgb, var(--panel) 92%, black);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}

label {
  display: block;
  margin: 0.85rem 0 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  background: #0e0c10;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.8rem;
  font: inherit;
}

textarea { resize: vertical; }

.row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 0.75rem;
}

.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

@media (max-width: 560px) {
  .presets { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
}

.preset {
  text-align: left;
  background: var(--chip);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.75rem;
  cursor: pointer;
}

.preset strong { display: block; font-size: 0.95rem; }
.preset span { display: block; color: var(--muted); font-size: 0.78rem; margin-top: 0.2rem; }
.preset.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

button {
  font: inherit;
  border-radius: 999px;
  border: none;
  padding: 0.7rem 1.1rem;
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: wait; }

.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  color: white;
  font-weight: 600;
  margin-top: 1rem;
  width: 100%;
}

.secondary {
  background: var(--chip);
  color: var(--text);
  border: 1px solid var(--border);
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.mini {
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
  border-radius: 999px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

@media (min-width: 560px) {
  .actions {
    grid-template-columns: 2fr 1.4fr;
  }
  .actions .primary { margin-top: 0; width: auto; }
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}

.meta-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.meta-actions button {
  flex: 1;
  margin-top: 0;
}

.story-log {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: min(58vh, 640px);
  overflow-y: auto;
  padding-right: 0.25rem;
}

.turn {
  background: #140f16;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
}

.turn-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.turn .n {
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.turn-tools {
  display: flex;
  gap: 0.35rem;
}

.turn .body {
  white-space: pre-wrap;
  font-size: 1.02rem;
}

.turn .you {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.turn img.scene {
  display: block;
  width: 100%;
  border-radius: 10px;
  margin-top: 0.65rem;
  border: 1px solid var(--border);
}

.suggestions {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin: 0.4rem 0 0.6rem;
}

.sug {
  text-align: left;
  background: var(--chip);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
}

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

.error {
  color: var(--err);
  margin-top: 0.75rem;
  white-space: pre-wrap;
}

.loading {
  margin-top: 0.75rem;
  color: var(--ok);
  font-weight: 600;
}

.ended-msg {
  text-align: center;
  font-size: 1.3rem;
  margin: 1rem 0 0.5rem;
}

.image-box {
  margin-top: 1rem;
  background: #100c12;
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 0.75rem;
}

.image-box img {
  width: 100%;
  border-radius: 10px;
  margin: 0.4rem 0;
}

.image-box pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.8rem;
  color: #e0d4dc;
  margin: 0.4rem 0;
  max-height: 8rem;
  overflow: auto;
}

.hint { color: var(--muted); font-size: 0.8rem; margin: 0.25rem 0; }

.userbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.35rem;
}
.userbar .hint { margin: 0; }

.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.25rem 0;
}

.saves-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.save-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 0.4rem;
  align-items: center;
  background: var(--chip);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
}

.save-row .title {
  font-size: 0.92rem;
}
.save-row .meta {
  margin: 0;
  font-size: 0.75rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 1rem;
  z-index: 50;
}

@media (min-width: 560px) {
  .modal { align-items: center; }
}

.modal[hidden] { display: none !important; }

.modal-card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem;
}

.modal-card h3 { margin: 0 0 0.4rem; }

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 0.5rem;
  margin-top: 0.75rem;
}
.modal-actions .primary { margin-top: 0; }

.tool-card {
  background: #140f16;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  margin: 0.75rem 0;
}

.tool-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1.02rem;
}

.tool-card .secondary {
  margin-top: 0.75rem;
  width: 100%;
}

.tool-btn-wrap {
  display: flex;
  align-items: flex-end;
}

.tool-btn-wrap .secondary {
  width: 100%;
  margin-top: 1.6rem;
}

.tool-out {
  margin-top: 0.75rem;
}

.tool-out img,
.tool-out video {
  display: block;
  width: 100%;
  max-height: 480px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0a080c;
}

.tool-insert {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}

input[type="file"] {
  width: 100%;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
}

/* Generation progress bars */
.gen-progress {
  margin: 0.75rem 0 0.25rem;
  padding: 0.65rem 0.75rem;
  background: #120e14;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.gen-progress-track {
  height: 10px;
  background: #2a2230;
  border-radius: 999px;
  overflow: hidden;
}

.gen-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #c45cff, #ff6b9d 55%, #ffb86b);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.gen-progress.indeterminate .gen-progress-fill {
  width: 35% !important;
  animation: gen-indeterminate 1.2s ease-in-out infinite;
}

@keyframes gen-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.gen-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.tool-progress {
  margin-top: 0.65rem;
}
