/* ═══════════════════════════════════════════════════════════════
   Story Forge — Dark Theme, Writer-Friendly
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242838;
  --bg-hover: #2a2e3d;
  --border: #2e3348;
  --text-primary: #e8e6e3;
  --text-secondary: #989aa8;
  --text-muted: #666980;
  --accent: #f0a040;
  --accent-hover: #f5b860;
  --accent-dim: #8a5a20;
  --danger: #e05570;
  --success: #4caf88;
  --info: #5b9bd5;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Georgia", "Times New Roman", serif;
  --font-mono: "JetBrains Mono", "Fira Code", monospace;
  --transition: 0.2s ease;
  --drawer-width: 420px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--bg-tertiary) var(--bg-primary);
}

/* ── Scrollbars ─────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-hover); }
* { scrollbar-width: thin; scrollbar-color: var(--bg-tertiary) var(--bg-primary); }

/* ── Typography ─────────────────────────────────────────────────── */
h1 { font-size: 1.8rem; font-weight: 700; }
h2 { font-size: 1.4rem; font-weight: 600; }
h3 { font-size: 1.1rem; font-weight: 600; }
h4 { font-size: 0.9rem; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Buttons ────────────────────────────────────────────────────── */
button { cursor: pointer; border: none; font-family: var(--font-ui); font-size: 0.875rem; transition: all var(--transition); }
.btn-primary { background: var(--accent); color: #000; padding: 10px 24px; border-radius: var(--radius); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: transparent; color: var(--text-secondary); padding: 8px 14px; border-radius: var(--radius); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-small { background: var(--bg-tertiary); color: var(--text-secondary); padding: 6px 14px; border-radius: var(--radius); font-size: 0.8rem; }
.btn-small:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }

/* ── Forms ──────────────────────────────────────────────────────── */
input, textarea, select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.875rem;
  width: 100%;
  transition: border var(--transition);
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(240, 160, 64, 0.15);
}
textarea { resize: vertical; min-height: 100px; font-family: var(--font-ui); }
.field-label { display: block; font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; margin-top: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Login ──────────────────────────────────────────────────────── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; padding: 20px; overflow-y: auto;
  background: radial-gradient(ellipse at top, #1a1d27, #0f1117);
}
.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
}
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 32px; font-size: 0.9rem; }
.login-card input { margin-bottom: 14px; }
.login-card .btn-primary { width: 100%; margin-top: 8px; }
.login-card .switch { text-align: center; margin-top: 20px; font-size: 0.85rem; color: var(--text-muted); }

/* ── Top Bar ────────────────────────────────────────────────────── */
.top-bar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.top-bar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.badge {
  padding: 4px 10px; border-radius: 20px; font-size: 0.7rem;
  font-weight: 600; text-transform: uppercase;
  background: var(--bg-tertiary); color: var(--text-muted);
}
.badge.draft { color: var(--text-muted); }
.badge.in_progress { color: var(--info); background: rgba(91, 155, 213, 0.1); }
.badge.complete { color: var(--success); background: rgba(76, 175, 136, 0.1); }

/* ── Dashboard ──────────────────────────────────────────────────── */
.dashboard { height: 100vh; overflow-y: auto; }
.dash-content { max-width: 1000px; margin: 0 auto; padding: 32px 24px; }
.dash-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 24px; }
.story-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; margin-bottom: 40px; }
.story-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; cursor: pointer; position: relative;
  transition: all var(--transition);
}
.story-card .card-del-btn { opacity: 0; transition: opacity var(--transition); }
.story-card:hover .card-del-btn { opacity: 1; }
.story-card:hover { border-color: var(--accent-dim); transform: translateY(-2px); box-shadow: var(--shadow); }
.story-card h4 { color: var(--text-primary); margin-bottom: 6px; text-transform: none; font-size: 1rem; }
.story-card p { color: var(--text-secondary); font-size: 0.85rem; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }
.story-card .meta { display: flex; gap: 12px; margin-top: 12px; font-size: 0.75rem; color: var(--text-muted); }
.dash-section { margin-bottom: 32px; }
.item-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.item-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 14px; background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 20px; font-size: 0.8rem; cursor: pointer;
  transition: all var(--transition);
}
.item-chip:hover { border-color: var(--accent); }
.item-chip .chip-del { opacity: 0; font-size: 0.7rem; margin-left: 4px; }
.item-chip:hover .chip-del { opacity: 0.6; }

/* ── Workspace ──────────────────────────────────────────────────── */
.workspace { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.ws-body { display: flex; flex: 1; overflow: hidden; }

/* Sidebar */
.scene-sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--bg-secondary); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 12px;
  overflow: hidden;
}
.scene-sidebar .btn-small {
  flex-shrink: 0;
}
.sidebar-scenes { display: flex; flex-direction: column; gap: 3px; flex: 1; overflow-y: auto; margin-top: 8px; }
.scene-chip {
  padding: 8px 12px; border-radius: var(--radius);
  font-size: 0.78rem; cursor: pointer;
  background: var(--bg-tertiary); color: var(--text-secondary);
  border: 1px solid transparent; transition: all var(--transition);
  text-align: left;
}
.scene-chip:hover { background: var(--bg-hover); }
.scene-chip.active { background: var(--accent-dim); color: var(--accent); font-weight: 600; border-color: var(--accent); }
.scene-chip.generating { border-color: var(--info); animation: pulse 1.5s infinite; }
.scene-chip.draft { opacity: 0.5; }

/* Main Content */
.ws-main { flex: 1; overflow-y: auto; }

/* Scenes Stack */
.scenes-stack { max-width: 780px; margin: 0 auto; padding: 24px 24px 120px; }
.scene-block {
  margin-bottom: 32px; padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.3s ease;
}
  margin-bottom: 32px; padding-bottom: 32px;
  border-bottom: 1px solid var(--border);
  animation: fadeIn 0.3s ease;
}
.scene-block:last-child { border-bottom: none; }
.scene-tools {
  display: flex; gap: 4px; margin-bottom: 12px; align-items: center;
  justify-content: flex-end;
  position: sticky; top: 0; z-index: 10;
  background: var(--bg-primary);
  padding: 8px 0;
}
.scene-tools .btn-sm { padding: 4px 10px; font-size: 0.72rem; }
.scene-content {
  font-family: var(--font-serif); font-size: 1.0rem; line-height: 1.7;
  color: var(--text-primary); white-space: pre-wrap;
  min-height: 40px; padding: 8px 0;
}
.scene-content:empty::before {
  content: "No content yet. Click ✨ Generate to write this scene.";
  color: var(--text-muted); font-family: var(--font-ui); font-size: 0.9rem; font-style: italic;
}

/* Scene formatting tags */
.scene-content { line-height: 1.6; }
.scene-fmt-action { color: var(--text-primary); }
.scene-fmt-thought { color: #c882dc; font-style: italic; }
.scene-fmt-dialogue { color: #5b9bd5; font-weight: 500; }

/* Hints row */
.scene-hints-row { margin-top: 16px; }
.hints-input {
  width: 100%; min-height: 48px; font-size: 0.82rem;
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-secondary); resize: none; font-family: var(--font-ui);
}
.hints-input:focus { border-color: var(--accent); outline: none; }

/* Assets */
.scene-assets { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.asset-card {
  position: relative; max-width: 100%; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border); background: var(--bg-tertiary);
}
.asset-card img, .asset-card video { max-width: 100%; height: auto; display: block; }
.asset-card .asset-actions {
  position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity var(--transition);
}
.asset-card:hover .asset-actions { opacity: 1; }
.asset-card .asset-actions button {
  background: rgba(0,0,0,0.7); color: #fff; border-radius: 4px; padding: 4px 8px; font-size: 0.7rem;
}
.asset-card .asset-type {
  position: absolute; bottom: 6px; left: 6px;
  padding: 2px 8px; background: rgba(0,0,0,0.7); border-radius: 4px; font-size: 0.65rem; color: var(--text-secondary);
}

/* Generation Progress */
.gen-progress {
  display: flex; align-items: center; gap: 12px;
  padding: 16px; background: var(--bg-secondary); border: 1px solid var(--info);
  border-radius: var(--radius); margin-top: 16px;
}
.gen-progress.hidden { display: none; }
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite;
}
.gen-content {
  margin-top: 12px; max-height: 400px; overflow-y: auto;
  font-family: var(--font-serif); font-size: 0.95rem; line-height: 1.7;
  white-space: pre-wrap; color: var(--text-primary);
}

/* ── Drawer ─────────────────────────────────────────────────────── */
/* ── Pre-flight (inside Memory drawer) ────────────────────────────── */
.pf-done-row, .pf-pending-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px; border-radius: var(--radius);
  font-size: 0.82rem;
}
.pf-done-row { background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.25); }
.pf-pending-row { background: var(--bg-tertiary); border: 1px dashed var(--accent-dim); }
.pf-done-icon { font-size: 1rem; }
.pf-pending-icon { font-size: 1rem; }
.pf-tag {
  padding: 2px 7px; border-radius: 8px; font-size: 0.7rem;
  background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-secondary);
}
.pf-tag.done { background: rgba(34,197,94,0.12); border-color: #22c55e; color: #22c55e; }

.drawer-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
  transition: opacity var(--transition);
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: var(--drawer-width);
  background: var(--bg-secondary); border-left: 1px solid var(--border);
  z-index: 201; overflow-y: auto;
  transition: transform var(--transition);
}
.drawer.hidden { transform: translateX(100%); }
.drawer-overlay.hidden { opacity: 0; pointer-events: none; }
.drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-secondary); z-index: 1;
}
.drawer-body { padding: 20px; }

/* ── Modal ──────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300;
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 90%; max-width: 560px;
  max-height: 85vh; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--bg-secondary); z-index: 1;
}
.modal-body { padding: 24px; }

/* ── Memory Manager ─────────────────────────────────────────────── */
.memory-filters { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.memory-filter {
  padding: 4px 12px; border-radius: 20px; font-size: 0.72rem;
  background: var(--bg-tertiary); color: var(--text-muted); cursor: pointer;
  border: 1px solid transparent; transition: all var(--transition);
}
.memory-filter:hover { color: var(--text-secondary); }
.memory-filter.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }
.memory-card {
  padding: 12px 16px; background: var(--bg-tertiary); border-radius: var(--radius);
  margin-bottom: 8px; border-left: 3px solid var(--border);
  transition: all var(--transition);
}
.memory-card:hover { border-left-color: var(--accent); }
.memory-card.inactive { opacity: 0.4; }
.memory-card.contradiction { border-left-color: var(--danger); }
.memory-card .mem-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.memory-card .mem-cat {
  font-size: 0.6rem; padding: 2px 8px; border-radius: 10px;
  font-weight: 600; text-transform: uppercase;
}
.mem-cat.character { background: rgba(91,155,213,0.2); color: var(--info); }
.mem-cat.plot { background: rgba(240,160,64,0.2); color: var(--accent); }
.mem-cat.world { background: rgba(76,175,136,0.2); color: var(--success); }
.mem-cat.visual { background: rgba(200,130,220,0.2); color: #c882dc; }
.mem-cat.relationship { background: rgba(224,85,112,0.2); color: var(--danger); }
.memory-card .mem-key { font-weight: 600; font-size: 0.85rem; }
.memory-card .mem-value {
  font-size: 0.82rem; color: var(--text-secondary); line-height: 1.4;
  max-height: 200px; overflow-y: auto; word-break: break-word;
  white-space: pre-wrap;
}
.memory-card .mem-footer { display: flex; align-items: center; gap: 12px; margin-top: 8px; font-size: 0.7rem; color: var(--text-muted); }
.memory-importance { width: 60px; height: 4px; background: var(--bg-primary); border-radius: 2px; overflow: hidden; }
.memory-importance .fill { height: 100%; border-radius: 2px; }
.memory-actions { display: flex; gap: 4px; margin-left: auto; }

/* ── Config Panel ───────────────────────────────────────────────── */
.config-section { margin-bottom: 24px; }
.config-section h4 { margin-bottom: 12px; }
.config-row { display: flex; gap: 12px; margin-bottom: 10px; align-items: center; }
.config-row label { font-size: 0.82rem; color: var(--text-secondary); min-width: 100px; }
.config-row select, .config-row input[type="range"] { width: auto; flex: 1; }
.standing-instructions { min-height: 80px; font-family: var(--font-mono); font-size: 0.78rem; }

/* ── Utility ────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.field-group { margin-bottom: 16px; }
.toggle-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.toggle-row label { color: var(--text-secondary); font-size: 0.85rem; cursor: pointer; }
.toggle-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.cap-grid { display: flex; flex-direction: column; gap: 6px; }
.cap-grid .toggle-row { margin-bottom: 0; }
.toggle {
  width: 40px; height: 22px; background: var(--bg-tertiary); border-radius: 11px;
  position: relative; cursor: pointer; transition: background var(--transition);
  border: 1px solid var(--border);
}
.toggle.on { background: var(--accent-dim); border-color: var(--accent); }
.toggle::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--text-secondary);
  transition: all var(--transition);
}
.toggle.on::after { left: 20px; background: var(--accent); }

/* ── Provider Cards ─────────────────────────────────────────────── */
.provider-card {
  padding: 16px; background: var(--bg-tertiary); border-radius: var(--radius);
  border: 1px solid var(--border); margin-bottom: 12px;
}
.provider-card .prov-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.provider-card .prov-name { font-weight: 600; }
.provider-card .prov-type { font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; background: var(--bg-primary); color: var(--text-muted); }
.provider-card .prov-key { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); }
.provider-card .prov-actions { display: flex; gap: 6px; margin-top: 10px; }

/* ── Animations ─────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn 0.3s ease; }

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .scene-content-pane { grid-template-columns: 1fr; }
  .drawer { width: 100%; }
  .top-bar { padding: 10px 16px; }
  .top-bar h2 { font-size: 1.1rem; }
  .story-grid { grid-template-columns: 1fr; }
  .login-card { padding: 32px 24px; }

  /* Sidebar → bottom bar */
  .ws-body { flex-direction: column; }
  .scene-sidebar {
    width: 100%; height: 48px; flex-shrink: 0;
    border-right: none; border-top: 1px solid var(--border);
    display: flex; flex-direction: row; align-items: center;
    padding: 0 8px; gap: 4px; order: 2; overflow: visible;
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  }
  .scene-sidebar .btn-small {
    flex-shrink: 0; width: auto; padding: 4px 10px; font-size: 0.75rem;
  }
  .sidebar-scenes {
    display: flex; flex-direction: row; gap: 4px; flex: 1;
    overflow-x: auto; overflow-y: hidden; margin-top: 0;
    scrollbar-width: none;
  }
  .sidebar-scenes::-webkit-scrollbar { display: none; }
  .scene-chip {
    flex-shrink: 0; padding: 4px 10px; font-size: 0.72rem;
    white-space: nowrap;
  }
  .scene-chip-title { display: none; }
  .scene-sidebar .btn-small { font-size: 0; }
  .scene-sidebar .btn-small::after { content: "+"; font-size: 1rem; }
  #btn-add-scene { width: auto !important; margin: 0 6px 0 0 !important; flex-shrink: 0; }
  .sidebar-scenes { flex: 1; }
  .btn-label { display: none; }
  .top-bar .btn-ghost { padding: 6px 8px; font-size: 0.85rem; }
  .ws-main { padding-bottom: 56px; }
  .scenes-stack { padding: 16px 16px 80px; }
}

/* ═══════════════════════════════════════════════════════════════
   Toast Notification
   ═══════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.45);
  animation: toast-in 0.25s ease-out;
  pointer-events: auto;
  max-width: 420px;
  text-align: center;
  line-height: 1.4;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }
.toast.info { border-color: var(--info); color: var(--info); }
.toast.confirm-toast {
  cursor: pointer;
  border-color: var(--accent);
}
.toast.confirm-toast:hover { background: var(--bg-hover); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-12px); }
}
