@font-face {
  font-family: "Press Start 2P";
  src: url("/fonts/press-start-2p.woff2") format("woff2");
  font-display: swap;
}
@font-face {
  font-family: "VT323";
  src: url("/fonts/vt323.woff2") format("woff2");
  font-display: swap;
}

:root {
  --space: #1d1e2b;      /* night sky, matches the starfield image */
  --gold: #ffe94a;       /* Geocities headline yellow */
  --silver: #c0c0c0;     /* Win95 chrome */
  --shadow: #808080;
  --navy: #000080;
  --oracle: #1c1a25;     /* 8-ball text, the ball's own dark */
  --ink: #000;
  --paper: #fff;
  color-scheme: dark;
  /* Win95 raised edge for scrollbar parts */
  --bevel: inset 1px 1px 0 #dfdfdf, inset -1px -1px 0 var(--ink),
    inset 2px 2px 0 var(--paper), inset -2px -2px 0 var(--shadow);
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

/* Stop phones inflating text in landscape. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  /* At least one screen tall, so the footer sits at the bottom of the screen
     even when the window is closed. svh = height with the phone's address bar
     showing, so the footer is visible without scrolling. */
  min-height: 100vh;
  min-height: 100svh;
  background-color: var(--space);
  color: var(--paper);
  font: 1.35rem/1.3 "VT323", ui-monospace, monospace;
  display: flex;
  flex-direction: column;
  align-items: center;
}

main {
  position: relative; /* anchors the window trails */
  width: 100%;
  max-width: 560px;
  padding: 32px 16px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}

h1 {
  margin: 0;
  font: 400 clamp(1.1rem, 5vw, 1.75rem)/1.2 "Press Start 2P", monospace;
  color: var(--gold);
  text-shadow: 3px 3px 0 #c2185b, 6px 6px 0 var(--navy);
  letter-spacing: 0.02em;
}
@media (pointer: fine) {
  h1 { font-size: clamp(1.1rem, 5vw, 2.25rem); }
}

/* Pixel-art starfield behind everything. A fixed layer instead of
   background-attachment: fixed, which iOS Safari ignores. Tiled at a fixed
   2x size rather than scaled to the screen, so it never zooms when a phone's
   address bar slides in and out, and the pixels stay crisp. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: url("/images/starfield.png") center top / 1600px 720px repeat;
  image-rendering: pixelated;
}

/* --- The ball: the one loud thing on the page --- */
.ball {
  width: min(280px, 72vw);
  aspect-ratio: 1;
  border-radius: 50%;
  background: url("/images/ball.png") center / contain no-repeat;
  image-rendering: pixelated;
  box-shadow: 0 18px 0 -6px rgba(0, 0, 0, 0.55);
  display: grid;
  place-items: center;
}

.window {
  width: 48%; /* the white disc in ball.png */
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  text-align: center;
}

#ball-text {
  font: 400 3.4rem/1 "Press Start 2P", monospace;
  color: var(--oracle);
  /* Press Start 2P draws each glyph in the top-left 7x7 of an 8x8 cell,
     so shift it by half a font pixel to sit in the middle. */
  translate: 0.0625em 0.0625em;
}

.ball.shaking { animation: shake 0.5s steps(4) infinite; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  25% { transform: translate(-8px, 3px) rotate(-4deg); }
  50% { transform: translate(7px, -4px) rotate(3deg); }
  75% { transform: translate(-5px, -2px) rotate(-2deg); }
}

/* --- Win95 dialog --- */
.dialog {
  color-scheme: light; /* light form controls inside the grey window */
  width: 100%;
  background: var(--silver);
  color: var(--ink);
  border: 2px solid;
  border-color: var(--paper) var(--ink) var(--ink) var(--paper);
  box-shadow: inset -2px -2px 0 var(--shadow), inset 2px 2px 0 #dfdfdf;
  padding: 3px;
}

.titlebar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, var(--navy), #1084d0);
  color: var(--paper);
  font: 400 0.6rem/1 "Press Start 2P", monospace;
  padding: 6px 6px;
}
.titlebar .x {
  min-width: 0;
  font: inherit;
  background: var(--silver);
  color: var(--ink);
  padding: 2px 5px;
  border: 1px solid;
  border-color: var(--paper) var(--ink) var(--ink) var(--paper);
  box-shadow: none;
}
.titlebar .x:active { border-color: var(--ink) var(--paper) var(--paper) var(--ink); }
.titlebar .x:focus-visible { outline-offset: -3px; }

/* Frozen copies left behind by a dragged window (see app.js). */
.dialog.trail { position: absolute; margin: 0; }

/* The closed window: a Win98 desktop icon. Selected = navy label. */
.desktop-icon {
  min-width: 0;
  padding: 4px;
  background: none;
  border: 0;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font: 1.1rem/1.1 "VT323", monospace;
  color: var(--paper);
  cursor: default;
}
.desktop-icon:active { padding: 4px; border: 0; box-shadow: none; }
.desktop-icon:focus-visible { outline: none; }
.desktop-icon img { image-rendering: pixelated; }
.desktop-icon span { padding: 0 3px; border: 1px dotted transparent; }
.desktop-icon:focus span { background: var(--navy); border-color: var(--paper); }

.body { padding: 16px 14px 14px; }

.q { margin: 0 0 12px; font-size: 1.6rem; display: block; }

.buttons {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 14px;
}

button {
  font: 400 0.7rem/1 "Press Start 2P", monospace;
  color: var(--ink);
  background: var(--silver);
  padding: 10px 16px;
  min-width: 88px;
  border: 2px solid;
  border-color: var(--paper) var(--ink) var(--ink) var(--paper);
  box-shadow: inset -2px -2px 0 var(--shadow), inset 2px 2px 0 #dfdfdf;
  cursor: pointer;
  appearance: none;
  border-radius: 0;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
button:active {
  border-color: var(--ink) var(--paper) var(--paper) var(--ink);
  box-shadow: inset 2px 2px 0 var(--shadow);
  padding: 11px 15px 9px 17px;
}
button:focus-visible, textarea:focus-visible, .scroll:focus-visible {
  outline: 2px dotted var(--ink);
  outline-offset: -6px;
}

textarea {
  width: 100%;
  font: 1.3rem/1.2 "VT323", monospace;
  padding: 8px;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid;
  border-color: var(--shadow) var(--paper) var(--paper) var(--shadow);
  box-shadow: inset 2px 2px 0 var(--ink);
  resize: none;
  appearance: none;
  border-radius: 0;
}

.meta { margin: 6px 0 0; font-size: 1.05rem; color: #333; }
.meta.count { text-align: right; }
.meta.error { color: #a00000; }

/* On touch screens, the same height as the ask window's content above its
   button: question line (.q) + 4-row text box with padding and border
   (textarea) + character count (.meta). Keep in step if those change.
   On computers, halfway between that and 46% of the window. */
.scroll {
  --ask-height: calc(1.6rem * 1.3 + 12px + 4 * 1.3rem * 1.2 + 20px + 1.05rem * 1.3 + 6px);
  height: var(--ask-height);
  overflow-y: auto;
  background: var(--paper);
  padding: 10px 14px;
  border: 2px solid;
  border-color: var(--shadow) var(--paper) var(--paper) var(--shadow);
  box-shadow: inset 2px 2px 0 var(--ink);
}
@media (pointer: fine) {
  .scroll { height: calc((var(--ask-height) + 46vh) / 2); }
}

/* Win95 scrollbar for the white boxes (.win95-scroll): bevelled thumb and
   arrow buttons in Chrome-based browsers and Safari. They ignore these rules
   if scrollbar-color is set, so Firefox, which can only recolour, gets
   scrollbar-color on its own. */
.win95-scroll::-webkit-scrollbar { width: 16px; background: #dfdfdf; }
.win95-scroll::-webkit-scrollbar-thumb,
.win95-scroll::-webkit-scrollbar-button:single-button {
  background: var(--silver) no-repeat center;
  box-shadow: var(--bevel);
}
.win95-scroll::-webkit-scrollbar-thumb { min-height: 24px; }
.win95-scroll::-webkit-scrollbar-button:single-button { display: block; height: 16px; }
.win95-scroll::-webkit-scrollbar-button:single-button:vertical:decrement { background-image: url("/images/arrow-up.svg"); }
.win95-scroll::-webkit-scrollbar-button:single-button:vertical:increment { background-image: url("/images/arrow-down.svg"); }
.win95-scroll::-webkit-scrollbar-button:single-button:active { box-shadow: inset 0 0 0 1px var(--shadow); }
@supports not selector(::-webkit-scrollbar) {
  .win95-scroll { scrollbar-color: var(--shadow) #dfdfdf; }
}

/* Phones hide scrollbars until you scroll, so on touch screens draw an
   always-visible Win95 one. The thumb follows the box's scroll position
   through a scroll-driven animation; app.js makes the arrows, track and
   thumb respond to taps and drags. Browsers without scroll-driven
   animations keep their own scrollbar. */
.scroll-wrap { position: relative; }
.fake-scrollbar { display: none; }
@media (pointer: coarse) {
  @supports (animation-timeline: --howto) and (timeline-scope: --howto) {
    .scroll-wrap { timeline-scope: --howto; }
    .scroll {
      scroll-timeline: --howto block;
      scrollbar-width: none;
      padding-right: 30px;
    }
    .scroll::-webkit-scrollbar { display: none; }
    .fake-scrollbar {
      --arrow: 16px; /* arrow buttons are square; app.js reads this too */
      --thumb: 28px;
      display: block;
      position: absolute;
      top: 2px;
      right: 2px;
      bottom: 2px; /* inside the box's border */
      width: var(--arrow);
      background: #dfdfdf;
      touch-action: none; /* dragging the bar mustn't scroll the page */
    }
    .fake-scrollbar::before,
    .fake-scrollbar::after,
    .thumb {
      position: absolute;
      left: 0;
      width: var(--arrow);
      background: var(--silver) no-repeat center;
      box-shadow: var(--bevel);
    }
    .fake-scrollbar::before { content: ""; top: 0; height: var(--arrow); background-image: url("/images/arrow-up.svg"); }
    .fake-scrollbar::after { content: ""; bottom: 0; height: var(--arrow); background-image: url("/images/arrow-down.svg"); }
    .thumb {
      top: var(--arrow); /* below the up arrow, also when there is nothing to scroll */
      height: var(--thumb);
      animation: thumb auto linear both;
      animation-timeline: --howto;
    }
  }
}
/* From just below the up arrow to just above the down arrow. */
@keyframes thumb {
  from { top: var(--arrow); }
  to { top: calc(100% - var(--arrow) - var(--thumb)); }
}
.scroll h2 { font: 400 0.85rem/1.4 "Press Start 2P", monospace; margin: 4px 0 10px; }
.scroll h3 { font: 400 0.65rem/1.4 "Press Start 2P", monospace; margin: 16px 0 4px; color: var(--navy); }
.scroll p, .scroll ul { margin: 0 0 6px; }
.scroll ul { padding-left: 20px; }
code { font: inherit; background: #e8e8e8; padding: 0 3px; }

.answer { margin: 0; font-size: 1.6rem; overflow-wrap: anywhere; }
.answer:focus, .q:focus { outline: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

footer {
  margin: auto 0 0;
  padding: 16px;
  font-size: 1.05rem;
  color: #9aa0d8;
}

[hidden] { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .ball.shaking { animation: pulse 1.2s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.6; } }
}
