/* ==========================================================================
   base.css — tokens, resets, typography, utilities, accessibility
   “Curated clutter, maximalist clarity.”
   ========================================================================== */

/* ------------------------------
   Design tokens
------------------------------ */
:root {
  /* Type */
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Apple Color Emoji",
    "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --fs-00: 0.8125rem; /* 13 */
  --fs-0: 0.9375rem;  /* 15 */
  --fs-1: 1.0625rem;  /* 17 */
  --fs-2: 1.25rem;    /* 20 */
  --fs-3: 1.5rem;     /* 24 */
  --fs-4: 1.875rem;   /* 30 */

  --lh-tight: 1.2;
  --lh-base: 1.55;

  /* Spacing */
  --space-1: 0.25rem;  /* 4 */
  --space-2: 0.5rem;   /* 8 */
  --space-3: 0.75rem;  /* 12 */
  --space-4: 1rem;     /* 16 */
  --space-5: 1.25rem;  /* 20 */
  --space-6: 1.5rem;   /* 24 */
  --space-7: 2rem;     /* 32 */
  --space-8: 2.5rem;   /* 40 */
  --space-9: 3rem;     /* 48 */

  /* Radii */
  --r-1: 8px;
  --r-2: 12px;
  --r-3: 18px;

  /* Lines/shadows */
  --line: 2px;

  /* Slightly stronger borders for “framed modules” */
  --border: rgba(40, 32, 28, 0.28);
  --border-strong: rgba(40, 32, 28, 0.44);

  --shadow-1: 0 1px 0 rgba(0,0,0,0.10), 0 10px 22px rgba(0,0,0,0.08);
  --shadow-2: 0 2px 0 rgba(0,0,0,0.12), 0 18px 40px rgba(0,0,0,0.12);

  /* Motion */
  --ease: cubic-bezier(.2,.8,.2,1);
  --dur-1: 120ms;
  --dur-2: 220ms;

  /* Page width */
  --max: 1120px;

  /* Default theme (overridden by body theme classes) */
  /* Deeper wall tone + brighter “paper” = more layered look */
  --bg: #fbf3ea;
  --bg-2: #e9d6c7;
  --paper: rgba(255, 255, 255, 0.88);

  --ink: #1f1713;
  --ink-2: rgba(31, 23, 19, 0.82);
  --muted: rgba(31, 23, 19, 0.64);

  /* Slightly richer accents */
  --accent: #c03a71;   /* rose */
  --accent-2: #23878f; /* teal */
  --accent-3: #b18616; /* brass */
  --glow: rgba(192, 58, 113, 0.20);

  --link: #1b5a86;
  --link-hover: #c03a71;

  --focus: #1b5a86;
  --focus-bg: rgba(27, 90, 134, 0.16);

  /* Backdrop texture (kept from your edit) */
  --tile: url("../../images/ui/bg-tile-1x1.jpg");
  --noise: radial-gradient(circle at 10% 10%, rgba(0,0,0,0.035), transparent 50%),
           radial-gradient(circle at 90% 30%, rgba(0,0,0,0.03), transparent 45%),
           radial-gradient(circle at 30% 90%, rgba(0,0,0,0.025), transparent 55%);

  /* NEW: gentle “room light” wash (very subtle) */
  --wash: radial-gradient(circle at 30% 0%, rgba(192, 58, 113, 0.10), transparent 55%),
          radial-gradient(circle at 85% 20%, rgba(35, 135, 143, 0.10), transparent 55%),
          linear-gradient(180deg, rgba(255,255,255,0.10), rgba(0,0,0,0.05));
}

/* ------------------------------
   Themes (swap by body class)
------------------------------ */
body.theme-cozy-chaos {
  /* Warmer parlor */
  --bg: #fbf3ea;
  --bg-2: #e6cfbe;
  --paper: rgba(255, 255, 255, 0.90);

  --ink: #201713;
  --ink-2: rgba(32, 23, 19, 0.84);
  --muted: rgba(32, 23, 19, 0.66);

  --accent: #c03a71;
  --accent-2: #23878f;
  --accent-3: #b18616;
  --glow: rgba(192, 58, 113, 0.22);

  --link: #1b5a86;
  --link-hover: #c03a71;

  --focus: #1b5a86;

  --wash: radial-gradient(circle at 30% 0%, rgba(192, 58, 113, 0.12), transparent 55%),
          radial-gradient(circle at 85% 20%, rgba(35, 135, 143, 0.10), transparent 55%),
          linear-gradient(180deg, rgba(255,255,255,0.12), rgba(0,0,0,0.05));
}

body.theme-night-lamp {
  /* Moody lamp lounge */
  --bg: #141216;
  --bg-2: #1c1920;
  --paper: rgba(28, 25, 32, 0.82);

  --ink: #f3ebe0;
  --ink-2: rgba(243, 235, 224, 0.84);
  --muted: rgba(243, 235, 224, 0.64);

  --border: rgba(243, 235, 224, 0.18);
  --border-strong: rgba(243, 235, 224, 0.30);

  --accent: #ff4f8d;
  --accent-2: #52c7c2;
  --accent-3: #f2c14e;
  --glow: rgba(255, 79, 141, 0.26);

  --link: #86c7ff;
  --link-hover: #ff4f8d;

  --focus: #86c7ff;
  --focus-bg: rgba(134, 199, 255, 0.18);

  --wash: radial-gradient(circle at 30% 0%, rgba(255, 79, 141, 0.14), transparent 55%),
          radial-gradient(circle at 85% 20%, rgba(82, 199, 194, 0.12), transparent 55%),
          linear-gradient(180deg, rgba(255,255,255,0.06), rgba(0,0,0,0.20));
}

body.theme-morning-linen {
  /* Bright, friendly daylight */
  --bg: #f6f0e6;
  --bg-2: #e0d2c2;
  --paper: rgba(255, 255, 255, 0.92);

  --ink: #201c18;
  --ink-2: rgba(32, 28, 24, 0.82);
  --muted: rgba(32, 28, 24, 0.62);

  --accent: #7c3aed;
  --accent-2: #0f766e;
  --accent-3: #a16207;
  --glow: rgba(124, 58, 237, 0.16);

  --link: #0f4c81;
  --link-hover: #7c3aed;

  --focus: #0f4c81;

  --wash: radial-gradient(circle at 30% 0%, rgba(124, 58, 237, 0.10), transparent 55%),
          radial-gradient(circle at 85% 20%, rgba(15, 118, 110, 0.10), transparent 55%),
          linear-gradient(180deg, rgba(255,255,255,0.12), rgba(0,0,0,0.04));
}

/* ------------------------------
   Reset-ish
------------------------------ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body.theme-night-lamp {
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-1);
  line-height: var(--lh-base);
  color: var(--ink);

  /* Kept from your edit: wallpaper tile is a real layer */
  background:
    var(--noise),
    var(--tile),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);

  background-size:
    auto,
    320px 320px,
    cover;

  background-repeat:
    repeat,
    repeat,
    no-repeat;

  background-attachment: fixed;
}

/* Subtle paper + sticker-bomb vibe without heavy images */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;

  /* Your wallpaper tile is large; don’t shrink it to 120px */
  opacity: 0.55;
  background-image: var(--tile);
  background-size: 1024px 1024px;
  background-repeat: repeat;
  background-position: 0 0;

  /* Multiply can “erase” pale florals; normal keeps them visible */
  mix-blend-mode: normal;
}

/* NEW: gentle “room light” wash that sits above wallpaper */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: var(--wash);
  opacity: 0.55;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
  display: block;
}

img {
  border-radius: calc(var(--r-1) - 2px);
}

a {
  color: var(--link);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.18em;
  transition: color var(--dur-2) var(--ease), background-color var(--dur-2) var(--ease);
}

a:hover {
  color: var(--link-hover);
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
  border-radius: var(--r-1);
}

::selection {
  background: var(--focus-bg);
}

hr {
  border: none;
  border-top: 1px dashed var(--border-strong);
  margin: var(--space-5) 0;
}

/* ------------------------------
   Type hierarchy
------------------------------ */
h1, h2, h3 {
  line-height: var(--lh-tight);
  margin: 0;
}

p {
  margin: 0 0 var(--space-4);
}

ul, ol {
  margin: 0 0 var(--space-4);
  padding-left: 1.2em;
}

code, pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
}

pre.code,
pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  padding: var(--space-4);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.22);
}

body.theme-night-lamp pre.code,
body.theme-night-lamp pre {
  background: rgba(255,255,255,0.06);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08);
}

/* ------------------------------
   Icons
------------------------------ */
.icon {
  display: inline-block;
  vertical-align: -0.12em;
  fill: currentColor;
}

/* ------------------------------
   Accessibility helpers
------------------------------ */
.skip-link {
  position: absolute;
  left: var(--space-4);
  top: var(--space-4);
  transform: translateY(-150%);
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border-strong);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--r-2);
  box-shadow: var(--shadow-1);
  z-index: 999;
}

.skip-link:focus {
  transform: translateY(0);
}

/* ------------------------------
   Utilities
------------------------------ */
.tiny { font-size: var(--fs-00); }
.dim  { color: var(--muted); }
.kbd  { font-family: var(--font-mono); font-size: 0.92em; padding: 0.1em 0.4em; border: 1px solid var(--border); border-radius: 6px; background: rgba(0,0,0,0.03); }

.btn,
.toy-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: linear-gradient(180deg, rgba(255,255,255,0.82), rgba(255,255,255,0.56));
  color: var(--ink);
  border-radius: var(--r-2);
  padding: 0.5rem 0.75rem;
  font: inherit;
  cursor: pointer;
  box-shadow: var(--shadow-1);
  transition: transform var(--dur-1) var(--ease), box-shadow var(--dur-1) var(--ease), background-color var(--dur-2) var(--ease);
}

body.theme-night-lamp .btn,
body.theme-night-lamp .toy-btn {
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.07));
}

.btn:hover,
.toy-btn:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-2);
}

.btn[disabled],
.toy-btn[disabled],
[aria-disabled="true"] {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

/* Aspect ratios for your AI-friendly image pipeline */
.ratio-1x1  { aspect-ratio: 1 / 1; }
.ratio-16x9 { aspect-ratio: 16 / 9; }
.ratio-9x16 { aspect-ratio: 9 / 16; }
.ratio-4x3  { aspect-ratio: 4 / 3; }
.ratio-3x4  { aspect-ratio: 3 / 4; }

.media,
.card-media,
.micro-img,
.avatar {
  border: 1px solid var(--border);
  border-radius: var(--r-2);
  overflow: hidden;
  background: rgba(255,255,255,0.40);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.20);
}

body.theme-night-lamp .media,
body.theme-night-lamp .card-media,
body.theme-night-lamp .micro-img,
body.theme-night-lamp .avatar {
  background: rgba(255,255,255,0.06);
}

.media img,
.card-media img,
.micro-img img,
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  a, .btn, .toy-btn { transition: none !important; }
  .btn:hover, .toy-btn:hover { transform: none; }
}