/* ===========================================================================
   LAWBOX — styles.css  (owner: claude)
   The "feel": deep-space calm that warms as the universe wakes.
   main.js drives two custom properties:
     --liveliness : 0..1   how awake the cosmos is (gray -> alive)
     --accent-h   : hue    a slowly drifting accent hue
   ========================================================================= */

:root {
  --liveliness: 0;
  --accent-h: 265;

  /* Ink + glass, nudged warmer/brighter as liveliness rises. */
  --bg0: hsl(240 28% calc(3% + 1% * var(--liveliness)));
  --bg1: hsl(255 32% calc(6% + 3% * var(--liveliness)));
  --ink: hsl(250 20% calc(78% + 14% * var(--liveliness)));
  --ink-dim: hsl(250 14% calc(52% + 10% * var(--liveliness)));
  --glass: hsla(250 40% 80% / calc(0.04 + 0.05 * var(--liveliness)));
  --glass-line: hsla(250 60% 85% / calc(0.08 + 0.12 * var(--liveliness)));
  --accent: hsl(var(--accent-h) calc(40% + 50% * var(--liveliness)) calc(58% + 8% * var(--liveliness)));

  --display: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg0);
  color: var(--ink);
  font-family: var(--ui);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  transition: background 1.2s var(--ease), color 1.2s var(--ease);
}

#cosmos {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  z-index: 0;
}

/* Filmic vignette + faint warmth from the center. */
.vignette {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    radial-gradient(120% 90% at 50% 38%,
      transparent 40%,
      hsla(255 40% 4% / 0.35) 78%,
      hsla(255 50% 2% / 0.7) 100%),
    radial-gradient(80% 60% at 50% 30%,
      hsla(var(--accent-h) 70% 60% / calc(0.06 * var(--liveliness))),
      transparent 70%);
  mix-blend-mode: normal;
}

/* All HUD chrome sits above the canvas. */
#nameplate, #liveliness, #shelf, #laws, #hint, #discovery, #curtain {
  position: fixed;
  z-index: 3;
}

/* ---- Nameplate (now-playing) ------------------------------------------- */
#nameplate {
  top: clamp(18px, 5vh, 46px);
  left: 0;
  right: 0;
  text-align: center;
  pointer-events: none;
  padding: 0 16px;
}
#phenomenon-name {
  font-family: var(--display);
  font-size: clamp(22px, 4.4vw, 46px);
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.05;
  color: var(--ink);
  text-shadow: 0 0 28px hsla(var(--accent-h) 80% 70% / calc(0.15 + 0.35 * var(--liveliness)));
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
}
#phenomenon-name.swap { opacity: 0; transform: translateY(-8px); }
#phenomenon-sub {
  margin-top: 8px;
  font-size: clamp(11px, 1.5vw, 14px);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
#phenomenon-name.marquee {
  color: hsl(var(--accent-h) 90% 78%);
}

/* ---- Liveliness meter --------------------------------------------------- */
#liveliness {
  top: clamp(16px, 4vh, 30px);
  left: clamp(16px, 3vw, 34px);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-dim);
  pointer-events: none;
}
#liveliness-track {
  width: clamp(90px, 12vw, 150px);
  height: 5px;
  border-radius: 999px;
  background: hsla(250 40% 80% / 0.08);
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--glass-line);
}
#liveliness-fill {
  height: 100%;
  width: calc(100% * var(--liveliness));
  border-radius: 999px;
  background: linear-gradient(90deg,
    hsl(calc(var(--accent-h) - 40) 70% 60%),
    hsl(var(--accent-h) 90% 66%));
  box-shadow: 0 0 12px hsla(var(--accent-h) 90% 65% / 0.7);
  transition: width 0.9s var(--ease);
}

/* ---- Constellation shelf ----------------------------------------------- */
#shelf {
  top: 50%;
  right: clamp(14px, 2.4vw, 30px);
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 12px;
  border-radius: 18px;
  background: var(--glass);
  border: 1px solid var(--glass-line);
  backdrop-filter: blur(14px) saturate(1.2);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
}
.shelf-title {
  font-size: 9px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.shelf-slots { display: flex; flex-direction: column; gap: 10px; }
.pin-slot {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  border: 1px dashed var(--glass-line);
  background: hsla(250 40% 80% / 0.03);
  color: var(--ink-dim);
  font-family: var(--display);
  font-size: 13px;
  line-height: 1.05;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px;
  overflow: hidden;
  transition: transform 0.2s var(--ease), border-color 0.3s var(--ease), background 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.pin-slot:hover { transform: translateY(-2px); border-color: var(--accent); }
.pin-slot.filled {
  border-style: solid;
  border-color: hsla(var(--slot-h, 265) 80% 70% / 0.6);
  background: hsla(var(--slot-h, 265) 60% 50% / 0.14);
  color: var(--ink);
  box-shadow: 0 0 18px hsla(var(--slot-h, 265) 80% 60% / 0.25);
  font-size: 9px;
}
.pin-slot .pin-empty { font-size: 20px; opacity: 0.5; }
#pin-now {
  margin-top: 4px;
  font-family: var(--ui);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink);
  background: hsla(var(--accent-h) 70% 60% / 0.16);
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background 0.25s var(--ease), opacity 0.25s var(--ease), transform 0.15s var(--ease);
}
#pin-now:hover:not(:disabled) { background: hsla(var(--accent-h) 80% 62% / 0.3); transform: translateY(-1px); }
#pin-now:disabled { opacity: 0.3; cursor: default; }

/* ---- Discovery banner --------------------------------------------------- */
#discovery {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s var(--ease), transform 0.5s var(--ease);
}
#discovery.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.disc-kicker {
  font-size: 12px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: hsl(var(--accent-h) 90% 76%);
  margin-bottom: 12px;
}
#discovery-name {
  font-family: var(--display);
  font-size: clamp(34px, 7vw, 78px);
  font-weight: 700;
  line-height: 1.0;
  color: #fff;
  text-shadow: 0 0 40px hsla(var(--accent-h) 90% 70% / 0.6);
}
#discovery-praise {
  margin-top: 16px;
  font-size: clamp(12px, 1.8vw, 16px);
  font-style: italic;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

/* ---- Law rail ----------------------------------------------------------- */
#laws {
  bottom: clamp(46px, 9vh, 78px);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: clamp(12px, 2.4vw, 26px);
  padding: 0 16px;
}
.law {
  position: relative;
  width: clamp(58px, 8vw, 76px);
  height: clamp(58px, 8vw, 76px);
  border-radius: 50%;
  border: 1px solid var(--glass-line);
  background:
    radial-gradient(120% 120% at 50% 22%, hsla(250 40% 80% / 0.06), transparent 60%),
    var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: var(--ink-dim);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: transform 0.22s var(--ease), border-color 0.3s var(--ease),
              box-shadow 0.35s var(--ease), color 0.3s var(--ease), background 0.3s var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.law:hover { transform: translateY(-4px); color: var(--ink); border-color: hsla(var(--law-h, 265) 80% 70% / 0.7); }
.law .glyph { font-size: clamp(20px, 3vw, 26px); line-height: 1; }
.law .label {
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
/* Active law: lit with its own color, gently breathing. */
.law.active {
  color: #fff;
  border-color: hsla(var(--law-h) 85% 70% / 0.85);
  background:
    radial-gradient(120% 120% at 50% 20%, hsla(var(--law-h) 90% 70% / 0.45), transparent 62%),
    hsla(var(--law-h) 70% 40% / 0.22);
  box-shadow:
    0 0 0 1px hsla(var(--law-h) 90% 75% / 0.4),
    0 0 26px hsla(var(--law-h) 90% 60% / calc(0.35 + 0.5 * var(--intensity, 0.6))),
    0 8px 30px hsla(var(--law-h) 90% 40% / 0.3);
  animation: breathe 3.4s var(--ease) infinite;
}
@keyframes breathe {
  0%, 100% { transform: translateY(-2px) scale(1); }
  50% { transform: translateY(-5px) scale(1.035); }
}
/* Intensity ring drawn with a conic gradient behind the rune. */
.law .ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: conic-gradient(
    hsl(var(--law-h) 90% 65%) calc(var(--intensity, 0.6) * 360deg),
    transparent 0);
  -webkit-mask: radial-gradient(transparent 60%, #000 61%);
          mask: radial-gradient(transparent 60%, #000 61%);
  transition: opacity 0.3s var(--ease);
}
.law.active .ring { opacity: 0.85; }
/* The law about to be bumped off when a 4th is added. */
.law.dropping { animation: dropPulse 0.45s var(--ease); }
@keyframes dropPulse {
  0% { box-shadow: 0 0 0 2px hsl(0 80% 65%); }
  100% { box-shadow: none; }
}

/* ---- Hint --------------------------------------------------------------- */
#hint {
  bottom: clamp(14px, 3vh, 24px);
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--ink-dim);
  pointer-events: none;
  opacity: 0.7;
  padding: 0 16px;
}
#hint b { color: var(--ink); font-weight: 600; }

/* ---- Curtain (first gesture) ------------------------------------------- */
#curtain {
  inset: 0;
  position: fixed;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(80% 70% at 50% 42%, hsl(258 35% 9%), hsl(245 40% 3%) 80%);
  transition: opacity 0.9s var(--ease), visibility 0.9s var(--ease);
}
#curtain.gone { opacity: 0; visibility: hidden; }
.curtain-inner { text-align: center; padding: 24px; max-width: 540px; }
.logo {
  font-family: var(--display);
  font-size: clamp(54px, 13vw, 128px);
  font-weight: 700;
  letter-spacing: 0.02em;
  margin: 0;
  color: #fff;
  text-shadow: 0 0 60px hsla(265 90% 70% / 0.5);
}
.logo span { color: hsl(265 85% 74%); }
.tagline {
  margin: 18px 0 30px;
  font-size: clamp(14px, 2.2vw, 19px);
  line-height: 1.6;
  color: hsl(250 25% 78%);
}
#open-box {
  font-family: var(--ui);
  font-size: 14px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #fff;
  background: hsla(265 70% 60% / 0.18);
  border: 1px solid hsla(265 80% 75% / 0.5);
  border-radius: 999px;
  padding: 16px 34px;
  cursor: pointer;
  transition: transform 0.2s var(--ease), background 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
#open-box:hover {
  transform: translateY(-2px);
  background: hsla(265 80% 62% / 0.34);
  box-shadow: 0 0 40px hsla(265 90% 65% / 0.4);
}
.curtain-inner .sub {
  margin-top: 26px;
  font-size: 11px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: hsl(250 15% 50%);
}

.hidden { display: none !important; }

/* Respect reduced-motion: kill the looping animations, keep the toy usable. */
@media (prefers-reduced-motion: reduce) {
  .law.active { animation: none; }
  * { transition-duration: 0.001ms !important; }
}

/* =======================================================================
   v2 — Almanac, locked laws, requests, toasts, greater wonders
   ===================================================================== */

/* ---- Almanac toggle button (top-right, mirrors the liveliness meter) --- */
#almanac-btn {
  position: fixed; z-index: 4;
  top: clamp(14px, 4vh, 28px); right: clamp(14px, 3vw, 34px);
  font-family: var(--ui); font-size: 11px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink); background: var(--glass); border: 1px solid var(--glass-line);
  border-radius: 999px; padding: 9px 16px; cursor: pointer;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  transition: transform .2s var(--ease), background .3s var(--ease), box-shadow .3s var(--ease);
}
#almanac-btn:hover { transform: translateY(-2px); background: hsla(var(--accent-h) 70% 60% / .22); box-shadow: 0 0 24px hsla(var(--accent-h) 80% 60% / .3); }

/* ---- Locked / unlockable laws ----------------------------------------- */
.law.locked { cursor: help; opacity: .5; }
.law.locked:hover { transform: none; border-color: var(--glass-line); color: var(--ink-dim); }
.law.locked .glyph, .law.locked .label { opacity: .18; }
.law .lock {
  position: absolute; inset: 0; display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 1px; pointer-events: none;
}
.law.locked .lock { display: flex; }
.law .lock-ico { font-size: 17px; color: var(--ink-dim); }
.law .lock-n { font-size: 10px; font-weight: 700; color: var(--ink); }
.law.shake { animation: shake .4s var(--ease); }
@keyframes shake {
  0%, 100% { transform: translateX(0); } 20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); } 60% { transform: translateX(-3px); } 80% { transform: translateX(3px); }
}
.law.just-unlocked { animation: unlockPop 1s var(--ease); }
@keyframes unlockPop {
  0% { transform: scale(.55); box-shadow: 0 0 0 0 hsla(var(--law-h) 90% 70% / .9); }
  55% { transform: scale(1.18); }
  100% { transform: scale(1); box-shadow: 0 0 44px hsla(var(--law-h) 90% 60% / .55); }
}

/* ---- Toast (unlocks / pleased dark / locked nudges) -------------------- */
#toast {
  position: fixed; z-index: 6; left: 50%; bottom: clamp(124px, 22vh, 184px);
  transform: translateX(-50%) translateY(10px);
  max-width: min(90vw, 470px); text-align: center;
  font-size: 13px; letter-spacing: .02em; color: #fff;
  background: hsla(var(--toast-h, 265) 55% 22% / .9);
  border: 1px solid hsla(var(--toast-h, 265) 80% 72% / .5);
  border-radius: 14px; padding: 12px 20px;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 10px 44px hsla(var(--toast-h, 265) 80% 28% / .5);
  opacity: 0; pointer-events: none;
  transition: opacity .35s var(--ease), transform .35s var(--ease);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Cosmic Request banner -------------------------------------------- */
#request {
  position: fixed; z-index: 3; left: 50%; top: clamp(108px, 17vh, 168px);
  transform: translateX(-50%) translateY(-8px);
  max-width: min(92vw, 540px); text-align: center;
  font-family: var(--display); font-style: italic; font-size: clamp(13px, 2vw, 18px);
  color: hsl(var(--accent-h) 45% 82%); text-shadow: 0 0 24px hsla(var(--accent-h) 80% 60% / .3);
  opacity: 0; pointer-events: none;
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
#request.show { opacity: .92; transform: translateX(-50%) translateY(0); }

/* ---- The Almanac drawer ----------------------------------------------- */
#almanac {
  position: fixed; z-index: 8; top: 0; right: 0; height: 100%;
  width: min(440px, 92vw);
  background: linear-gradient(180deg, hsla(255 42% 8% / .97), hsla(245 46% 5% / .98));
  border-left: 1px solid var(--glass-line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  transform: translateX(105%); transition: transform .5s var(--ease);
  display: flex; flex-direction: column; padding: 26px 22px; gap: 16px; overflow-y: auto;
  box-shadow: -24px 0 70px rgba(0, 0, 0, .55);
}
#almanac.open { transform: translateX(0); }
.almanac-head { display: flex; align-items: center; justify-content: space-between; }
.almanac-head h2 { font-family: var(--display); font-size: 26px; margin: 0; color: #fff; letter-spacing: .01em; }
#almanac-close { background: none; border: none; color: var(--ink-dim); font-size: 30px; line-height: 1; cursor: pointer; }
#almanac-close:hover { color: #fff; }
#almanac-counts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--glass); border: 1px solid var(--glass-line); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-family: var(--display); font-size: 22px; color: hsl(var(--accent-h) 80% 78%); }
.stat span { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-dim); }
#almanac-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.almanac-card {
  background: hsla(250 40% 80% / .03); border: 1px solid var(--glass-line);
  border-radius: 14px; padding: 12px; min-height: 96px;
}
.almanac-card.found {
  background: hsla(var(--card-h, 265) 50% 42% / .15);
  border-color: hsla(var(--card-h, 265) 70% 65% / .45);
  box-shadow: 0 0 22px hsla(var(--card-h, 265) 70% 50% / .18);
}
.ac-glyphs { font-size: 18px; letter-spacing: .2em; color: var(--ink); margin-bottom: 6px; }
.ac-name { font-family: var(--display); font-size: 16px; color: #fff; margin-bottom: 4px; line-height: 1.1; }
.almanac-card:not(.found) .ac-name { color: var(--ink-dim); letter-spacing: .1em; }
.ac-lore { font-size: 11px; font-style: italic; color: var(--ink-dim); line-height: 1.4; }
#almanac-hint {
  font-family: var(--display); font-style: italic; font-size: 14px; text-align: center;
  color: hsl(var(--accent-h) 50% 76%); padding-top: 12px; border-top: 1px solid var(--glass-line);
}

/* ---- Greater wonder (3-law) discovery flavor -------------------------- */
#discovery.greater .disc-kicker { color: hsl(45 95% 70%); }
#discovery.greater #discovery-name { color: hsl(45 100% 82%); text-shadow: 0 0 52px hsla(45 95% 60% / .7); }

/* Tuck the shelf away on small screens so the cosmos stays the star. */
@media (max-width: 560px) {
  #shelf { flex-direction: row; top: auto; bottom: clamp(112px, 20vh, 150px); right: 50%; transform: translateX(50%); }
  .shelf-slots { flex-direction: row; }
  #liveliness-track { width: 84px; }
}
