* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: manipulation;
}

:root {
  --accent: #38e54d;
  --accent2: #ffd93d;
  --bg: #0c1218;
  --panel: rgba(15, 22, 32, 0.88);
  --text: #f4f7fb;
  --border: rgba(255, 255, 255, 0.16);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

.screen {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ===== THEME GATE ===== */
#theme-gate {
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  background: radial-gradient(circle at top, #1f1b3a 0%, #090c14 70%);
}
.gate-bg {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px);
  background-size: 36px 36px;
  pointer-events: none;
}
.gate-content {
  position: relative;
  z-index: 2;
  max-width: 1020px;
  width: 100%;
  text-align: center;
}
.gate-badge {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 217, 61, 0.14);
  border: 1px solid rgba(255, 217, 61, 0.5);
  color: #ffd93d;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 2px;
  margin-bottom: 12px;
}
.gate-title {
  font-size: clamp(28px, 5vw, 54px);
  font-weight: 900;
  letter-spacing: 2px;
  text-shadow: 0 0 24px rgba(56, 229, 77, 0.45), 0 4px 0 #000;
  margin-bottom: 10px;
}
.gate-subtitle {
  color: #b7c4d6;
  max-width: 680px;
  margin: 0 auto 26px;
  font-size: clamp(14px, 2vw, 17px);
  line-height: 1.45;
}
.theme-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}
.theme-card {
  background: rgba(19, 27, 42, 0.9);
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 20px;
  padding: 24px 20px;
  color: #fff;
  cursor: pointer;
  text-align: left;
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.theme-card:hover, .theme-card:active {
  transform: translateY(-5px) scale(1.01);
  border-color: #ffd93d;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5), 0 0 24px rgba(255, 217, 61, 0.25);
}
.theme-card[data-theme="garden"] { border-top: 5px solid #4ade80; }
.theme-card[data-theme="petri"]  { border-top: 5px solid #22d3ee; }
.theme-card[data-theme="kitchen"]{ border-top: 5px solid #fb7185; }
.theme-icon { font-size: 44px; }
.theme-name { font-size: 22px; font-weight: 800; }
.theme-desc { font-size: 14px; color: #b9c7da; line-height: 1.45; flex: 1; }
.theme-tags { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-tags span {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,0.09);
  color: #e5eefc;
}
.gate-footer {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 13px;
  color: #8ea0b8;
}

/* ===== 3D ARCADE ROOM ===== */
#arcade-room {
  background: #080b10;
}
#room-canvas-wrap {
  position: absolute;
  inset: 0;
  touch-action: none;
}
.room-hud-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  z-index: 10;
  pointer-events: none;
  flex-wrap: wrap;
}
.hud-stats {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.hud-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--panel);
  border: 1.5px solid var(--border);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.hud-theme-pill { cursor: pointer; }
.pill-sub {
  font-size: 10px;
  background: rgba(255,255,255,0.14);
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 1px;
}
.hud-btn { cursor: pointer; transition: transform 0.12s; }
.hud-btn:active { transform: scale(0.95); }

.nearby-prompt {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  background: rgba(12, 18, 28, 0.94);
  border: 2px solid var(--accent);
  border-radius: 20px;
  padding: 14px 22px;
  text-align: center;
  min-width: 260px;
  max-width: 92vw;
  box-shadow: 0 12px 34px rgba(0,0,0,0.6), 0 0 24px rgba(56,229,77,0.28);
  animation: popUp 0.18s ease-out;
}
.nearby-prompt.hidden { display: none; }
@keyframes popUp {
  from { opacity: 0; transform: translate(-50%, 16px) scale(0.95); }
  to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
}
.nearby-badge {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.6px;
  color: var(--accent2);
  margin-bottom: 2px;
}
.nearby-title { font-size: 20px; font-weight: 900; }
.nearby-sub { font-size: 13px; color: #b7c6db; margin-bottom: 10px; }
.insert-coin-btn {
  width: 100%;
  padding: 12px 18px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffd93d, #ff9f1c);
  color: #161616;
  font-weight: 900;
  font-size: 15px;
  letter-spacing: 0.8px;
  cursor: pointer;
  box-shadow: 0 4px 0 #b86b00;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.insert-coin-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #b86b00; }

/* Touch joystick */
.room-controls {
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  pointer-events: none;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.touch-stick {
  pointer-events: auto;
  position: relative;
  width: 116px;
  height: 116px;
  touch-action: none;
}
.stick-base {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.28);
  backdrop-filter: blur(4px);
}
.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-left: -24px;
  margin-top: -24px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff, #94a3b8);
  box-shadow: 0 4px 12px rgba(0,0,0,0.45);
}
.stick-label {
  position: absolute;
  bottom: -18px;
  width: 100%;
  text-align: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.7);
}
.room-hint {
  font-size: 12px;
  color: rgba(255,255,255,0.72);
  background: rgba(0,0,0,0.45);
  padding: 6px 12px;
  border-radius: 999px;
}

/* Directory Drawer */
.game-drawer {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(8, 12, 20, 0.94);
  backdrop-filter: blur(10px);
  padding: 20px;
  overflow-y: auto;
}
.game-drawer.hidden { display: none; }
.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1050px;
  margin: 0 auto 14px;
}
.close-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.drawer-section-title {
  max-width: 1050px;
  margin: 18px auto 10px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.8px;
  color: var(--accent2);
}
.drawer-grid {
  max-width: 1050px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
}
.drawer-item {
  background: rgba(255,255,255,0.06);
  border: 1.5px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 12px;
  color: #fff;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.14s, transform 0.14s;
}
.drawer-item:hover { border-color: var(--accent); transform: translateY(-2px); }
.drawer-item-title { font-weight: 800; font-size: 15px; margin-bottom: 3px; }
.drawer-item-sub { font-size: 12px; color: #b5c4d8; }
.drawer-item-actions { display: flex; gap: 6px; margin-top: 8px; }
.mini-btn {
  flex: 1;
  padding: 6px 8px;
  border-radius: 8px;
  border: none;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}
.mini-btn.walk { background: rgba(255,255,255,0.14); color: #fff; }
.mini-btn.play { background: var(--accent); color: #09120b; }

/* ===== COIN INSERTION ANIMATION ===== */
.coin-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(5, 8, 14, 0.86);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.coin-overlay.hidden { display: none; }
.coin-slot-box {
  background: linear-gradient(180deg, #273142, #121824);
  border: 3px solid #ffd93d;
  border-radius: 24px;
  padding: 28px 36px;
  text-align: center;
  position: relative;
  min-width: 290px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7), 0 0 36px rgba(255,217,61,0.3);
}
.coin-machine-title {
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 1.5px;
  margin-bottom: 18px;
  color: #ffd93d;
}
.coin-slot-plate {
  width: 120px;
  height: 150px;
  margin: 0 auto 14px;
  background: linear-gradient(145deg, #4b5563, #1f2937);
  border: 3px solid #9ca3af;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  box-shadow: inset 0 0 18px rgba(0,0,0,0.7);
}
.coin-slot-slit {
  width: 12px;
  height: 54px;
  background: #030712;
  border: 2px solid #fbbf24;
  border-radius: 4px;
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.6);
}
.coin-slot-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 1.2px;
  color: #fef08a;
}
.coin-return-btn {
  padding: 4px 12px;
  border-radius: 6px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 900;
  box-shadow: inset 0 -2px 0 #7f1d1d, 0 0 10px rgba(220,38,38,0.6);
}
.animated-coin {
  position: absolute;
  left: 50%;
  top: 225px;
  font-size: 46px;
  transform: translateX(-50%);
  pointer-events: none;
}
.animated-coin.drop {
  animation: coinSlideIn 0.9s cubic-bezier(.22,.82,.36,1) forwards;
}
@keyframes coinSlideIn {
  0%   { top: 245px; transform: translateX(-50%) scale(1.25) rotateY(0deg); opacity: 1; }
  55%  { top: 105px; transform: translateX(-50%) scale(0.9) rotateY(360deg); opacity: 1; }
  85%  { top: 96px;  transform: translateX(-50%) scaleX(0.25) scaleY(0.85); opacity: 0.9; }
  100% { top: 96px;  transform: translateX(-50%) scale(0.05); opacity: 0; }
}
.coin-status {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1.6px;
  color: #4ade80;
}

/* ===== ACTIVE GAME MODAL ===== */
#game-modal {
  background: #070a0f;
  z-index: 25;
}
.game-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: rgba(14, 20, 30, 0.96);
  border-bottom: 1.5px solid var(--border);
  gap: 8px;
  flex-wrap: wrap;
  z-index: 5;
}
.game-topbar-left, .game-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}
.top-action-btn {
  padding: 8px 12px;
  border-radius: 10px;
  border: 1.5px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}
.top-action-btn:active { transform: scale(0.96); }
.active-game-title { font-weight: 900; font-size: 15px; }
.active-game-sub { font-size: 11px; color: #9db0c9; }
.active-game-hud {
  font-family: 'Courier New', monospace;
  font-weight: 800;
  font-size: 14px;
  color: #ffd93d;
  background: rgba(0,0,0,0.45);
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,217,61,0.3);
}

.game-stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 8px;
  touch-action: none;
}

/* Retro CRT wrapper */
.crt-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  gap: 8px;
}
.crt-canvas {
  background: #000;
  border: 4px solid #2b3545;
  border-radius: 14px;
  box-shadow: 0 0 32px rgba(0,0,0,0.8), inset 0 0 24px rgba(0,0,0,0.6);
  image-rendering: pixelated;
  max-width: 100%;
  max-height: calc(100% - 82px);
  touch-action: none;
}
.crt-scanlines {
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.025) 0px,
    rgba(255,255,255,0.025) 1px,
    transparent 1px,
    transparent 3px
  );
}

/* Shared Tablet Control Bars */
.pad-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 720px;
  gap: 10px;
  padding: 4px 6px;
}
.pad-group {
  display: flex;
  gap: 8px;
  align-items: center;
}
.pad-btn {
  min-width: 58px;
  height: 52px;
  padding: 0 14px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,0.22);
  background: rgba(30, 41, 59, 0.9);
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  cursor: pointer;
  touch-action: none;
}
.pad-btn:active, .pad-btn.pressed {
  background: var(--accent);
  color: #08120a;
  transform: scale(0.95);
}
.pad-btn.fire {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-color: #fca5a5;
  min-width: 84px;
}
.pad-btn.alt {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  border-color: #93c5fd;
}
.pad-bar.rotated {
  transform: rotate(180deg);
}

/* 3D Floor Game Container */
.floor3d-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.floor3d-canvas {
  width: 100%;
  height: 100%;
  border-radius: 12px;
  overflow: hidden;
  touch-action: none;
}
.floor-overlay-ui {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 10;
  width: min(94%, 560px);
  pointer-events: none;
}
.floor-overlay-ui > * { pointer-events: auto; }
.meter-card {
  width: 100%;
  background: rgba(10, 15, 24, 0.88);
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.meter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.meter-label {
  font-size: 11px;
  font-weight: 900;
  width: 64px;
  letter-spacing: 1px;
  color: #cbd5e1;
}
.meter-track {
  position: relative;
  flex: 1;
  height: 18px;
  border-radius: 999px;
  background: #1e293b;
  overflow: hidden;
  border: 1.5px solid rgba(255,255,255,0.2);
}
.meter-sweet {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 38%;
  width: 24%;
  background: rgba(74, 222, 128, 0.3);
}
.meter-fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 0%;
  background: linear-gradient(90deg, #38bdf8, #4ade80, #facc15, #ef4444);
}
.meter-needle {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 8px;
  margin-left: -4px;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 0 10px #fff;
  left: 50%;
}
.mode-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.mode-pill {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid rgba(255,255,255,0.25);
  background: rgba(15, 23, 42, 0.88);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  cursor: pointer;
}
.mode-pill.active {
  background: #ffd93d;
  color: #111;
  border-color: #ffd93d;
}
