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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #101010;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f5f5f5;
}

#game-root {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: radial-gradient(circle at top, #2c2c2c 0, #050505 60%);
}

#game-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* HUD */

#hud {
  position: absolute;
  bottom: 0.7rem;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  z-index: 5;
}

#schedule-bar {
  background: rgba(0, 0, 0, 0.8);
  padding: 0.4rem 1rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  display: flex;
  gap: 1rem;
  font-size: 0.9rem;
  color: #fff;
  text-shadow: 0 0 5px rgba(255,255,255,0.3);
}

#current-lesson {
  color: #8fef8f;
  font-weight: bold;
}

.hud-buttons {
  display: flex;
  gap: 0.4rem;
}

.hud-btn {
  padding: 0.5rem 0.8rem;
  font-size: 0.8rem;
  border-radius: 999px;
  border: none;
  background: rgba(15, 15, 15, 0.85);
  color: #f5f5f5;
  border: 1px solid rgba(255, 255, 255, 0.12);
  min-width: 3.5rem;
}

.hud-btn:disabled {
  opacity: 0.45;
}

#btn-run-mobile {
  display: none;
}

@media (max-width: 768px) {
  #btn-run-mobile {
    display: block;
  }
}

#lesson-input {
  background: #222;
  border: 1px solid #444;
  color: white;
  padding: 0.3rem;
  border-radius: 4px;
  width: 100%;
}

/* Joystick */

#joystick-zone {
  position: absolute;
  left: 0.5rem;
  bottom: 0.5rem;
  width: 120px;
  height: 120px;
  z-index: 4;
  touch-action: none;
}

/* Overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.overlay.visible {
  display: flex;
}

/* Main menu */

.menu-panel {
  width: min(480px, 92vw);
  background: rgba(0, 0, 0, 0.75);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.7);
  padding: 1rem 1.2rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.menu-section h2 {
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.role-buttons {
  display: flex;
  gap: 0.4rem;
}

.role-btn {
  flex: 1;
  border-radius: 999px;
  border: none;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  background: #202020;
  color: #f5f5f5;
  border: 1px solid transparent;
}

.role-btn.active {
  background: #f5f5f5;
  color: #111;
}

.menu-footer {
  font-size: 0.75rem;
  color: #c4c4c4;
  min-height: 1.2em;
}

/* Role detail */

#role-detail-section {
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.6rem;
  max-height: 260px;
  overflow-y: auto;
}

.role-detail-header {
  font-size: 0.82rem;
  margin-bottom: 0.4rem;
  color: #d8d8d8;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 0.4rem;
}

.character-card {
  border-radius: 10px;
  background: #181818;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.7rem;
}

.character-card img {
  width: 64px;
  height: 64px;
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
}

.character-name {
  text-align: center;
  font-size: 0.74rem;
}

.character-role-label {
  font-size: 0.65rem;
  color: #a0a0a0;
}

.character-card button {
  margin-top: 0.1rem;
  padding: 0.25rem 0.45rem;
  font-size: 0.65rem;
  border-radius: 999px;
  border: none;
  background: #f5f5f5;
  color: #111;
}

/* Rules */

.rules-panel {
  width: min(480px, 92vw);
  max-height: 80vh;
  background: rgba(5, 5, 5, 0.96);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  padding: 0.9rem 1rem 1.1rem;
  position: relative;
  overflow: hidden;
}

.rules-panel h2 {
  font-size: 1rem;
  margin-bottom: 0.4rem;
}

.rules-content {
  font-size: 0.78rem;
  line-height: 1.35;
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.rules-content ol {
  padding-left: 1.1rem;
}

.rules-content li + li {
  margin-top: 0.25rem;
}

.close-btn {
  position: absolute;
  right: 0.5rem;
  top: 0.45rem;
  border: none;
  background: none;
  color: #f5f5f5;
  font-size: 0.9rem;
}

/* Door hint */

#door-hint {
  position: absolute;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  padding: 0.25rem 0.45rem;
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-out;
  z-index: 6;
}

/* Responsive tweaks */

@media (min-width: 768px) {
  #hud {
    bottom: 1rem;
  }

  #joystick-zone {
    width: 140px;
    height: 140px;
  }
}