@import url('https://fonts.googleapis.com/css2?family=Gilda+Display&family=Hanken+Grotesk:wght@400;500;600;700&family=Tiro+Devanagari+Sanskrit&display=swap');

/* =========================================================
   Learning about Home - "Temple Stone" theme
   Layers (low -> high): tokens, base, type, motion, surfaces,
   controls, shell, bento, utilities.
   Existing token + class names are preserved so every page
   (path, prayer bank, mandir finder, lessons) re-themes at once.
   Page-level <style> blocks are unlayered and still win.
========================================================= */
@layer tokens, base, type, motion, surfaces, controls, shell, bento, utilities;

/* ---------- 1. Tokens ---------- */
@layer tokens {
  :root {
    --stone-950: #0F0D14;
    --stone-900: #16131D;
    --stone-800: #1F1B28;
    --stone-700: #2B2635;
    --stone-line: rgba(232, 182, 90, 0.14);

    --ghee: #E8B65A;
    --saffron-glow: #F08A24;
    --turmeric: #E9A81C;
    --terracotta: #B4532A;
    --ember: #7A2E14;

    /* legacy names -> new values */
    --bg: var(--stone-950);
    --bg-alt: var(--stone-900);
    --surface: var(--stone-800);
    --surface-raised: var(--stone-700);
    --border: #3A3346;
    --saffron: #F08A24;
    --saffron-dark: #B4532A;
    --gold: #E8B65A;
    --marigold: #E9A81C;
    --maroon: #A6334F;
    --cream: #F3E8D4;
    --text: #F3E8D4;
    --text-dim: #B9AC98;
    --text-faint: #7B7167;

    --satya: #E6D6A6;   --satya-deep: #7F7140;
    --shiva: #C3D0DE;   --shiva-deep: #3F5866;
    --treta: #DB6A52;   --treta-deep: #8E3724;
    --dvapara: #DDAA2E; --dvapara-deep: #84651A;
    --kali: #C4473A;    --kali-deep: #6A1D1B;
    --why: #F0BE72;     --why-deep: #8A5A1E;
    --rivers: #84C4D2;  --rivers-deep: #2A6877;

    --radius: 26px;
    --radius-sm: 12px;
    --radius-tile: 30px 30px 30px 8px;
    --shadow-lift: 0 18px 40px -18px rgba(0, 0, 0, .7);

    --font-display: 'Gilda Display', 'Tiro Devanagari Sanskrit', serif;
    --font-body: 'Hanken Grotesk', system-ui, sans-serif;
    --font-sanskrit: 'Tiro Devanagari Sanskrit', serif;

    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --spring: linear(0, 0.42 6%, 0.94 15%, 1.12 24%, 1.05 33%, 0.98 45%, 1.01 62%, 1);
    --dur-1: 160ms; --dur-2: 320ms; --dur-3: 640ms;
  }
}

/* ---------- 2. Base ---------- */
@layer base {
  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: var(--font-body); -webkit-font-smoothing: antialiased; }
  body {
    min-height: 100vh; overflow-x: hidden;
    background-image:
      radial-gradient(60% 40% at 12% 0%, rgba(240,138,36,.12), transparent 70%),
      radial-gradient(50% 45% at 100% 100%, rgba(180,83,42,.14), transparent 70%),
      linear-gradient(180deg, var(--stone-950), var(--stone-900));
    background-attachment: fixed;
  }
  body::before {
    content: ''; position: fixed; inset: 0; z-index: 999; pointer-events: none; opacity: .07; mix-blend-mode: overlay;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  }
  a { color: inherit; text-decoration: none; }
  button { font-family: inherit; cursor: pointer; }
  :focus-visible { outline: 2px solid var(--ghee); outline-offset: 3px; border-radius: 8px; }
  ::selection { background: rgba(240,138,36,.35); }
  ::-webkit-scrollbar { width: 10px; }
  ::-webkit-scrollbar-track { background: var(--bg); }
  ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
}

/* ---------- 3. Type ---------- */
@layer type {
  h1, h2, h3, .display { font-family: var(--font-display); font-weight: 400; letter-spacing: 0; line-height: 1.08; }
  .sanskrit { font-family: var(--font-sanskrit); line-height: 1.7; }
  .mono, .stat-num { font-family: var(--font-body); font-variant-numeric: tabular-nums; font-weight: 600; }
  .wordmark { font-family: var(--font-display); font-weight: 400; }
  .wordmark .om-letter { color: var(--saffron); font-size: 1.15em; display: inline-block; transform: translateY(.08em); line-height: 0; }
  .t-fine { font-size: 12.5px; color: var(--text-faint); letter-spacing: .01em; }
}

/* ---------- 4. Motion ---------- */
@layer motion {
  @keyframes flame { 0%,100% { transform: scale(1,1) rotate(-1deg); } 50% { transform: scale(.94,1.07) rotate(1.5deg); } }
  @keyframes breathe { 0%,100% { opacity: .55; transform: scale(1); } 50% { opacity: .95; transform: scale(1.06); } }
  @keyframes orbit { to { transform: rotate(360deg); } }
  @keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.98); } to { opacity: 1; transform: none; } }
  @keyframes shimmer { to { background-position: -200% 0; } }
  @keyframes ring-pulse { 0% { box-shadow: 0 0 0 0 rgba(240,138,36,.45); } 100% { box-shadow: 0 0 0 18px rgba(240,138,36,0); } }
  @keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

  .anim-flame { animation: flame 2.4s var(--ease-in-out) infinite; transform-origin: 50% 90%; }
  .anim-breathe { animation: breathe 5s var(--ease-in-out) infinite; }
  .anim-orbit { animation: orbit 90s linear infinite; }
  .anim-rise { animation: rise var(--dur-3) var(--ease-out) both; animation-delay: calc(var(--i, 0) * 70ms); }

  .skeleton {
    color: transparent !important; border-radius: 10px; pointer-events: none;
    background: linear-gradient(100deg, var(--stone-800) 30%, rgba(232,182,90,.16) 50%, var(--stone-800) 70%);
    background-size: 200% 100%; animation: shimmer 1.6s linear infinite;
  }
  .skeleton * { visibility: hidden; }

  body.leaving main, body.leaving .path-page { transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out); opacity: 0; transform: scale(.985) translateY(6px); }

  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
  }
}

/* ---------- 5. Surfaces ---------- */
@layer surfaces {
  .glass {
    background: linear-gradient(160deg, rgba(255,235,200,.055), rgba(255,235,200,.015));
    border: 1px solid var(--stone-line);
    backdrop-filter: blur(18px) saturate(1.2); -webkit-backdrop-filter: blur(18px) saturate(1.2);
    box-shadow: inset 0 1px 0 rgba(255,235,200,.07), var(--shadow-lift);
  }
  .glow-edge { position: relative; isolation: isolate; }
  .glow-edge::after {
    content: ''; position: absolute; inset: 0; border-radius: inherit; padding: 1px; z-index: -1; pointer-events: none;
    background: radial-gradient(260px circle at var(--mx, 50%) var(--my, 0%), rgba(240,138,36,.85), transparent 60%);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude;
    opacity: 0; transition: opacity var(--dur-2) var(--ease-out);
  }
  .glow-edge:hover::after, .glow-edge:focus-visible::after { opacity: 1; }
  .lamp { background: radial-gradient(120% 90% at 20% 0%, rgba(240,138,36,.28), transparent 60%), linear-gradient(160deg, var(--ember), var(--stone-900)); }
}

/* ---------- 6. Controls ---------- */
@layer controls {
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 13px 26px; border-radius: 999px; border: 1px solid transparent;
    font-weight: 600; font-size: 15px; letter-spacing: .01em;
    transition: transform var(--dur-2) var(--spring), box-shadow var(--dur-2) var(--ease-out), background var(--dur-2) var(--ease-out);
  }
  .btn:hover { transform: translateY(-1px) scale(1.02); }
  .btn:active { transform: scale(.96); transition-duration: var(--dur-1); }
  .btn-primary { background: linear-gradient(180deg, #F5A03F, #E07418); color: #2A1100; box-shadow: 0 10px 26px -10px rgba(240,138,36,.7), inset 0 1px 0 rgba(255,255,255,.35); }
  .btn-primary:hover { box-shadow: 0 14px 34px -10px rgba(240,138,36,.85), inset 0 1px 0 rgba(255,255,255,.4); }
  .btn-ghost { background: transparent; color: var(--ghee); border-color: var(--stone-line); }
  .btn-ghost:hover { border-color: var(--saffron); box-shadow: 0 0 0 1px var(--saffron), 0 0 24px -6px rgba(240,138,36,.5); }
  .btn-disabled { background: var(--surface-raised); color: var(--text-faint); cursor: not-allowed; }

  .stat-pill { display: flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; background: rgba(255,235,200,.04); border: 1px solid var(--stone-line); font-size: 14px; font-weight: 600; }
  .stat-pill .stat-num { font-size: 14px; }
  .signout-link { background: none; border: none; color: var(--text-faint); font-size: 12.5px; font-weight: 600; transition: color var(--dur-2) var(--ease-out); }
  .signout-link:hover { color: var(--saffron); }
  .signout-link.danger:hover { color: #E0584A; }

  .modal-overlay { position: fixed; inset: 0; z-index: 1000; background: rgba(10,8,14,.62); backdrop-filter: blur(6px); display: none; align-items: center; justify-content: center; padding: 20px; }
  .modal-overlay.open { display: flex; }
  .modal-overlay.open .modal-box { animation: rise var(--dur-3) var(--ease-out) both; }
  .modal-box { background: var(--stone-800); border: 1px solid var(--stone-line); border-radius: var(--radius); max-width: 420px; width: 100%; padding: 28px; box-shadow: 0 40px 80px rgba(0,0,0,.55); text-align: center; }
  .modal-box.left { text-align: left; }
  .modal-box h3 { margin: 0 0 8px; font-size: 24px; }
  .modal-box p { color: var(--text-dim); font-size: 14px; line-height: 1.6; margin: 0 0 10px; }
  .modal-box input[type="text"] { width: 100%; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 14px; background: var(--stone-700); color: var(--text); margin-bottom: 6px; }
  .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
  .modal-actions button { flex: 1; border-radius: 10px; padding: 11px; font-weight: 600; font-size: 13px; border: 1px solid var(--border); }
  .modal-status { font-size: 12.5px; margin-top: 10px; min-height: 16px; }
  .modal-status.err { color: #E0584A; }
  .modal-status.ok { color: #6CC58B; }
  #globalDelCancel { background: transparent; color: var(--text-dim); }
  #globalDelConfirmBtn { background: #B3392D; color: #fff; border: none; }
  #globalDelConfirmBtn:disabled { opacity: .5; cursor: not-allowed; }
}

/* ---------- 7. Shell ---------- */
@layer shell {
  .topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 28px; background: rgba(15,13,20,.72); backdrop-filter: blur(16px) saturate(1.3); border-bottom: 1px solid var(--stone-line); }
  .topbar-left { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-size: 24px; flex-shrink: 0; }
  .stats-cluster { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
  .nav-links { display: flex; gap: 2px; }
  .nav-link { position: relative; padding: 8px 14px; font-size: 14px; font-weight: 500; color: var(--text-dim); white-space: nowrap; border-radius: 10px; transition: color var(--dur-2) var(--ease-out); }
  .nav-link::after { content: ''; position: absolute; left: 14px; right: 14px; bottom: 3px; height: 1px; background: var(--saffron); transform: scaleX(0); transform-origin: left; transition: transform var(--dur-3) var(--ease-out); }
  .nav-link:hover { color: var(--cream); }
  .nav-link.active { color: var(--ghee); }
  .nav-link:hover::after, .nav-link.active::after { transform: scaleX(1); }

  .nav-toggle { display: none; background: none; border: none; color: var(--text); font-size: 22px; line-height: 1; padding: 6px 8px; border-radius: 8px; flex-shrink: 0; }
  .nav-toggle:hover { color: var(--saffron); }
  .nav-menu-divider { display: none; }

  @media (max-width: 720px) {
    .topbar { flex-wrap: nowrap; padding: 12px 16px; }
    .nav-toggle { display: inline-flex; }
    .nav-links { display: none; position: absolute; top: 100%; left: 0; right: 0; flex-direction: column; gap: 2px; background: rgba(22,19,29,.96); backdrop-filter: blur(16px); border-bottom: 1px solid var(--stone-line); padding: 10px 16px 16px; box-shadow: var(--shadow-lift); }
    .nav-links.open { display: flex; animation: rise var(--dur-2) var(--ease-out) both; }
    .nav-link { text-align: left; padding: 12px 14px; }
    .stats-cluster { flex-wrap: nowrap; overflow-x: auto; max-width: 46vw; scrollbar-width: none; }
    .stats-cluster::-webkit-scrollbar { display: none; }
    .stat-pill { font-size: 12px; padding: 5px 9px; white-space: nowrap; }
    .stats-cluster.in-mobile-menu { flex-wrap: wrap; justify-content: flex-start; max-width: none; overflow: visible; gap: 8px; }
    .stats-cluster.in-mobile-menu .stat-pill { font-size: 13px; padding: 7px 12px; }
    .stats-cluster.in-mobile-menu .signout-link { width: 100%; text-align: left; padding: 10px 2px; }
    .nav-menu-divider { display: block; height: 1px; background: var(--stone-line); margin: 10px 0; }
  }

  @media (max-width: 1280px) { .topbar { padding: 12px 16px; gap: 10px; } .nav-link { padding: 8px 8px; font-size: 13px; } .nav-link::after { left: 8px; right: 8px; } }

  .site-footer { max-width: 720px; margin: 0 auto; padding: 28px 24px 22px; text-align: center; }
  .site-footer a { color: var(--text-faint); font-size: 12.5px; font-weight: 500; text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 3px; }
  .site-footer a:hover { color: var(--saffron); }
}

/* ---------- 8. Bento tile system ---------- */
@layer bento {
  .bento { display: grid; grid-template-columns: repeat(6, 1fr); grid-auto-rows: minmax(132px, auto); gap: 14px; max-width: 1080px; margin: 0 auto; padding: 0 20px 60px; }
  .tile {
    position: relative; display: flex; flex-direction: column; justify-content: flex-end; gap: 6px; overflow: hidden;
    padding: 22px; border-radius: var(--radius-tile); color: var(--text); text-align: left;
    transform: translateZ(0) scale(var(--s, 1)); transition: transform 520ms var(--spring), box-shadow var(--dur-2) var(--ease-out);
  }
  .tile:hover { --s: 1.015; }
  .tile:active { --s: .965; transition-duration: var(--dur-1); }
  .tile h3 { margin: 0; font-size: 26px; }
  .tile p { margin: 0; font-size: 13.5px; line-height: 1.5; color: var(--text-dim); max-width: 30ch; }
  .tile .tag { align-self: flex-start; margin-bottom: auto; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: rgba(0,0,0,.35); border: 1px solid var(--stone-line); color: var(--ghee); }
  .tile[aria-disabled="true"] { cursor: default; opacity: .72; }
  .tile[aria-disabled="true"]:hover, .tile[aria-disabled="true"]:active { --s: 1; }

  .t-cal  { grid-column: span 4; grid-row: span 2; }
  .t-path { grid-column: span 2; grid-row: span 2; }
  .t-gita, .t-why { grid-column: span 3; }
  .t-mandir, .t-prayer, .t-shop { grid-column: span 2; }

  @media (max-width: 820px) {
    .bento { grid-template-columns: repeat(2, 1fr); padding: 0 14px 50px; gap: 12px; }
    .t-cal, .t-path, .t-gita, .t-why { grid-column: span 2; }
    .t-cal { grid-row: span 3; }
    .t-mandir, .t-prayer, .t-shop { grid-column: span 1; }
    .tile h3 { font-size: 22px; }
  }
}

/* ---------- 9. Utilities ---------- */
@layer utilities {
  .u-ghee { color: var(--ghee); } .u-dim { color: var(--text-dim); } .u-faint { color: var(--text-faint); }
  .u-flex { display: flex; } .u-col { flex-direction: column; } .u-between { justify-content: space-between; } .u-center { align-items: center; }
  .u-gap-1 { gap: 6px; } .u-gap-2 { gap: 12px; } .u-gap-3 { gap: 20px; }
  .u-nowrap { white-space: nowrap; }
}
