/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #faf8f5;
  --bg-card: #fff;
  --text: #2c2418;
  --text-muted: #7a6e5d;
  --border: #e8e0d4;
  --accent: #6b4c8a;
  --accent-light: #f0eaf6;
  --success: #3a7d44;
  --error: #c0392b;

  --level-0: #9e9e9e;
  --level-1: #5c82c1;
  --level-2: #7e57a0;
  --level-3: #4a9e5c;
  --level-4: #c49a2a;

  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-story: Georgia, 'Times New Roman', serif;
  --max-width: 720px;
  --radius: 8px;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}

.view { display: flex; flex-direction: column; min-height: 100dvh; }
.view[hidden] { display: none !important; }

/* --- Login --- */
.login-card {
  margin: auto;
  padding: 2.5rem 2rem;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.login-card h1 {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}
.login-subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
  font-size: 0.95rem;
}
.login-card input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  margin-bottom: 1rem;
  transition: border-color 0.2s;
}
.login-card input:focus {
  outline: none;
  border-color: var(--accent);
}
.login-card button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.login-card button:hover { opacity: 0.9; }
.error { color: var(--error); font-size: 0.875rem; margin-top: 0.5rem; }

/* --- Header --- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 { font-size: 1.25rem; color: var(--accent); }
.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
}
.btn-text:hover { color: var(--text); }

/* --- Review Status Tabs --- */
.review-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: var(--bg-card);
  border-bottom: none;
}
.review-tabs .tab {
  flex: 1;
  border-radius: 0;
  border: none;
  border-bottom: 3px solid var(--border);
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg);
}
.review-tabs .tab:hover {
  color: var(--text);
  border-color: var(--text-muted);
}
.review-tabs .tab.active {
  background: transparent;
}
.review-tabs .tab[data-review="pending"].active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.review-tabs .tab[data-review="reviewed"].active {
  background: var(--success);
  color: #fff;
  border-color: var(--success);
}

/* --- Level Tabs --- */
.level-tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0.5rem 1.25rem 0.75rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.tab {
  padding: 0.4rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: transparent;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  color: var(--text-muted);
}
.tab:hover { border-color: var(--accent); color: var(--accent); }
.tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* --- Stories Grid --- */
.loading {
  text-align: center;
  padding: 3rem;
  color: var(--text-muted);
}
.stories-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}
@media (min-width: 600px) {
  .stories-grid { grid-template-columns: 1fr 1fr; }
}

.story-card {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  border-left: 4px solid var(--card-level-color, var(--border));
}
.story-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.story-card .card-title {
  font-weight: 600;
  font-size: 0.95rem;
}
.story-card .card-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-level { color: #fff; }
.badge-level[data-level="0"] { background: var(--level-0); }
.badge-level[data-level="1"] { background: var(--level-1); }
.badge-level[data-level="2"] { background: var(--level-2); }
.badge-level[data-level="3"] { background: var(--level-3); }
.badge-level[data-level="4"] { background: var(--level-4); }
.badge-category { background: var(--accent-light); color: var(--accent); }
.badge-review { background: #fff3cd; color: #856404; }
.badge-series { background: #e3f2fd; color: #1565c0; }

/* --- Series Filter Dropdown --- */
.series-filter {
  padding: 0.25rem 1.25rem 0.5rem;
  background: var(--bg-card);
}
.series-filter select {
  padding: 0.4rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  background: var(--bg-card);
  color: var(--text);
  cursor: pointer;
}
.series-filter select:focus { outline: none; border-color: var(--accent); }

/* --- Collection Card (series group header) --- */
.collection-card {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--accent-light);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition: box-shadow 0.2s;
}
.collection-card:hover {
  box-shadow: 0 2px 8px rgba(107,76,138,0.12);
}
.collection-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.collection-title { font-weight: 700; font-size: 0.95rem; color: var(--accent); }
.collection-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.collection-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.btn-series-detail {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-series-detail:hover {
  background: var(--accent);
  color: #fff;
}
.collection-chevron {
  font-size: 1rem;
  color: var(--accent);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.collection-card.expanded .collection-chevron { transform: rotate(90deg); }

/* --- Series Detail Header (when filtering specific series) --- */
.series-detail-link {
  padding: 0.5rem 1.25rem;
  background: var(--accent-light);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}
.series-detail-link a {
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.series-detail-link a:hover { text-decoration: underline; }

/* --- Episode Card (indented child of collection) --- */
.episode-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem 1rem 0.75rem 1.25rem;
  margin-left: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.episode-card:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.episode-card .card-title { font-weight: 600; font-size: 0.9rem; }
.episode-card .ep-number {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.episode-card .card-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* --- Series Navigator (in story detail) --- */
.series-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem;
  background: var(--accent-light);
  font-size: 0.8rem;
  border-bottom: 1px solid var(--border);
}
.series-nav-info { color: var(--accent); font-weight: 600; }
.series-nav-links { display: flex; gap: 1rem; }
.series-nav a {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
}
.series-nav a:hover { text-decoration: underline; }

/* --- Series Episodes Table --- */
.series-episodes-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-family: var(--font-ui);
  font-size: 0.85rem;
}
.series-episodes-table th, .series-episodes-table td {
  border: 1px solid var(--border);
  padding: 0.4rem 0.6rem;
  text-align: left;
}
.series-episodes-table th { background: var(--accent-light); font-weight: 600; }
.series-ep-link { color: var(--accent); text-decoration: none; }
.series-ep-link:hover { text-decoration: underline; }

/* --- Detail View --- */
.detail-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: sticky;
  top: 0;
  z-index: 10;
}
.btn-back {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
}
.btn-back:hover { text-decoration: underline; }
.detail-meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.85rem;
}

.detail-main {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

/* --- Story Content (rendered markdown) --- */
.story-content {
  font-family: var(--font-story);
  font-size: 1.05rem;
  line-height: 1.75;
}
.story-content h1 { font-size: 1.6rem; margin-bottom: 1rem; color: var(--accent); }
.story-content h2 { font-size: 1.25rem; margin: 1.5rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
.story-content h3 { font-size: 1.1rem; margin: 1.25rem 0 0.4rem; }
.story-content p { margin-bottom: 0.75rem; }
.story-content ul, .story-content ol { margin: 0.5rem 0 0.75rem 1.5rem; }
.story-content li { margin-bottom: 0.25rem; }
.story-content table { width: 100%; border-collapse: collapse; margin: 1rem 0; font-family: var(--font-ui); font-size: 0.85rem; }
.story-content th, .story-content td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: left; }
.story-content th { background: var(--accent-light); font-weight: 600; }
.story-content pre { background: #f5f2ed; padding: 1rem; border-radius: var(--radius); overflow-x: auto; font-size: 0.85rem; margin: 0.75rem 0; }
.story-content code { background: #f5f2ed; padding: 0.15rem 0.35rem; border-radius: 3px; font-size: 0.9em; }
.story-content pre code { background: none; padding: 0; }
.story-content strong { color: var(--text); }
.story-content blockquote { border-left: 3px solid var(--accent); padding-left: 1rem; color: var(--text-muted); margin: 0.75rem 0; }

/* --- Review Section --- */
.review-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}
.review-section h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
  color: var(--text-muted);
}
.review-content {
  font-family: var(--font-ui);
  font-size: 0.9rem;
  background: #fdf8ee;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border: 1px solid #f0e6cd;
}
.review-content h2 { font-size: 1rem; margin: 1rem 0 0.5rem; }
.review-content h3 { font-size: 0.9rem; margin: 0.75rem 0 0.25rem; }
.review-content p, .review-content li { margin-bottom: 0.35rem; }

/* --- Comment Form --- */
.comment-section {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 2px solid var(--border);
}
.comment-section h2 {
  font-size: 1.1rem;
  margin-bottom: 1rem;
}
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}
.radio-group {
  display: flex;
  gap: 1.25rem;
}
.radio-group label {
  font-weight: 400;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 0.95rem;
  line-height: 1.5;
  resize: vertical;
  transition: border-color 0.2s;
}
textarea:focus { outline: none; border-color: var(--accent); }
/* --- Action Buttons --- */
.action-buttons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.action-buttons-review {
  display: flex;
  gap: 0.5rem;
}
.btn-action {
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  color: #fff;
}
.btn-action:hover { opacity: 0.9; }
.btn-action:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-rework { background: var(--accent); }
.btn-approve { background: var(--success); }
.btn-delete { background: var(--error); }

.status {
  font-size: 0.875rem;
  margin-top: 0.5rem;
}
.status.success { color: var(--success); }
.status.error { color: var(--error); }

/* --- Demo Player --- */
.demo-player {
  margin-top: 1rem;
}

.demo-breadcrumb {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.demo-crumb {
  background: var(--accent-light);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s;
  border: none;
  font-size: 0.7rem;
  font-weight: 500;
}
.demo-crumb:hover { background: var(--accent); color: #fff; }
.demo-crumb.current { background: var(--accent); color: #fff; cursor: default; }
.demo-crumb-sep { color: var(--border); font-size: 0.65rem; }

.demo-node-inner {
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
@keyframes demoFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.demo-node-id {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.demo-node-text {
  font-family: var(--font-story);
  font-size: 1.05rem;
  line-height: 1.75;
  margin-bottom: 1.25rem;
}
.demo-node-text p { margin-bottom: 0.6rem; }
.demo-node-text p:last-child { margin-bottom: 0; }

.demo-choice-prompt {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: var(--accent);
}

.demo-choices {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.demo-choice-or {
  text-align: left;
  font-size: 0.8rem;
  font-style: italic;
  color: var(--text-muted);
  opacity: 0.7;
  margin: -0.1rem 0;
  padding-left: 1rem;
}
.demo-choice-btn {
  display: block;
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--accent-light);
  border: 1.5px solid transparent;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
  color: var(--text);
}
.demo-choice-btn:hover {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 2px 8px rgba(107,76,138,0.1);
}

/* Ending styles */
.demo-node-inner.demo-ending { border-color: var(--accent); border-width: 2px; }
.demo-ending-type {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.75rem;
  color: #fff;
}
.demo-ending-type[data-type="happy"] { background: #4caf50; }
.demo-ending-type[data-type="classic"] { background: #5c82c1; }
.demo-ending-type[data-type="surprising"] { background: #ff9800; }
.demo-ending-type[data-type="bittersweet"] { background: #8d6e63; }

.demo-epilogue {
  font-family: var(--font-story);
  font-style: italic;
  color: var(--text-muted);
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  margin-top: 1.25rem;
  font-size: 0.95rem;
  line-height: 1.6;
}

.demo-restart {
  margin-top: 1.25rem;
  padding: 0.7rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}
.demo-restart:hover { opacity: 0.9; }

.demo-auto-link {
  margin-top: 1rem;
  text-align: center;
}
.demo-auto-link button {
  padding: 0.7rem 1.5rem;
  background: var(--accent-light);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--accent);
  transition: all 0.2s;
}
.demo-auto-link button:hover { background: var(--accent); color: #fff; }

.demo-start-row {
  padding: 0.5rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.btn-demo-full {
  display: block;
  width: 100%;
  padding: 0.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  letter-spacing: 0.02em;
}
.btn-demo-full:hover { opacity: 0.85; }

.btn-demo-exit {
  margin-top: 1.25rem;
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
  font-size: 0.85rem;
  padding: 0.5rem 1rem;
}
.btn-demo-exit:hover { border-color: var(--accent); color: var(--accent); }

/* --- Copy Buttons Row --- */
.copy-buttons-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.4rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.btn-copy {
  padding: 0.35rem 0.75rem;
  background: transparent;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}
.btn-copy:hover { border-color: var(--accent); color: var(--accent); }
.btn-copy:disabled { opacity: 0.6; cursor: default; color: var(--success); border-color: var(--success); }

/* Small copy buttons on story cards */
.card-copy-row {
  display: flex;
  gap: 0.35rem;
  margin-top: 0.2rem;
}
.btn-copy-sm {
  padding: 0.2rem 0.5rem;
  font-size: 0.65rem;
}
