:root {
  --bg-deep: #090814;
  --bg-panel: #131129;
  --bg-card: #1a1738;
  --bg-card-hover: #25204d;
  --neon-cyan: #00f5d4;
  --neon-pink: #ff2a85;
  --neon-yellow: #ffd60a;
  --neon-green: #38ef7d;
  --neon-purple: #a855f7;
  --neon-blue: #38bdf8;
  --text-bright: #f8fafc;
  --border-glow: rgba(0, 245, 212, 0.35);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(circle at 50% 15%, #19153a 0%, var(--bg-deep) 80%);
  color: var(--text-bright);
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  width: 100dvw;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.hidden {
  display: none !important;
}

/* Top Bar */
#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  background: rgba(19, 17, 41, 0.92);
  border-bottom: 2px solid rgba(0, 245, 212, 0.25);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  z-index: 20;
  flex-shrink: 0;
  gap: 0.5rem;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.icon-btn, .pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 2px solid rgba(163, 155, 248, 0.35);
  border-radius: 14px;
  padding: 0.35rem 0.55rem;
  min-height: 44px;
  min-width: 44px;
  color: var(--text-bright);
  cursor: pointer;
  box-shadow: 0 4px 0 #0c0a1e, 0 0 12px rgba(0, 245, 212, 0.12);
  transition: transform 0.1s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.icon-btn:hover, .pill-btn:hover {
  border-color: var(--neon-cyan);
  background: var(--bg-card-hover);
}

.icon-btn:active, .pill-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #0c0a1e;
}

.gold-pill {
  border-color: rgba(255, 214, 10, 0.5);
  box-shadow: 0 4px 0 #0c0a1e, 0 0 14px rgba(255, 214, 10, 0.18);
}

.ui-svg {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.ui-svg-lg {
  width: 32px;
  height: 32px;
}

.ui-svg-xl {
  width: 42px;
  height: 42px;
}

.arcade-code {
  font-size: clamp(1rem, 0.85rem + 0.8vw, 1.35rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(0, 245, 212, 0.5);
}

.arcade-num {
  font-size: clamp(1rem, 0.85rem + 0.8vw, 1.35rem);
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 8px rgba(255, 214, 10, 0.45);
}

/* Lobby Grid View */
#lobby-view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: clamp(0.6rem, 1.5vw, 1.4rem);
  container-type: inline-size;
  touch-action: pan-y;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(135px, 1fr));
  gap: clamp(0.65rem, 1.6vw, 1.2rem);
  max-width: 1360px;
  margin: 0 auto;
  padding-bottom: 2rem;
}

@container (min-width: 640px) {
  .game-grid {
    grid-template-columns: repeat(auto-fill, minmax(165px, 1fr));
  }
}

@container (min-width: 1024px) {
  .game-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.game-card {
  position: relative;
  aspect-ratio: 1;
  background: linear-gradient(160deg, #211c47 0%, #120f29 100%);
  border: 2.5px solid rgba(140, 130, 240, 0.35);
  border-radius: 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem;
  cursor: pointer;
  box-shadow: 0 6px 0 #0a0818, 0 8px 20px rgba(0, 0, 0, 0.45);
  transition: transform 0.14s cubic-bezier(0.2, 0.9, 0.3, 1.2), border-color 0.15s ease, box-shadow 0.15s ease;
  overflow: hidden;
}

.game-card:hover, .game-card:focus-visible {
  transform: translateY(-4px) scale(1.02);
  border-color: var(--card-accent, var(--neon-cyan));
  box-shadow: 0 8px 0 #0a0818, 0 0 22px var(--card-glow, rgba(0, 245, 212, 0.4));
  outline: none;
}

.game-card:active {
  transform: translateY(3px) scale(0.98);
  box-shadow: 0 2px 0 #0a0818;
}

.card-art {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem;
}

.card-art svg {
  width: 100%;
  height: 100%;
  max-width: 112px;
  max-height: 112px;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.5));
}

.card-score-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  background: rgba(9, 8, 20, 0.78);
  border-radius: 11px;
  padding: 0.22rem 0.45rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.card-score-bar .mini-trophy {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.card-score-bar .arcade-code {
  font-size: clamp(0.75rem, 0.65rem + 0.35vw, 0.92rem);
}

.card-score-bar .arcade-num {
  font-size: clamp(0.78rem, 0.68rem + 0.35vw, 0.95rem);
}

/* Active Game View */
#game-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 100%;
}

#game-hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 0.85rem;
  background: rgba(15, 13, 33, 0.85);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.hud-left, .hud-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.hud-mini-icon {
  width: 30px;
  height: 30px;
}

.hud-mini-icon svg {
  width: 100%;
  height: 100%;
}

.hud-lives, .hud-stars {
  display: flex;
  gap: 0.2rem;
}

.hud-level-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  background: rgba(26, 23, 56, 0.9);
  border: 1.5px solid rgba(0, 245, 212, 0.35);
  border-radius: 10px;
  padding: 0.1rem 0.25rem;
}

.lvl-step-btn {
  background: transparent;
  border: none;
  color: var(--neon-cyan);
  font-size: 0.85rem;
  font-weight: 900;
  padding: 0.15rem 0.3rem;
  cursor: pointer;
  line-height: 1;
}

.lvl-step-btn:active {
  transform: scale(0.88);
  color: var(--neon-yellow);
}

.life-heart, .hud-star-svg {
  width: 20px;
  height: 20px;
}

.hud-score-num {
  font-size: clamp(1.4rem, 1.1rem + 1.5vw, 2.2rem);
  font-weight: 900;
  color: #ffffff;
  text-shadow: 0 0 12px var(--neon-cyan), 0 2px 0 #000;
  letter-spacing: 0.06em;
}

.mini-trophy {
  width: 20px;
  height: 20px;
}

#stage-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.35rem;
  gap: 0.35rem;
  min-height: 0;
  overflow: hidden;
}

#canvas-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

#game-canvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  aspect-ratio: 600 / 720;
  background: #070612;
  border: 2.5px solid rgba(0, 245, 212, 0.45);
  border-radius: 16px;
  box-shadow: 0 0 28px rgba(0, 245, 212, 0.18), inset 0 0 20px rgba(0, 0, 0, 0.8);
  touch-action: none;
  display: block;
}

/* Stage Overlay (Visual How-To-Play & Game Over) */
#stage-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(7, 6, 18, 0.82);
  backdrop-filter: blur(5px);
  z-index: 10;
  padding: 0.75rem;
}

.overlay-card {
  background: linear-gradient(165deg, #1e1942 0%, #100d26 100%);
  border: 2.5px solid var(--neon-cyan);
  border-radius: 24px;
  padding: 1rem;
  width: min(94vw, 410px);
  max-height: 100%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.75), 0 0 25px rgba(0, 245, 212, 0.25);
}

#overlay-top-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.overlay-game-icon {
  width: 58px;
  height: 58px;
}

.overlay-game-icon svg {
  width: 100%;
  height: 100%;
}

.big-score-num {
  font-size: clamp(2rem, 1.5rem + 2.5vw, 3rem);
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 16px rgba(255, 214, 10, 0.65);
}

#demo-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
}

#demo-canvas {
  width: 100%;
  max-width: 340px;
  aspect-ratio: 360 / 220;
  background: #090818;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
}

.input-badges {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
}

.input-mode-svg {
  width: 30px;
  height: 30px;
  opacity: 0.9;
}

/* Initials Roller */
.initials-roller {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
}

.letter-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.roll-btn {
  width: 54px;
  height: 36px;
  background: #272154;
  border: 2px solid rgba(0, 245, 212, 0.45);
  border-radius: 10px;
  color: var(--neon-cyan);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #0c0a1e;
}

.roll-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #0c0a1e;
}

.letter-cell {
  width: 54px;
  height: 58px;
  background: #090814;
  border: 2.5px solid var(--neon-yellow);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.1rem;
  font-weight: 900;
  color: var(--neon-yellow);
  text-shadow: 0 0 12px rgba(255, 214, 10, 0.65);
}

#gameover-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
}

.mini-board {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  max-width: 300px;
  max-height: 175px;
  overflow-y: auto;
  background: rgba(9, 8, 20, 0.78);
  border-radius: 12px;
  padding: 0.45rem 0.75rem;
  border: 1px solid rgba(255, 255, 255, 0.14);
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.15rem 0.25rem;
  border-radius: 6px;
}

.score-row.highlight {
  background: rgba(255, 214, 10, 0.18);
}

.overlay-actions, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  margin-top: 0.2rem;
}

.action-circle-btn {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 3px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 6px 0 #080612, 0 0 22px rgba(56, 239, 125, 0.45);
  transition: transform 0.12s ease;
}

.action-circle-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #080612;
}

.play-circle {
  background: linear-gradient(135deg, #38ef7d 0%, #11998e 100%);
  border-color: #bbf7d0;
  animation: pulse-play 1.6s infinite ease-in-out;
}

.back-circle {
  width: 56px;
  height: 56px;
  background: #25204d;
  border-color: rgba(163, 155, 248, 0.6);
  box-shadow: 0 5px 0 #080612;
}

.dice-circle {
  width: 56px;
  height: 56px;
  background: #3b1d6e;
  border-color: #d8b4fe;
  box-shadow: 0 5px 0 #080612;
}

@keyframes pulse-play {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}

/* On-Screen Touch / Click Controls */
#touch-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  width: 100%;
  max-width: 540px;
  min-height: 64px;
  padding: 0.15rem 0.5rem;
  flex-shrink: 0;
  touch-action: none;
}

.ctrl-pad {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 0.5rem;
}

.ctrl-cluster {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.dpad-grid {
  display: grid;
  grid-template-columns: repeat(3, 50px);
  grid-template-rows: repeat(2, 46px);
  gap: 0.3rem;
}

.ctrl-btn {
  min-width: 54px;
  height: 52px;
  border-radius: 14px;
  background: linear-gradient(180deg, #2d2663 0%, #1c1742 100%);
  border: 2px solid rgba(0, 245, 212, 0.5);
  color: var(--neon-cyan);
  font-size: 1.45rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 0 #090814;
  touch-action: none;
}

.ctrl-btn.action-a {
  min-width: 68px;
  height: 58px;
  border-radius: 29px;
  background: linear-gradient(180deg, #ff2a85 0%, #be125d 100%);
  border-color: #fbcfe8;
  color: #fff;
}

.ctrl-btn.action-b {
  min-width: 62px;
  height: 58px;
  border-radius: 29px;
  background: linear-gradient(180deg, #ffd60a 0%, #ca8a04 100%);
  border-color: #fef08a;
  color: #090814;
}

.ctrl-btn.wide-btn {
  min-width: 140px;
}

.ctrl-btn:active, .ctrl-btn.pressed {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #090814;
  filter: brightness(1.25);
}

/* Native <dialog> Modals */
dialog {
  margin: auto;
  border: none;
  background: transparent;
  color: var(--text-bright);
  max-width: 95dvw;
  max-height: 92dvh;
}

dialog::backdrop {
  background-color: rgba(5, 4, 14, 0.78);
  backdrop-filter: blur(4px);
}

.dialog-panel {
  background: linear-gradient(165deg, #1f1a45 0%, #110e29 100%);
  border: 3px solid var(--neon-cyan);
  border-radius: 26px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.8), 0 0 28px rgba(0, 245, 212, 0.3);
}

.leaderboard-panel {
  width: min(92dvw, 560px);
  max-height: 86dvh;
  overflow-y: auto;
}

.totals-list {
  width: 100%;
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: rgba(9, 8, 20, 0.75);
  border-radius: 16px;
  padding: 0.65rem 0.9rem;
  border: 1.5px solid rgba(255, 214, 10, 0.4);
}

.champions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(98px, 1fr));
  gap: 0.45rem;
  width: 100%;
  max-height: 200px;
  overflow-y: auto;
  padding: 0.25rem;
}

.champ-cell {
  background: rgba(26, 23, 56, 0.9);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  cursor: pointer;
}

.champ-cell.active-champ {
  border-color: var(--neon-yellow);
  box-shadow: 0 0 14px rgba(255, 214, 10, 0.4);
}

.champ-cell svg {
  width: 38px;
  height: 38px;
}

#install-guide-canvas {
  border-radius: 16px;
  background: #090818;
  border: 2px solid rgba(168, 85, 247, 0.5);
  max-width: 100%;
}
