/* Codeman Club: a late-90s homepage around a 3D lobby.
   Win98-style windows on a starfield, chrome logo and a ticker. */

:root {
  --space: #05041a;
  --space-2: #0d0a33;
  --star: #cfd6ff;
  --text-on-space: #e6e4ff;
  --muted-on-space: #9b98d0;

  /* Win98 window chrome */
  --face: #c0c0c0;
  --face-light: #dfdfdf;
  --highlight: #ffffff;
  --shadow: #808080;
  --shadow-dark: #0a0a0a;
  --caption-a: #000080;
  --caption-b: #1084d0;
  --ink: #000000;
  --ink-muted: #3c3c3c;
  --link: #0000ee;
  --link-visited: #551a8b;
  --link-hover: #e3242b;

  --gold: #f0b860;
}

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

body {
  min-height: 100vh;
  background-color: var(--space);
  /* Tiled starfield, like an old background GIF */
  background-image:
    radial-gradient(1px 1px at 12px 18px, var(--star), transparent),
    radial-gradient(1px 1px at 70px 90px, #fff, transparent),
    radial-gradient(1.5px 1.5px at 130px 40px, #ffe8b0, transparent),
    radial-gradient(1px 1px at 160px 140px, var(--star), transparent),
    radial-gradient(1px 1px at 40px 150px, #b0c4ff, transparent),
    radial-gradient(ellipse 120% 80% at 50% 0%, var(--space-2), var(--space) 70%);
  background-size: 180px 180px, 180px 180px, 180px 180px, 180px 180px, 180px 180px, 100% 100%;
  background-attachment: fixed;
  color: var(--text-on-space);
  font-family: Verdana, Tahoma, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  padding: 1.5rem 16px 2rem;
  overflow-x: hidden;
}

main {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  gap: 1.5rem;
}

a:focus-visible, button:focus-visible, .viewport:focus-visible {
  outline: 1px dotted currentColor;
  outline-offset: 2px;
}

/* ---------- Header: chrome logo ---------- */

.site-header {
  text-align: center;
  margin-bottom: 1rem;
}

.logo {
  display: inline-block;
  font-family: "Orbitron", Verdana, sans-serif;
  font-weight: 900;
  font-size: clamp(1.9rem, 8.5vw, 4.2rem);
  line-height: 1.1;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: transparent;
  /* A moving shine over a chrome gradient */
  background:
    linear-gradient(110deg, transparent 42%, rgba(255,255,255,0.95) 50%, transparent 58%),
    linear-gradient(180deg, #ffffff 0%, #c8d0ff 38%, #2b2f6e 50%, #8d9bff 54%, #ffffff 100%);
  background-size: 300% 100%, 100% 100%;
  background-position: 120% 0, 0 0;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-stroke: 1px #0b0a26;
  filter: drop-shadow(0 3px 0 #000) drop-shadow(0 0 14px rgba(120, 140, 255, 0.45));
  animation: shine 5s ease-in-out infinite;
}

@keyframes shine {
  0%, 55% { background-position: 120% 0, 0 0; }
  100% { background-position: -20% 0, 0 0; }
}

.tagline {
  margin-top: 0.6rem;
  font-family: "VT323", monospace;
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--gold);
  letter-spacing: 0.03em;
  text-wrap: balance;
}

/* ---------- Ticker ---------- */

.ticker {
  max-width: 820px;
  margin: 0 auto 1.5rem;
  overflow: hidden;
  border-top: 1px solid #2a2766;
  border-bottom: 1px solid #2a2766;
  background: rgba(0, 0, 0, 0.45);
  font-family: "VT323", monospace;
  font-size: 1.25rem;
  color: #7dff9a;
  white-space: nowrap;
}

.ticker-track {
  display: inline-flex;
  gap: 2.5rem;
  padding: 0.15rem 0 0.15rem 100%;
  animation: ticker 32s linear infinite;
}

@keyframes ticker {
  to { transform: translateX(-100%); }
}

/* ---------- Win98 window ---------- */

.window {
  background: var(--face);
  color: var(--ink);
  padding: 3px;
  box-shadow:
    inset -1px -1px var(--shadow-dark),
    inset 1px 1px var(--face-light),
    inset -2px -2px var(--shadow),
    inset 2px 2px var(--highlight),
    0 18px 40px -12px rgba(0, 0, 0, 0.8);
  font-family: Tahoma, Verdana, "Segoe UI", sans-serif;
}

.titlebar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 24px;
  padding: 2px 6px;
  background: linear-gradient(90deg, var(--caption-a), var(--caption-b));
  color: #fff;
}

.titlebar h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.titlebar-icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  /* Tiny pixel "cube" icon for the VRML file */
  background:
    linear-gradient(135deg, #ffd36b 0 50%, #e8a13c 50% 100%);
  box-shadow: inset 0 0 0 1px #000;
}
.titlebar-icon-doc {
  background: linear-gradient(#fff 0 0) padding-box, #fff;
  box-shadow: inset 0 0 0 1px #000, inset 3px 4px 0 -2px #fff, inset 0 -3px 0 -1px #808080;
}

.titlebar-hint {
  margin-left: auto;
  font-size: 12px;
  color: #c9dcff;
  white-space: nowrap;
}
.hint-touch { display: none; }

.motion-toggle {
  flex-shrink: 0;
  height: 18px;
  padding: 0 6px;
  font-size: 11px;
}
.titlebar-hint + .titlebar-hint + .motion-toggle { margin-left: 0.4rem; }
@media (hover: none) {
  .hint-keys { display: none; }
  .hint-touch { display: inline; }
}

/* ---------- Buttons (raised bevel) ---------- */

.btn {
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--face);
  border: none;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    inset -1px -1px var(--shadow-dark),
    inset 1px 1px var(--highlight),
    inset -2px -2px var(--shadow),
    inset 2px 2px var(--face-light);
}
.btn:active:not(:disabled) {
  box-shadow:
    inset -1px -1px var(--highlight),
    inset 1px 1px var(--shadow-dark),
    inset -2px -2px var(--face-light),
    inset 2px 2px var(--shadow);
}
.btn:disabled { color: var(--shadow); text-shadow: 1px 1px var(--highlight); cursor: default; }
.btn:focus-visible { outline: 1px dotted var(--ink); outline-offset: -5px; }

/* ---------- 3D viewport ---------- */

.viewport {
  position: relative;
  margin-top: 3px;
  aspect-ratio: 16 / 10;
  background: #000;
  overflow: hidden;
  box-shadow:
    inset -1px -1px var(--highlight),
    inset 1px 1px var(--shadow),
    inset -2px -2px var(--face-light),
    inset 2px 2px var(--shadow-dark);
  padding: 2px;
  touch-action: pan-y;
}
.viewport:focus-visible { outline: 1px dotted var(--ink); outline-offset: 2px; }

.scene {
  display: block;
  width: 100%;
  height: 100%;
  /* Rendered at low resolution and scaled up: the PS1 / VRML look */
  image-rendering: pixelated;
  cursor: grab;
}
.scene.over-door { cursor: pointer; }

.turn {
  position: absolute;
  top: 50%;
  width: 40px;
  height: 44px;
  transform: translateY(-50%);
  z-index: 2;
}
.turn-left { left: 10px; }
.turn-right { right: 10px; }

.arrow-left, .arrow-right {
  width: 0;
  height: 0;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
}
.arrow-left { border-right: 8px solid var(--ink); margin-right: 2px; }
.arrow-right { border-left: 8px solid var(--ink); margin-left: 2px; }

/* Flash-style loading screen, shown once per browser session */
.splash {
  position: absolute;
  inset: 2px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  padding: 1rem;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,0.03) 0 1px, transparent 1px 3px),
    radial-gradient(ellipse at 50% 40%, #1b1650, #000 75%);
  color: #fff;
  text-align: center;
  transition: opacity 0.5s ease;
}
.splash[hidden] { display: none; }
.splash.leaving { opacity: 0; pointer-events: none; }

.splash-title {
  font-family: "Press Start 2P", monospace;
  font-size: clamp(0.95rem, 3.6vw, 1.6rem);
  color: var(--gold);
  text-shadow: 0 0 8px rgba(240, 184, 96, 0.7), 3px 3px 0 #3a1d00;
  text-transform: uppercase;
}
.splash-sub {
  font-family: "Press Start 2P", monospace;
  font-size: 0.6rem;
  letter-spacing: 0.4em;
  color: var(--muted-on-space);
  text-transform: uppercase;
  margin-top: -0.4rem;
}

.progress {
  width: min(260px, 80%);
  height: 20px;
  padding: 3px;
  background: var(--face);
  box-shadow: inset -1px -1px var(--highlight), inset 1px 1px var(--shadow);
}
.progress-fill {
  display: block;
  height: 100%;
  width: 0;
  /* Chunky Win98 progress blocks */
  background: repeating-linear-gradient(90deg, var(--caption-a) 0 10px, transparent 10px 12px);
  transition: width 0.25s steps(6);
}

.splash-enter {
  min-width: 140px;
  height: 30px;
  padding: 0 1rem;
}
.splash-enter:not(:disabled) { animation: blink 1.1s steps(2, start) infinite; }
@keyframes blink { 50% { color: var(--caption-a); } }

/* White-out when walking through a door */
.flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

/* ---------- Status bar ---------- */

.statusbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 4px;
  margin-top: 4px;
}

.status-field {
  display: flex;
  align-items: center;
  padding: 4px 8px;
  font-size: 13px;
  box-shadow: inset -1px -1px var(--highlight), inset 1px 1px var(--shadow);
}

.status-info {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  min-height: 46px;
}
.status-name { font-size: 14px; }
.status-name::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  background: var(--door-color, var(--gold));
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.6);
  vertical-align: 0;
}
.status-desc { color: var(--ink-muted); font-size: 12px; }

.btn-enter {
  min-width: 96px;
  padding: 0 1rem;
  font-weight: 700;
}
.btn-enter::after {
  content: "";
  margin-left: 8px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid currentColor;
}

/* ---------- Directory window ---------- */

/* Collapsible directory: the title bar is the <summary> */
.directory > summary {
  list-style: none;
  cursor: pointer;
}
.directory > summary::-webkit-details-marker { display: none; }
.directory > summary:focus-visible { outline: 1px dotted #fff; outline-offset: -3px; }

/* Win98-style +/- box on the right of the title bar */
.titlebar-toggle {
  position: relative;
  margin-left: auto;
  width: 16px;
  height: 14px;
  flex-shrink: 0;
}
.titlebar-toggle::before,
.titlebar-toggle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  background: var(--ink);
  transform: translate(-50%, -50%);
}
.titlebar-toggle::before { width: 8px; height: 2px; }
.titlebar-toggle::after { width: 2px; height: 8px; }
.directory[open] .titlebar-toggle::after { display: none; }

.directory-body {
  margin-top: 3px;
  padding: 0.9rem 1rem 1rem;
  background: #fff;
  box-shadow:
    inset -1px -1px var(--highlight),
    inset 1px 1px var(--shadow),
    inset -2px -2px var(--face-light),
    inset 2px 2px var(--shadow-dark);
}

.directory-intro {
  font-size: 13px;
  color: var(--ink-muted);
  margin-bottom: 0.6rem;
}

.dir-list {
  list-style: none;
  display: grid;
  gap: 0.15rem;
}

.dir-link {
  --c: var(--gold);
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  column-gap: 0.65rem;
  padding: 0.45rem 0.5rem;
  text-decoration: none;
  color: var(--ink);
}
.dir-link::before {
  content: "";
  grid-row: 1 / span 2;
  width: 12px;
  height: 12px;
  margin-top: 4px;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.55), inset -2px -2px rgba(0, 0, 0, 0.25), inset 2px 2px rgba(255, 255, 255, 0.45);
}
.dir-name {
  color: var(--link);
  text-decoration: underline;
  font-weight: 700;
}
.dir-link:visited .dir-name { color: var(--link-visited); }
.dir-link:hover { background: #000080; color: #fff; }
.dir-link:hover .dir-name, .dir-link:hover .dir-desc { color: #fff; }
.dir-desc {
  color: var(--ink-muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

/* No WebGL: hide the lobby, the directory is the page */
.no-webgl .lobby { display: none; }
.no-webgl .directory-intro { display: none; }
.no-webgl .ticker-controls { display: none; }

/* ---------- Footer ---------- */

.site-footer {
  max-width: 820px;
  margin: 2rem auto 0;
  text-align: center;
  color: var(--muted-on-space);
  display: grid;
  justify-items: center;
  gap: 1rem;
}

.site-name {
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  letter-spacing: 0.3em;
  color: #4b4880;
  text-transform: uppercase;
}

/* ---------- Phone ---------- */

@media (max-width: 600px) {
  body { padding-top: 1.1rem; }
  .viewport { aspect-ratio: 4 / 3; }
  .turn { width: 36px; height: 44px; }
  .btn-enter { min-width: 80px; }
  .turn-left { left: 6px; }
  .turn-right { right: 6px; }
}

/* ---------- Motion off (system setting or the Motion button; see motion.js) ---------- */

/* Too narrow for the hint and the Motion button; the ticker explains the controls */
@media (max-width: 420px) {
  .titlebar-hint { display: none !important; }
  .motion-toggle { margin-left: auto; }
}

.reduce-motion .logo,
.reduce-motion .splash-enter:not(:disabled) { animation: none; }
/* Still ticker: one message at a time, swapped by ticker.js */
.reduce-motion .ticker-track {
  animation: none;
  display: block;
  padding: 0.15rem 0.75rem;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reduce-motion .ticker-track > span:not(.current) { display: none; }

/* Phones: let a long message wrap, at a fixed two-line height so the page doesn't jump */
@media (max-width: 600px) {
  .reduce-motion .ticker-track {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(2lh + 0.3rem);
    line-height: 1.15;
    white-space: normal;
    text-wrap: balance;
  }
}
