/* ================================
   SAM THE SPIDER — samspider.today
   Warm storybook aesthetic
   ================================ */

/* --- Design Tokens --- */
:root,
[data-theme='light'] {
  /* Storybook palette — warm cream + earthy brown + soft red accent */
  --color-bg:              #faf7f2;
  --color-surface:         #f5f0e8;
  --color-surface-2:       #ede6d8;
  --color-border:          #d9ceba;
  --color-divider:         #e4dccf;

  --color-text:            #2c2416;
  --color-text-muted:      #7a6f5e;
  --color-text-faint:      #b5a990;
  --color-text-inverse:    #faf7f2;

  --color-primary:         #c0392b;   /* Sam's red scarf */
  --color-primary-hover:   #96261e;
  --color-primary-active:  #701c16;
  --color-primary-highlight: #f5dbd8;

  --color-accent:          #8b6914;   /* warm gold */
  --color-accent-hover:    #6d5210;

  /* Character colors */
  --color-sam-brown:       #8b7355;
  --color-cream:           #faf7f2;
  --color-dark:            #2c2416;

  /* Type scale */
  --text-xs:   clamp(0.75rem,  0.7rem + 0.25vw, 0.875rem);
  --text-sm:   clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem,     0.95rem + 0.25vw, 1.125rem);
  --text-lg:   clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl:   clamp(1.5rem,   1.2rem + 1.25vw, 2.25rem);
  --text-2xl:  clamp(2rem,     1.2rem + 2.5vw, 3.5rem);
  --text-3xl:  clamp(2.5rem,   1rem + 4vw, 5rem);

  /* Spacing */
  --space-1:  0.25rem;
  --space-2:  0.5rem;
  --space-3:  0.75rem;
  --space-4:  1rem;
  --space-5:  1.25rem;
  --space-6:  1.5rem;
  --space-8:  2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;

  /* Fonts */
  --font-display: 'Boska', 'Georgia', serif;
  --font-body:    'Nunito', 'Helvetica Neue', sans-serif;

  /* Radius */
  --radius-sm:   0.375rem;
  --radius-md:   0.75rem;
  --radius-lg:   1.25rem;
  --radius-xl:   2rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px oklch(0.2 0.05 60 / 0.08);
  --shadow-md: 0 4px 16px oklch(0.2 0.05 60 / 0.12);
  --shadow-lg: 0 12px 40px oklch(0.2 0.05 60 / 0.16);

  /* Transition */
  --transition: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Content widths */
  --content-narrow:  640px;
  --content-default: 960px;
  --content-wide:    1200px;
}

[data-theme='dark'] {
  --color-bg:              #1a1610;
  --color-surface:         #221d15;
  --color-surface-2:       #2a2419;
  --color-border:          #3d3525;
  --color-divider:         #302a1e;

  --color-text:            #e8dfc8;
  --color-text-muted:      #9a8f7a;
  --color-text-faint:      #5e5648;
  --color-text-inverse:    #1a1610;

  --color-primary:         #e55b4d;
  --color-primary-hover:   #f27367;
  --color-primary-active:  #ff9088;
  --color-primary-highlight: #3d1e1a;

  --color-accent:          #d4a843;
  --color-accent-hover:    #e8c46a;

  --color-sam-brown:       #a08060;
  --color-cream:           #e8dfc8;
  --color-dark:            #1a1610;

  --shadow-sm: 0 1px 3px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 16px oklch(0 0 0 / 0.4);
  --shadow-lg: 0 12px 40px oklch(0 0 0 / 0.5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg:              #1a1610;
    --color-surface:         #221d15;
    --color-surface-2:       #2a2419;
    --color-border:          #3d3525;
    --color-divider:         #302a1e;
    --color-text:            #e8dfc8;
    --color-text-muted:      #9a8f7a;
    --color-text-faint:      #5e5648;
    --color-text-inverse:    #1a1610;
    --color-primary:         #e55b4d;
    --color-primary-hover:   #f27367;
    --color-primary-highlight: #3d1e1a;
    --color-accent:          #d4a843;
    --color-sam-brown:       #a08060;
    --color-cream:           #e8dfc8;
    --color-dark:            #1a1610;
  }
}

/* --- Base Reset --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  -webkit-font-smoothing: antialiased;
  scroll-behavior: smooth;
  scroll-padding-top: var(--space-16);
}
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}
img { display: block; max-width: 100%; height: auto; }
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-primary); }
h1,h2,h3,h4,h5,h6 { font-family: var(--font-display); line-height: 1.15; text-wrap: balance; }
p, li { text-wrap: pretty; max-width: 68ch; }

/* --- Header --- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-divider);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.header-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  padding: var(--space-4) var(--space-8);
  display: flex;
  align-items: center;
  gap: var(--space-6);
}
.logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}
.logo-svg { width: 40px; height: 40px; flex-shrink: 0; }
.logo-text {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
}
.header-nav {
  display: flex;
  gap: var(--space-6);
  margin-left: auto;
}
.header-nav a {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  transition: color var(--transition);
}
.header-nav a:hover { color: var(--color-primary); }
.theme-toggle {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover { background: var(--color-surface-2); color: var(--color-text); }

/* --- Hero --- */
.hero {
  padding: clamp(var(--space-12), 8vw, var(--space-24)) var(--space-8);
  background: linear-gradient(160deg, var(--color-surface) 0%, var(--color-bg) 60%);
  border-bottom: 1px solid var(--color-divider);
}
.hero-inner {
  max-width: var(--content-wide);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-16);
  align-items: center;
}
.hero-eyebrow {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: var(--space-4);
}
.hero-title {
  font-size: var(--text-3xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-6);
  line-height: 1.1;
}
.hero-title em {
  font-style: italic;
  color: var(--color-primary);
}
.hero-sub {
  font-size: var(--text-lg);
  color: var(--color-text-muted);
  margin-bottom: var(--space-8);
  line-height: 1.7;
}
.hero-poster {
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  margin-left: auto;
}
.hero-image { display: flex; justify-content: center; }

/* --- Buttons --- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-8);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 700;
  border-radius: var(--radius-full);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  border: none;
  cursor: pointer;
}
.btn-primary:hover {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--color-text-inverse);
}
.btn-primary:active { transform: translateY(0); }
.btn-hero {
  font-size: var(--text-lg);
  padding: var(--space-5) var(--space-12);
  box-shadow: var(--shadow-md);
}

/* --- Section Shared --- */
.section-inner {
  max-width: var(--content-default);
  margin: 0 auto;
  padding: clamp(var(--space-12), 8vw, var(--space-20)) var(--space-8);
}
.section-label {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-primary);
  margin-bottom: var(--space-3);
}
.section-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-10);
}

/* --- Story Section --- */
.story-section { background: var(--color-bg); }
.story-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-16);
  color: var(--color-text-muted);
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.story-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.story-poster {
  width: 100%;
  height: auto;
  display: block;
}
.story-body {
  padding: var(--space-10) var(--space-12);
}
.story-meta {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-6);
}
.story-episode {
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.story-location {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-inverse);
  background: var(--color-primary);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}
.story-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-4);
}
.story-summary {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  margin-bottom: var(--space-6);
  line-height: 1.7;
}
.story-characters {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-8);
}
.story-char-tag {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-accent);
  background: color-mix(in oklab, var(--color-accent) 12%, var(--color-surface));
  border: 1px solid color-mix(in oklab, var(--color-accent) 25%, transparent);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}
.story-moral {
  border-left: 3px solid var(--color-primary);
  padding: var(--space-4) var(--space-6);
  background: var(--color-primary-highlight);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: var(--space-6);
}
.story-moral-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-primary);
  margin-bottom: var(--space-1);
}
.story-moral-text {
  font-size: var(--text-base);
  font-style: italic;
  color: var(--color-text);
  max-width: none;
}
.story-read-link {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--space-5) var(--space-8);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  font-family: var(--font-body);
  font-size: var(--text-lg);
  font-weight: 700;
  border-radius: var(--radius-full);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  margin-bottom: var(--space-6);
  gap: var(--space-3);
}
.story-read-link:hover {
  background: var(--color-primary-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  color: var(--color-text-inverse);
}
.story-read-link::after { content: '→'; font-size: 1.2em; }
.story-reading-level {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-accent);
  background: color-mix(in oklab, var(--color-accent) 12%, var(--color-surface));
  border: 1px solid color-mix(in oklab, var(--color-accent) 25%, transparent);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
}
.story-tags {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-6);
}
.story-tag {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border);
}

/* --- Word & Fact --- */
.word-section, .fact-section {
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
}
.word-card, .fact-card {
  display: flex;
  align-items: flex-start;
  gap: var(--space-6);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-10);
  box-shadow: var(--shadow-sm);
}
.word-icon, .fact-icon { font-size: 2.5rem; flex-shrink: 0; line-height: 1; }
.word-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-3);
}
.word-def {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.7;
  max-width: none;
}
.fact-text {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.7;
  max-width: none;
}

/* --- Cast Grid --- */
.cast-section { background: var(--color-bg); border-top: 1px solid var(--color-divider); }
.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-6);
}
.cast-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.cast-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.cast-card img {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  object-position: top;
}
.cast-card h3 {
  font-size: var(--text-base);
  font-weight: 700;
  padding: var(--space-4) var(--space-5) var(--space-2);
  color: var(--color-text);
}
.cast-card p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  padding: 0 var(--space-5) var(--space-5);
  max-width: none;
  line-height: 1.6;
}

/* --- Map Section --- */
.map-section {
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
}
.map-placeholder {
  background: var(--color-bg);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-16) var(--space-12);
  text-align: center;
}
.map-pin-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}
.map-pin {
  width: 20px; height: 20px;
  background: var(--color-primary);
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: var(--shadow-md);
}
.map-location {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-weight: 700;
  color: var(--color-text);
  max-width: none;
}
.map-note {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: 48ch;
  margin: 0 auto;
}

/* --- Subscribe --- */
.subscribe-section {
  background: var(--color-primary);
  border-top: 1px solid var(--color-primary-hover);
}
.subscribe-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  flex-wrap: wrap;
}
.subscribe-text h2 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text-inverse);
  margin-bottom: var(--space-2);
}
.subscribe-text p {
  font-size: var(--text-base);
  color: color-mix(in oklab, var(--color-text-inverse) 75%, transparent);
  max-width: none;
}
.subscribe-actions { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
#push-btn {
  background: var(--color-text-inverse);
  color: var(--color-primary);
}
#push-btn:hover { background: var(--color-surface); color: var(--color-primary-hover); }
.subscribe-note {
  font-size: var(--text-xs);
  color: color-mix(in oklab, var(--color-text-inverse) 65%, transparent);
  max-width: none;
}

.header--scrolled {
  box-shadow: var(--shadow-sm);
}

/* --- Origin Section --- */
.origin-section {
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
}
.origin-inner {
  max-width: var(--content-narrow);
  text-align: center;
}
.origin-icon {
  margin-bottom: var(--space-6);
}
.origin-sam {
  width: 120px;
  height: 120px;
  object-fit: cover;
  object-position: top;
  border-radius: 50%;
  border: 3px solid var(--color-primary-highlight);
  box-shadow: var(--shadow-md);
  margin: 0 auto;
}
.origin-title {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-8);
  line-height: 1.2;
}
.origin-text p {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  line-height: 1.8;
  margin-bottom: var(--space-5);
  max-width: 58ch;
  margin-left: auto;
  margin-right: auto;
}
.origin-quote {
  font-family: var(--font-display);
  font-size: var(--text-lg);
  font-style: italic;
  color: var(--color-text);
  border-left: none;
  background: var(--color-primary-highlight);
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-8);
  margin: var(--space-8) auto;
  max-width: 52ch;
  line-height: 1.6;
}
.origin-quote strong {
  color: var(--color-primary);
  font-style: normal;
}
.origin-dedication {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--color-text-muted) !important;
  font-size: var(--text-base) !important;
  margin-top: var(--space-10) !important;
  padding-top: var(--space-8) !important;
  border-top: 1px solid var(--color-divider);
  line-height: 1.8;
}

/* --- Footer --- */
.site-footer {
  background: var(--color-surface);
  border-top: 1px solid var(--color-divider);
  padding: var(--space-12) var(--space-8);
}
.footer-inner {
  max-width: var(--content-default);
  margin: 0 auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.footer-story {
  font-family: var(--font-display);
  font-size: var(--text-base);
  font-style: italic;
  color: var(--color-text-muted);
  max-width: 52ch;
  margin: 0 auto;
  line-height: 1.7;
}
.footer-links {
  display: flex;
  justify-content: center;
  gap: var(--space-6);
  flex-wrap: wrap;
}
.footer-links a {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  font-weight: 600;
  transition: color var(--transition);
}
.footer-links a:hover { color: var(--color-primary); }
.footer-copy {
  font-size: var(--text-xs);
  color: var(--color-text-faint);
  max-width: none;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .hero-inner { grid-template-columns: 1fr; }
  .hero-image { order: -1; }
  .hero-poster { max-width: 320px; margin: 0 auto; }
  .header-nav { display: none; }
  .word-card, .fact-card { flex-direction: column; }
  .subscribe-inner { flex-direction: column; text-align: center; }
  .subscribe-actions { align-items: center; width: 100%; }
  .story-body { padding: var(--space-6) var(--space-6); }
}

@media (max-width: 480px) {
  .section-inner { padding-left: var(--space-5); padding-right: var(--space-5); }
  .header-inner { padding: var(--space-3) var(--space-5); }
  .cast-grid { grid-template-columns: 1fr 1fr; }
}

/* --- iOS Prompt Modal --- */
#ios-prompt {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.ios-prompt-box {
  background: var(--color-bg);
  border-radius: var(--radius-xl) var(--radius-xl) var(--radius-lg) var(--radius-lg);
  padding: var(--space-8) var(--space-8) var(--space-10);
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.ios-prompt-sam {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto var(--space-4);
  display: block;
}
.ios-prompt-box h3 {
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: var(--space-3);
}
.ios-prompt-box p {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
  max-width: none;
}
.ios-prompt-box ol {
  text-align: left;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  line-height: 1.8;
  padding-left: var(--space-6);
  margin-bottom: var(--space-8);
}
.ios-prompt-box ol li { max-width: none; }
.ios-prompt-box ol strong { color: var(--color-text); }
.ios-share-icon {
  font-size: 1.1em;
  color: var(--color-primary);
}
.ios-prompt-box .btn-primary { width: 100%; justify-content: center; }

/* --- Reduced motion --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
