/* ═══════════════════════════════════════════════
   BASE — Reset, body, typography
   ═══════════════════════════════════════════════ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overflow-y: scroll;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-faint) var(--paper-edge);
}

/* ═══════════════════════════════════════════════
   SCROLLBAR — Theme-aware via design tokens (PO06)
   Tokens auto-swap per theme; no data-theme overrides needed.
   See docs/polish/SCROLLBAR_SPEC.md.
   ═══════════════════════════════════════════════ */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--paper-edge);
}

::-webkit-scrollbar-thumb {
  background: var(--ink-faint);
  border-radius: 9999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink-soft);
}

body {
  font-family: var(--font-base);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

h1, h2, h3 {
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}

p {
  line-height: 1.6;
  color: var(--text-muted);
}

input[type="text"] {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: var(--font-base);
  background: var(--bg-surface);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}

input[type="text"]:focus {
  border-color: var(--color-primary);
}

input[type="text"]::placeholder {
  color: var(--text-faint);
}

button {
  font-family: var(--font-base);
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

/* ═══════════════════════════════════════════════
   MIXTAPE TEXTURE + STRIPE (Step 5)
   Per spec §5 (motion) and §6 (components).
   Level 3 texture = grain + drifting warmth glow + drifting motifs.
   Per-theme motif SVG variants are a Step 10 task (Phase 2).
   ═══════════════════════════════════════════════ */

/* Stripe — 5px at top of page, desktop only.
   On mobile the stripe lives on the bottom-nav per spec §9 (M3 / position C).
   Sits on body::before so it's outside any overflow:hidden container. */
@media (min-width: 768px) {
  body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 5px;
    background: linear-gradient(90deg,
      var(--red) 0 33%,
      var(--yellow) 33% 66%,
      var(--blue) 66% 100%);
    z-index: 200;
    pointer-events: none;
  }
}

/* Ambient texture layer — grain + drifting warmth + drifting motifs.
   Fixed-position, covers the viewport, behind all app content.
   --side-motif-svg is the per-theme drifting motif pattern (Step 10).
   Side A default lives here; Side B override is below. */
.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='220' height='220'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.16  0 0 0 0 0.12  0 0 0 0 0.10  0 0 0 0.08 0'/></filter><rect width='220' height='220' filter='url(%23n)'/></svg>");
  background-size: 260px 260px;
  --side-motif-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'><g fill='none' stroke-width='1'><path d='M50 60 l4 -6 l2 6 l6 2 l-6 2 l-2 6 l-4 -6 l-6 -2 z' fill='%23C3342B' opacity='0.45'/><circle cx='160' cy='120' r='1.8' fill='%234F6C8E' opacity='0.55'/><path d='M280 95 q4 -6 8 0 q4 6 8 0' stroke='%23C3342B' opacity='0.35'/><circle cx='360' cy='180' r='1.5' fill='%23E8B33A' opacity='0.7'/><path d='M90 240 l3 -5 l1.5 5 l5 1.5 l-5 1.5 l-1.5 5 l-3 -5 l-5 -1.5 z' fill='%23E8B33A' opacity='0.4'/><circle cx='220' cy='280' r='2' fill='%23C3342B' opacity='0.35'/><path d='M320 310 q5 -7 10 0 q5 7 10 0' stroke='%234F6C8E' opacity='0.4'/><circle cx='80' cy='360' r='1.4' fill='%234F6C8E' opacity='0.5'/><path d='M190 380 l3 -5 l1.5 5 l5 1.5 l-5 1.5 l-1.5 5 l-3 -5 l-5 -1.5 z' fill='%23C3342B' opacity='0.3'/></g></svg>");
}

/* Side B motif: salmon + teal + yellow, tuned to read on maroon. */
[data-theme="side-b"] .ambient {
  --side-motif-svg: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'><g fill='none' stroke-width='1'><path d='M50 60 l4 -6 l2 6 l6 2 l-6 2 l-2 6 l-4 -6 l-6 -2 z' fill='%23F07A5E' opacity='0.45'/><circle cx='160' cy='120' r='1.8' fill='%235EAAA8' opacity='0.55'/><path d='M280 95 q4 -6 8 0 q4 6 8 0' stroke='%23F07A5E' opacity='0.35'/><circle cx='360' cy='180' r='1.5' fill='%23E8B33A' opacity='0.7'/><path d='M90 240 l3 -5 l1.5 5 l5 1.5 l-5 1.5 l-1.5 5 l-3 -5 l-5 -1.5 z' fill='%23E8B33A' opacity='0.4'/><circle cx='220' cy='280' r='2' fill='%23F07A5E' opacity='0.35'/><path d='M320 310 q5 -7 10 0 q5 7 10 0' stroke='%235EAAA8' opacity='0.4'/><circle cx='80' cy='360' r='1.4' fill='%235EAAA8' opacity='0.5'/><path d='M190 380 l3 -5 l1.5 5 l5 1.5 l-5 1.5 l-1.5 5 l-3 -5 l-5 -1.5 z' fill='%23F07A5E' opacity='0.3'/></g></svg>");
}

/* Warmth glow — radial gradients drifting 55s per spec §5. */
.ambient::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    radial-gradient(40% 35% at 22% 30%, rgba(232, 179, 58, 0.22), transparent 70%),
    radial-gradient(50% 40% at 78% 72%, rgba(195, 52, 43, 0.14), transparent 70%),
    radial-gradient(35% 30% at 55% 10%, rgba(79, 108, 142, 0.10), transparent 70%);
  animation: drift-warmth 55s ease-in-out infinite alternate;
  filter: blur(10px);
  pointer-events: none;
}

/* Drifting motif pattern — stars, dots, squiggles.
   Palette comes from --side-motif-svg (defined on .ambient above). */
.ambient::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background-image: var(--side-motif-svg);
  background-size: 420px 420px;
  animation: drift-motifs 70s linear infinite;
  pointer-events: none;
}

/* Keep screens above the ambient texture layer. */
#login-screen,
#app-screen {
  position: relative;
  z-index: 1;
}

@keyframes drift-warmth {
  0%   { transform: translate(0, 0) rotate(0deg); }
  50%  { transform: translate(2%, -2%) rotate(1deg); }
  100% { transform: translate(-1%, 1%) rotate(-0.5deg); }
}

@keyframes drift-motifs {
  from { background-position: 0 0; }
  to   { background-position: -420px -420px; }
}

@media (prefers-reduced-motion: reduce) {
  .ambient::before,
  .ambient::after {
    animation: none !important;
  }
}