/* ===========================================================================
   Trap Run — tr.css
   Dark, moody, neon-trap theme. Deliberately its own visual world (not the
   light notebook theme used by the rest of RivalPit's casual games) --
   consistent with how Real Battle and Flappy Flight get their own dark
   in-game palette. Ink blue / red accents echo the brand without looking
   like a ruled notebook page.
   =========================================================================== */
:root {
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --ink: #3ddc84;
  --red: #d64545;
  --panel: #171d38;
  --panel-border: #2b3a67;
  --text: #eef0fb;
  --muted: #9aa1c4;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; padding: 0; background: #0d1224; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  user-select: none;
}

#tr-canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ------------------------------------------------------------------ HUD --- */
#tr-hud { position: fixed; inset: 0; pointer-events: none; z-index: 40; }
#tr-hud-pause {
  position: fixed; top: calc(12px + var(--sat)); left: calc(12px + var(--sal));
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--panel-border);
  background: rgba(23, 29, 56, .78); color: var(--text); font-size: 16px;
  pointer-events: auto; cursor: pointer;
}
#tr-hud-top {
  position: fixed; top: calc(12px + var(--sat)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 14px; align-items: center;
  background: rgba(23, 29, 56, .78); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 8px 16px; font-weight: 700; font-size: 14px;
}
#tr-level-name { color: var(--muted); font-weight: 600; }
#tr-timer { font-variant-numeric: tabular-nums; }
#tr-deaths { color: var(--red); }
#tr-mock-msg {
  position: fixed; top: calc(64px + var(--sat)); left: 50%; transform: translate(-50%, -10px);
  background: rgba(214, 69, 69, .16); border: 1px solid rgba(214, 69, 69, .5);
  color: #ffb3b3; border-radius: 10px; padding: 6px 14px; font-size: 13px; font-weight: 600;
  opacity: 0; visibility: hidden; transition: transform .25s ease, opacity .25s ease, visibility 0s linear .25s;
  max-width: min(80vw, 360px); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#tr-mock-msg.on { opacity: 1; visibility: visible; transform: translate(-50%, 0); transition: transform .25s ease, opacity .25s ease; }

#tr-peer-bar-wrap {
  position: fixed; top: calc(12px + var(--sat)); right: calc(12px + var(--sar));
  width: 160px; background: rgba(23, 29, 56, .78); border: 1px solid var(--panel-border);
  border-radius: 12px; padding: 8px 10px; display: none;
}
#tr-peer-bar-wrap.on { display: block; }
.tr-peer-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.tr-peer-track { height: 6px; border-radius: 4px; background: #0d1224; overflow: hidden; }
.tr-peer-fill { height: 100%; width: 0%; background: linear-gradient(90deg, #a24fd6, #3ddc84); transition: width .2s ease; }
.tr-peer-deaths { font-size: 11px; color: var(--red); margin-top: 4px; }

/* ---------------------------------------------------------- touch pad --- */
#tr-touch { position: fixed; inset: 0; pointer-events: none; z-index: 35; display: none; }
#tr-touch.on { display: block; }
.tr-touch-btn {
  position: absolute; bottom: calc(24px + var(--sab)); width: 66px; height: 66px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); background: rgba(23, 29, 56, .55); color: #fff;
  font-size: 26px; pointer-events: auto; touch-action: none; display: flex; align-items: center; justify-content: center;
}
#tr-btn-left { left: calc(24px + var(--sal)); }
#tr-btn-right { left: calc(102px + var(--sal)); }
.tr-touch-jump { right: calc(24px + var(--sar)); width: 80px; height: 80px; font-size: 30px; background: rgba(61, 220, 132, .28); border-color: rgba(61, 220, 132, .5); }

/* --------------------------------------------------------------- menus --- */
#tr-menus { position: fixed; inset: 0; z-index: 50; pointer-events: none; }
#tr-menus.on { pointer-events: auto; }
.tr-screen {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center;
  justify-content: center; gap: 14px; text-align: center;
  padding: calc(16px + var(--sat)) calc(16px + var(--sar)) calc(16px + var(--sab)) calc(16px + var(--sal));
  overflow-y: auto;
}
.tr-screen.on { display: flex; }
.tr-screen.tr-overlay { background: rgba(6, 9, 17, .72); backdrop-filter: blur(3px); }
.tr-screen h2 { margin: 0 0 6px; font-size: 22px; font-weight: 800; }

.tr-logo { display: flex; align-items: center; gap: 10px; font-size: 42px; font-weight: 900; letter-spacing: 1px; }
.tr-logo-icon { font-size: 34px; }
.tr-logo-trap { color: var(--text); }
.tr-logo-run { color: var(--ink); }
.tr-tagline { color: var(--muted); font-size: 15px; margin-top: -8px; }
.tr-stats-line { color: var(--muted); font-size: 13px; background: rgba(23,29,56,.6); border: 1px solid var(--panel-border); border-radius: 20px; padding: 6px 14px; }
.tr-footer-note { position: absolute; bottom: calc(14px + var(--sab)); color: var(--muted); font-size: 12px; }

.tr-menu-col { display: flex; flex-direction: column; gap: 10px; width: min(320px, 84vw); }
.tr-menu-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.tr-btn {
  appearance: none; border: 1px solid var(--panel-border); background: var(--panel); color: var(--text);
  border-radius: 12px; padding: 12px 18px; font-size: 15px; font-weight: 700; cursor: pointer;
  font-family: inherit;
}
.tr-btn:active { transform: scale(.97); }
.tr-btn-big { padding: 15px 18px; font-size: 16px; }
.tr-btn-primary { background: linear-gradient(135deg, #3ddc84, #2bb56b); border-color: #2bb56b; color: #06210f; }
.tr-btn-online { background: linear-gradient(135deg, #a24fd6, #7a35a8); border-color: #7a35a8; color: #fff; }

.tr-panel {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 16px;
  padding: 22px; width: min(420px, 90vw); max-height: calc(100vh - 24px - var(--sat) - var(--sab)); overflow-y: auto;
}
.tr-panel p { color: var(--muted); font-size: 14px; line-height: 1.5; text-align: left; }

/* level select */
.tr-level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; width: min(600px, 92vw); }
.tr-level-card {
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px; padding: 12px;
  cursor: pointer; text-align: left;
}
.tr-level-card:active { transform: scale(.97); }
.tr-level-card .n { font-size: 22px; font-weight: 900; color: var(--ink); }
.tr-level-card .name { font-size: 13px; font-weight: 700; margin: 4px 0; }
.tr-level-card .stat { font-size: 11px; color: var(--muted); }
.tr-level-card.locked { cursor: not-allowed; opacity: .55; }
.tr-level-card.locked:active { transform: none; }
.tr-level-card.locked .n { color: var(--muted); }

/* online lobby */
.tr-join-row { display: flex; gap: 8px; }
.tr-join-row input {
  flex: 1; background: #0d1224; border: 1px solid var(--panel-border); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 16px; text-align: center; text-transform: uppercase; letter-spacing: 2px;
}
#tr-online-status { min-height: 20px; color: var(--muted); font-size: 13px; }

#tr-lobby-code {
  background: none; border: 1px dashed var(--panel-border); border-radius: 10px; padding: 10px 16px;
  color: var(--ink); font-size: 22px; font-weight: 900; letter-spacing: 4px; cursor: pointer; display: flex;
  flex-direction: column; gap: 2px;
}
#tr-lobby-code small { color: var(--muted); font-size: 10px; letter-spacing: 0; font-weight: 500; }
#tr-lobby-players { display: flex; flex-direction: column; gap: 6px; width: min(320px, 84vw); }
.tr-lobby-player { display: flex; justify-content: space-between; background: #0d1224; border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.tr-lobby-player .ready { color: var(--ink); font-weight: 700; }
.tr-lobby-player .notready { color: var(--muted); }
.tr-cfg-row { display: flex; align-items: center; gap: 10px; }
.tr-cfg-row label { color: var(--muted); font-size: 13px; }
.tr-seg-row { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.tr-seg { background: #0d1224; border: 1px solid var(--panel-border); color: var(--text); border-radius: 8px; padding: 6px 10px; font-size: 13px; cursor: pointer; }
.tr-seg.sel { background: var(--ink); color: #06210f; border-color: var(--ink); }
#tr-lobby-wait { color: var(--muted); font-size: 13px; min-height: 18px; }

/* countdown */
#tr-scr-countdown { pointer-events: none; }
#tr-countdown-num { font-size: 96px; font-weight: 900; color: var(--ink); text-shadow: 0 0 30px rgba(61,220,132,.6); }

/* results */
#tr-res-banner { font-size: 26px; font-weight: 900; margin-bottom: 10px; }
#tr-res-stats { display: flex; gap: 18px; justify-content: center; margin-bottom: 16px; }
#tr-res-stats .stat { text-align: center; }
#tr-res-stats .stat .v { font-size: 22px; font-weight: 900; color: var(--ink); }
#tr-res-stats .stat .l { font-size: 11px; color: var(--muted); }

/* toast */
#tr-toast {
  position: fixed; bottom: calc(20px + var(--sab)); left: 50%; transform: translateX(-50%);
  background: rgba(23,29,56,.92); border: 1px solid var(--panel-border); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; z-index: 90;
  opacity: 0; visibility: hidden; transition: opacity .25s ease, visibility 0s linear .25s;
  pointer-events: none;
}
#tr-toast.on { opacity: 1; visibility: visible; transition: opacity .25s ease; }

/* fullscreen + mute toggles -- z-index deliberately ABOVE #tr-menus (50):
   #tr-menus covers the full viewport with pointer-events:auto whenever any
   menu screen is shown (title, pause, results, etc.), and since these
   buttons previously sat at z-index 45 -- below that -- every click on them
   while a menu was open was silently swallowed by the (invisible, but
   still pointer-capturing) menu layer underneath. That's why fullscreen
   looked "broken" specifically from the main menu but worked mid-game
   (where #tr-menus is hidden). */
#tr-btn-fullscreen, #tr-btn-mute {
  position: fixed; bottom: calc(10px + var(--sab));
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--panel-border);
  background: rgba(23, 29, 56, .55); color: var(--muted); font-size: 15px; z-index: 60; cursor: pointer;
}
#tr-btn-fullscreen { right: calc(10px + var(--sar)); }
#tr-btn-mute { right: calc(52px + var(--sar)); }
/* while the on-screen touch joystick/jump buttons are actually showing
   (gameplay on a touch device), lift these two above that button row
   instead of sitting underneath/behind the big jump button */
#tr-touch.on ~ #tr-btn-fullscreen, #tr-touch.on ~ #tr-btn-mute {
  bottom: calc(112px + var(--sab));
}

/* ---------------------------------------------------------- environment --- */
.tr-env-sub { color: var(--muted); font-size: 13px; max-width: min(420px, 88vw); margin-top: -6px; }
.tr-env-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; width: min(600px, 92vw); }
.tr-env-card {
  background: var(--panel); border: 2px solid var(--panel-border); border-radius: 12px; padding: 8px;
  cursor: pointer; text-align: center;
}
.tr-env-card:active { transform: scale(.97); }
.tr-env-card.sel { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.tr-env-swatch { width: 100%; height: 60px; border-radius: 8px; margin-bottom: 8px; }
.tr-env-name { font-size: 12px; font-weight: 700; }

/* rotate overlay */
#tr-rotate-overlay {
  display: none; position: fixed; inset: 0; z-index: 100; background: #0d1224;
  align-items: center; justify-content: center; text-align: center; color: var(--text);
}
.tr-rotate-icon { font-size: 46px; margin-bottom: 10px; }
@media (max-width: 900px) and (orientation: portrait) {
  #tr-rotate-overlay { display: flex; }
}

@media (max-width: 680px) {
  #tr-hud-top { font-size: 12px; gap: 10px; padding: 6px 12px; }
  .tr-logo { font-size: 30px; }
  #tr-peer-bar-wrap { width: 120px; }
}
