* {
  box-sizing: border-box;
}

/* ── Boot screen ────────────────────────────────────────────── */
#intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: radial-gradient(ellipse at 50% 48%, #1e140a 0%, #090604 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

#boot-vignette {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 50%, transparent 35%, rgba(0, 0, 0, 0.75) 100%);
  pointer-events: none;
}

#boot-content {
  position: relative;
  z-index: 1;
  text-align: center;
  pointer-events: none;
  user-select: none;
}

#boot-tagline {
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.9rem;
  color: #c49a4a;
  margin-bottom: 20px;
  opacity: 0;
}

#boot-name {
  font-family: 'Press Start 2P', monospace;
  font-size: clamp(1.8rem, 5vw, 3rem);
  color: #e8c97a;
  text-shadow:
    4px 4px 0 rgba(0, 0, 0, 0.7),
    0 0 30px rgba(232, 201, 122, 0.35);
  line-height: 1.4;
  opacity: 0;
  transform: translateY(12px);
}

#boot-divider {
  width: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #c49a4a 30%, #c49a4a 70%, transparent);
  margin: 22px auto;
  opacity: 0;
}

#boot-prompt {
  font-family: 'Press Start 2P', monospace;
  font-size: 0.7rem;
  color: #e8c97a;
  border: 2px solid #c49a4a;
  padding: 12px 20px;
  margin-top: 12px;
  background: rgba(196, 154, 74, 0.08);
  display: inline-block;
  opacity: 1;
  transition: opacity 0.12s;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: #fdf3df;
  color: #3a2a17;
  cursor: url('../assets/cursor.svg') 0 0, auto;
}

#view-toggle {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #3d2410;
  color: #ffd24a;
  border: 2px solid #c97b3d;
  padding: 8px 22px;
  border-radius: 4px;
  cursor: pointer;
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.88rem;
  z-index: 200;
  letter-spacing: 0.04em;
  text-shadow: 1px 1px 0 #1a0a00;
  box-shadow: 2px 2px 0 #1a0a00, 0 0 12px rgba(201, 123, 61, 0.35);
  white-space: nowrap;
}

#view-toggle:hover {
  background: #5c3318;
  color: #ffe880;
  box-shadow: 2px 2px 0 #1a0a00, 0 0 18px rgba(255, 210, 74, 0.4);
}

#game-view {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

#game-container {
  width: 100%;
  height: 100%;
}

#game-container canvas {
  display: block;
  margin: 0 auto;
}

#building-labels {
  position: absolute;
  z-index: 5;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

@keyframes labelBob {
  0%, 100% { transform: translate(-50%, 0px); }
  50%       { transform: translate(-50%, -5px); }
}

.building-label {
  position: absolute;
  z-index: 5;
  transform: translate(-50%, 0);
  animation: labelBob 1.8s ease-in-out infinite;
  background: linear-gradient(#a9764a, #7c4f2c);
  color: #fff7e8;
  text-shadow: 1px 1px 0 #3d2614, -1px -1px 0 #3d2614, 1px -1px 0 #3d2614, -1px 1px 0 #3d2614;
  border: 3px solid #3d2614;
  border-radius: 2px;
  padding: 4px 10px 5px;
  font-size: 13px;
  font-family: 'DotGothic16', sans-serif;
  font-weight: 400;
  white-space: nowrap;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5);
}

.building-label::before {
  content: '';
  position: absolute;
  top: -7px;
  left: 14%;
  width: 3px;
  height: 7px;
  background: #4a2e16;
}

.building-label::after {
  content: '';
  position: absolute;
  top: -7px;
  right: 14%;
  width: 3px;
  height: 7px;
  background: #4a2e16;
}

#fps-counter {
  position: absolute;
  top: 14px;
  left: 14px;
  color: #ffd24a;
  font-size: 11px;
  font-family: 'DotGothic16', sans-serif;
  background: rgba(20, 16, 12, 0.55);
  border: 1px solid #6b4a2c;
  border-radius: 4px;
  padding: 2px 6px;
  pointer-events: none;
  z-index: 6;
}

#music-toggle {
  position: absolute;
  top: 57px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(20, 16, 12, 0.55);
  border: 2px solid #6b4a2c;
  color: #ffd24a;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
}

#music-toggle:hover { background: rgba(40, 30, 20, 0.75); }
#music-toggle.muted { color: #555; border-color: #444; }

#daynight-indicator {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: rgba(20, 16, 12, 0.55);
  border: 2px solid #6b4a2c;
  pointer-events: none;
}

#sun-icon,
#moon-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  transition: opacity 0.4s linear;
}

#sun-icon {
  color: #ffd24a;
  text-shadow: 0 0 6px rgba(255, 210, 74, 0.8);
}

#moon-icon {
  color: #cdd6f4;
  text-shadow: 0 0 6px rgba(205, 214, 244, 0.7);
}

#daynight-controls {
  position: absolute;
  top: 100px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(20, 16, 12, 0.55);
  border: 2px solid #6b4a2c;
  border-radius: 8px;
  padding: 5px 8px;
  z-index: 6;
}

#day-pause-btn {
  background: none;
  border: none;
  color: #ffd24a;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  width: 16px;
  text-align: center;
}

#day-pause-btn:hover {
  color: #fff;
}

#day-slider {
  width: 80px;
  accent-color: #c97b3d;
  cursor: pointer;
}

#day-time {
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.65rem;
  color: #ffd24a;
  white-space: nowrap;
  min-width: 34px;
  text-align: right;
}

#interact-prompt {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 16, 12, 0.85);
  color: #f4e9d8;
  border: 1px solid #6b4a2c;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  pointer-events: none;
}

#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#joystick-base {
  position: absolute;
  left: 24px;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(244, 233, 216, 0.15);
  border: 2px solid rgba(244, 233, 216, 0.4);
  pointer-events: auto;
  touch-action: none;
}

#joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 40px;
  height: 40px;
  margin: -20px;
  border-radius: 50%;
  background: rgba(244, 233, 216, 0.6);
}

#interact-button {
  position: absolute;
  right: 28px;
  bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #6b4a2c;
  color: #f4e9d8;
  border: 2px solid rgba(244, 233, 216, 0.4);
  font-size: 1.2rem;
  pointer-events: auto;
  touch-action: none;
}

#username-box {
  position: absolute;
  top: 136px;
  left: 14px;
  background: rgba(20, 16, 12, 0.78);
  border: 1px solid #6b4a2c;
  border-radius: 6px;
  padding: 6px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 6;
}

.username-label {
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.68rem;
  color: #f4e9d8;
  white-space: nowrap;
}

#username-input {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  color: #f4e9d8;
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.72rem;
  padding: 2px 6px;
  width: 90px;
  outline: none;
}

#username-input::placeholder {
  color: rgba(244,233,216,0.35);
}

#username-set-btn {
  background: #6b4a2c;
  color: #f4e9d8;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 3px;
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.68rem;
  padding: 2px 7px;
  cursor: pointer;
  white-space: nowrap;
}

#username-set-btn:hover {
  background: #8a5f38;
}

#controls-hint {
  position: absolute;
  top: 44px;
  left: 14px;
  background: rgba(20, 16, 12, 0.78);
  border: 1px solid #6b4a2c;
  border-radius: 6px;
  padding: 8px 12px;
  font-family: 'DotGothic16', sans-serif;
  font-size: 0.72rem;
  color: #f4e9d8;
  z-index: 6;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}

.ctrl-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.ctrl-key {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 3px;
  padding: 1px 5px;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

#list-view[hidden] { display: none; }

#list-view {
  padding: 20px;
  padding-top: 60px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  min-height: 100vh;
  overflow-y: auto;
  background: #1a130c;
}

.project-card {
  background: #2b2520;
  border: 1px solid #463a2e;
  border-radius: 8px;
  padding: 12px;
  text-align: left;
  color: #f4e9d8;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.project-card img {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: 6px;
}

.project-card h3 {
  margin: 0;
  font-size: 1rem;
}

.card-year {
  font-size: 0.8rem;
  opacity: 0.7;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  background: #4f8a2a;
  color: #fdf3df;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.75rem;
}

#project-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 300;
}

#project-modal[hidden] {
  display: none;
}

.modal-box {
  background: #2b2520;
  color: #f4e9d8;
  border-radius: 10px;
  padding: 24px;
  max-width: 640px;
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}

#modal-close {
  position: absolute;
  top: 10px;
  right: 14px;
  background: none;
  border: none;
  color: #f4e9d8;
  font-size: 1.5rem;
  cursor: pointer;
}

#modal-title {
  margin: 0 0 4px;
}

#modal-meta {
  margin: 0 0 10px;
  opacity: 0.7;
  font-size: 0.85rem;
}

#modal-description {
  margin-top: 14px;
  line-height: 1.5;
}

#modal-description ul {
  padding-left: 20px;
}

#modal-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

#modal-gallery img {
  width: 100%;
  border-radius: 6px;
}

#modal-links {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.modal-link {
  background: #6b4a2c;
  color: #f4e9d8;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  font-size: 0.85rem;
}

.demo-note {
  margin: 0;
  font-size: 0.8rem;
  opacity: 0.75;
}

/* ── Player join toasts ──────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 6px;
  z-index: 400;
  pointer-events: none;
}

.player-toast {
  font-family: 'DotGothic16', sans-serif;
  font-size: 13px;
  color: #ffd24a;
  background: rgba(20, 12, 6, 0.92);
  border: 2px solid #c97b3d;
  box-shadow: 2px 2px 0 #1a0a00;
  padding: 5px 13px;
  white-space: nowrap;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.player-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

/* ── Touch devices: hide keyboard hint, reposition elements ──── */
@media (hover: none) and (pointer: coarse) {
  body {
    cursor: auto;
  }

  #controls-hint {
    display: none;
  }

  #username-box {
    top: 44px;
  }

  /* Push interact prompt above the joystick */
  #interact-prompt {
    bottom: calc(148px + env(safe-area-inset-bottom, 0px));
  }

  /* Compact the day/night slider */
  #day-slider {
    width: 56px;
  }
}

/* ── Small screens ───────────────────────────────────────────── */
@media (max-width: 480px) {
  #view-toggle {
    font-size: 0.78rem;
    padding: 7px 14px;
  }

  /* Slot username below the music toggle in the right-side stack */
  #username-box {
    top: 144px;
    left: auto;
    right: 14px;
    transform: none;
  }

  .username-label {
    display: none;
  }

  #username-input {
    width: 60px;
  }

  #list-view {
    padding: 12px;
    padding-top: 56px;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .modal-box {
    padding: 16px;
    border-radius: 6px;
    max-height: 92vh;
  }

  #modal-gallery {
    grid-template-columns: 1fr 1fr;
  }

  /* Collapse day/night controls to just the indicator + pause */
  #daynight-controls {
    top: 57px;
    padding: 4px 6px;
    gap: 4px;
  }

  #day-slider {
    width: 48px;
  }

  #day-time {
    display: none;
  }

  #music-toggle {
    top: 100px;
  }
}
