/* Stonk Processing Unit. The page is the machine: a moulded bezel around one tube, and
   everything the site does happens on the glass. Every plastic surface here is a rendered
   object cut out of its backdrop and nine-sliced, never a border and a radius. */

@font-face {
  font-family: "Technor";
  src: url("/assets/fonts/Technor-Black.woff2") format("woff2");
  font-weight: 900;
  font-display: swap;
}
@font-face {
  font-family: "Departure Mono";
  src: url("/assets/fonts/DepartureMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

:root {
  --void: #04120a;
  --screen: #04170a;
  --screen-lit: #0e3617;
  --lime: #c4ff2f;
  --lime-hot: #f2ffc4;
  --lime-deep: #7cb01c;
  --lime-ink: #1d2f06;
  --plastic: #ece6f2;
  --amber: #ffb03a;
  --red: #ff5b4e;

  --ui: "Departure Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --display: "Technor", system-ui, sans-serif;

  --bezel: clamp(26px, 4.4vmin, 56px);

  /* Where the moulded lime title strip actually sits inside window.webp, measured off the
     render: the band runs y 125..211 of the 258px top slice and x 61..963 of 1024. Every
     caption is placed with these, so a title can never drift off its own bar again. */
  --band-y: 0.4845;
  --band-h: 0.3372;
  --band-x: 0.4550;
  --band-r: 0.4586;

  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--void);
  color: var(--lime);
  font-family: var(--ui);
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  /* the room his render sits in: dark green with soft out of focus lime blobs */
  background:
    radial-gradient(38vmax 30vmax at 12% 18%, rgba(160, 255, 40, 0.30), transparent 62%),
    radial-gradient(30vmax 26vmax at 88% 22%, rgba(120, 220, 30, 0.22), transparent 60%),
    radial-gradient(44vmax 34vmax at 70% 92%, rgba(140, 240, 40, 0.24), transparent 64%),
    radial-gradient(26vmax 22vmax at 22% 86%, rgba(90, 190, 20, 0.20), transparent 60%),
    var(--void);
}

/* ---------------------------------------------------------------- the machine */

#machine {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  padding: clamp(6px, 1.4vmin, 18px) clamp(6px, 1.4vmin, 18px) 0;
}

#screen {
  position: relative;
  min-height: 0;
  border-style: solid;
  border-width: calc(var(--bezel) * 1.02) calc(var(--bezel) * 0.84) calc(var(--bezel) * 1.53)
    calc(var(--bezel) * 0.84);
  border-image: url("/assets/art/bezel.webp") 192 158 288 157 fill / 1 / 0 stretch;
  filter: drop-shadow(0 calc(var(--bezel) * 0.4) calc(var(--bezel) * 0.9) rgba(0, 0, 0, 0.55));
  background: var(--screen);
}

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 110% at 50% 42%, var(--screen-lit), var(--screen) 70%, #020c05 100%);
  isolation: isolate;
}

/* scanlines, tube vignette and the one flash frame */
#glass {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 40;
  background:
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.20) 0 1px,
      rgba(0, 0, 0, 0) 1px 3px
    ),
    radial-gradient(120% 120% at 50% 50%, transparent 52%, rgba(0, 0, 0, 0.55) 100%);
  mix-blend-mode: multiply;
}
#glass::after {
  content: "";
  position: absolute;
  inset: 0;
  mix-blend-mode: screen;
  background: radial-gradient(70% 60% at 50% 20%, rgba(196, 255, 47, 0.07), transparent 70%);
}
#flash {
  position: absolute;
  inset: 0;
  background: var(--lime-hot);
  opacity: 0;
  mix-blend-mode: screen;
}
#flash.hit { animation: flash 620ms ease-out; }
@keyframes mark {
  from { opacity: 0; transform: scale(0.86); }
  to { opacity: 1; transform: none; }
}
@keyframes flash {
  0% { opacity: 0.96; }
  14% { opacity: 0.5; }
  100% { opacity: 0; }
}

#fx {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  pointer-events: none;
}

/* ------------------------------------------------------------- the chin plate */

/* the plate is a photographed object: it keeps its own aspect or the knob turns into an
   oval. 1009 x 194 is the alpha bounding box of the render, so the box matches the pixels. */
#chin {
  position: relative;
  width: min(520px, 80%);
  aspect-ratio: 1009 / 194;
  margin: calc(var(--bezel) * -0.5) auto 0;
  z-index: 60;
}
#chinplate {
  position: absolute;
  inset: 0;
  background: url("/assets/art/chin.webp") center / 100% 100% no-repeat;
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.5));
}
.chinbtn,
#volwrap {
  position: absolute;
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
}
/* the moulded features sit at fixed places on the plate, so the real controls are placed
   over them in the same proportions, measured off the cropped render */
#btn-power2 { left: 45.2%; width: 12.6%; top: 11%; height: 67%; border-radius: 50%; }
#volwrap    { left: 64.1%; width: 13%; top: 11.2%; height: 67.6%; cursor: grab; border-radius: 50%; touch-action: none; }
#volwrap:active { cursor: grabbing; }

#volwrap .vislabel { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
#vol {
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: inherit;
  margin: 0;
}
/* the knob is its own object and it really turns: the one moulded into the plate was
   painted out in art/chin-noknob.py so this could sit in its place */
#knob {
  position: absolute;
  left: 64.1%;
  top: 11.2%;
  width: 13%;
  height: 67.6%;
  pointer-events: none;
  transform-origin: 50% 50%;
  background: url("/assets/art/knob.webp") center / contain no-repeat;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.55));
}
#led {
  position: absolute;
  left: 85.5%;
  top: 38.6%;
  width: 4%;
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: none;
  background: #6b1a14;
  box-shadow: 0 0 8px rgba(255, 91, 78, 0.55);
}
#led.on { background: var(--lime); box-shadow: 0 0 14px rgba(196, 255, 47, 0.95); }

#btn-power2 span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

.chinbtn:focus-visible {
  outline: 3px solid var(--lime-hot);
  outline-offset: 3px;
}
#vol:focus-visible {
  opacity: 1;
  outline: 3px solid var(--lime-hot);
  outline-offset: 3px;
}

/* ------------------------------------------------------------------ act 1: cold */

#cold {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  isolation: isolate;
  place-content: center;
  justify-items: center;
  gap: clamp(10px, 2.4vmin, 22px);
  padding: 6vmin;
  text-align: center;
  overflow: auto;
}

/* the machine is in there, it is just not on yet */
#cold::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(62vmin, 620px);
  aspect-ratio: 1;
  transform: translate(-50%, -46%);
  background: url("/assets/art/chip.webp") center / contain no-repeat;
  opacity: 0.07;
  filter: grayscale(0.4);
  pointer-events: none;
}

#wordmark {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(24px, 6.2vmin, 72px);
  line-height: 0.98;
  letter-spacing: 0.01em;
  text-transform: uppercase;
  text-wrap: balance;
  /* his plate sets the register: brushed chrome type over the green */
  background: linear-gradient(
    176deg,
    #ffffff 0%, #cfd0e2 16%, #8e91a8 30%, #f6f7ff 44%,
    #b9bccf 56%, #6f7387 68%, #e8eaf5 82%, #9a9db2 100%
  );
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 0 rgba(20, 34, 8, 0.9)) drop-shadow(0 0 24px rgba(196, 255, 47, 0.35));
}
#wordmark { position: relative; }

#coldsub,
#coldnote {
  margin: 0;
  color: var(--lime);
  font-size: clamp(12px, 1.7vmin, 16px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
#coldnote { color: var(--lime-deep); max-width: 34ch; line-height: 1.6; letter-spacing: 0.08em; }

#power {
  position: relative;
  margin-top: 1vmin;
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-height: 56px;
  cursor: pointer;
  color: var(--lime-ink);
  font: inherit;
  font-size: clamp(13px, 1.9vmin, 17px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  border-style: solid;
  border-width: 34px 24px 28px 24px;
  border-image: url("/assets/art/window.webp") 258 133 208 134 fill / 1 / 0 stretch;
  background: linear-gradient(180deg, #d9ff7a, #a8e01c);
  background-clip: padding-box;
  padding: 10px 14px;
}
#power .label { position: relative; top: -1px; }
#power .ring {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex: none;
  background: var(--lime);
  box-shadow: 0 0 0 3px rgba(29, 47, 6, 0.7), 0 0 18px rgba(196, 255, 47, 0.9);
  animation: pulse 1.9s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.8); opacity: 0.55; }
}
#power:hover { filter: brightness(1.08); }
#power:active { transform: translateY(2px); }
#power:focus-visible { outline: 3px solid var(--lime-hot); outline-offset: 6px; }

/* ------------------------------------------------------------------ act 2: boot */

#boot {
  position: absolute;
  inset: 0;
  z-index: 10;
  padding: clamp(10px, 2.4vmin, 26px);
}
#post {
  margin: 0;
  font-family: var(--ui);
  font-size: clamp(11px, 1.62vmin, 17px);
  line-height: 1.42;
  color: var(--lime);
  text-shadow: 0 0 10px rgba(196, 255, 47, 0.4);
  white-space: pre-wrap;
  word-break: break-word;
}
#post b { color: var(--lime-hot); font-weight: 400; }
#post i { color: var(--amber); font-style: normal; }
#post u { color: var(--red); text-decoration: none; }

#bootmark {
  text-shadow: 0 3px 0 rgba(8, 20, 3, 0.9), 0 0 34px rgba(196, 255, 47, 0.85);
  animation: mark 520ms cubic-bezier(0.16, 1, 0.3, 1) both;
  position: absolute;
  inset: auto 4% 14% 4%;
  margin: 0;
  text-align: center;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(20px, 5.4vmin, 62px);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--lime-hot);
}

#btn-skip {
  position: absolute;
  right: clamp(10px, 2vmin, 22px);
  bottom: clamp(10px, 2vmin, 22px);
  z-index: 50;
  min-height: 44px;
  padding: 10px 16px;
  font: inherit;
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lime);
  background: rgba(4, 20, 9, 0.85);
  border: 2px solid var(--lime-deep);
  cursor: pointer;
}
#btn-skip:hover { color: var(--lime-hot); border-color: var(--lime); }
#btn-skip:focus-visible { outline: 3px solid var(--lime-hot); outline-offset: 3px; }

/* ------------------------------------------------------- acts 3 and 4: the desktop */

#desktop {
  position: absolute;
  inset: 0;
  z-index: 20;
}
#paper {
  position: absolute;
  inset: -6%;
  z-index: 15;
  background: url("/assets/art/shrine.webp") center / cover no-repeat;
  filter: blur(26px) brightness(0.6) saturate(2.4) hue-rotate(-12deg);
  opacity: 0.92;
  animation: drift 46s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes drift {
  from { transform: scale(1.04) translate3d(-1.4%, -1%, 0); }
  to { transform: scale(1.14) translate3d(1.6%, 1.2%, 0); }
}

.win {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 50% 50%;
  border-style: solid;
  border-width: var(--bt) var(--bs) 21px var(--bs);
  border-image: url("/assets/art/window.webp") 258 133 208 134 fill / 1 / 0 stretch;
  background: transparent;
  will-change: transform;
}
.win.settled { transition: transform 400ms cubic-bezier(0.16, 0.92, 0.22, 1); }
.cap {
  position: absolute;
  left: calc(var(--bs) * (var(--band-x) - 1));
  right: calc(var(--bs) * (var(--band-r) - 1));
  top: calc(var(--bt) * (var(--band-y) - 1));
  height: calc(var(--bt) * var(--band-h));
  display: flex;
  align-items: center;
  padding: 0 calc(var(--bs) * 0.55);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-transform: uppercase;
  color: var(--lime-ink);
}

.win {
  --bt: 46px;
  --bs: 15px;
}
.win .cap {
  font-size: 11px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.win .cap:focus-visible { outline: 3px solid var(--lime-ink); outline-offset: -2px; }
.win.dragging .cap { cursor: grabbing; }
.win .body {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #030f06;
}
.win img,
.win video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.win canvas { width: 100%; height: 100%; display: block; }
.win .shot {
  border: 0;
  padding: 0;
  margin: 0;
  width: 100%;
  height: 100%;
  background: transparent;
  cursor: zoom-in;
  display: block;
}
.win .shot:focus-visible { outline: 3px solid var(--lime-hot); outline-offset: -3px; }

/* the three actions, centre column, raised after the snap */
.panel {
  position: absolute;
  left: 0;
  top: 0;
  /* the two actions and the contract are never buried by a dragged window */
  z-index: 400;
  --bt: 52px;
  --bs: 19px;
  border-style: solid;
  border-width: var(--bt) var(--bs) 25px var(--bs);
  border-image: url("/assets/art/window.webp") 258 133 208 134 fill / 1 / 0 stretch;
  opacity: 0;
  transform: translateY(26px) scale(0.96);
  transition: opacity 260ms ease-out, transform 320ms cubic-bezier(0.2, 1.1, 0.3, 1);
  will-change: transform;
  pointer-events: none;
}
.panel.up { opacity: 1; transform: none; pointer-events: auto; }
.panel .cap {
  font-size: 12px;
  letter-spacing: 0.1em;
}
.panel .body {
  position: absolute;
  inset: 0;
  background: #030f06;
  display: grid;
  overflow: hidden;
}

.act {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  height: 100%;
  padding: 0 14px;
  color: var(--lime);
  text-decoration: none;
  font-size: clamp(12px, 1.7vmin, 16px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(180deg, rgba(196, 255, 47, 0.12), rgba(196, 255, 47, 0.02));
}
.act:hover { background: rgba(196, 255, 47, 0.2); color: var(--lime-hot); }
.act:focus-visible { outline: 3px solid var(--lime-hot); outline-offset: -4px; }
.act .mark { width: 34px; height: 34px; flex: none; display: block; }
.act svg.mark { fill: var(--lime); }
.act:hover svg.mark { fill: var(--lime-hot); }
.act[aria-disabled="true"] {
  color: var(--lime-deep);
  background: rgba(196, 255, 47, 0.04);
  cursor: not-allowed;
}
.act[aria-disabled="true"] svg.mark { fill: var(--lime-deep); }
.act small {
  display: block;
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--lime-deep);
}

#ca-panel .body {
  grid-template-rows: minmax(72px, 1fr) auto auto auto auto;
  align-content: stretch;
  justify-items: start;
  gap: 6px;
  padding: 10px 12px 12px;
}
#ca-chip {
  position: relative;
  justify-self: stretch;
  align-self: stretch;
  min-height: 0;
}
#ca-chip img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 18px rgba(196, 255, 47, 0.4));
}
#ca-label {
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--lime-deep);
}
/* an address breaks anywhere, a sentence breaks between words */
#ca-field {
  font-size: clamp(11px, 1.45vmin, 14px);
  line-height: 1.45;
  color: var(--lime-hot);
  overflow-wrap: anywhere;
  word-break: break-all;
  user-select: all;
  -webkit-user-select: all;
}
#ca-field.empty {
  color: var(--lime-deep);
  word-break: normal;
  overflow-wrap: break-word;
  user-select: auto;
  -webkit-user-select: auto;
}
#copy-ca {
  justify-self: start;
  min-height: 40px;
  padding: 8px 14px;
  font: inherit;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--lime-ink);
  background: var(--lime);
  border: 0;
  cursor: pointer;
}
#copy-ca:hover { background: var(--lime-hot); }
#copy-ca:focus-visible { outline: 3px solid var(--lime-hot); outline-offset: 3px; }
#copy-ca[disabled] { background: rgba(196, 255, 47, 0.16); color: var(--lime-deep); cursor: not-allowed; }
#copy-note { font-size: 11px; letter-spacing: 0.08em; color: var(--lime); min-height: 1.3em; }
#copy-note.bad { color: var(--red); }

/* the load readout is the mechanic, so it gets its own window */
#load-win .body { display: grid; grid-template-rows: minmax(0, 1fr) 12px auto; }
#load-win canvas { min-height: 0; height: 100%; }
#load-bar { position: relative; background: rgba(196, 255, 47, 0.12); }
#load-bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: var(--lime);
  transition: width 140ms linear;
}
#load-bar.hot i { background: var(--red); }
#defrag {
  min-height: 34px;
  font: inherit;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--lime-ink);
  background: var(--lime);
  border: 0;
  cursor: pointer;
}
#defrag:hover { background: var(--lime-hot); }
#defrag:focus-visible { outline: 3px solid var(--lime-hot); outline-offset: -3px; }

/* ------------------------------------------------------------------ the lightbox */

#viewer {
  border: 0;
  padding: 0;
  /* the pictures are square, so the frame has to be bounded by the SHORT side */
  max-width: min(92vw, 78vh, 880px);
  max-height: 92vh;
  background: transparent;
  overflow: visible;
  color: var(--lime);
}
#viewer::backdrop { background: rgba(2, 10, 4, 0.88); }
#viewer .frame {
  position: relative;
  --bt: 56px;
  --bs: 20px;
  border-style: solid;
  border-width: var(--bt) var(--bs) 27px var(--bs);
  border-image: url("/assets/art/window.webp") 258 133 208 134 fill / 1 / 0 stretch;
}
#viewer .cap {
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  letter-spacing: 0.1em;
}
#viewer img { display: block; width: 100%; height: auto; max-height: calc(92vh - 88px); object-fit: contain; background: #030f06; }
#viewer-close {
  font: inherit;
  font-size: 12px;
  color: var(--lime-ink);
  background: transparent;
  border: 0;
  cursor: pointer;
  min-height: 23px;
  padding: 0 4px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
#viewer-close:focus-visible { outline: 2px solid var(--lime-ink); }

/* ------------------------------------------------------------------- narrow screens */

@media (max-width: 780px) {
  :root { --bezel: clamp(15px, 4.4vmin, 24px); }
  #desktop { overflow-y: auto; overflow-x: hidden; }
  #desktop.locked { overflow: hidden; }
  #chin { width: min(400px, 94%); }
  .win { --bt: 42px; --bs: 13px; }
  .panel { --bt: 46px; --bs: 16px; }
  #power { border-width: 30px 20px 24px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  #power .ring { animation: none; }
  #paper { animation: none; }
  #stage.shaking { animation: none; }
  #stage.glitch { filter: none; }
  #flash.hit { animation: none; opacity: 0; }
  .win.settled { transition: transform 200ms linear; }
  .panel { transition: opacity 200ms linear; transform: none; }
}

/* the machine misbehaving: four one-off frames in the whole boot, never a strobe */
#stage.glitch { filter: invert(1) hue-rotate(90deg) saturate(1.3); }
#stage.shaking { animation: shake 780ms cubic-bezier(0.36, 0.07, 0.19, 0.97) both; }
@keyframes shake {
  10%, 90% { transform: translate(-2px, 1px); }
  20%, 80% { transform: translate(5px, -2px); }
  30%, 50%, 70% { transform: translate(-8px, 3px); }
  40%, 60% { transform: translate(8px, -3px); }
  100% { transform: none; }
}
#desktop .spacer { position: absolute; left: 0; top: 0; width: 1px; pointer-events: none; }
