/* ============================================================
   THE GREAT HALL — atmosphere
   Dark arcade sanctum. Neon purple, neon blue, warm amber.
   ============================================================ */

:root {
  --bg: #0a0a0f;
  --bg-raised: #12121c;
  --purple: #b44aff;
  --blue: #4a9eff;
  --amber: #ffaa4a;
  --text: #e8e6f0;
  --text-dim: #8a87a0;
  --font-pixel: 'Press Start 2P', monospace;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   LAYER 1 — THE ROOM
   ============================================================ */

.room {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.8s ease, transform 0.8s ease, background 0.8s ease;
}

.room.transitioning {
  opacity: 0;
  transform: scale(0.985);
}

/* State-specific ambient glows */
.room[data-state="attract"] {
  background:
    radial-gradient(ellipse 80% 60% at 50% 110%, rgba(180, 74, 255, 0.16), transparent 60%),
    radial-gradient(ellipse 70% 50% at 15% -10%, rgba(74, 158, 255, 0.12), transparent 60%),
    radial-gradient(ellipse 50% 40% at 90% 20%, rgba(255, 170, 74, 0.05), transparent 60%),
    var(--bg);
}

.room[data-state="game"] {
  background:
    radial-gradient(ellipse 120% 100% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.85) 100%),
    #050508;
}

.room[data-state="library"] {
  background:
    radial-gradient(ellipse 90% 70% at 50% -20%, rgba(74, 158, 255, 0.14), transparent 65%),
    radial-gradient(ellipse 70% 50% at 80% 110%, rgba(180, 74, 255, 0.10), transparent 60%),
    #0d0d15;
}

.room[data-state="loading"] {
  background:
    radial-gradient(ellipse 60% 50% at 50% 50%, rgba(180, 74, 255, 0.12), transparent 70%),
    var(--bg);
  animation: loading-pulse 2s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.25); }
}

/* ============================================================
   LAYER 2 — AMBIENCE (scanlines + particles)
   ============================================================ */

.scanlines {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.018) 0px,
    rgba(255, 255, 255, 0.018) 1px,
    transparent 1px,
    transparent 3px
  );
  mix-blend-mode: overlay;
}

.scanlines::after {
  /* faint vignette over everything for the CRT-glass feel */
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 120% 120% at 50% 50%, transparent 60%, rgba(0, 0, 0, 0.35) 100%);
}

.particles {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

/* ============================================================
   ATTRACT MODE — the landing experience
   ============================================================ */

.attract {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem;
}

.attract-title {
  font-family: var(--font-pixel);
  font-size: clamp(1.4rem, 5vw, 3.2rem);
  letter-spacing: 0.12em;
  color: var(--text);
  text-shadow:
    0 0 8px rgba(180, 74, 255, 0.9),
    0 0 24px rgba(180, 74, 255, 0.6),
    0 0 64px rgba(180, 74, 255, 0.4),
    0 0 120px rgba(74, 158, 255, 0.3);
  animation: title-glow 3.4s ease-in-out infinite;
  user-select: none;
}

@keyframes title-glow {
  0%, 100% {
    text-shadow:
      0 0 8px rgba(180, 74, 255, 0.9),
      0 0 24px rgba(180, 74, 255, 0.6),
      0 0 64px rgba(180, 74, 255, 0.4),
      0 0 120px rgba(74, 158, 255, 0.3);
  }
  50% {
    text-shadow:
      0 0 12px rgba(74, 158, 255, 0.95),
      0 0 36px rgba(74, 158, 255, 0.7),
      0 0 90px rgba(180, 74, 255, 0.5),
      0 0 150px rgba(180, 74, 255, 0.35);
  }
}

.attract-subtitle {
  margin-top: 1.6rem;
  font-size: clamp(0.95rem, 2.2vw, 1.25rem);
  color: var(--text-dim);
  letter-spacing: 0.04em;
  opacity: 0;
  animation: fade-up 1.4s ease 0.6s forwards;
}

@keyframes fade-up {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.attract-cards {
  margin-top: 2.6rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1.1rem;
  justify-content: center;
  max-width: 880px;
  opacity: 0;
  animation: fade-up 1.4s ease 1s forwards;
}

.attract-card {
  position: relative;
  padding: 1rem 1.3rem;
  min-width: 160px;
  max-width: 220px;
  background: rgba(18, 18, 28, 0.7);
  border: 1px solid rgba(180, 74, 255, 0.25);
  border-radius: 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
  animation: card-float 6s ease-in-out infinite;
}

/* stagger the float so cards drift independently */
.attract-card:nth-child(2n)   { animation-delay: -1.5s; animation-duration: 7s; }
.attract-card:nth-child(3n)   { animation-delay: -3s; animation-duration: 6.5s; }
.attract-card:nth-child(4n)   { animation-delay: -2.2s; animation-duration: 7.5s; }
.attract-card:nth-child(5n)   { animation-delay: -4.1s; animation-duration: 8s; }

@keyframes card-float {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25%      { transform: translateY(-7px) rotate(0.4deg); }
  50%      { transform: translateY(-3px) rotate(-0.3deg); }
  75%      { transform: translateY(-9px) rotate(0.2deg); }
}

.attract-card:hover {
  border-color: var(--purple);
  box-shadow:
    0 0 18px rgba(180, 74, 255, 0.4),
    0 0 50px rgba(180, 74, 255, 0.15);
  transform: translateY(-6px) scale(1.04);
  animation-play-state: paused;
}

.attract-card .card-title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.35;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.attract-empty {
  margin-top: 2.6rem;
  max-width: 460px;
  color: var(--text-dim);
  font-size: 1.05rem;
  line-height: 1.7;
  font-style: italic;
  opacity: 0;
  animation: fade-up 1.4s ease 1s forwards;
}

.attract-hint {
  position: absolute;
  bottom: 7.5rem;
  left: 50%;
  transform: translateX(-50%);
  color: var(--text-dim);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  white-space: nowrap;
  animation: hint-pulse 2.8s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.95; }
}

/* ============================================================
   SYSTEM BADGES
   ============================================================ */

.badge {
  display: inline-block;
  font-family: var(--font-pixel);
  font-size: 0.5rem;
  padding: 0.32em 0.7em;
  border-radius: 4px;
  letter-spacing: 0.08em;
  border: 1px solid;
  text-transform: uppercase;
  user-select: none;
}

.badge-nes     { color: #ff6b6b; border-color: rgba(255, 107, 107, 0.5); background: rgba(255, 107, 107, 0.08); }
.badge-snes    { color: #b44aff; border-color: rgba(180, 74, 255, 0.5);  background: rgba(180, 74, 255, 0.08); }
.badge-genesis { color: #4a9eff; border-color: rgba(74, 158, 255, 0.5);  background: rgba(74, 158, 255, 0.08); }
.badge-gba     { color: #7a5cff; border-color: rgba(122, 92, 255, 0.5);  background: rgba(122, 92, 255, 0.08); }
.badge-n64     { color: #4aff9e; border-color: rgba(74, 255, 158, 0.5);  background: rgba(74, 255, 158, 0.08); }
.badge-psx     { color: #c8c8d8; border-color: rgba(200, 200, 216, 0.5); background: rgba(200, 200, 216, 0.08); }
.badge-arcade  { color: #ffaa4a; border-color: rgba(255, 170, 74, 0.5);  background: rgba(255, 170, 74, 0.08); }

/* ============================================================
   LIBRARY — the Vault, browsable
   ============================================================ */

.library {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 2rem clamp(1rem, 4vw, 3rem);
  overflow: hidden;
}

.library-header {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.4rem;
  flex-shrink: 0;
}

.library-title {
  font-family: var(--font-pixel);
  font-size: clamp(0.85rem, 2.4vw, 1.3rem);
  color: var(--blue);
  text-shadow: 0 0 16px rgba(74, 158, 255, 0.6);
  letter-spacing: 0.1em;
}

.library-count {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.library-close {
  margin-left: auto;
  background: none;
  border: 1px solid rgba(138, 135, 160, 0.4);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 0.4rem 0.9rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.25s, color 0.25s;
}

.library-close:hover { border-color: var(--amber); color: var(--amber); }

.library-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
  padding: 0.25rem 0.25rem 6.5rem;
  align-content: start;
}

.game-card {
  background: rgba(18, 18, 28, 0.85);
  border: 1px solid rgba(138, 135, 160, 0.18);
  border-radius: 12px;
  padding: 1.1rem 1.2rem;
  cursor: pointer;
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.game-card:hover {
  transform: translateY(-4px);
  border-color: var(--purple);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5), 0 0 22px rgba(180, 74, 255, 0.25);
}

.game-card .card-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.4;
  margin-bottom: 0.6rem;
}

.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1rem;
  color: var(--text-dim);
  font-style: italic;
  font-size: 1.05rem;
  line-height: 1.8;
}

/* ============================================================
   GAME MODE — the Vault, playing
   ============================================================ */

.game-stage {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.game-stage::after {
  /* vignette frame around the playing field */
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
  box-shadow: inset 0 0 120px 30px rgba(0, 0, 0, 0.65);
}

.game-titlebar {
  position: absolute;
  top: 0.9rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.45rem 1.1rem;
  background: rgba(10, 10, 15, 0.72);
  border: 1px solid rgba(180, 74, 255, 0.3);
  border-radius: 999px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 0.82rem;
  color: var(--text-dim);
  opacity: 0.85;
  transition: opacity 0.3s;
  pointer-events: none;
  white-space: nowrap;
}

.game-titlebar .game-name { color: var(--text); font-weight: 600; }

/* ============================================================
   LOADING
   ============================================================ */

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
}

.spinner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid rgba(180, 74, 255, 0.18);
  border-top-color: var(--purple);
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 24px rgba(180, 74, 255, 0.3);
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-family: var(--font-pixel);
  font-size: 0.72rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  animation: hint-pulse 1.8s ease-in-out infinite;
}

/* ============================================================
   LAYER 3 — THE HOST (chat overlay)
   ============================================================ */

.host {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  width: min(560px, calc(100vw - 2rem));
  border-radius: 16px 16px 0 0;
  background: rgba(14, 14, 22, 0.72);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  border: 1px solid rgba(180, 74, 255, 0.25);
  border-bottom: none;
  box-shadow: 0 -8px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(180, 74, 255, 0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

.host.collapsed { transform: translateX(-50%) translateY(calc(100% - 46px)); }

.host-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  height: 46px;
  padding: 0 1rem;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}

.host-orb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--purple);
  box-shadow: 0 0 10px var(--purple), 0 0 22px rgba(180, 74, 255, 0.6);
  animation: orb-breathe 3s ease-in-out infinite;
}

@keyframes orb-breathe {
  0%, 100% { box-shadow: 0 0 8px var(--purple), 0 0 18px rgba(180, 74, 255, 0.5); }
  50%      { box-shadow: 0 0 14px var(--blue), 0 0 32px rgba(74, 158, 255, 0.7); background: var(--blue); }
}

.host-title {
  font-family: var(--font-pixel);
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  color: var(--text);
}

.host-controls {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.2s, transform 0.2s;
}

.icon-btn:hover { opacity: 1; transform: scale(1.12); }

.host-chevron {
  color: var(--text-dim);
  transition: transform 0.4s ease;
}

.host.collapsed .host-chevron { transform: rotate(180deg); }

.host-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.host-messages {
  height: 280px;
  overflow-y: auto;
  padding: 0.6rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  scroll-behavior: smooth;
}

/* themed thin scrollbar */
.host-messages::-webkit-scrollbar,
.library-grid::-webkit-scrollbar { width: 6px; }
.host-messages::-webkit-scrollbar-track,
.library-grid::-webkit-scrollbar-track { background: transparent; }
.host-messages::-webkit-scrollbar-thumb,
.library-grid::-webkit-scrollbar-thumb {
  background: rgba(180, 74, 255, 0.35);
  border-radius: 3px;
}
.host-messages::-webkit-scrollbar-thumb:hover,
.library-grid::-webkit-scrollbar-thumb:hover { background: rgba(180, 74, 255, 0.6); }
.host-messages, .library-grid {
  scrollbar-width: thin;
  scrollbar-color: rgba(180, 74, 255, 0.35) transparent;
}

.msg {
  max-width: 82%;
  padding: 0.6rem 0.9rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.5;
  animation: msg-in 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  word-wrap: break-word;
  white-space: pre-wrap;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(10px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.msg-host {
  align-self: flex-start;
  background: rgba(180, 74, 255, 0.14);
  border: 1px solid rgba(180, 74, 255, 0.25);
  border-bottom-left-radius: 4px;
}

.msg-user {
  align-self: flex-end;
  background: rgba(74, 158, 255, 0.14);
  border: 1px solid rgba(74, 158, 255, 0.3);
  border-bottom-right-radius: 4px;
}

.host-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.65rem 1rem 0.85rem;
  flex-shrink: 0;
}

.host-input {
  flex: 1;
  background: rgba(10, 10, 15, 0.7);
  border: 1px solid rgba(138, 135, 160, 0.3);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.host-input::placeholder { color: var(--text-dim); }

.host-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 1px rgba(180, 74, 255, 0.4), 0 0 16px rgba(180, 74, 255, 0.25);
}

.host-send {
  background: linear-gradient(135deg, rgba(180, 74, 255, 0.25), rgba(74, 158, 255, 0.25));
  border: 1px solid rgba(180, 74, 255, 0.4);
  border-radius: 10px;
  color: var(--text);
  padding: 0 0.95rem;
  font-size: 0.95rem;
  cursor: pointer;
  transition: box-shadow 0.25s, transform 0.15s;
}

.host-send:hover { box-shadow: 0 0 16px rgba(180, 74, 255, 0.4); }
.host-send:active { transform: scale(0.94); }

/* ============================================================
   MOBILE
   ============================================================ */

@media (max-width: 640px) {
  .host {
    width: 100vw;
    border-radius: 14px 14px 0 0;
    left: 0;
    transform: none;
  }
  .host.collapsed { transform: translateY(calc(100% - 46px)); }

  .host-messages { height: 220px; }

  .library-grid { grid-template-columns: 1fr; }

  .attract-cards { gap: 0.7rem; }
  .attract-card { min-width: 130px; padding: 0.8rem 1rem; }

  .attract-hint { bottom: 4.2rem; font-size: 0.78rem; }
}
