@font-face {
  font-family: 'PixelFont';
  src: url('Assets/shared/PixelFont.ttf') format('truetype');
  font-display: block;
}

html, body {
  margin: 0;
  height: 100%;
  background: #000;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

/* Everything visible sits in #app; JS sizes it in px (see `layout` in src/main.js). */
#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Phone held upright: rotate the whole app a quarter turn so the site is always played in
   landscape. Works even when the device's rotation lock is on — turning the phone
   counter-clockwise brings it upright. The transform also makes #app the containing block
   for the fixed-position HUD / controls / overlay inside it, so they rotate along with it. */
body.rotated #app {
  position: fixed;
  top: 0;
  left: 0;
  transform-origin: top left;
  transform: rotate(90deg) translateY(-100%);
}

body.touch {
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

#stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* JS sets the exact integer-scaled width/height on resize. */
}

/* The canvas blackouts (city <-> runner, and the runner's venue swap) are painted into the
   canvas, which can't reach the DOM UI sitting on top of it. render() in src/main.js drives
   --ui-fade so these go dark in step instead of staying lit over a black screen. */
#hud,
#touch-controls {
  opacity: var(--ui-fade, 1);
}

/* HUD: social links + classic-site toggle, over the canvas. */
#hud {
  position: fixed;
  top: 14px;
  right: 16px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 14px;
}

#social {
  display: flex;
  gap: 10px;
}

.hud-icon {
  color: rgba(244, 233, 193, 0.78);
  font-size: 22px;
  line-height: 1;
  text-decoration: none;
  transition: color 0.15s, transform 0.15s;
}

.hud-icon:hover {
  color: #ffe066;
  transform: translateY(-2px);
}

#classic-toggle,
#skin-toggle,
#settings-toggle {
  font-family: 'PixelFont', monospace;
  font-size: 15px;
  color: #14131f;
  background: #ffe066;
  padding: 7px 12px;
  border: 2px solid #f4e9c1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

#classic-toggle:hover,
#skin-toggle:hover,
#settings-toggle:hover {
  background: #fff0a0;
}

/* In the runner minigame the two switches are hidden: a stray click would reskin the world
   mid-run or leave the page, and they sit right where the score reads. src/main.js adds
   body.in-runner at the moment the scene swap is fully black, so they never blink out.
   Settings deliberately stays: it holds the music toggle, and muting mid-run is harmless
   and useful (opening it pauses the run anyway). */
body.in-runner #skin-toggle,
body.in-runner #classic-toggle {
  display: none;
}

/* Narrow stage (phone in landscape): shrink the HUD so it doesn't eat the scene. */
body.compact #hud {
  top: 8px;
  right: 10px;
  gap: 9px;
}

body.compact #social { gap: 8px; }
body.compact .hud-icon { font-size: 17px; }

body.compact #classic-toggle,
body.compact #skin-toggle,
body.compact #settings-toggle {
  font-size: 12px;
  padding: 5px 8px;
  border-width: 1px;
}

/* ---- Touch gamepad ---- */
#touch-controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7; /* above the canvas, below the overlay */
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0 18px 18px;
  pointer-events: none; /* only the buttons themselves are tappable */
}

#touch-controls.hidden,
body.overlay-open #touch-controls {
  display: none;
}

.pad { display: flex; gap: 12px; align-items: flex-end; }
.pad-right { flex-direction: column; align-items: flex-end; }
.pad-row { display: flex; gap: 12px; }

.tbtn {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  padding: 0;
  font-family: 'PixelFont', monospace;
  font-size: 24px;
  color: #f4e9c1;
  background: rgba(20, 19, 31, 0.5);
  border: 2px solid rgba(255, 224, 102, 0.7);
  border-radius: 0;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.tbtn.active {
  background: rgba(255, 224, 102, 0.85);
  color: #14131f;
  border-color: #f4e9c1;
}

.tbtn.hidden { display: none; }

/* Contextual "enter this building" button — only shown when the player is next to one. */
.tbtn-enter {
  width: auto;
  height: 44px;
  padding: 0 14px;
  font-size: 15px;
  background: rgba(255, 224, 102, 0.9);
  color: #14131f;
  margin-bottom: 4px;
}

body.compact .tbtn { width: 52px; height: 52px; font-size: 20px; }
body.compact .tbtn-enter { width: auto; height: 40px; font-size: 13px; }

/* Runner minigame: there is nothing to walk toward and nothing to sprint past, so the walk
   pad and the sprint button go away and jump takes over the whole right side. */
#touch-controls.runner { justify-content: flex-end; }
#touch-controls.runner .pad-left,
#touch-controls.runner .tbtn[data-action="sprint"] { display: none; }
#touch-controls.runner .tbtn[data-action="jump"] { width: 88px; height: 88px; font-size: 32px; }
body.compact #touch-controls.runner .tbtn[data-action="jump"] { width: 74px; height: 74px; font-size: 28px; }

/* ---- Rotate-your-phone hint (drawn inside the already-rotated frame) ---- */
#rotate-hint {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 8;
  padding: 8px 14px;
  font-family: 'PixelFont', monospace;
  font-size: 14px;
  white-space: nowrap;
  color: #14131f;
  background: #ffe066;
  border: 2px solid #f4e9c1;
  transition: opacity 0.6s ease;
}

#rotate-hint.hidden { display: none; }
#rotate-hint.fading { opacity: 0; }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 10; /* above the vignette and HUD */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
  font-family: 'PixelFont', monospace;
}

#overlay.hidden {
  display: none;
}

#overlay-panel {
  position: relative;
  background: #14131f;
  color: #f4e9c1;
  padding: 28px 30px;
  border: 4px solid #ffe066; /* sharp pixel frame, no rounded corners */
  border-radius: 0;
  box-shadow: 0 0 0 4px #14131f; /* inset gap for a double-border pixel look */
  max-width: 720px;
  width: 92%;
  /* % of #overlay (which fills #app) rather than vh — under body.rotated the viewport's
     height is the app's *width*, so vh would be wrong. */
  max-height: 84%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y; /* body.touch disables gestures; the panel still needs to scroll */
  image-rendering: pixelated;
}

#overlay-content h2 {
  margin: 0 0 16px;
  font-size: 30px;
  font-weight: normal;
  letter-spacing: 1px;
  color: #ffe066;
}

#overlay-content p {
  margin: 0;
  font-size: 15px;
  line-height: 1.9;
}

#overlay-close {
  position: absolute;
  top: 6px;
  right: 12px;
  background: none;
  border: none;
  color: #f4e9c1;
  font-family: 'PixelFont', monospace;
  font-size: 26px;
  cursor: pointer;
  line-height: 1;
}

/* ---- Rich section content ---- */
#overlay-content h3 {
  margin: 24px 0 8px;
  font-size: 18px;
  font-weight: normal;
  letter-spacing: 0.5px;
  color: #ffe066;
}

#overlay-content p { margin: 0 0 12px; }
#overlay-content p.lead { font-size: 17px; color: #fff; }
#overlay-content .meta { font-size: 13px; color: #9aa0b8; }
#overlay-content strong { color: #fff; }

#overlay-content ul {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 15px;
  line-height: 1.9;
}
#overlay-content li { margin-bottom: 4px; }

#overlay-content a {
  color: #ffe066;
  text-decoration: none;
}

/* Image placeholder — swap for <img> later (img inherits the frame). */
.img-ph, #overlay-content img {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 140px;
  margin: 0 0 16px;
  border: 2px dashed rgba(244, 233, 193, 0.35);
  background: rgba(255, 255, 255, 0.03);
  color: #6f7590;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-align: center;
  box-sizing: border-box;
}
#overlay-content img { border-style: solid; border-color: rgba(244, 233, 193, 0.25); min-height: 0; height: 200px; object-fit: cover; }
.img-ph.portrait { max-width: 180px; min-height: 180px; }
#overlay-content img.portrait { max-width: 200px; height: 200px; }

/* Skill chips */
.skill-block { margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: 13px;
  padding: 5px 10px;
  background: rgba(255, 224, 102, 0.12);
  border: 1px solid rgba(255, 224, 102, 0.4);
  color: #f4e9c1;
}

/* Project cards */
.card-grid { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.card {
  display: flex;
  gap: 14px;
  padding: 12px;
  border: 2px solid rgba(244, 233, 193, 0.2);
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}
.card:hover { border-color: #ffe066; transform: translateY(-2px); background: rgba(255, 224, 102, 0.06); }
.card .card-thumb { flex: 0 0 150px; min-height: 96px; height: 96px; margin: 0; object-fit: cover; }
.card .card-text { flex: 1; }
.card .card-text h3 { margin: 0 0 4px; color: #fff; }
.card .card-text p { margin: 6px 0 0; font-size: 14px; line-height: 1.7; }
.card .card-text .jam-results { font-size: 13.5px; line-height: 1.6; }
.card .card-text .jam-results strong { color: #fff; }
.card .card-text .jam-results .of { color: #cfd5e6; font-size: 13px; }
.badge {
  font-size: 11px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
  background: #ffe066;
  color: #14131f;
}

/* bilibili progress + CTA */
.cta-block { margin-top: 24px; }
.progress { margin-bottom: 14px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #9aa0b8;
  margin-bottom: 6px;
}
.progress-track {
  height: 14px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(244, 233, 193, 0.25);
}
.progress-fill {
  height: 100%;
  background: repeating-linear-gradient(90deg, #ffe066 0, #ffe066 6px, #ffd23a 6px, #ffd23a 12px);
}
.cta {
  display: inline-block;
  font-family: 'PixelFont', monospace;
  font-size: 16px;
  color: #14131f !important;
  background: #ffe066;
  padding: 10px 18px;
  border: 2px solid #f4e9c1;
}
.cta:hover { background: #fff0a0; }
.cta + .cta { margin-left: 10px; } /* itch.io + bilibili sit side by side */

/* ---- Compact stage (phone landscape) ----
   Driven by a body class instead of a media query: when the app is force-rotated the CSS
   viewport is still portrait, so `max-width` would describe the wrong axis. `layout()` in
   src/main.js sets .compact from the app's own width. */
body.compact #overlay-panel {
  width: 94%;
  max-height: 88%;
  padding: 18px 20px;
  border-width: 3px;
}

body.compact #overlay-content h2 { font-size: 22px; margin-bottom: 10px; }
body.compact #overlay-content h3 { font-size: 16px; margin: 16px 0 6px; }
body.compact #overlay-content p { font-size: 13px; line-height: 1.7; }
body.compact #overlay-content p.lead { font-size: 14px; }
body.compact #overlay-content ul { font-size: 13px; line-height: 1.7; }
body.compact #overlay-content img { height: 140px; }
body.compact #overlay-content img.portrait { max-width: 140px; height: 140px; }
body.compact .card .card-thumb { flex: 0 0 110px; height: 74px; min-height: 74px; }
body.compact .cta { font-size: 14px; padding: 8px 14px; }

/* Bigger tap target for the close button on touch. */
body.touch #overlay-close {
  top: 0;
  right: 4px;
  width: 44px;
  height: 44px;
  font-size: 30px;
}

/* Very narrow app: stack card thumbs above their text. (A `max-width` media query can't be
   used here — when rotated, the CSS viewport width is the app's height.) */
body.narrow .card { flex-direction: column; }
body.narrow .card .card-thumb { flex-basis: auto; width: 100%; }

/* ---- Settings rows (inside the section overlay) ---- */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 16px;
  margin-bottom: 12px;
  border: 2px solid rgba(244, 233, 193, 0.2);
  background: rgba(255, 255, 255, 0.02);
}

.setting-row .setting-info h3 { margin: 0 0 4px; }
.setting-row .setting-info p.meta { margin: 0; }

.setting-btn {
  flex: 0 0 auto;
  min-width: 96px;
  font-family: 'PixelFont', monospace;
  font-size: 15px;
  color: #14131f;
  background: #ffe066;
  padding: 8px 14px;
  border: 2px solid #f4e9c1;
  cursor: pointer;
}
.setting-btn:hover { background: #fff0a0; }

/* An off toggle reads hollow, so the row's state is visible at a glance. */
.setting-btn.off {
  background: transparent;
  color: #f4e9c1;
  border-color: rgba(244, 233, 193, 0.5);
}
.setting-btn.off:hover { border-color: #f4e9c1; background: rgba(244, 233, 193, 0.08); }

.setting-btn.danger {
  background: transparent;
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.6);
}
.setting-btn.danger:hover { background: rgba(255, 107, 107, 0.12); border-color: #ff6b6b; }
.setting-btn.danger.confirm {
  background: #d43d3d;
  color: #fff;
  border-color: #ffb3b3;
}

body.compact .setting-row { padding: 10px 12px; gap: 12px; }
body.compact .setting-btn { min-width: 80px; font-size: 12px; padding: 6px 10px; }

/* ---- First-visit world picker ----
   Fully opaque and above everything (HUD included): until a world is chosen there is no
   world to peek at. Lives inside #app so it rotates with the phone like the rest. */
#theme-picker {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 34px;
  background: #0d0c15;
  font-family: 'PixelFont', monospace;
}

#theme-picker.hidden { display: none; }

/* Header: this is a personal site first — the name leads, the world prompt follows. */
#picker-head { text-align: center; }

#picker-head h1 {
  margin: 0 0 10px;
  font-size: 34px;
  font-weight: normal;
  letter-spacing: 3px;
  color: #f4e9c1;
}

#picker-head p {
  margin: 0 0 26px;
  font-size: 13px;
  letter-spacing: 1px;
  color: #9aa0b8;
}

#picker-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: normal;
  letter-spacing: 3px;
  color: #ffe066;
}

.theme-options {
  display: flex;
  justify-content: center;
  gap: 4%;
  width: 92%;
  max-width: 780px;
}

.theme-option {
  flex: 0 1 220px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.theme-option img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  border: 3px solid rgba(244, 233, 193, 0.35);
  box-sizing: border-box;
  image-rendering: pixelated;
  transition: border-color 0.15s, transform 0.15s;
}

.theme-name {
  font-size: 17px;
  letter-spacing: 1px;
  color: #f4e9c1;
  transition: color 0.15s;
}

.theme-option:hover img { border-color: #ffe066; transform: translateY(-3px); }
.theme-option:hover .theme-name { color: #ffe066; }

/* The sealed third world: dimmed, and its hover glow is red instead of gold. */
.theme-option.locked { cursor: not-allowed; }
.theme-option.locked img { filter: brightness(0.45) saturate(0.6); }
.theme-option.locked .theme-name { color: rgba(244, 233, 193, 0.45); }
.theme-option.locked:hover img { border-color: rgba(255, 77, 77, 0.8); transform: none; filter: brightness(0.55) saturate(0.7); }
.theme-option.locked:hover .theme-name { color: #ff4d4d; }

#theme-denied {
  min-height: 22px; /* reserved so the flash doesn't shove the covers upward */
  font-size: 18px;
  letter-spacing: 2px;
  color: #ff4d4d;
  opacity: 0;
}

#theme-denied.flash { animation: denied-shake 0.5s steps(2) both; }

@keyframes denied-shake {
  0% { opacity: 1; transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
  100% { opacity: 1; transform: translateX(0); }
}

body.compact #theme-picker { gap: 18px; }
body.compact #picker-head h1 { font-size: 22px; margin-bottom: 6px; }
body.compact #picker-head p { font-size: 10px; margin-bottom: 14px; }
body.compact #picker-head h2 { font-size: 14px; }
body.compact .theme-name { font-size: 13px; }
body.compact #theme-denied { font-size: 14px; min-height: 17px; }
