/* ============================================================
   beyondthetag® — interactive essay on language inflation
   Dark editorial palette: ink black / cream / coral / neon
   ============================================================ */

:root {
  --bg: #141311;
  --bg-2: #1b1a17;
  --cream: #f2ede3;
  --cream-dim: rgba(242, 237, 227, 0.55);
  --gray: #8a877d;
  --coral: #ff6a4d;
  --coral-deep: #e8604c;
  --warm: #f5ead6;
  --sans: "Helvetica Neue", Helvetica, "Segoe UI", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--cream);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

body { user-select: none; }

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 10%, var(--bg-2) 0%, var(--bg) 62%);
  will-change: transform;
}

canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#plants, #ripples { pointer-events: none; opacity: 0; transition: opacity 1.2s ease; }
#plants.on, #ripples.on { opacity: 1; }
#fx { pointer-events: none; z-index: 3; }
#storm { pointer-events: none; z-index: 6; opacity: 0; transition: opacity .4s ease; }
#storm.on { opacity: 1; }

.layer {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .5s ease;
}
.layer.on { opacity: 1; }
#p2.on #slider-wrap { pointer-events: auto; }
#p4.on #write-ui { pointer-events: auto; }

/* ---------------- logo ---------------- */
#logo {
  position: fixed;
  top: 26px; left: 34px;
  z-index: 40;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.02em;
  color: var(--cream);
}
#logo span { color: var(--gray); font-weight: 400; }
#logo sup { font-size: 9px; vertical-align: super; margin-left: 1px; color: var(--cream); }

/* ---------------- sound toggle ---------------- */
#snd-toggle {
  position: fixed;
  right: 30px; bottom: 24px;
  z-index: 45;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--gray);
  background: rgba(20, 19, 17, 0.55);
  border: 1px solid rgba(242, 237, 227, 0.22);
  padding: 6px 10px;
  cursor: pointer;
  transition: color .25s ease, border-color .25s ease;
}
#snd-toggle:hover { color: var(--cream); border-color: rgba(242, 237, 227, 0.5); }

/* ---------------- engagement score ---------------- */
#score-module {
  position: fixed;
  top: 24px; right: 30px;
  z-index: 40;
  width: 172px;
  padding: 12px 14px 10px;
  border: 1px solid rgba(242, 237, 227, 0.22);
  background: rgba(20, 19, 17, 0.55);
  backdrop-filter: blur(6px);
  font-family: var(--mono);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .6s ease, transform .6s ease;
}
#score-module.on { opacity: .92; transform: none; }
#score-module .sm-label {
  font-size: 9px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--cream-dim);
}
#score-value {
  font-size: 30px; line-height: 1.15; font-weight: 700;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}
#score-module .sm-foot { font-size: 9px; color: var(--gray); letter-spacing: .12em; }
#score-module .lock { display: none; width: 12px; height: 12px; position: absolute; top: 12px; right: 12px; color: var(--gray); }
#score-module.frozen { filter: grayscale(1); opacity: .45; }
#score-module.frozen .lock { display: block; }
#score-module.frozen .sm-foot::after { content: " · frozen"; }
#score-module.spike #score-value { filter: blur(1.1px); color: var(--coral); }
#score-module.garbage { animation: mod-shake .12s infinite; }
#score-module.garbage #score-value { color: var(--coral); font-size: 24px; letter-spacing: .04em; }
#score-module.dead { display: none; }
@keyframes mod-shake {
  0% { transform: translate(0, 0) rotate(0deg); }
  25% { transform: translate(-3px, 2px) rotate(-.6deg); }
  50% { transform: translate(3px, -2px) rotate(.5deg); }
  75% { transform: translate(-2px, -2px) rotate(.3deg); }
  100% { transform: translate(2px, 2px) rotate(-.4deg); }
}

/* ---------------- readout & cues ---------------- */
#readout {
  position: fixed;
  left: 34px; bottom: 24px;
  z-index: 40;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--gray);
  opacity: 0;
  transition: opacity .5s ease;
}
#readout.on { opacity: .85; }

#scroll-cue {
  position: fixed;
  left: 50%; bottom: 34px;
  transform: translateX(-50%);
  z-index: 40;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--cream-dim);
  opacity: 0;
  transition: opacity .8s ease;
  animation: cue-bob 2.2s ease-in-out infinite;
}
#scroll-cue.on { opacity: 1; }
.arrow { display: inline-block; animation: cue-bob 1.4s ease-in-out infinite; }
@keyframes cue-bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(5px); } }

/* ---------------- phase 0 modal ---------------- */
#modal {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  background: rgba(10, 10, 9, 0.72);
  backdrop-filter: blur(10px);
  transition: opacity .2s ease;
}
#modal.gone { opacity: 0; pointer-events: none; }
#modal-card {
  width: min(560px, calc(100vw - 48px));
  padding: 38px 40px 30px;
  background: var(--bg-2);
  border: 1px solid rgba(242, 237, 227, 0.16);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6);
  text-align: left;
}
.mc-kicker {
  font-family: var(--mono);
  font-size: 10px; letter-spacing: .26em; text-transform: uppercase;
  color: var(--coral);
  margin-bottom: 18px;
}
#modal-card h1 {
  font-size: 19px; line-height: 1.5; font-weight: 500;
  color: var(--cream);
  margin-bottom: 24px;
}
#modal-card h1 em { color: var(--gray); font-style: italic; font-family: var(--serif); }
#chips { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 26px; }
.chip {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 8px 14px;
  color: var(--cream);
  background: transparent;
  border: 1px solid rgba(242, 237, 227, 0.3);
  border-radius: 999px;
  cursor: pointer;
  transition: transform .16s ease, background .16s ease, border-color .16s ease, color .16s ease;
}
.chip:hover { border-color: var(--cream); }
.chip.sel {
  background: var(--coral);
  border-color: var(--coral);
  color: #17130f;
  transform: scale(1.07);
  box-shadow: 0 0 0 3px rgba(255, 106, 77, 0.22);
}
#confirm-btn {
  display: block;
  width: 100%;
  padding: 13px 0;
  font-family: var(--mono);
  font-size: 13px; letter-spacing: .3em; text-transform: uppercase;
  background: var(--coral);
  color: #17130f;
  border: none;
  cursor: pointer;
  transition: opacity .2s ease, filter .2s ease;
}
#confirm-btn:disabled {
  background: rgba(242, 237, 227, 0.1);
  color: var(--gray);
  cursor: not-allowed;
}
#confirm-btn:not(:disabled):hover { filter: brightness(1.12); }
#confirm-help {
  margin-top: 10px;
  text-align: center;
  font-family: var(--mono);
  font-size: 10.5px; letter-spacing: .18em;
  color: var(--gray);
  min-height: 14px;
}

/* ---------------- phase 1 decoy input ---------------- */
#decoy-wrap {
  position: absolute;
  left: 50%; top: 42%;
  transform: translate(-50%, -50%);
  z-index: 2;
  text-align: center;
  opacity: 0;
  transition: opacity .8s ease;
  pointer-events: none;
}
#decoy-wrap.on { opacity: 1; }
#decoy-input {
  width: min(430px, 78vw);
  height: 54px;
  border: 1px solid rgba(242, 237, 227, 0.28);
  background: rgba(27, 26, 23, 0.6);
  display: flex; align-items: center;
  padding: 0 18px;
}
#decoy-input .caret {
  width: 1.5px; height: 22px;
  background: var(--cream);
  animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }
#decoy-caption {
  margin-top: 12px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 13px;
  color: var(--gray);
  letter-spacing: .04em;
}

/* ---------------- phase 2 ---------------- */
#p2 { z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 46px; }
#sentence-box {
  position: relative;
  width: min(880px, 86vw);
  min-height: 190px;
}
.s-block {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  text-align: center;
  font-family: var(--serif);
  font-size: clamp(20px, 3.1vw, 34px);
  line-height: 1.55;
  color: var(--cream);
  opacity: 0;
}
.s-block .morph { position: relative; display: inline-block; }
.s-block .morph .a, .s-block .morph .b { transition: none; }
.s-block .morph .b {
  position: absolute; left: 0; top: 0;
  color: var(--coral);
  font-family: var(--mono);
  font-size: .78em;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
}
.s-block .morph .a { color: var(--cream); }
.s-block.v2 { font-family: var(--mono); font-size: clamp(15px, 2vw, 22px); line-height: 1.8; }
.s-block.v2 b { color: var(--coral); font-weight: 700; }
.s-block.v3 { font-size: clamp(26px, 4vw, 46px); letter-spacing: .06em; }
.s-block .add { opacity: 0; color: var(--coral); font-family: var(--mono); font-size: .78em; font-weight: 700; }

#slider-wrap { width: min(520px, 76vw); opacity: 0; transform: translateY(14px); transition: opacity .7s ease, transform .7s ease; }
#slider-wrap.on { opacity: 1; transform: none; }
#slider-meta {
  display: flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: .24em; text-transform: uppercase;
  color: var(--gray); margin-bottom: 12px;
}
#slider-pct { color: var(--coral); }
#flatten-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px;
  background: transparent;
  cursor: grab;
}
#flatten-slider:active { cursor: grabbing; }
#flatten-slider::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, rgba(242,237,227,.4), rgba(255,106,77,.75));
}
#flatten-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px; margin-top: -8px;
  border-radius: 50%;
  background: var(--coral);
  border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--coral), 0 0 18px rgba(255, 106, 77, .55);
}
#flatten-slider::-moz-range-track { height: 2px; background: rgba(242,237,227,.4); }
#flatten-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--coral); border: 3px solid var(--bg);
  box-shadow: 0 0 0 1px var(--coral);
}
#slider-scale {
  display: flex; justify-content: space-between;
  font-family: var(--serif); font-style: italic;
  font-size: 12px; color: var(--gray); margin-top: 8px;
}
#scroll-hint {
  position: absolute; bottom: 8%;
  left: 50%; transform: translateX(-50%);
  font-family: var(--mono); font-size: 11px;
  letter-spacing: .3em; text-transform: uppercase;
  color: var(--cream-dim);
  opacity: 0; transition: opacity .6s ease;
}
#scroll-hint.on { opacity: 1; }

/* ---------------- phase 3 glitch overlay ---------------- */
#glitch-overlay { position: absolute; inset: 0; z-index: 7; pointer-events: none; opacity: 0; mix-blend-mode: screen; }
#glitch-overlay.on { opacity: 1; }
#glitch-overlay i {
  position: absolute; left: -5%; width: 110%; height: 14%;
  background: linear-gradient(90deg, rgba(255, 0, 60, .16), rgba(0, 200, 255, .16));
  animation: gl 1.1s steps(3) infinite;
}
#glitch-overlay i:nth-child(1) { top: 18%; }
#glitch-overlay i:nth-child(2) { top: 47%; animation-delay: .27s; animation-duration: .8s; }
#glitch-overlay i:nth-child(3) { top: 74%; animation-delay: .53s; animation-duration: 1.4s; }
@keyframes gl {
  0% { transform: translateX(-4%) scaleY(1); opacity: .9; }
  33% { transform: translateX(5%) scaleY(.5); opacity: .5; }
  66% { transform: translateX(-2%) scaleY(1.6); opacity: .8; }
  100% { transform: translateX(3%) scaleY(.8); opacity: .4; }
}
#storm.stutter { filter: blur(2px) saturate(1.8); }

/* ---------------- BSOD / flash / blackout ---------------- */
#flash {
  position: fixed; inset: 0; z-index: 80;
  background: #fff; opacity: 0; pointer-events: none;
}
#flash.go { animation: flash-a .34s ease-out; }
@keyframes flash-a { 0% { opacity: 0; } 18% { opacity: .95; } 100% { opacity: 0; } }

#bsod {
  position: fixed; inset: 0; z-index: 85;
  background: #0078d7;
  color: #fff;
  display: none;
  padding: 12vh 10vw;
  font-family: var(--mono);
  cursor: default;
}
#bsod.on { display: block; }
.bsod-inner { max-width: 760px; }
.sad { font-size: clamp(60px, 10vw, 120px); font-family: var(--sans); font-weight: 300; margin-bottom: 4vh; }
.bsod-lead { font-size: clamp(14px, 1.6vw, 20px); line-height: 1.7; margin-bottom: 3vh; font-family: var(--sans); font-weight: 300; }
.bsod-pct { font-size: 14px; margin-bottom: 6vh; font-family: var(--sans); }
.bsod-codes { font-size: 12px; line-height: 1.9; opacity: .85; }
#cracks { position: absolute; inset: 0; width: 100%; height: 100%; }
#cracks path {
  fill: none; stroke: rgba(255, 255, 255, .85); stroke-width: .35;
  stroke-dasharray: 60; stroke-dashoffset: 60;
  filter: drop-shadow(0 0 2px rgba(255,255,255,.9));
}

#blackout {
  position: fixed; inset: 0; z-index: 88;
  background: #000;
  opacity: 0; pointer-events: none;
  transition: opacity .5s ease;
}
#blackout.on { opacity: 1; }

/* ---------------- phase 4 sanctuary ---------------- */
#glow {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 0%;
  z-index: 1;
  background: linear-gradient(0deg, rgba(245, 234, 214, .30) 0%, rgba(245, 234, 214, .10) 45%, rgba(245, 234, 214, 0) 100%);
  transition: height 2.4s cubic-bezier(.22,.7,.3,1), opacity 1s ease;
  opacity: 0;
  pointer-events: none;
}
#glow.on { height: 78%; opacity: 1; }

#p4 { z-index: 8; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 34px; }
#p4-lines { width: min(760px, 84vw); text-align: center; }
#p4-lines .line {
  font-family: var(--serif);
  font-size: clamp(17px, 2.2vw, 25px);
  line-height: 1.75;
  color: var(--warm);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 1.1s ease, transform 1.1s ease;
  margin-bottom: 10px;
}
#p4-lines .line.on { opacity: .95; transform: none; }

#write-ui {
  position: relative;
  display: flex; align-items: flex-start; gap: 18px;
  width: min(640px, 84vw);
  opacity: 0; transform: translateY(16px);
  transition: opacity 1s ease, transform 1s ease;
}
#write-ui.on { opacity: 1; transform: none; }
#no-emoji { width: 44px; height: 44px; flex: 0 0 auto; color: rgba(245, 234, 214, .5); margin-top: 4px; }
#no-emoji svg { width: 100%; height: 100%; }
#reflect {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(245, 234, 214, .3);
  color: var(--warm);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.8;
  resize: none;
  outline: none;
  user-select: text;
  padding: 8px 2px 12px;
  caret-color: var(--coral);
  transition: border-color .4s ease;
}
#reflect:focus { border-color: rgba(245, 234, 214, .65); }
#reflect::placeholder { color: rgba(245, 234, 214, .32); font-style: italic; }
#char-note {
  position: absolute;
  right: 0; bottom: -22px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: .2em; text-transform: uppercase;
  color: rgba(245, 234, 214, .4);
}

#seed-zone {
  position: absolute;
  bottom: 5%;
  left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  opacity: 0; pointer-events: none;
  transition: opacity 1s ease;
}
#seed-zone.on { opacity: 1; pointer-events: auto; }
#seed-btn {
  width: 46px; height: 54px;
  background: transparent; border: none; cursor: pointer;
  color: rgba(245, 234, 214, .75);
  transition: transform .3s ease, color .3s ease;
  animation: cue-bob 3s ease-in-out infinite;
}
#seed-btn:hover { transform: scale(1.12); color: var(--warm); }
#seed-btn svg { width: 100%; height: 100%; }
#seed-label {
  font-family: var(--serif); font-style: italic;
  font-size: 12px; color: rgba(245, 234, 214, .5);
}
#seed-popup {
  position: absolute;
  bottom: 74px;
  width: 260px;
  padding: 20px 22px;
  background: rgba(27, 26, 23, .92);
  border: 1px solid rgba(245, 234, 214, .25);
  text-align: left;
  opacity: 0; pointer-events: none;
  transform: translateY(8px);
  transition: opacity .35s ease, transform .35s ease;
}
#seed-popup.on { opacity: 1; pointer-events: auto; transform: none; }
.sp-title { font-family: var(--serif); font-size: 16px; color: var(--warm); margin-bottom: 6px; }
.sp-sub { font-size: 12px; color: rgba(245, 234, 214, .55); margin-bottom: 14px; line-height: 1.5; }
#dict-link {
  display: inline-block;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: .18em; text-transform: uppercase;
  color: #17130f;
  background: var(--warm);
  padding: 9px 14px;
  text-decoration: none;
}
#dict-link:hover { background: var(--coral); }
#seed-close {
  position: absolute; top: 6px; right: 8px;
  background: none; border: none; color: var(--gray);
  font-size: 16px; cursor: pointer;
}
#disclaimer {
  margin-top: 8px;
  max-width: 560px;
  text-align: center;
  font-family: var(--mono);
  font-size: 10.5px;
  line-height: 1.9;
  letter-spacing: .06em;
  color: rgba(245, 234, 214, .42);
}

/* ---------------- slang toast ---------------- */
#slang-toast {
  position: fixed;
  left: 50%; bottom: 9%;
  transform: translate(-50%, 16px);
  z-index: 70;
  max-width: min(460px, 86vw);
  padding: 14px 40px 14px 18px;
  background: rgba(27, 26, 23, .82);
  border: 1px solid rgba(255, 106, 77, .5);
  backdrop-filter: blur(8px);
  color: var(--cream);
  font-size: 13px;
  line-height: 1.6;
  opacity: 0;
  pointer-events: none;
  transition: opacity .45s ease, transform .45s ease;
}
#slang-toast.on { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#slang-toast b { color: var(--coral); font-family: var(--mono); }
#slang-close {
  position: absolute; top: 6px; right: 10px;
  background: none; border: none;
  color: var(--gray); font-size: 15px; cursor: pointer;
}

/* ---------------- misc ---------------- */
.hidden { display: none !important; }

@media (max-width: 640px) {
  #logo { top: 18px; left: 20px; font-size: 18px; }
  #score-module { top: 16px; right: 16px; width: 140px; }
  #readout { left: 20px; bottom: 16px; }
  #modal-card { padding: 28px 24px 22px; }
  #write-ui { flex-direction: column; }
  #no-emoji { width: 34px; height: 34px; }
}
