/* ============ BramMario — Mobile-first landscape UI ============ */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --sky: #5c94fc;
  --brick: #c84c0c;
  --gold: #fbd000;
  --green: #00a800;
  --red: #d82800;
  --dark: #101024;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--dark);
  font-family: 'Courier New', monospace;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
  position: fixed;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  position: fixed; inset: 0;
  z-index: 10;
  align-items: center; justify-content: center;
  flex-direction: column;
}
.screen.active { display: flex; }

/* ---------- Rotate overlay ---------- */
#rotate-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 1000;
  background: linear-gradient(160deg, #1a1a40 0%, #2d1b69 50%, #451f55 100%);
  align-items: center; justify-content: center;
  text-align: center; color: #fff;
}
body.portrait #rotate-overlay { display: flex; }
.rotate-inner h2 { font-size: 1.4rem; margin: 16px 0 8px; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.rotate-inner p { font-size: .95rem; opacity: .85; line-height: 1.5; }
.rotate-phone {
  font-size: 4rem;
  animation: rotatePhone 2s ease-in-out infinite;
  display: inline-block;
}
@keyframes rotatePhone {
  0%, 20% { transform: rotate(0deg); }
  60%, 80% { transform: rotate(90deg); }
  100% { transform: rotate(90deg); }
}

/* ---------- Menu ---------- */
#screen-menu { background: var(--sky); overflow: hidden; }
.menu-sky { position: absolute; inset: 0; pointer-events: none; }
.cloud {
  position: absolute; width: 120px; height: 40px; background: #fff; border-radius: 40px;
  opacity: .9; animation: drift 40s linear infinite;
}
.cloud::before { content:''; position:absolute; width:50px;height:50px;background:#fff;border-radius:50%;top:-20px;left:20px; }
.cloud::after { content:''; position:absolute; width:40px;height:40px;background:#fff;border-radius:50%;top:-14px;left:60px; }
.c1 { top: 12%; left: -140px; }
.c2 { top: 28%; left: -140px; animation-delay: -15s; transform: scale(.7); }
.c3 { top: 8%;  left: -140px; animation-delay: -28s; transform: scale(1.2); }
@keyframes drift { to { transform: translateX(calc(100vw + 300px)); } }
.menu-hill {
  position: absolute; bottom: -40px; border-radius: 50% 50% 0 0; background: #00a800;
}
.h1 { width: 340px; height: 150px; left: -60px; }
.h2 { width: 260px; height: 110px; right: -40px; background: #008000; }

#menu-title { text-align: center; z-index: 2; }
.game-logo {
  font-size: clamp(2.2rem, 8vw, 4rem);
  color: #fff; letter-spacing: 2px;
  text-shadow: 3px 3px 0 var(--red), 6px 6px 0 rgba(0,0,0,.35);
}
.game-logo span { color: var(--gold); }
.tagline { color: #fff; text-shadow: 1px 1px 0 #000; margin-top: 4px; font-size: .9rem; }

.menu-panel {
  z-index: 2; margin-top: 18px;
  display: flex; flex-direction: column; gap: 10px;
  width: min(320px, 86vw);
}
.menu-panel input, .join-row input {
  padding: 12px 14px; font-size: 1rem; font-family: inherit;
  border: 3px solid #000; border-radius: 8px; background: #fff;
  text-align: center; outline: none;
}
#join-code { text-transform: uppercase; letter-spacing: 4px; width: 0; flex: 1; }
.join-row { display: flex; gap: 8px; }
.join-row .btn { flex: 0 0 42%; }

.btn {
  padding: 12px 16px; font-size: 1rem; font-weight: bold; font-family: inherit;
  border: 3px solid #000; border-radius: 8px; cursor: pointer;
  color: #fff; text-shadow: 1px 1px 0 rgba(0,0,0,.5);
  box-shadow: 0 4px 0 rgba(0,0,0,.4);
  transition: transform .06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.4); }
.btn-primary { background: var(--red); }
.btn-green { background: var(--green); }
.btn-blue { background: #0058f8; }
.btn-gold { background: #e8a000; }
.btn-red { background: #b02020; }
.menu-footer {
  position: absolute; bottom: calc(8px + var(--safe-b)); color: #fff;
  font-size: .7rem; opacity: .7; z-index: 2;
}

/* ---------- Panels (lobby / leaderboard / overlay) ---------- */
#screen-lobby, #screen-leaderboard { background: rgba(10,10,30,.96); }
.panel {
  background: #202040; border: 4px solid #000; border-radius: 14px;
  padding: 20px 26px; color: #fff; text-align: center;
  width: min(400px, 90vw); max-height: 88vh; overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0,0,0,.6);
}
.panel h2 { color: var(--gold); margin-bottom: 12px; text-shadow: 2px 2px 0 #000; }
#room-code-box {
  background: #000; border-radius: 10px; padding: 10px; margin-bottom: 12px;
}
#room-code-box span { display: block; font-size: .65rem; color: #8f8; letter-spacing: 2px; }
#room-code-box strong { font-size: 2rem; color: var(--gold); letter-spacing: 8px; }
.lobby-status { font-size: .85rem; color: #aaf; margin-bottom: 10px; min-height: 1.2em; }
.player-list { list-style: none; margin-bottom: 14px; }
.player-list li {
  background: rgba(255,255,255,.08); margin: 5px 0; padding: 8px 12px;
  border-radius: 8px; display: flex; justify-content: space-between; font-size: .9rem;
}
.player-list li .p-role { color: #8f8; font-size: .75rem; }
.row-gap { display: flex; gap: 10px; justify-content: center; }
.lb-list { margin-bottom: 14px; text-align: left; }
.lb-row {
  display: flex; justify-content: space-between; padding: 7px 10px; margin: 4px 0;
  background: rgba(255,255,255,.07); border-radius: 6px; font-size: .85rem;
}
.lb-row .lb-rank { color: var(--gold); width: 2.2em; }
.lb-row .lb-name { flex: 1; }
.lb-row .lb-score { color: #8f8; }
.lb-loading { color: #99a; padding: 20px 0; text-align: center; }

/* ---------- Game ---------- */
#game-container { display: none; position: fixed; inset: 0; z-index: 20; background: #000; }
#game-container.active { display: block; }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; }

#hud {
  position: absolute; top: 6px; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r));
  display: flex; gap: 4%; justify-content: flex-start;
  color: #fff; font-weight: bold; font-size: clamp(.7rem, 2.2vw, 1rem);
  text-shadow: 2px 2px 0 #000; pointer-events: none; z-index: 5;
}
#btn-sound-game, #btn-fullscreen, #btn-quit {
  position: absolute; top: 4px; z-index: 6;
  width: 38px; height: 38px; border-radius: 8px;
  border: 2px solid rgba(255,255,255,.5); background: rgba(0,0,0,.45); color: #fff;
  font-size: 1.1rem; cursor: pointer;
}
#btn-sound-game { right: calc(96px + var(--safe-r)); }
#btn-fullscreen { right: calc(52px + var(--safe-r)); }
#btn-quit { right: calc(8px + var(--safe-r)); }
#btn-sound-game.muted { opacity: .55; }

/* Menu sound toggle */
.btn-sound {
  background: #555; color: #fff; border-color: #333;
  font-size: .85rem; padding: 8px 12px;
}
.btn-sound.muted { background: #3a3a3a; color: #aaa; }

/* ---------- Touch controls ---------- */
#touch-controls { position: absolute; inset: 0; z-index: 4; pointer-events: none; display: none; }
body.touch #touch-controls { display: block; }
.tbtn {
  position: absolute; pointer-events: auto;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.14); border: 2px solid rgba(255,255,255,.4);
  color: rgba(255,255,255,.85); font-weight: bold;
  border-radius: 14px; font-size: 1.5rem;
  backdrop-filter: blur(2px);
}
.tbtn.pressed { background: rgba(255,255,255,.42); }
#t-left  { left: calc(14px + var(--safe-l)); bottom: calc(26px + var(--safe-b)); width: 64px; height: 64px; }
#t-right { left: calc(92px + var(--safe-l)); bottom: calc(26px + var(--safe-b)); width: 64px; height: 64px; }
#t-down  { left: calc(53px + var(--safe-l)); bottom: calc(96px + var(--safe-b)); width: 56px; height: 44px; font-size: 1.1rem; }
.abtn { border-radius: 50%; width: 68px; height: 68px; font-size: 1.3rem; }
#t-a { right: calc(16px + var(--safe-r)); bottom: calc(60px + var(--safe-b)); background: rgba(216,40,0,.35); }
#t-b { right: calc(96px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); background: rgba(0,88,248,.35); }

/* ---------- Overlay & toast ---------- */
#game-overlay {
  position: absolute; inset: 0; z-index: 30;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center;
}
#game-overlay.hidden { display: none; }
#overlay-stats { margin: 10px 0 14px; line-height: 1.7; font-size: .95rem; }
#overlay-submit { margin-bottom: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 14vh; transform: translateX(-50%) translateY(20px);
  background: #000; color: var(--gold); border: 2px solid var(--gold);
  padding: 10px 18px; border-radius: 10px; font-size: .85rem; font-weight: bold;
  opacity: 0; transition: all .25s; z-index: 2000; pointer-events: none;
  max-width: 84vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
