/* ════════════════════════════════════════════════
   StoryWeave – Application Stylesheet
   Literary / Editorial aesthetic
   ════════════════════════════════════════════════ */

:root {
  --cream:       #F7F3ED;
  --cream-dark:  #EDE5D8;
  --ink:         #1C1917;
  --ink-light:   #44403C;
  --amber:       #D4A853;
  --amber-light: #E8C97A;
  --wood:        #8B4513;
  --wood-light:  #B05A28;
  --muted:       #9C948A;
  --border:      #E8E0D5;
  --chat-bg:     #2C2420;
  --chat-text:   #E8DDD4;
  --surface:     #FFFDF9;
  --red:         #DC2626;
  --green:       #16A34A;
  --shadow:      rgba(28,25,23,0.10);
  --shadow-lg:   rgba(28,25,23,0.18);
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--cream);
  color: var(--ink);
  font-family: 'DM Sans', system-ui, sans-serif;
  line-height: 1.6;
}

/* ── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--cream-dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Typography ────────────────────────────────── */
h1, h2, h3, h4 {
  font-family: 'Playfair Display', Georgia, serif;
  line-height: 1.25;
  color: var(--ink);
}

.story-text {
  font-family: 'Lora', Georgia, serif;
  font-size: 1rem;
  line-height: 1.85;
  color: var(--ink-light);
}

/* ── Buttons ───────────────────────────────────── */
.sw-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0.55rem 1.25rem;
  border-radius: 6px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
  border: 1.5px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.sw-btn:disabled { opacity: 0.45; cursor: not-allowed; }

.sw-btn-primary {
  background: var(--wood);
  color: #fff;
  border-color: var(--wood);
}
.sw-btn-primary:hover:not(:disabled) { background: var(--wood-light); border-color: var(--wood-light); }

.sw-btn-amber {
  background: var(--amber);
  color: var(--ink);
  border-color: var(--amber);
}
.sw-btn-amber:hover:not(:disabled) { background: var(--amber-light); }

.sw-btn-outline {
  background: transparent;
  color: var(--wood);
  border-color: var(--wood);
}
.sw-btn-outline:hover:not(:disabled) { background: var(--wood); color: #fff; }

.sw-btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.sw-btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--muted); }

.sw-btn-danger {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.sw-btn-sm { padding: 0.35rem 0.85rem; font-size: 0.8rem; }
.sw-btn-lg { padding: 0.75rem 1.75rem; font-size: 1rem; }

/* ── Forms ─────────────────────────────────────── */
.sw-input {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font-family: 'DM Sans', sans-serif;
  font-size: 0.9rem;
  transition: border-color 0.18s, box-shadow 0.18s;
  outline: none;
}
.sw-input:focus {
  border-color: var(--wood);
  box-shadow: 0 0 0 3px rgba(139,69,19,0.12);
}
.sw-input::placeholder { color: var(--muted); }

.sw-textarea {
  resize: vertical;
  min-height: 80px;
}

.sw-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.sw-form-group { margin-bottom: 1.25rem; }

/* ── Cards ─────────────────────────────────────── */
.sw-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow);
}

/* ── Badge ─────────────────────────────────────── */
.sw-badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  background: var(--amber);
  color: var(--ink);
  border-radius: 99px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sw-badge-outline {
  background: transparent;
  border: 1.5px solid var(--amber);
  color: var(--wood);
}

/* ── Flash messages ────────────────────────────── */
.sw-flash {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  margin-bottom: 0.5rem;
  border: 1.5px solid;
}
.sw-flash--success { background: #f0fdf4; border-color: #86efac; color: #15803d; }
.sw-flash--error   { background: #fef2f2; border-color: #fca5a5; color: #b91c1c; }
.sw-flash--info    { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; }
.sw-flash--warning { background: #fffbeb; border-color: #fcd34d; color: #92400e; }

/* ── Nav ───────────────────────────────────────── */
.sw-nav { font-family: 'DM Sans', sans-serif; }
.sw-logo { letter-spacing: -0.02em; }
.nav-link { position: relative; text-decoration: none; }

/* ── Story page layout ─────────────────────────── */
.story-layout {
  display: grid;
  grid-template-rows: 1fr auto;
  grid-template-columns: 1fr 320px;
  gap: 0;
  height: calc(100vh - 56px);
  overflow: hidden;
}

.story-content-area {
  grid-row: 1 / 2;
  grid-column: 1 / 2;
  overflow-y: auto;
  padding: 1.5rem 2rem;
  background: var(--surface);
  border-right: 1.5px solid var(--border);
}

.story-chat-area {
  grid-row: 1 / 2;
  grid-column: 2 / 3;
  display: flex;
  flex-direction: column;
  background: var(--chat-bg);
  color: var(--chat-text);
  overflow: hidden;
}

.story-pen-area {
  grid-row: 2 / 3;
  grid-column: 1 / 3;
  background: var(--cream-dark);
  border-top: 2px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

/* Mobile story layout */
@media (max-width: 768px) {
  .story-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto auto;
    height: auto;
    min-height: calc(100vh - 56px);
  }
  .story-content-area { grid-column: 1; border-right: none; border-bottom: 1.5px solid var(--border); padding: 1rem; }
  .story-chat-area    { grid-row: 2; grid-column: 1; min-height: 280px; }
  .story-pen-area     { grid-row: 3; grid-column: 1; flex-direction: column; }
}

/* ── Cloudlets (wolkjes) ───────────────────────── */
.cloudlet {
  position: relative;
  background: #fff;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 1px 4px var(--shadow);
  transition: box-shadow 0.2s;
  animation: cloudlet-appear 0.35s ease;
}

.cloudlet:hover { box-shadow: 0 3px 12px var(--shadow); }

@keyframes cloudlet-appear {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.cloudlet-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.75rem;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
}

.cloudlet-author { font-weight: 600; color: var(--wood); }
.cloudlet-time   { }

.cloudlet-text   { font-family: 'Lora', Georgia, serif; font-size: 0.95rem; line-height: 1.8; }

.cloudlet-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.6rem;
}

.like-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  padding: 0.2rem 0.5rem;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: none;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.like-btn:hover      { color: var(--wood); border-color: var(--wood); }
.like-btn.active-up  { color: var(--green); border-color: var(--green); background: #f0fdf4; }
.like-btn.active-down{ color: var(--red);   border-color: var(--red);   background: #fef2f2; }

/* ── Chapter headings ──────────────────────────── */
.chapter-heading {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.35rem;
  color: var(--ink);
  padding: 1.25rem 0 0.75rem;
  margin-top: 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.chapter-number {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  display: block;
  margin-bottom: 0.25rem;
}

/* ── Live pen indicator ────────────────────────── */
.pen-live-preview {
  background: #fffbf0;
  border: 1.5px dashed var(--amber);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  margin-bottom: 0.75rem;
  font-family: 'Lora', serif;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--ink-light);
  min-height: 3rem;
  display: none;
}

.pen-holder-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--amber-light);
  border: 1.5px solid var(--amber);
  border-radius: 99px;
  padding: 0.15rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--wood);
  animation: pen-pulse 1.8s ease-in-out infinite;
}

@keyframes pen-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.65; }
}

/* ── Pen input area ────────────────────────────── */
.pen-textarea {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border: 2px solid var(--wood);
  border-radius: 8px;
  background: #fff;
  font-family: 'Lora', Georgia, serif;
  font-size: 0.95rem;
  line-height: 1.7;
  resize: none;
  min-height: 72px;
  max-height: 180px;
  outline: none;
  transition: box-shadow 0.2s;
  width: 100%;
}

.pen-textarea:focus { box-shadow: 0 0 0 3px rgba(139,69,19,0.15); }

.pen-info {
  font-size: 0.75rem;
  color: var(--muted);
  font-family: 'DM Sans', sans-serif;
  margin-top: 0.3rem;
}

/* ── Queue list ────────────────────────────────── */
.queue-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.4rem;
}

.queue-item {
  font-size: 0.7rem;
  background: var(--cream-dark);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.1rem 0.5rem;
  color: var(--muted);
}

/* ── Chat ──────────────────────────────────────── */
.chat-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(232,221,212,0.5);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-msg {
  animation: msg-appear 0.2s ease;
}

@keyframes msg-appear {
  from { opacity: 0; transform: translateX(6px); }
  to   { opacity: 1; transform: translateX(0); }
}

.chat-msg-meta {
  font-size: 0.68rem;
  color: rgba(232,221,212,0.4);
  margin-bottom: 0.1rem;
  font-family: 'DM Sans', sans-serif;
}

.chat-msg-author { font-weight: 600; color: var(--amber-light); }

.chat-msg-text {
  font-size: 0.85rem;
  color: var(--chat-text);
  line-height: 1.5;
  word-break: break-word;
  font-family: 'DM Sans', sans-serif;
}

.chat-msg.system .chat-msg-text {
  font-style: italic;
  color: rgba(232,221,212,0.5);
  font-size: 0.78rem;
}

.chat-msg.vote .chat-msg-text {
  color: var(--amber-light);
  font-weight: 500;
  font-size: 0.82rem;
}

.chat-typing {
  font-size: 0.72rem;
  color: rgba(232,221,212,0.4);
  font-style: italic;
  padding: 0 1rem 0.4rem;
  min-height: 1.2rem;
  font-family: 'DM Sans', sans-serif;
}

.chat-input-area {
  padding: 0.75rem 1rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  display: flex;
  gap: 0.5rem;
}

.chat-input {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 99px;
  padding: 0.5rem 1rem;
  color: var(--chat-text);
  font-size: 0.85rem;
  outline: none;
  font-family: 'DM Sans', sans-serif;
  transition: border-color 0.15s;
}

.chat-input:focus { border-color: rgba(232,201,122,0.4); }
.chat-input::placeholder { color: rgba(232,221,212,0.3); }

.chat-send-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--amber);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink);
  transition: background 0.15s;
}

.chat-send-btn:hover { background: var(--amber-light); }

/* ── Participants ──────────────────────────────── */
.participants-bar {
  padding: 0.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.participant-dot {
  width: 8px; height: 8px;
  background: var(--green);
  border-radius: 50%;
  display: inline-block;
  margin-right: 3px;
}

/* ── Vote banner ───────────────────────────────── */
.vote-banner {
  background: #fffbeb;
  border: 2px solid var(--amber);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: none;
}

.vote-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--wood);
}

/* ── Progress bars ─────────────────────────────── */
.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--wood), var(--amber));
  transition: width 0.4s ease;
}

/* ── Dashboard grid ────────────────────────────── */
.story-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 5px var(--shadow);
  transition: box-shadow 0.2s, transform 0.2s;
  text-decoration: none;
  color: inherit;
  display: block;
}

.story-card:hover {
  box-shadow: 0 4px 16px var(--shadow-lg);
  transform: translateY(-2px);
}

/* ── Login / Register pages ────────────────────── */
.auth-wrap {
  min-height: calc(100vh - 120px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 2.5rem 2rem;
  box-shadow: 0 8px 32px var(--shadow-lg);
}

.auth-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: var(--ink);
}

.auth-subtitle {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 2rem;
}

/* ── Universal story preview on homepage ───────── */
.universal-preview {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 2px 8px var(--shadow);
  position: relative;
  overflow: hidden;
}

.universal-preview::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 80px;
  background: linear-gradient(to bottom, transparent, var(--surface));
  pointer-events: none;
}

/* ── Loading spinner ───────────────────────────── */
.sw-spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(139,69,19,0.2);
  border-top-color: var(--wood);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tooltip ───────────────────────────────────── */
[data-tooltip] {
  position: relative;
  cursor: help;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 0.72rem;
  padding: 0.3rem 0.6rem;
  border-radius: 5px;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 100;
  font-family: 'DM Sans', sans-serif;
}

[data-tooltip]:hover::after { opacity: 1; }

/* ── Homepage hero ─────────────────────────────── */
.hero {
  background: linear-gradient(135deg, #2C2420 0%, #1C1917 100%);
  color: #fff;
  padding: 5rem 1.5rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    radial-gradient(ellipse 60% 60% at 30% 40%, rgba(212,168,83,0.15) 0%, transparent 70%),
    radial-gradient(ellipse 40% 60% at 80% 60%, rgba(139,69,19,0.12) 0%, transparent 70%);
}

.hero-title {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: clamp(2.5rem, 6vw, 4.5rem);
  font-weight: 700;
  line-height: 1.1;
  position: relative;
  z-index: 1;
}

.hero-title em {
  color: var(--amber);
  font-style: italic;
}

.hero-sub {
  font-size: clamp(0.95rem, 2vw, 1.1rem);
  color: rgba(255,255,255,0.65);
  margin-top: 1rem;
  position: relative;
  z-index: 1;
  max-width: 540px;
  margin-left: auto;
  margin-right: auto;
}

.hero-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-top: 2.5rem;
  position: relative;
  z-index: 1;
  flex-wrap: wrap;
}

/* ── Pen status bar ────────────────────────────── */
.pen-status {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

/* ── Responsive helpers ────────────────────────── */
@media (max-width: 640px) {
  .sw-card    { padding: 1rem; }
  .auth-card  { padding: 1.5rem 1.25rem; }
  .hero       { padding: 3rem 1rem; }
}

/* ── Animations ────────────────────────────────── */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.fade-in { animation: fade-in 0.3s ease; }

/* ── Ink ornament ──────────────────────────────── */
.ink-ornament {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  color: var(--amber);
  opacity: 0.3;
  line-height: 1;
  user-select: none;
}
