/* ─────────────────────────────────────────────
   myrddin.ai — a wizard's workshop
   ───────────────────────────────────────────── */

:root {
  --bg:        #f4efe4;
  --bg-warm:   #ece4d0;
  --ink:       #1a1625;
  --ink-soft:  #3a3448;
  --muted:     #6b6478;
  --line:      rgba(26, 22, 37, 0.12);

  --purple:    #6b3fa0;
  --gold:      #d4a017;
  --btc:       #f7931a;
  --cyan:      #00b8d9;
  --pink:      #ff5a8a;
  --green:     #3aa76d;

  --font-serif: 'Fraunces', 'Georgia', serif;
  --font-sans:  'Inter', system-ui, -apple-system, sans-serif;
  --font-mono:  'JetBrains Mono', ui-monospace, 'SF Mono', monospace;

  --radius:    18px;
  --shadow-sm: 0 2px 8px rgba(26, 22, 37, 0.06);
  --shadow-md: 0 8px 24px rgba(26, 22, 37, 0.10);
  --shadow-lg: 0 24px 60px rgba(26, 22, 37, 0.16);
}

/* Dark theme — applied via OS preference OR manual [data-theme="dark"] */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:       #14111c;
    --bg-warm:  #1c1828;
    --ink:      #f2ece0;
    --ink-soft: #d4ccbc;
    --muted:    #8b8398;
    --line:     rgba(242, 236, 224, 0.10);
  }
}
:root[data-theme="dark"] {
  --bg:       #14111c;
  --bg-warm:  #1c1828;
  --ink:      #f2ece0;
  --ink-soft: #d4ccbc;
  --muted:    #8b8398;
  --line:     rgba(242, 236, 224, 0.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

body {
  line-height: 1.55;
  font-size: 17px;
}

a { color: inherit; text-decoration: none; }

em { font-style: italic; font-family: var(--font-serif); font-weight: 500; }

/* subtle paper grain overlay */
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 100;
  opacity: 0.35;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.1  0 0 0 0 0.09  0 0 0 0 0.14  0 0 0 0.35 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .grain { mix-blend-mode: screen; opacity: 0.15; }
}
:root[data-theme="dark"] .grain { mix-blend-mode: screen; opacity: 0.15; }

/* ─── Header ─────────────────────────────────── */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 40px;
  backdrop-filter: blur(12px) saturate(1.2);
  -webkit-backdrop-filter: blur(12px) saturate(1.2);
  background: color-mix(in oklab, var(--bg) 78%, transparent);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.brand-mark {
  color: var(--gold);
  animation: spin 12s linear infinite;
  display: inline-block;
}
.brand-tld {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 400;
}

.nav {
  display: flex;
  gap: 28px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--ink-soft);
}
.nav a {
  position: relative;
  padding: 4px 0;
  transition: color 0.2s;
}
.nav a::after {
  content: '';
  position: absolute;
  left: 0; bottom: 0;
  width: 0; height: 1.5px;
  background: var(--purple);
  transition: width 0.25s ease;
}
.nav a:hover { color: var(--ink); }
.nav a:hover::after { width: 100%; }

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

/* ─── Hero ───────────────────────────────────── */

.hero {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: center;
  padding: 60px 40px 100px;
  max-width: 1280px;
  margin: 0 auto;
  min-height: calc(100vh - 80px);
}

.hero-copy { max-width: 520px; }

.eyebrow {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.02em;
  text-transform: lowercase;
  margin: 0 0 20px;
}
.blink { animation: blink 1.1s steps(1) infinite; color: var(--purple); }
@keyframes blink { 50% { opacity: 0; } }

h1 {
  font-family: var(--font-serif);
  font-size: clamp(44px, 6vw, 78px);
  font-weight: 600;
  line-height: 1.02;
  letter-spacing: -0.025em;
  margin: 0 0 28px;
}

.grad {
  background: linear-gradient(120deg, var(--purple) 0%, var(--btc) 55%, var(--gold) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-style: italic;
}

.lede {
  font-size: 18px;
  color: var(--ink-soft);
  max-width: 460px;
  margin: 0;
}

/* Stage: wizard + runes */
.stage {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  user-select: none;
}

.aura {
  position: absolute;
  inset: 15%;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in oklab, var(--purple) 30%, transparent) 0%, transparent 70%);
  transition: background 0.5s ease, transform 0.4s ease;
  pointer-events: none;
  filter: blur(4px);
}
.stage.charged .aura {
  transform: scale(1.15);
  animation: pulse 1.4s ease-out;
}
@keyframes pulse {
  0%   { transform: scale(1); opacity: 1; }
  50%  { transform: scale(1.25); opacity: 0.85; }
  100% { transform: scale(1.15); opacity: 1; }
}

.wizard {
  position: absolute;
  inset: 10% 15%;
  width: 70%;
  height: auto;
  filter: drop-shadow(0 12px 24px rgba(26, 22, 37, 0.18));
  animation: float 5s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-8px); }
}
.stage.charged .wizard { animation-duration: 2s; }

.wizard .eyes .pupil { transition: transform 0.15s ease-out; }

.bubble {
  position: absolute;
  top: 8%;
  right: -4%;
  background: var(--ink);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  white-space: nowrap;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(6px) scale(0.95);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
  z-index: 5;
}
.bubble::after {
  content: '';
  position: absolute;
  left: 20px;
  bottom: -6px;
  width: 12px; height: 12px;
  background: var(--ink);
  transform: rotate(45deg);
  border-radius: 2px;
}
.bubble.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* Runes */
.rune {
  position: absolute;
  left: var(--x);
  top: var(--y);
  transform: translate(-50%, -50%);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
  background: var(--bg-warm);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  touch-action: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s;
  z-index: 3;
}
.rune:hover {
  transform: translate(-50%, -50%) scale(1.08) rotate(-2deg);
  box-shadow: var(--shadow-md);
  background: var(--bg);
}
.rune.dragging {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: var(--shadow-lg);
  z-index: 20;
  transition: none;
}
.rune .glyph {
  font-family: var(--font-serif);
  font-size: 22px;
  line-height: 1;
  font-weight: 600;
}
.rune[data-key="ai"]   .glyph { color: var(--cyan); }
.rune[data-key="btc"]  .glyph { color: var(--btc); }
.rune[data-key="code"] .glyph { color: var(--purple); font-family: var(--font-mono); font-size: 18px; }
.rune[data-key="game"] .glyph { color: var(--green); }
.rune[data-key="rock"] .glyph { color: var(--pink); font-size: 18px; }
.rune .label {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ─── Sections ───────────────────────────────── */

.section {
  padding: 100px 40px;
  max-width: 1180px;
  margin: 0 auto;
  border-top: 1px solid var(--line);
}

.section-head { margin-bottom: 48px; }
.section-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}
.section h2 {
  font-family: var(--font-serif);
  font-size: clamp(34px, 4.5vw, 52px);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.05;
}

/* Cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.card {
  position: relative;
  display: block;
  background: var(--bg-warm);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  isolation: isolate;
}
.card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-lg);
}
.card:hover .card-glow { opacity: 0.6; }

.card-top {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: color-mix(in oklab, var(--ink) 90%, transparent);
  color: var(--bg);
  font-family: var(--font-mono);
  font-size: 12px;
}
.card-host { margin-left: 12px; color: rgba(255,255,255,0.7); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-r { background: #ff5f57; }
.dot-y { background: #febc2e; }
.dot-g { background: #28c840; }

/* Pixel-art scene above each card body */
.pixel-scene {
  position: relative;
  height: 110px;
  background:
    linear-gradient(180deg,
      color-mix(in oklab, var(--bg-warm) 40%, transparent) 0%,
      transparent 100%);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  color: var(--ink);
}
.pixel-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  shape-rendering: crispEdges;
}

/* Bug scene */
.scene-bug .bug {
  transform-origin: center;
  animation: bugScuttle 6s ease-in-out infinite;
}
.scene-bug .bug-eyes {
  animation: bugBlink 3.2s steps(1) infinite;
  transform-origin: center;
}
@keyframes bugScuttle {
  0%   { transform: translateX(0)   scaleX(1); }
  40%  { transform: translateX(14px) scaleX(1); }
  45%  { transform: translateX(14px) scaleX(-1); }
  85%  { transform: translateX(-2px) scaleX(-1); }
  90%  { transform: translateX(-2px) scaleX(1); }
  100% { transform: translateX(0)   scaleX(1); }
}
@keyframes bugBlink {
  0%, 92%  { opacity: 1; }
  94%, 98% { opacity: 0; }
  100%     { opacity: 1; }
}

/* Nodes scene */
.scene-nodes .node {
  transform-origin: center;
  animation: nodePulse 2.4s ease-in-out infinite;
}
.scene-nodes .node-2 { animation-delay: 0.4s; }
.scene-nodes .node-3 { animation-delay: 0.8s; }
.scene-nodes .link { animation: linkFlicker 2.4s ease-in-out infinite; }
.scene-nodes .link-b { animation-delay: 0.4s; }
.scene-nodes .link-c { animation-delay: 0.8s; }
@keyframes nodePulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(1.25); opacity: 0.85; }
}
@keyframes linkFlicker {
  0%, 100% { opacity: 0.25; }
  50%      { opacity: 0.9; }
}

/* Robot scene */
.scene-robot .robot-eyes { animation: robotBlink 3.6s steps(1) infinite; }
.scene-robot .antenna    { transform-origin: 16px 3px; animation: antennaWobble 2.6s ease-in-out infinite; }
.scene-robot .signal rect { animation: signalPulse 1.6s ease-in-out infinite; }
.scene-robot .signal rect:nth-child(2) { animation-delay: 0.4s; }
.scene-robot .chest-light rect { animation: chestBlink 1.4s ease-in-out infinite; }
@keyframes robotBlink {
  0%, 88%  { opacity: 1; }
  90%, 96% { opacity: 0; }
  100%     { opacity: 1; }
}
@keyframes antennaWobble {
  0%, 100% { transform: rotate(-8deg); }
  50%      { transform: rotate(8deg); }
}
@keyframes signalPulse {
  0%, 100% { opacity: 0; }
  50%      { opacity: 1; }
}
@keyframes chestBlink {
  0%, 100% { opacity: 0.35; }
  50%      { opacity: 1; }
}

.card-body { padding: 32px 28px 36px; }
.card-body h3 {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 600;
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}
.card-body p {
  margin: 0 0 20px;
  color: var(--ink-soft);
}
.card-cta {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--purple);
  font-weight: 500;
}

.card-glow {
  position: absolute;
  inset: -40%;
  background: radial-gradient(circle at 30% 20%, var(--glow, var(--purple)) 0%, transparent 55%);
  opacity: 0;
  transition: opacity 0.4s;
  z-index: -1;
  filter: blur(30px);
}

/* Pills */
.pills {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.pills li {
  padding: 14px 20px;
  background: var(--bg-warm);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 15px;
  transition: transform 0.2s, background 0.2s;
  cursor: default;
}
.pills li:hover {
  transform: translateY(-3px) rotate(-1deg);
  background: var(--bg);
  border-color: var(--purple);
}

/* About */
.about-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  align-items: start;
}
.about-copy p {
  font-size: 18px;
  color: var(--ink-soft);
  margin: 0 0 20px;
}
.about-copy p:last-child { margin: 0; }

.dropcap {
  font-family: var(--font-serif);
  font-size: 56px;
  font-weight: 700;
  float: left;
  line-height: 0.9;
  padding: 6px 10px 0 0;
  color: var(--purple);
}

/* Terminal */
.terminal {
  background: #0f0c17;
  border-radius: var(--radius);
  overflow: hidden;
  font-family: var(--font-mono);
  font-size: 13px;
  box-shadow: var(--shadow-md);
}
.terminal-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #1a1524;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.terminal-title {
  margin-left: 12px;
  color: rgba(255,255,255,0.5);
  font-size: 12px;
}
.terminal pre {
  margin: 0;
  padding: 20px 22px;
  color: #d4ccbc;
  line-height: 1.7;
  white-space: pre-wrap;
}
.c-dim { color: #6b6478; }
.c-out { color: #d4a017; }

/* Signal */
.signal { text-align: center; }
.signal .section-head { text-align: left; }
.signal-line {
  font-size: 20px;
  color: var(--ink-soft);
  max-width: 640px;
  margin: 0 auto 36px;
}
.signal-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn {
  display: inline-block;
  padding: 14px 26px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 14px;
  transition: transform 0.2s, box-shadow 0.2s;
}
.btn.primary {
  background: var(--ink);
  color: var(--bg);
}
.btn.primary:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.btn.ghost {
  border: 1px solid var(--line);
  color: var(--ink-soft);
}
.btn.ghost:hover { border-color: var(--purple); color: var(--ink); }

/* Footer */
.site-footer {
  padding: 40px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
  gap: 12px;
}
.footer-sep { margin: 0 10px; }
.footer-mono { font-family: var(--font-mono); }

/* ─── Theme toggle ───────────────────────────── */

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  margin-left: 6px;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--ink-soft);
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 15px;
  line-height: 1;
  transition: color 0.2s, border-color 0.2s, transform 0.2s;
}
.theme-toggle:hover {
  color: var(--ink);
  border-color: var(--purple);
  transform: rotate(-15deg);
}
.theme-icon { display: none; }

/* Default (light theme): show moon, meaning "click to go dark" */
.theme-icon-moon { display: inline; }

/* Dark theme (via OS or manual): show sun */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-icon-moon { display: none; }
  :root:not([data-theme="light"]) .theme-icon-sun  { display: inline; }
}
:root[data-theme="dark"] .theme-icon-moon { display: none; }
:root[data-theme="dark"] .theme-icon-sun  { display: inline; }
/* Explicit light override wins */
:root[data-theme="light"] .theme-icon-sun  { display: none; }
:root[data-theme="light"] .theme-icon-moon { display: inline; }

/* ─── Responsive ─────────────────────────────── */

@media (max-width: 900px) {
  .site-header { padding: 16px 20px; }
  .nav { gap: 18px; font-size: 13px; }
  .hero {
    grid-template-columns: 1fr;
    padding: 40px 20px 60px;
    gap: 20px;
    min-height: auto;
  }
  .hero-copy { text-align: center; margin: 0 auto; }
  .lede { margin: 0 auto; }
  .stage { max-width: 420px; }
  .section { padding: 70px 20px; }
  .about-grid { grid-template-columns: 1fr; }
  .site-footer { padding: 24px 20px; text-align: center; justify-content: center; }
}

@media (max-width: 480px) {
  h1 { font-size: 40px; }
  .rune { padding: 8px 10px; }
  .rune .glyph { font-size: 18px; }
  .rune .label { font-size: 10px; }
  .bubble { font-size: 12px; padding: 8px 12px; }
}

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