/* ============================================================
   Consett Steelworks: cosy pixel UI
   ============================================================ */
:root {
  --ink: #2b2620;
  --paper: #f6ead8;
  --paper-2: #efdfc6;
  --accent: #c9572e;       /* furnace orange */
  --accent-2: #e08a3c;
  --steel: #5d6672;
  --shadow: rgba(43, 38, 32, 0.35);
  --radius: 14px;
  --font-pixel: 'Pixelify Sans', monospace;
  --font-body: 'Nunito', system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  color: var(--ink);
  background: #a8d8ea;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* red-dust atmosphere */
#dust-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.6s;
  background:
    radial-gradient(ellipse at 50% 110%, rgba(156, 82, 54, 0.55), transparent 60%),
    linear-gradient(rgba(156, 82, 54, 0.12), rgba(156, 82, 54, 0.12));
  mix-blend-mode: multiply;
  z-index: 2;
}

/* ---------------- header ---------------- */
#topbar {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100% - 20px);
  text-align: center;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 2px 0 var(--shadow);
}
#topbar h1 {
  font-family: var(--font-pixel);
  font-size: clamp(20px, 5.5vw, 32px);
  font-weight: 700;
  color: var(--paper);
  letter-spacing: 1px;
}
#topbar p {
  font-size: clamp(10px, 2.8vw, 13px);
  font-weight: 700;
  color: var(--paper-2);
  opacity: 0.9;
}

#hint {
  position: fixed;
  top: calc(74px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(43, 38, 32, 0.65);
  color: var(--paper);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  z-index: 5;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.8s;
}
#hint.hide { opacity: 0; }

/* ---------------- time bar ---------------- */
#timebar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 20px));
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--shadow);
  padding: 10px 14px 16px;
  z-index: 10;
  touch-action: pan-x;
}

#year-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

#play-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--accent);
  color: var(--paper);
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform 0.08s;
}
#play-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
#play-btn .icon-pause { display: none; }
#play-btn.playing .icon-play { display: none; }
#play-btn.playing .icon-pause { display: inline; }

#year-display { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
#year-label {
  /* body font for digits: pixel-font 2s and 8s are too easy to confuse */
  font-family: var(--font-body);
  font-size: 32px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  line-height: 1;
}
#era-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--steel);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------- slider + milestone ticks ---------------- */
#slider-wrap { position: relative; height: 34px; }

#ticks {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tick {
  position: absolute;
  top: 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  background: var(--accent-2);
  border: 2px solid var(--ink);
  transform: rotate(45deg);
  border-radius: 3px;
  cursor: pointer;
  pointer-events: auto;
  z-index: 2;
  padding: 0;
}
.tick:hover { background: var(--accent); }

#year-slider {
  -webkit-appearance: none;
  appearance: none;
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  height: 10px;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 999px;
  outline: none;
  z-index: 3;
  touch-action: pan-x;
}
#year-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--accent);
  border: 3px solid var(--ink);
  box-shadow: 0 2px 0 var(--shadow);
  cursor: grab;
}
#year-slider::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: var(--accent);
  border: 3px solid var(--ink);
  box-shadow: 0 2px 0 var(--shadow);
  cursor: grab;
}

/* ---------------- milestone card (top, under the title) ---------------- */
#milestone-card {
  position: fixed;
  left: 50%;
  transform: translate(-50%, -14px);
  top: calc(70px + env(safe-area-inset-top));
  width: min(480px, calc(100% - 28px));
  background: rgba(246, 234, 216, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--shadow);
  padding: 14px 38px 14px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 9;
}
#milestone-card.show {
  opacity: 1;
  pointer-events: auto;
  transform: translate(-50%, 0);
}
#ms-year {
  font-family: var(--font-body);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  font-size: 14px;
  background: var(--accent);
  color: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 2px 8px;
  display: inline-block;
}
#ms-title {
  font-family: var(--font-pixel);
  font-size: 20px;
  margin: 6px 0 4px;
}
#ms-text { font-size: 14px; line-height: 1.45; }
#ms-continue {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.5px;
  margin-top: 8px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s;
}
#milestone-card.autopause #ms-continue { opacity: 0.85; }

/* ---------------- building info sheet ---------------- */
#info-sheet {
  position: fixed;
  left: 50%;
  transform: translate(-50%, calc(100% + 200px));
  visibility: hidden;
  bottom: calc(152px + env(safe-area-inset-bottom));
  width: min(480px, calc(100% - 28px));
  background: rgba(246, 234, 216, 0.7);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  cursor: pointer;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--shadow);
  padding: 14px 38px 14px 16px;
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.1), visibility 0s 0.32s;
  z-index: 11;
  max-height: 42vh;
  overflow-y: auto;
}
#info-sheet.open {
  transform: translate(-50%, 0);
  visibility: visible;
  transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.1), visibility 0s 0s;
}
#sheet-name {
  font-family: var(--font-pixel);
  font-size: 21px;
  color: var(--ink);
}
#sheet-dates {
  display: inline-block;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--paper);
  background: var(--steel);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 2px 8px;
  margin: 4px 0 8px;
}
#sheet-text { font-size: 14px; line-height: 1.5; }

/* the patrol car's sheet: the milestone card is dismissed for it,
   so it can take more of the screen */
#info-sheet.tall { max-height: 64vh; }

/* ---------------- the other timeline ---------------- */
.glitch-btn {
  font-family: var(--font-pixel);
  font-size: 15px;
  font-weight: 700;
  color: #7df5e6;
  background: #241a3d;
  border: 3px solid var(--ink);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
  text-shadow: 2px 0 #ff4ad1, -2px 0 #43d6ff;
  animation: glitch-jitter 1.3s infinite, glitch-shadow 0.34s steps(2) infinite;
}
.glitch-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
#what-if { display: block; width: 100%; margin-top: 12px; }
#what-if[hidden], #reality-btn[hidden] { display: none; }
#reality-btn {
  position: fixed;
  right: 12px;
  bottom: calc(160px + env(safe-area-inset-bottom));
  z-index: 8;
  font-size: 13px;
  padding: 8px 12px;
}
@keyframes glitch-jitter {
  0%, 84%, 100% { transform: translate(0); filter: none; }
  86% { transform: translate(-2px, 1px) skewX(-6deg); }
  88% { transform: translate(3px, -1px); filter: hue-rotate(50deg); }
  91% { transform: translate(-1px, 2px) skewX(5deg); }
  94% { transform: translate(2px, 0); filter: hue-rotate(-40deg); }
  97% { transform: translate(-2px, -1px); }
}
@keyframes glitch-shadow {
  0% { text-shadow: 2px 0 #ff4ad1, -2px 0 #43d6ff; }
  50% { text-shadow: -2px 0 #ff4ad1, 2px 0 #43d6ff; }
  100% { text-shadow: 2px 1px #ff4ad1, -2px -1px #43d6ff; }
}

#glitch-fx {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  display: none;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 74, 209, 0.18) 0 3px,
    rgba(67, 214, 255, 0.18) 3px 6px,
    transparent 6px 11px
  );
  mix-blend-mode: screen;
}
#glitch-fx.active { display: block; animation: glitch-wipe 0.55s steps(10) forwards; }
@keyframes glitch-wipe {
  0% { opacity: 1; transform: translateX(0); }
  20% { transform: translateX(-14px) skewX(4deg); }
  40% { transform: translateX(11px); }
  60% { transform: translateX(-7px) skewX(-3deg); }
  80% { transform: translateX(4px); }
  100% { opacity: 0; transform: translateX(0); }
}

/* golden bloom + drifting sparkles for crossing into the dream */
#bloom-fx {
  position: fixed;
  inset: 0;
  z-index: 41;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(circle at 50% 45%, rgba(255, 250, 224, 0.95), rgba(255, 233, 168, 0.5) 35%, rgba(255, 255, 255, 0) 72%);
}
#bloom-fx.active { animation: bloom-burst 1.1s ease-out forwards; }
@keyframes bloom-burst {
  0% { opacity: 0; transform: scale(0.6); }
  25% { opacity: 1; }
  100% { opacity: 0; transform: scale(1.5); }
}

#magic-fx {
  position: fixed;
  inset: 0;
  z-index: 42;
  pointer-events: none;
  overflow: hidden;
}
#magic-fx .star {
  position: absolute;
  color: #ffe9a8;
  text-shadow: 0 0 8px #fff7d6, 0 0 18px #ffd76e;
  animation: star-pop 1.5s ease-out forwards;
  opacity: 0;
}
@keyframes star-pop {
  0% { transform: scale(0) rotate(0deg); opacity: 0; }
  25% { opacity: 1; }
  100% { transform: scale(1.5) rotate(50deg) translateY(-46px); opacity: 0; }
}

#ms-close, #sheet-close, #sources-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper-2);
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  cursor: pointer;
}

/* ---------------- intro ---------------- */
#intro {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 30%, rgba(224, 138, 60, 0.25), transparent 60%),
    linear-gradient(#3a3330, #211d1a);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  transition: opacity 0.6s;
  padding: 20px;
}
#intro.hide { opacity: 0; pointer-events: none; }

#intro-card {
  width: min(440px, 100%);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 8px 0 var(--shadow);
  padding: 26px 24px;
  text-align: center;
}
#intro-card h1 {
  font-family: var(--font-pixel);
  font-size: clamp(34px, 9vw, 46px);
  line-height: 1.05;
  color: var(--accent);
  text-shadow: 2px 2px 0 var(--paper-2);
}
#intro-card .sub {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  color: var(--steel);
  margin: 8px 0 14px;
}
#intro-card p { font-size: 14px; line-height: 1.5; margin-bottom: 10px; }
#start-btn {
  margin-top: 8px;
  font-family: var(--font-pixel);
  font-size: 18px;
  font-weight: 700;
  color: var(--paper);
  background: var(--accent);
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 12px 26px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--shadow);
  transition: transform 0.08s;
}
#start-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--shadow); }

/* ---------------- menu ---------------- */
#menu-btn {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 10px;
  z-index: 30;
  width: 42px;
  height: 42px;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--shadow);
  transition: transform 0.08s;
}
#menu-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }

#menu-panel {
  position: fixed;
  top: calc(58px + env(safe-area-inset-top));
  left: 10px;
  z-index: 30;
  min-width: 210px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 4px 0 var(--shadow);
  padding: 6px;
  display: none;
}
#menu-panel.open { display: block; }
#menu-panel ul { list-style: none; }
#menu-panel li + li { border-top: 2px solid var(--paper-2); }
#menu-panel button {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  background: none;
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
#menu-panel button:hover { background: var(--paper-2); }

#sources-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(43, 38, 32, 0.55);
  padding: 20px;
}
#sources-modal.open { display: flex; }
#sources-card {
  position: relative;
  width: min(520px, 100%);
  max-height: 80vh;
  overflow-y: auto;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 0 6px 0 var(--shadow);
  padding: 18px 20px;
}
#sources-card h2 {
  font-family: var(--font-pixel);
  font-size: 20px;
  margin: 0 26px 6px 0;
}
#sources-card p { font-size: 13px; line-height: 1.5; margin-bottom: 10px; }
#sources-list { list-style: none; }
#sources-list li { margin: 8px 0; }
#sources-list a {
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  word-break: break-word;
}

/* when the selected year predates or outlives the open building,
   the sheet quietly fades away */
#info-sheet.vaporise {
  opacity: 0;
  transform: translate(-50%, -10px) scale(0.97);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}

/* ---------------- small screens ---------------- */
@media (max-width: 420px) {
  #year-label { font-size: 28px; }
  #era-label { font-size: 11px; }
  #play-btn { width: 42px; height: 42px; }
  #info-sheet { bottom: calc(142px + env(safe-area-inset-bottom)); }
}
@media (max-height: 500px) and (orientation: landscape) {
  #topbar { display: none; }
  #timebar { width: min(480px, calc(100% - 20px)); padding: 6px 12px 10px; }
  #milestone-card { top: 10px; max-height: 60vh; }
  #info-sheet { bottom: auto; top: 10px; max-height: 60vh; }
}
