/* ==========================================================================
   Until — a calm countdown. Tier 1, pure static, no network at runtime.
   Tokens below descend from apps/_shared/style.css (warm paper + ember),
   pinned to the dark end: the app is a dark, cinematic instrument by design,
   not a document that follows the OS light/dark setting.

   Type: Fraunces (heading + event name) and Space Grotesk (the number) are
   self-hosted variable woff2 in ./fonts (SIL OFL 1.1, licenses beside them).
   font-display: swap; a system stack carries the first paint.
   ========================================================================== */

/* --- fonts: latin + latin-ext per family, swap ----------------------- */
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-latin-var.woff2") format("woff2");
  font-weight: 300 600;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-latin-ext-var.woff2") format("woff2");
  font-weight: 300 600;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/spacegrotesk-latin-var.woff2") format("woff2");
  font-weight: 300 700;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/spacegrotesk-latin-ext-var.woff2") format("woff2");
  font-weight: 300 700;
  font-stretch: normal;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: dark;

  --bg:        #16150f;
  --bg-deep:   #0b0a07;
  --surface:   #201e18;
  --fg:        #ece9e0;
  --muted:     #9a968c;
  --rule:      #2e2c25;
  --accent:    #e8865a;
  --accent-fg: #1b1a17;
  --focus:     #7cb3e8;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  --font-serif: "Fraunces", "Iowan Old Style", "Palatino Linotype", Palatino,
               "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-grotesk: "Space Grotesk", ui-sans-serif, -apple-system,
               BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-7: 3rem;

  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body, h1, p { margin: 0; }
img, svg, canvas { display: block; max-width: 100%; }
input, button { font: inherit; color: inherit; }

body {
  /* three declarations, cascading: flat fallback, sRGB multi-stop, then the
     preferred OKLCH ramp (even lightness, no muddy-grey midpoint). Browsers
     that don't parse oklch() simply keep the sRGB stops. */
  background-color: #16150f;
  background-image: radial-gradient(135% 105% at 50% 16%,
      #2b2417 0%, #221c13 30%, #191510 58%, #100e08 100%);
  background-image: radial-gradient(135% 105% at 50% 16%,
      oklch(0.305 0.036 68) 0%,
      oklch(0.235 0.028 63) 30%,
      oklch(0.170 0.020 58) 58%,
      oklch(0.110 0.013 54) 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: var(--fg);
  font-family: var(--font-sans);
  line-height: 1.5;
  isolation: isolate;           /* contain the grain's blend mode to the page */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

/* --- baked grain: one static feTurbulence, never animated ----------- */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  mix-blend-mode: soft-light;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='3' stitchTiles='stitch' color-interpolation-filters='sRGB'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --- shared surfaces ----------------------------------------------- */
#viz, #glviz {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  transition: opacity 850ms var(--ease-out);
}
#viz   { opacity: 1; }
#glviz { opacity: 0; }
body.gl-active #viz   { opacity: 0; }
body.gl-active #glviz { opacity: 1; }

.scrim {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  /* dark vignette — stays sRGB on purpose (it darkens, it is not a light
     ramp), layered so the corners fall further than the mid-field. */
  background:
    radial-gradient(122% 84% at 50% 40%,
      rgba(11, 10, 7, 0) 38%, rgba(11, 10, 7, 0.5) 82%, rgba(5, 4, 3, 0.8) 100%);
  transition: background 900ms var(--ease-out);
}

/* --- setup ------------------------------------------------------- */
.setup {
  position: relative;
  z-index: 2;
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  /* definite, shrinkable track — without this the auto track sizes to the
     inner block's max-content and overflows narrow (mobile) viewports */
  grid-template-columns: minmax(0, 1fr);
  padding: var(--sp-6) var(--sp-5) calc(var(--sp-6) + env(safe-area-inset-bottom));
  background: transparent;         /* let the page ramp + grain read through */
  transition: opacity 520ms var(--ease-out), transform 520ms var(--ease-out);
}
.setup[hidden] { display: none; }
.setup.leaving {
  opacity: 0;
  transform: translateY(-14px);
  pointer-events: none;
}

.setup-inner {
  width: 100%;
  max-width: 30rem;
  text-align: center;
}

h1 {
  font-family: var(--font-serif);
  font-weight: 340;
  font-optical-sizing: none;
  font-variation-settings: "opsz" 96, "wght" 340;
  font-size: clamp(2.4rem, 8.4vw, 4rem);
  line-height: 1.03;
  letter-spacing: -0.014em;
  margin-bottom: var(--sp-6);
}

.composer {
  text-align: left;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  overflow: hidden;
  transition: border-color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--rule));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}

.c-name {
  width: 100%;
  border: 0;
  background: transparent;
  padding: var(--sp-4);
  font-size: 1.35rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  outline: none;
}
.c-name::placeholder { color: var(--muted); }

.c-when {
  display: flex;
  border-top: 1px solid var(--rule);
}
.c-when input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: var(--sp-3) var(--sp-4);
  font-size: 1rem;
  outline: none;
}
.c-when input + input { border-left: 1px solid var(--rule); }

/* the opening screen's one button — restrained: a thin accent underline
   that grows on hover, plus a soft inward ember glow. No filled rectangle. */
.btn {
  position: relative;
  display: block;
  width: 100%;
  border: 0;
  border-top: 1px solid var(--rule);
  background: transparent;
  color: var(--fg);
  padding: var(--sp-4);
  font-size: 0.98rem;
  font-weight: 400;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 220ms var(--ease-out), box-shadow 220ms var(--ease-out),
              color 220ms var(--ease-out);
}
.btn .arrow {
  display: inline-block;
  transition: transform 260ms var(--ease-out);
}
.btn::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--sp-4) - 7px);
  width: 1.7rem;
  height: 1px;
  background: color-mix(in srgb, var(--accent) 70%, transparent);
  transition: width 300ms var(--ease-out), background 300ms var(--ease-out);
}
.btn:hover {
  background: color-mix(in srgb, var(--accent) 7%, transparent);
  box-shadow: inset 0 -46px 60px -52px color-mix(in srgb, var(--accent) 62%, transparent);
}
.btn:hover::after {
  width: 3.4rem;
  background: color-mix(in srgb, var(--accent) 90%, transparent);
}
.btn:hover .arrow { transform: translateX(4px); }
.btn:active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: -3px; }

.shortcuts {
  margin-top: var(--sp-5);
  display: flex;
  gap: var(--sp-3);
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  font-size: 0.82rem;
  color: var(--muted);
}
.shortcuts button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 0;
  font-size: inherit;
  transition: color 180ms var(--ease-out);
}
.shortcuts button:hover { color: var(--fg); }
.shortcuts span { opacity: 0.35; }

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  30%, 70% { transform: translateX(2px); }
  50%      { transform: translateX(-3px); }
}
.composer.shake { animation: shake 400ms var(--ease-in-out); }

/* --- result --------------------------------------------------------- */
.result {
  position: fixed;
  inset: 0;
  z-index: 2;
}
.result[hidden] { display: none; }

/* entrance fade — #viz / #glviz are body-level siblings, so key off <body> */
body.entering #viz,
body.entering #glviz { opacity: 0; }
body.entering .readout { opacity: 0; transform: translateY(12px); }

.back {
  position: fixed;
  top: calc(var(--sp-5) + env(safe-area-inset-top));
  left: calc(var(--sp-5) + env(safe-area-inset-left));
  z-index: 4;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  transition: opacity 400ms var(--ease-out), visibility 0s, color 180ms var(--ease-out);
}
.back:hover { color: var(--fg); }

/* the readout sits in the upper-left third — the centre of the frame is
   left for the light to occupy. */
.readout {
  position: fixed;
  left: clamp(1.25rem, 7vw, 5.5rem);
  right: auto;
  top: clamp(2rem, 9vh, 5.5rem);
  z-index: 3;
  max-width: min(92vw, 38rem);
  text-align: left;
  padding: 0;
  transition: opacity 820ms var(--ease-out), transform 820ms var(--ease-out);
}

.event-name {
  font-family: var(--font-serif);
  font-optical-sizing: none;
  font-variation-settings: "opsz" 36, "wght" 370;
  font-size: clamp(1.05rem, 3vw, 1.6rem);
  font-weight: 400;
  letter-spacing: 0.004em;
  text-transform: none;
  color: color-mix(in srgb, var(--fg) 70%, var(--muted));
  /* keep legible over any part of the visualization (a bright sun, a
     dense point field) — the practical answer must always read instantly */
  text-shadow: 0 1px 3px rgba(6, 5, 3, 0.55), 0 0 30px rgba(6, 5, 3, 0.45);
}

.big-time {
  margin-top: var(--sp-4);
  font-weight: 300;
  letter-spacing: -0.01em;
  line-height: 1.05;
  overflow-wrap: break-word;
}
.big-time .value {
  display: block;
  font-family: var(--font-grotesk);
  font-weight: 300;
  font-variation-settings: "wght" 330;
  font-variant-numeric: tabular-nums slashed-zero;
  font-feature-settings: "tnum" 1, "zero" 1;
  font-size: clamp(2.05rem, 6vw, 3.5rem);
  letter-spacing: 0.02em;
  color: var(--fg);
  text-shadow: 0 1px 3px rgba(6, 5, 3, 0.55), 0 0 34px rgba(6, 5, 3, 0.5);
}
.big-time .value .unit { white-space: nowrap; display: inline-block; }
.big-time .affix {
  display: block;
  font-family: var(--font-sans);
  font-size: clamp(0.62rem, 1.8vw, 0.8rem);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.big-time .pre  { margin-bottom: var(--sp-3); }
.big-time .post { margin-top: var(--sp-3); }
.big-time:not(.past) .affix { display: none; }

.controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  gap: var(--sp-5);
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  padding: 0 var(--sp-5);
  transition: opacity 500ms var(--ease-out), visibility 0s;
}

.modes { display: flex; gap: var(--sp-4); }
.modes button {
  position: relative;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  letter-spacing: 0.18em;
  text-transform: lowercase;
  padding: var(--sp-2) 0;
  transition: color 180ms var(--ease-out);
}
.modes button:hover { color: var(--fg); }
.modes button.is-active { color: var(--fg); }
/* the single deliberate accent moment in the result view */
.modes button.is-active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: var(--accent);
}

.unit-note:empty { display: none; }
.unit-note {
  font-size: 0.75rem;
  letter-spacing: 0.13em;
  text-transform: lowercase;
  color: var(--muted);
  opacity: 0.7;
}

.keep {
  border: 1px solid var(--rule);
  background: none;
  color: var(--fg);
  cursor: pointer;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  padding: var(--sp-2) var(--sp-4);
  border-radius: 999px;
  transition: background 180ms var(--ease-out), border-color 180ms var(--ease-out);
}
.keep:hover {
  background: color-mix(in srgb, var(--fg) 6%, transparent);
  border-color: var(--muted);
}

.exit {
  position: fixed;
  top: calc(var(--sp-5) + env(safe-area-inset-top));
  right: calc(var(--sp-5) + env(safe-area-inset-right));
  z-index: 6;
  border: 1px solid var(--rule);
  background: rgba(11, 10, 7, 0.6);
  color: var(--fg);
  cursor: pointer;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  padding: var(--sp-2) var(--sp-4);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 400ms var(--ease-out);
}
.exit[hidden] { display: none; }
.exit.show { opacity: 1; }

/* --- ambient mode ------------------------------------------------- */
body.ambient .back,
body.ambient .controls {
  opacity: 0;
  visibility: hidden;              /* commit the hidden state even if the fade is interrupted */
  pointer-events: none;
  transition-delay: 0s, 500ms;     /* hold visibility until the fade finishes */
}
body.ambient .scrim {
  background: radial-gradient(130% 92% at 50% 46%,
              rgba(11, 10, 7, 0) 58%, rgba(11, 10, 7, 0.4) 100%);
}
body.ambient .readout {
  top: auto;
  bottom: calc(var(--sp-7) + env(safe-area-inset-bottom));
  left: calc(var(--sp-6) + env(safe-area-inset-left));
  right: auto;
  text-align: left;
  padding: 0;
  transform: scale(0.82);
  transform-origin: left bottom;
  opacity: 0.72;
}
body.ambient .big-time .value { font-size: clamp(1.6rem, 5vw, 2.4rem); }

/* --- responsive ------------------------------------------------- */
@media (max-width: 560px) {
  .readout {
    left: clamp(1rem, 5vw, 1.5rem);
    right: clamp(1rem, 5vw, 1.5rem);
    top: clamp(1.5rem, 7vh, 3rem);
    max-width: none;
  }
  .controls { gap: var(--sp-3); }
  .unit-note { order: 3; width: 100%; text-align: center; }
}

/* --- motion opt-out ------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
