/* ================================================================
   AWFST — Main Stylesheet
   ================================================================ */

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

:root {
  /* ── Brand palette ── */
  --brand-teal:     #4899a1;
  --brand-amber:    #eca938;
  --brand-coral:    #e2685c;
  --brand-sage:     #89a385;
  --brand-navy:     #1d365a;
  --brand-cream:    #f4ecdd;

  /* ── Dark theme (default) ── */
  --bg:           #000000;
  --bg-surface:   #0d0d0d;
  --bg-card:      #141414;
  --bg-card-hover:#1e1e1e;
  --accent:       #eca938;
  --accent-dim:   #c4881e;
  --accent2:      #4899a1;
  --accent3:      #e2685c;
  --text:         #f4ecdd;
  --text-muted:   #8fb4ba;
  --text-dim:     #4d7a80;
  --border:       rgba(72,153,161,0.18);
  --header-bg:    rgba(0,0,0,0.95);
  --radius:       14px;
  --radius-sm:    8px;
  --shadow:       0 4px 32px rgba(0,0,0,0.5);
  --font-body:    'Nunito', sans-serif;
  --font-story:   'Lora', serif;
  --transition:   0.2s ease;
}

[data-theme="light"] {
  --bg:           #f4ecdd;
  --bg-surface:   #ede3ce;
  --bg-card:      #fdf7ed;
  --bg-card-hover:#fff3e0;
  --accent:       #c47c18;
  --accent-dim:   #9e6212;
  --accent2:      #3a7d85;
  --accent3:      #c44d42;
  --text:         #1d365a;
  --text-muted:   #3d5f70;
  --text-dim:     #7a9aaa;
  --border:       rgba(29,54,90,0.14);
  --header-bg:    rgba(244,236,221,0.93);
  --shadow:       0 4px 32px rgba(29,54,90,0.12);
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ── Typography ── */
h1, h2, h3, h4 { line-height: 1.2; }

/* ================================================================
   HEADER
   ================================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  /* gradient bottom strip replaces plain border */
  border-bottom: none;
}
.site-header::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg,
    var(--brand-teal)  0%,
    var(--brand-amber) 33%,
    var(--brand-coral) 66%,
    var(--brand-sage)  100%);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  padding: 4px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}
.logo-img {
  height: 48px;
  width: auto;
  display: block;
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #d4902a);
  color: #1a1000;
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 14px;
}
.btn-ghost:hover { color: var(--text); background: var(--border); }

.btn-generate {
  width: 100%;
  padding: 16px;
  font-size: 1.1rem;
  justify-content: center;
  border-radius: var(--radius);
  letter-spacing: 0.3px;
}

/* ================================================================
   PAGES
   ================================================================ */
.page { display: none; }
.page.active { display: block; }

/* ================================================================
   HOMEPAGE
   ================================================================ */
main { max-width: 900px; margin: 0 auto; padding: 48px 24px 80px; }

.hero { text-align: center; margin-bottom: 40px; }
.hero-title {
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg,
    var(--brand-coral)  0%,
    var(--brand-amber)  33%,
    var(--brand-sage)   66%,
    var(--brand-teal)   100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.hero-subtitle { color: var(--accent2); opacity: 0.85; font-size: 1.05rem; }

/* Creator card */
.creator-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-top: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  box-shadow: var(--shadow);
}

.input-group { display: flex; flex-direction: column; gap: 10px; }
.input-label { font-weight: 700; font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; color: var(--accent2); }

/* Slider */
.slider-row { display: flex; align-items: center; gap: 14px; }
.slider-min, .slider-max { font-size: 0.85rem; color: var(--text-dim); white-space: nowrap; }
.slider {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  border-radius: 99px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--fill, 44%), var(--bg) var(--fill, 44%));
  outline: none;
  cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--bg-card);
  box-shadow: 0 0 0 2px var(--accent);
  transition: transform 0.15s;
}
.slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-value-display { text-align: center; }
.slider-value-display span {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 4px 16px;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
}

/* Textarea */
.story-textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color var(--transition);
}
.story-textarea:focus { border-color: var(--accent2); }
.story-textarea::placeholder { color: var(--text-dim); }

.char-count { text-align: right; font-size: 0.8rem; color: var(--brand-sage); }

/* ── Library ── */
.library-section { margin-top: 64px; }
.section-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 24px;
  color: var(--text);
  padding-left: 14px;
  border-left: 3px solid var(--accent2);
}

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 20px;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--brand-sage);
}
.empty-icon { font-size: 2.5rem; display: block; margin-bottom: 12px; color: var(--brand-teal); }

/* Story card */
.story-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}
.story-card:hover { transform: translateY(-3px); border-color: var(--accent2); box-shadow: 0 8px 32px rgba(72,153,161,0.2); }

.story-card-image {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  background: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
}
.story-card-image img { width: 100%; height: 100%; object-fit: cover; }
.story-card-image.placeholder { background: linear-gradient(135deg, var(--brand-navy) 0%, #0e1f30 55%, rgba(72,153,161,0.12) 100%); }

.story-card-body { padding: 16px; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.story-card-title { font-weight: 800; font-size: 1rem; line-height: 1.3; }
.story-card-synopsis { font-size: 0.85rem; color: var(--text-muted); line-height: 1.5; flex: 1; }
.story-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--accent2);
  opacity: 0.8;
  margin-top: 8px;
}

.story-card-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}
.story-card-actions .btn { flex: 1; justify-content: center; padding: 8px; font-size: 0.85rem; }
.btn-delete {
  background: transparent !important;
  color: var(--brand-coral) !important;
  border: 1px solid rgba(226,104,92,0.3) !important;
}
.btn-delete:hover:not(:disabled) {
  background: rgba(226,104,92,0.14) !important;
  border-color: var(--brand-coral) !important;
}

/* ================================================================
   READER
   ================================================================ */
.reader-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 40px;
  flex-wrap: wrap;
}
.reader-title-wrap { flex: 1; min-width: 0; }
.reader-title { font-size: 1.6rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-progress { font-size: 0.85rem; color: var(--brand-sage); }

/* Story page */
.story-page { display: none; }
.story-page.active { display: block; animation: fadeIn 0.4s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.story-text-section {
  font-family: var(--font-story);
  font-size: 1.15rem;
  line-height: 1.9;
  color: var(--text);
  max-width: 680px;
  margin: 0 auto 36px;
}
.story-text-section p { margin-bottom: 1.2em; }

/* Image section */
.image-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 36px;
}

.image-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.image-section-header span { font-size: 0.85rem; color: var(--brand-amber); font-weight: 700; }
.image-section-controls { display: flex; gap: 8px; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  padding: 2px;
}

.image-thumb {
  aspect-ratio: 1;
  background: var(--bg-surface);
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: opacity var(--transition);
}
.image-thumb:hover { opacity: 0.85; }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.image-thumb .img-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--transition);
  font-size: 1.5rem;
}
.image-thumb:hover .img-overlay { opacity: 1; }

.image-loading-grid {
  display: grid;
  grid-template-columns: repeat(2,1fr);
  gap: 2px;
  padding: 2px;
}
.image-skeleton {
  aspect-ratio: 1;
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-card-hover) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Full image (selected) */
.image-section.full-view .image-grid { display: none; }
.full-image-container { display: none; }
.image-section.full-view .full-image-container { display: block; }
.full-image-container img { width: 100%; display: block; max-height: 65vh; object-fit: contain; background: #000; }

/* Collapsed image section */
.image-section.collapsed .image-grid,
.image-section.collapsed .full-image-container,
.image-section.collapsed .image-loading-grid { display: none; }

/* Reader nav */
.reader-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 48px;
  padding-top: 24px;
  border-top: 2px solid;
  border-image: linear-gradient(90deg, var(--brand-teal), var(--brand-amber), var(--brand-coral)) 1;
}
/* Prev = teal, Next = amber */
#prevPageBtn {
  background: rgba(72,153,161,0.12);
  color: var(--brand-teal);
  border: 1px solid rgba(72,153,161,0.4);
}
#prevPageBtn:hover:not(:disabled) { background: rgba(72,153,161,0.22); }
#nextPageBtn {
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  color: #1a1000;
  border: none;
  font-weight: 800;
}
#nextPageBtn:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.page-indicator { color: var(--brand-amber); font-size: 0.9rem; font-weight: 700; }

/* ================================================================
   MODALS
   ================================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.2s ease;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}
.modal-header h3 { font-size: 1.2rem; font-weight: 800; }
.modal-body { padding: 24px; display: flex; flex-direction: column; gap: 28px; }
.modal-footer { padding: 0 24px 24px; }

.settings-group { display: flex; flex-direction: column; gap: 14px; }
.settings-group h4 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); font-weight: 700; }
.settings-row { display: flex; flex-direction: column; gap: 6px; }
.settings-row label { font-size: 0.85rem; color: var(--text-muted); }

select, .settings-row input {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.95rem;
  padding: 10px 14px;
  outline: none;
  width: 100%;
  transition: border-color var(--transition);
}
select:focus, .settings-row input:focus { border-color: var(--accent2); }
select option { background: var(--bg-card); }

.cost-note {
  font-size: 0.88rem;
  color: var(--brand-sage);
  background: var(--bg-surface);
  border-left: 3px solid var(--brand-sage);
  border-radius: var(--radius-sm);
  padding: 12px;
  line-height: 1.6;
}

/* Loading overlay */
.loading-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 36px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  min-width: 280px;
}
.loading-spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-title { font-size: 1.15rem; font-weight: 800; }
.loading-sub { font-size: 0.9rem; color: var(--text-muted); }

/* Lightbox */
.lightbox-inner {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}
.lightbox-close {
  position: absolute;
  top: -40px;
  right: 0;
  z-index: 1;
  font-size: 1.2rem;
}
.lightbox-img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius);
  display: block;
}

/* ================================================================
   CAST BUTTON — highlight when connected
   ================================================================ */
.btn-cast.connected { color: var(--accent); }

/* ================================================================
   TOAST NOTIFICATIONS
   ================================================================ */
#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s ease, fadeOut 0.4s ease 3.6s forwards;
  pointer-events: all;
}
.toast.error { border-left-color: var(--accent3); }
@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(40px); } }

/* ================================================================
   THEME TOGGLE, AUTH CHIP & LOGIN
   ================================================================ */
.header-nav { display: flex; align-items: center; gap: 6px; }
.btn-theme { font-size: 1.1rem; padding: 8px 10px; }

.auth-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px 5px 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 99px;
  cursor: pointer;
  transition: all var(--transition);
}
.auth-chip:hover { border-color: var(--accent2); }

.auth-initial {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent2);
  color: var(--bg);
  font-size: 0.75rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.auth-email {
  font-size: 0.82rem;
  color: var(--text-muted);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Auth required notice inside creator card */
.auth-required-notice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  text-align: center;
}
.auth-required-notice[hidden] { display: none; }
.auth-required-notice p { color: var(--text-muted); font-size: 0.9rem; }
.auth-required-notice .notice-icon { color: var(--accent); font-size: 1.4rem; }

/* Login modal */
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 0.82rem;
}
.login-divider::before, .login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-google {
  width: 100%;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text);
  gap: 10px;
}
.btn-google:hover { background: var(--bg-card-hover); }

.login-error {
  border-left: 3px solid var(--accent3) !important;
  color: var(--accent3) !important;
}
.login-error[hidden] { display: none; }

/* Approval note below register button */
.approval-note {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-align: center;
  line-height: 1.5;
}

/* Approval status badge (settings + auth chip area) */
.approval-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
}
.approval-approved {
  background: rgba(72,153,161,0.15);
  color: var(--accent2);
  border: 1px solid rgba(72,153,161,0.25);
}
.approval-pending {
  background: rgba(236,169,56,0.12);
  color: var(--accent);
  border: 1px solid rgba(236,169,56,0.25);
}

/* Pending approval notice — amber accent instead of teal */
.pending-notice {
  border-color: rgba(236,169,56,0.4) !important;
  border-style: solid !important;
}
.pending-notice .notice-icon { color: var(--accent); }
.pending-notice p strong { color: var(--text); }

/* Settings group separators */
.settings-group + .settings-group {
  border-top: 1px solid var(--border);
  padding-top: 24px;
}

/* Light mode scrollbar */
[data-theme="light"] ::-webkit-scrollbar-track { background: var(--bg-surface); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(29,54,90,0.2); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 600px) {
  main { padding: 32px 16px 60px; }
  .creator-card { padding: 20px 16px; }
  .reader-header { flex-direction: column; align-items: flex-start; }
  .reader-nav { flex-direction: column; gap: 14px; }
  .image-grid { grid-template-columns: repeat(2, 1fr); }
}
