:root {
  --night: #1b0f2a;     /* park sky */
  --dusk: #2e1c45;      /* panels, bezel */
  --dusk-2: #3d2a59;
  --bone: #f1e6cc;      /* ticket paper */
  --ink: #a8232b;       /* ticket print */
  --lamp: #f2a541;      /* sodium lamp: focus, progress */
  --fog: #b9abcc;       /* secondary text */
  --text: #efe7f6;
  --font-ui: "Atkinson Hyperlegible", system-ui, sans-serif;
  --font-ticket: "Rye", Georgia, serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1px 1px at 12% 18%, #fff8 50%, transparent 51%),
    radial-gradient(1px 1px at 78% 12%, #fff6 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 64% 32%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 28% 72%, #fff4 50%, transparent 51%),
    radial-gradient(1px 1px at 88% 64%, #fff5 50%, transparent 51%),
    radial-gradient(1px 1px at 44% 8%, #fff6 50%, transparent 51%),
    radial-gradient(120% 80% at 50% 110%, #3b1d52 0%, var(--night) 60%);
  background-color: var(--night);
  color: var(--text);
  font: 400 1rem/1.5 var(--font-ui);
}

button, .file-button {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid #ffffff2e;
  border-radius: 6px;
  padding: .4rem .8rem;
  cursor: pointer;
}
button:hover, .file-button:hover { border-color: #ffffff66; }
button:focus-visible, .file-button:focus-within { outline: 2px solid var(--lamp); outline-offset: 2px; }
.file-button input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-button { position: relative; display: inline-block; }

/* ---------- views ---------- */
#app[data-view="gate"] .game { display: none; }
#app[data-view="game"] .gate { display: none; }

/* ---------- the gate ---------- */
.gate {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 2.25rem;
  padding: 3rem 16px;
}

.ticket {
  --notch: 14px;
  width: min(660px, 100%);
  display: grid;
  grid-template-columns: 1fr 120px;
  color: var(--ink);
  background: var(--bone);
  transform: rotate(-1.5deg);
  box-shadow: 0 18px 50px #0008;
  /* notches at the perforation */
  -webkit-mask: radial-gradient(circle var(--notch) at calc(100% - 120px) 0, #0000 98%, #000) top / 100% 51% no-repeat,
                radial-gradient(circle var(--notch) at calc(100% - 120px) 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
          mask: radial-gradient(circle var(--notch) at calc(100% - 120px) 0, #0000 98%, #000) top / 100% 51% no-repeat,
                radial-gradient(circle var(--notch) at calc(100% - 120px) 100%, #0000 98%, #000) bottom / 100% 51% no-repeat;
}
.ticket-main {
  padding: 2rem 2rem 1.75rem;
  border: 3px double var(--ink);
  margin: 10px 0 10px 10px;
}
.ticket-park {
  margin: 0;
  font: 400 1.05rem/1 var(--font-ticket);
  letter-spacing: .04em;
}
.ticket h1 {
  margin: .35rem 0 .75rem;
  font: 400 clamp(2.1rem, 6.4vw, 3.5rem)/1.02 var(--font-ticket);
  letter-spacing: .01em;
  text-wrap: balance;
}
.ticket-fine {
  margin: 0 0 1.5rem;
  max-width: 34ch;
  color: #5b2a2e;
  font-size: .95rem;
}
.tear {
  color: var(--bone);
  background: var(--ink);
  border: 0;
  border-radius: 4px;
  padding: .75rem 1.25rem;
  font-weight: 700;
  font-size: 1.05rem;
}
.tear:hover { background: #8f1c23; }
.tear:disabled { opacity: .65; cursor: progress; }
.ticket-stub {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: .9rem;
  margin: 10px 10px 10px 0;
  border: 3px double var(--ink);
  border-left: 2px dashed var(--ink);
  font-family: var(--font-ticket);
}
.stub-admit { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 1.6rem; }
.stub-no { font-size: .8rem; }

.progress { margin-top: 1.25rem; }
.progress-track { height: 8px; background: #a8232b26; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ink); transition: width .2s linear; }
.progress-text { margin: .5rem 0 0; color: #5b2a2e; font-size: .9rem; }

/* tearing the stub off is the one bit of motion on the page */
.ticket-stub { transition: transform .5s cubic-bezier(.2,.8,.2,1), opacity .5s; }
.ticket.torn .ticket-stub { transform: translateY(8px) rotate(5deg); opacity: .3; }
@media (prefers-reduced-motion: reduce) {
  .ticket-stub { transition: none; }
  .ticket.torn .ticket-stub { transform: none; }
  .progress-fill { transition: none; }
}

.gate-notes {
  width: min(560px, 100%);
  color: var(--fog);
  font-size: .95rem;
}
.gate-notes p { margin: 0 0 .6rem; }
.gate-error { color: #ffcf8a; }
.gate-notes a { color: var(--fog); text-underline-offset: 2px; }
.gate-notes a:hover { color: var(--text); }
.gate-notes a:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

@media (max-width: 560px) {
  .ticket { grid-template-columns: 1fr 64px; transform: none;
    -webkit-mask: none; mask: none; }
  .ticket-main { padding: 1.4rem 1.2rem; }
  .stub-admit { font-size: 1.1rem; }
}

/* ---------- the game ---------- */
.game {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  background: #0c0714;
}
.bar { grid-row: 1; }
.saves-panel { grid-row: 2; }
.stage { grid-row: 3; }
.bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 16px;
  background: var(--dusk);
}
.bar-title { font: 400 1.1rem/1 var(--font-ticket); color: var(--bone); }
.bar-status { flex: 1; display: flex; gap: 1rem; color: var(--fog); font-size: .85rem; }
.bar-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.bar-actions button { font-size: .9rem; padding: .3rem .7rem; }

.saves-panel {
  padding: .9rem 16px 1rem;
  background: var(--dusk-2);
  font-size: .95rem;
}
.saves-panel p { margin: 0 0 .6rem; max-width: 70ch; }
.saves-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.saves-hint { color: var(--fog); font-size: .85rem; }

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  display: grid;
  place-items: center;
}
.screen-fit { width: 640px; height: 480px; }
#screen_container {
  width: 640px;
  height: 480px;
  transform-origin: 0 0;
  background: #000;
  box-shadow: 0 0 0 1px #ffffff14, 0 20px 60px #000c;
  overflow: hidden;
}
/* The page owns the screen size: v86 auto-doubles the canvas on high-DPI displays and
   measures it while hidden (giving 0x0), so override its inline sizing. */
#screen_container canvas {
  display: block;
  width: 640px !important;
  height: 480px !important;
  image-rendering: auto !important;
  cursor: none !important;
}
#screen_container .textmode {
  white-space: pre;
  font: 14px/14px monospace;
  color: #c9c1d6;
  padding: 4px;
}
.stage-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: #0c0714d9;
  text-align: center;
  padding: 16px;
}
.stage-overlay p { max-width: 46ch; }

.status-net { color: var(--lamp); }

/* ---------- full screen: only the game ----------
   #app.immersive is set while the stage is the full-screen element, or while the
   browser window itself fills the screen (the browser's own full-screen mode). */
#app.immersive .bar, #app.immersive .saves-panel { display: none; }
#app.immersive .game { grid-template-rows: 1fr; background: #000; }
#app.immersive .stage { grid-row: 1; background: #000; }
#app.immersive #screen_container { box-shadow: none; }
.stage:fullscreen { background: #000; }
.stage:-webkit-full-screen { background: #000; width: 100%; height: 100%; }
.fs-controls, .fs-hint { display: none; }
#app.immersive .fs-controls, #app.immersive .fs-hint { display: flex; }
.fs-controls {
  position: absolute; top: 12px; right: 12px; z-index: 4;
  gap: .4rem; padding: .4rem; border-radius: 8px;
  background: #1b0f2ae6;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
.fs-controls button { font-size: .85rem; padding: .3rem .65rem; }
.stage.show-controls .fs-controls { opacity: 1; pointer-events: auto; }
.fs-controls button[hidden] { display: none !important; }
.fs-hint {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%); margin: 0;
  padding: .35rem .75rem; border-radius: 6px; background: #1b0f2ad9; color: var(--fog); font-size: .85rem;
  opacity: 0; transition: opacity .4s; pointer-events: none;
}
.stage.show-hint .fs-hint { opacity: 1; }
@media (prefers-reduced-motion: reduce) { .fs-controls, .fs-hint { transition: none; } }
