body {
  margin: 0;
  background: #111;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  font-family: sans-serif;
  color: #ccc;
}

#container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

#roomCanvas {
  background: #1a1a1a;
  border: 1px solid #333;
  max-width: 100%;
  height: auto;
  display: block;
}

#inputBox {
  margin-top: 12px;
  width: 780px;
  max-width: 95vw;
  padding: 8px;
  background: #111;
  border: 1px solid #333;
  color: #ccc;
  outline: none;
}

/* ===== Game HUD ===== */
.game-hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 780px;
  max-width: 95vw;
  padding: 10px 0 6px;
  font-family: 'Courier New', monospace;
  font-size: 0.8rem;
  color: #555;
  user-select: none;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.hud-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-label {
  color: #444;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
}

.hud-value {
  color: #00aced;
  font-weight: bold;
  font-size: 0.9rem;
  min-width: 2ch;
  display: inline-block;
  text-align: center;
}

/* Focus Points glow when high */
.hud-value[id="fp-counter"] {
  color: #44cc44;
}

/* Alignment color shifts based on value */
.hud-value[id="align-counter"] {
  color: #00aced;
}

/* Alignment target hint */
.hud-value[id="align-counter"]::after {
  content: '/70';
  font-size: 0.6rem;
  color: #444;
  margin-left: 2px;
}

/* SELF — the other measurement, revealed in phase 2 */
.hud-value[id="self-counter"] {
  color: #b08fd8;
}

.hud-value[id="self-counter"].self-low {
  color: #ff4444;
  animation: selfFlicker 1.6s ease-in-out infinite;
}

#self-item.self-reveal {
  animation: selfReveal 2s ease;
}

@keyframes selfReveal {
  0% { opacity: 0; }
  30% { opacity: 1; }
  45% { opacity: 0.2; }
  60% { opacity: 1; }
  75% { opacity: 0.5; }
  100% { opacity: 1; }
}

@keyframes selfFlicker {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

/* Phase indicator dots */
.phase-dots {
  display: flex;
  gap: 5px;
  justify-content: center;
}

.phase-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2a2a2a;
  border: 1px solid #444;
  transition: all 0.4s ease;
}

.phase-dot.active {
  background: #00aced;
  border-color: #00aced;
  box-shadow: 0 0 6px rgba(0, 172, 237, 0.6);
}

.phase-dot.completed {
  background: #444;
  border-color: #666;
}

/* Leave Room button */
.leave-room-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 8px 24px;
  background: transparent;
  border: 1px solid #2a2a2a;
  color: #444;
  font-family: 'Courier New', monospace;
  font-size: 0.78rem;
  text-decoration: none;
  border-radius: 2px;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.05em;
}

.leave-room-btn:hover {
  border-color: #00aced;
  color: #00aced;
  background: rgba(0, 172, 237, 0.04);
  box-shadow: 0 0 8px rgba(0, 172, 237, 0.15);
}

.leave-room-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
  cursor: default;
}

.leave-room-btn.enabled {
  opacity: 0.7;
  transition: opacity 0.5s ease;
}

.leave-room-btn.enabled:hover {
  opacity: 1;
}

/* Exit hint text — fades in after enough inputs */
.exit-hint {
  font-size: 0.68rem;
  color: #333;
  font-family: 'Courier New', monospace;
  margin-top: 4px;
  margin-bottom: 2px;
  text-align: center;
  opacity: 0;
  transition: opacity 1.5s ease;
  pointer-events: none;
}

.exit-hint.visible {
  opacity: 1;
}

/* Input feedback glow */
#inputBox.feedback-fear {
  border-color: #ff4444 !important;
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.25);
  transition: border-color 0.3s, box-shadow 0.3s;
}

#inputBox.feedback-calm {
  border-color: #44cc44 !important;
  box-shadow: 0 0 10px rgba(68, 204, 68, 0.25);
  transition: border-color 0.3s, box-shadow 0.3s;
}

/* Canvas fade for room transitions */
#roomCanvas {
  transition: opacity 0.25s ease;
}

#roomCanvas.fading {
  opacity: 0.15;
}

/* Phase transition flash overlay */
.phase-flash-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  animation: phaseFlashAnim 0.8s ease-out forwards;
  border-radius: inherit;
}

@keyframes phaseFlashAnim {
  0% { opacity: 0; }
  10% { opacity: 1; }
  100% { opacity: 0; }
}

.phase-flash-overlay.phase-1-flash {
  background: radial-gradient(ellipse at center, rgba(0, 172, 237, 0.15), transparent 70%);
}

.phase-flash-overlay.phase-2-flash {
  background: radial-gradient(ellipse at center, rgba(100, 100, 140, 0.3), transparent 70%);
}

.phase-flash-overlay.phase-3-flash {
  background: radial-gradient(ellipse at center, rgba(140, 30, 30, 0.35), transparent 70%);
}

/* ===== Win / Lose Overlays ===== */
.game-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  animation: overlayFadeIn 1.5s ease;
}

.game-overlay.hidden {
  display: none;
}

@keyframes overlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.overlay-content {
  text-align: center;
  color: #ccc;
  font-family: 'Courier New', monospace;
  max-width: 500px;
  padding: 2rem;
  line-height: 1.8;
}

.overlay-content h2 {
  font-size: 1.6rem;
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-bottom: 1.5rem;
}

/* Onboarding overlay */
#onboarding-overlay .overlay-content h2 {
  color: #00aced;
  text-shadow: 0 0 20px rgba(0, 172, 237, 0.3);
  font-size: 1.3rem;
}

.onboarding-list {
  text-align: left;
  color: #999;
  font-size: 0.9rem;
  line-height: 1.8;
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.onboarding-list li {
  padding-left: 1.2em;
  position: relative;
}

.onboarding-list li::before {
  content: '>';
  position: absolute;
  left: 0;
  color: #00aced;
}

.hud-legend {
  color: #555;
  font-size: 0.75rem;
  font-family: 'Courier New', monospace;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #333;
}

#begin-btn {
  margin-top: 1rem;
}

/* Win overlay styling */
#win-overlay .overlay-content h2 {
  color: #00aced;
  text-shadow: 0 0 20px rgba(0, 172, 237, 0.5);
}

#win-overlay .overlay-content p {
  color: #888;
  font-size: 0.95rem;
}

#win-overlay .win-message {
  color: #44cc44;
  font-style: italic;
  margin-top: 1rem;
}

/* Assimilated overlay styling — serene on purpose; the calm is the horror */
#assimilated-overlay {
  background: rgba(8, 20, 28, 0.97);
}

#assimilated-overlay .overlay-content h2 {
  color: #7fd4ff;
  text-shadow: 0 0 24px rgba(127, 212, 255, 0.45);
  letter-spacing: 5px;
}

#assimilated-overlay .overlay-content p {
  color: #9fb8c4;
  font-size: 0.95rem;
}

#assimilated-overlay .assimilated-message {
  color: #d8eef8;
  font-style: italic;
  margin-top: 1rem;
}

/* Canvas tear during the crack ending */
#roomCanvas.cracking {
  animation: crackShake 0.25s linear infinite;
}

@keyframes crackShake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-3px, 2px); }
  50% { transform: translate(3px, -2px); }
  75% { transform: translate(-2px, -2px); }
  100% { transform: translate(0, 0); }
}

@media (prefers-reduced-motion: reduce) {
  #roomCanvas.cracking { animation: none; }
  #self-item.self-reveal { animation: none; }
  .hud-value[id="self-counter"].self-low { animation: none; }
}

/* Lose overlay styling */
#lose-overlay .overlay-content h2 {
  color: #ff4444;
  text-shadow: 0 0 20px rgba(255, 68, 68, 0.5);
  animation: glitchText 2s ease infinite;
}

#lose-overlay .overlay-content p {
  color: #666;
  font-size: 0.9rem;
}

#lose-overlay .lose-message {
  color: #ff4444;
  font-style: italic;
  margin-top: 1rem;
}

.overlay-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.overlay-btn {
  display: inline-block;
  padding: 0.6rem 1.5rem;
  border: 1px solid #444;
  background: transparent;
  color: #ccc;
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.3s ease;
  letter-spacing: 0.05em;
}

.overlay-btn:hover {
  border-color: #00aced;
  color: #00aced;
  background: rgba(0, 172, 237, 0.05);
  box-shadow: 0 0 10px rgba(0, 172, 237, 0.2);
}

#stay-btn:hover {
  border-color: #ff4444;
  color: #ff4444;
  background: rgba(255, 68, 68, 0.05);
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.2);
}

/* ===== Mobile Responsive ===== */
@media (max-width: 850px) {
  #inputBox {
    width: 90vw;
    padding: 10px;
  }
  .game-hud {
    width: 90vw;
    font-size: 0.75rem;
  }
  .hud-label {
    font-size: 0.65rem;
  }
  .hud-value {
    font-size: 0.85rem;
  }
}

@media (max-width: 600px) {
  body {
    align-items: flex-start;
    padding-top: 60px;
  }
  #container {
    width: 100%;
    align-items: center;
  }
  #inputBox {
    width: 92vw;
    padding: 12px;
    font-size: 16px; /* prevents iOS zoom on focus */
  }
  .game-hud {
    width: 95vw;
    font-size: 0.7rem;
    justify-content: center;
  }
  .hud-label {
    font-size: 0.6rem;
  }
  .hud-value {
    font-size: 0.8rem;
  }
  .overlay-content {
    max-width: 90vw;
    padding: 1.5rem 1rem;
  }
  .overlay-content h2 {
    font-size: 1.2rem;
  }
  .overlay-btn {
    font-size: 0.8rem;
    padding: 0.5rem 1rem;
  }
}
