* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #111; font-family: "Inter", "Segoe UI", system-ui, sans-serif; color: #fff; user-select: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }

.overlay { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(10, 14, 22, 0.55); backdrop-filter: blur(3px); z-index: 10; }
.card { background: #1b2230; border: 3px solid #ffd23f; border-radius: 18px; padding: 32px 40px; width: min(440px, 92vw); text-align: center; box-shadow: 0 12px 0 #0b0f17; }
.card h1 { margin: 0 0 6px; font-size: 44px; letter-spacing: 4px; color: #ffd23f; font-weight: 900; }
.card .sub { margin: 0 0 22px; color: #c9d1e0; }
.card .hint { color: #8b95a8; font-size: 13px; margin-top: 18px; }
input, button { font: inherit; font-size: 17px; border-radius: 10px; border: none; padding: 12px 16px; }
input { width: 100%; margin-bottom: 12px; background: #0f141e; color: #fff; border: 2px solid #33405a; text-align: center; }
button { background: #ffd23f; color: #1b2230; font-weight: 800; cursor: pointer; width: 100%; box-shadow: 0 4px 0 #b8901a; }
button:active { transform: translateY(2px); box-shadow: 0 2px 0 #b8901a; }
#lobby-players { color: #c9d1e0; line-height: 1.6; }
.start-from { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 4px 0 14px; color: #c9d1e0; font-weight: 700; }
.start-from select { font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 8px; background: #0f141e; color: #fff; border: 2px solid #33405a; }
.start-from select:disabled { opacity: 0.6; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px; border-radius: 50%; background: rgba(255,255,255,0.85); box-shadow: 0 0 0 2px rgba(0,0,0,0.35); }
#prompt { position: absolute; left: 50%; top: calc(50% + 28px); transform: translateX(-50%); background: rgba(15,20,30,0.8); padding: 6px 12px; border-radius: 8px; font-weight: 700; font-size: 15px; white-space: nowrap; }
#prompt:empty { display: none; }
#conn { position: absolute; left: 50%; top: 16px; transform: translateX(-50%); background: #d6453a; color: #fff; padding: 8px 16px; border-radius: 8px; font-weight: 800; z-index: 20; }
#conn[hidden] { display: none; }
#fixbar { position: absolute; left: 50%; top: calc(50% + 64px); transform: translateX(-50%); width: 240px; background: rgba(15,20,30,0.8); padding: 6px 10px 8px; border-radius: 8px; font-weight: 700; font-size: 13px; text-align: center; }
#fixbar[hidden] { display: none; }
#fixbar div { height: 8px; margin-top: 5px; background: #2a2f3a; border-radius: 4px; overflow: hidden; }
#fixbar i { display: block; height: 100%; width: 0; background: #ffd23f; transition: width 0.15s linear; }
#prompt kbd { background: #ffd23f; color: #1b2230; border-radius: 4px; padding: 0 6px; font-family: inherit; font-weight: 900; margin-right: 4px; }
#log { position: absolute; left: 16px; top: 16px; display: flex; flex-direction: column; gap: 6px; }
#log div { background: rgba(15,20,30,0.75); padding: 5px 10px; border-radius: 6px; font-size: 14px; animation: fade 6s forwards; }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
#clicktoplay { position: absolute; left: 50%; bottom: 40%; transform: translateX(-50%); background: rgba(15,20,30,0.85); padding: 10px 18px; border-radius: 10px; font-weight: 700; }

#crosshair.active { width: 12px; height: 12px; margin: -6px; background: #ffd23f; }

#editor-ui { position: fixed; right: 14px; top: 14px; z-index: 20; width: 360px; background: rgba(15,20,30,0.92); border: 2px solid #ffd23f; border-radius: 12px; padding: 12px 14px; font-size: 13px; line-height: 1.6; font-variant-numeric: tabular-nums; }
#editor-ui .row { display: flex; gap: 6px; margin: 6px 0; }
#editor-ui .row span { background: #33405a; border-radius: 5px; padding: 1px 8px; font-weight: 800; }
#editor-ui .row span.on { background: #ffd23f; color: #1b2230; }
#editor-ui .sel { color: #ffd23f; font-weight: 800; word-break: break-all; }
#editor-ui .help { color: #8b95a8; font-size: 12px; margin-top: 6px; }
#editor-ui .flash { color: #7bf1a8; font-weight: 800; }
#editor-ui .k { background: #ffd23f; color: #1b2230; border-radius: 4px; padding: 0 5px; font-weight: 900; }

/* ---------- loading + Half-Life/Portal-style menu ---------- */
#loading { position: fixed; inset: 0; z-index: 50; background: #07090c; display: grid; place-items: center; transition: opacity 0.6s; }
#loading.done { opacity: 0; pointer-events: none; }
.load-inner { width: min(520px, 80vw); }
.load-bar { height: 4px; background: #1c222b; margin: 26px 0 12px; overflow: hidden; }
#load-fill { height: 100%; width: 0; background: #ffd23f; transition: width 0.3s; }
#load-text { color: #8b95a8; font-size: 13px; letter-spacing: 3px; text-transform: uppercase; font-weight: 700; }

.menu { position: fixed; inset: 0; z-index: 10; pointer-events: none;
  background: linear-gradient(90deg, rgba(5,7,10,0.82) 0%, rgba(5,7,10,0.55) 32%, rgba(5,7,10,0) 62%); }
/* pause menu: the same left-hand menu, over a dimmed game */
#pause { background: linear-gradient(90deg, rgba(5,7,10,0.88) 0%, rgba(5,7,10,0.6) 40%, rgba(5,7,10,0.25) 75%); }
#pause .menu-col { max-height: 94vh; overflow-y: auto; }  /* (a phone on its side: it scrolls) */
.pause-sliders { margin-top: 18px; display: grid; gap: 12px; }
.pause-sliders label { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; color: #e6e9ef; font-weight: 800; font-size: 13px; letter-spacing: 0.08em; }
.pause-sliders span { color: #ffd23f; }
.pause-sliders input { grid-column: 1 / -1; width: 100%; height: 28px; margin: 0; padding: 0; border: none; background: none; accent-color: #ffd23f; touch-action: none; }
.pause-players { margin-top: 22px; display: grid; gap: 6px; }
.pause-players .row { display: flex; align-items: center; gap: 10px; color: #e6e9ef; font-weight: 700; font-size: 15px; }
.pause-players .row b { flex: 1; }
.pause-players .host { color: #ffd23f; font-size: 12px; letter-spacing: 0.1em; }
.pause-players button { all: unset; cursor: pointer; padding: 3px 10px; background: #2a3242; border: 2px solid #3a4458; color: #fff; font-size: 12px; font-weight: 800; letter-spacing: 0.06em; }
.pause-players button:hover { border-color: #ffd23f; }
/* the map's licence (ODbL) asks for this credit wherever the map's shown */
.menu-credit { position: absolute; left: 7vw; bottom: 18px; pointer-events: auto; color: #c9d1e0; opacity: 0.75; font-size: 12px; font-weight: 600; letter-spacing: 0.02em; }
.menu-credit a { color: #ffd23f; text-decoration: none; } .menu-credit a:hover { text-decoration: underline; }
.menu-col { position: absolute; left: 7vw; top: 50%; transform: translateY(-50%); width: min(520px, 80vw); pointer-events: auto; }
.menu-title { white-space: nowrap; font-size: clamp(30px, 3.4vw, 52px); font-weight: 700; color: #fff; line-height: 1.1; text-shadow: 0 2px 24px rgba(0,0,0,0.6); }
.menu-sub { color: #c9d1e0; letter-spacing: 0.22em; text-transform: uppercase; font-size: 13px; font-weight: 700; margin: 14px 0 46px; opacity: 0.85; }
.menu-items { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
/* Menu buttons: chunky Minecraft-style blocks in yellow (light bevel top-left, dark bottom-right, black outline; white outline on hover) */
.menu-item { all: unset; cursor: pointer; margin-top: 6px; padding: 10px 24px 12px; background: #ffd23f; color: #2b2000; font-size: 18px; font-weight: 800; letter-spacing: 0.08em; border: 3px solid #120d00; box-shadow: inset 3px 3px 0 #ffeb94, inset -3px -4px 0 #b8901a; text-shadow: 1px 1px 0 rgba(255,255,255,0.35); }
.menu-item:hover, .menu-item:focus-visible { background: #ffdc5e; border-color: #fff; box-shadow: inset 3px 3px 0 #fff3bd, inset -3px -4px 0 #c99d1f; }
.menu-item:active { box-shadow: inset -3px -3px 0 #ffeb94, inset 3px 4px 0 #b8901a; padding: 12px 24px 10px; }
.menu-item:disabled { cursor: default; filter: grayscale(1) brightness(0.7); }
.menu-input { all: unset; width: 280px; padding: 8px 0; margin-bottom: 8px; border-bottom: 2px solid rgba(255,255,255,0.35); color: #fff; font-size: 18px; font-weight: 700; letter-spacing: 0.12em; }
.menu-input:focus { border-color: #ffd23f; }
.menu-input::placeholder { color: rgba(255,255,255,0.4); }
.menu-field { display: flex; align-items: center; gap: 14px; color: #8b95a8; font-size: 12px; font-weight: 800; letter-spacing: 0.2em; margin: 2px 0; }
.menu-field span { width: 110px; }
.menu-field select { font: inherit; font-size: 14px; letter-spacing: 0.04em; color: #fff; background: rgba(15,20,30,0.7); border: 1px solid rgba(255,255,255,0.2); padding: 6px 8px; }
.menu-field select:disabled { opacity: 0.55; }
.menu-note { color: #c9d1e0; font-size: 14px; margin: 4px 0 10px; letter-spacing: 0.04em; }

/* controller button badges in hints: round, in the Xbox colours */
.padbtn { display: inline-flex; align-items: center; justify-content: center; width: 1.45em; height: 1.45em; border-radius: 50%; font-weight: 900; font-size: 0.82em; line-height: 1; color: #fff; vertical-align: -0.2em; margin: 0 0.1em; text-shadow: 0 1px 1px rgba(0,0,0,0.35); box-shadow: inset 0 -0.12em 0 rgba(0,0,0,0.28), 0 0 0 0.08em rgba(255,255,255,0.18); }
.pad-a { background: radial-gradient(circle at 35% 30%, #7fd65a, #3e9e2a); }
.pad-b { background: radial-gradient(circle at 35% 30%, #f06a5c, #c22a22); }
.pad-x { background: radial-gradient(circle at 35% 30%, #5f9cff, #1f5fc8); }
.pad-y { background: radial-gradient(circle at 35% 30%, #ffd24d, #d49a12); color: #3a2a00; text-shadow: none; }
.pad-view { width: auto; padding: 0 0.45em; border-radius: 0.45em; background: #4b525e; font-size: 0.7em; }

/* Controls overlay (H) */
#help { position: fixed; inset: 0; z-index: 12; display: grid; place-items: center; background: rgba(5,7,10,0.55); backdrop-filter: blur(2px); cursor: pointer; animation: help-in 0.15s ease-out; }
@keyframes help-in { from { opacity: 0; } }
.help-card { width: min(760px, 92vw); background: rgba(16,20,28,0.94); border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 22px 28px 18px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.help-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 16px; }
.help-head > span:first-child { font-size: 24px; font-weight: 700; }
.help-close { color: #8b95a8; font-size: 13px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
@media (max-width: 640px) { .help-cols { grid-template-columns: 1fr; } }
.help-cols h3 { margin: 0 0 10px; color: #ffd23f; font-size: 12px; font-weight: 800; letter-spacing: 0.14em; text-transform: uppercase; }
.help-cols dl { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; align-items: center; }
.help-cols dt { color: #c9d1e0; font-size: 13px; font-weight: 700; white-space: nowrap; text-align: right; }
.help-cols dd { margin: 0; color: #e6ebf3; font-size: 14px; }
#help kbd, #help-chip kbd { display: inline-block; min-width: 1.7em; padding: 1px 6px; margin: 0 1px; border-radius: 5px; background: #2a3242; border: 1px solid #3a4458; border-bottom-width: 2px; color: #fff; font: 700 12px/1.4 inherit; font-family: inherit; text-align: center; }
.help-foot { margin-top: 18px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.08); color: #8b95a8; font-size: 13px; text-align: center; }
/* frames per second, top right (F3 hides it) */
#fps { position: fixed; right: 10px; top: 8px; z-index: 6; pointer-events: none; background: rgba(15,20,30,0.55); color: #9ad8a4; padding: 2px 7px; border-radius: 6px; font: 700 12px/1.4 ui-monospace, Menlo, Consolas, monospace; }
#fps.meh { color: #ffcf5a; } #fps.bad { color: #ff7b6b; }
#help-chip { position: fixed; right: 16px; bottom: 16px; z-index: 6; pointer-events: none; background: rgba(15,20,30,0.6); color: #c9d1e0; padding: 5px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; }

/* touch screens (touch.js) */
#view { touch-action: none; }
.touching body, .touching #view { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#touch { position: fixed; inset: 0; z-index: 7; pointer-events: none; }
#touch .tbtn { position: absolute; pointer-events: auto; border: 0; border-radius: 12px; background: rgba(15,20,30,0.6); color: #fff; box-shadow: none;
  width: auto; margin: 0; font-family: inherit; font-weight: 800; font-size: 15px; line-height: 1; letter-spacing: 0.06em; -webkit-tap-highlight-color: transparent; touch-action: none; }
#touch .tbtn[hidden] { display: none; }
#touch .t-use { right: calc(40px + env(safe-area-inset-right)); bottom: calc(50px + env(safe-area-inset-bottom)); width: 104px; height: 104px; padding: 0; border-radius: 50%;
  background: rgba(15,20,30,0.45); border: 3px solid rgba(255,255,255,0.35); color: rgba(255,255,255,0.7); font-size: 17px; }
#touch .t-use.lit { background: rgba(255,207,90,0.85); border-color: #fff; color: #1a1a1a; }
#touch .t-use.down { transform: scale(0.94); }
#touch .tbtn.down { transform: scale(0.94); }
#touch .tbtn.active { background: rgba(255,207,90,0.85); color: #1a1a1a; }
/* left thumb: walk (and crouch / lie down above it) */
#touch .t-walk { left: calc(36px + env(safe-area-inset-left)); bottom: calc(44px + env(safe-area-inset-bottom)); width: 128px; height: 128px; padding: 0; border-radius: 50%;
  background: rgba(15,20,30,0.45); border: 3px solid rgba(255,255,255,0.4); font-size: 18px; }
#touch .t-walk.down { background: rgba(255,255,255,0.35); }
#touch .t-crouch, #touch .t-prone { left: calc(36px + env(safe-area-inset-left)); padding: 13px 0; width: 128px; font-size: 13px; }
#touch .t-crouch { bottom: calc(240px + env(safe-area-inset-bottom)); }
#touch .t-prone { bottom: calc(188px + env(safe-area-inset-bottom)); }
/* right thumb: use, jump, tickets / stand up */
#touch .t-jump { right: calc(160px + env(safe-area-inset-right)); bottom: calc(40px + env(safe-area-inset-bottom)); width: 92px; height: 92px; padding: 0; border-radius: 50%;
  background: rgba(15,20,30,0.45); border: 3px solid rgba(255,255,255,0.35); font-size: 15px; }
#touch .t-jump.down { background: rgba(255,255,255,0.35); }
#touch .t-stand, #touch .t-tickets { right: calc(40px + env(safe-area-inset-right)); bottom: calc(176px + env(safe-area-inset-bottom)); padding: 16px 18px; background: rgba(255,207,90,0.9); color: #1a1a1a; }
#touch .t-tickets { background: rgba(232,112,26,0.92); color: #fff; }
/* along the top */
#touch .t-pause { left: calc(14px + env(safe-area-inset-left)); top: calc(14px + env(safe-area-inset-top)); width: 46px; height: 46px; padding: 0; font-size: 17px; }
#touch .t-gyro { left: calc(70px + env(safe-area-inset-left)); top: calc(14px + env(safe-area-inset-top)); height: 46px; padding: 0 14px; font-size: 13px; color: #aab3c5; }
#touch .t-gyro.on { color: #9ad8a4; }
#touch .t-board { left: calc(176px + env(safe-area-inset-left)); top: calc(14px + env(safe-area-inset-top)); height: 46px; padding: 0 14px; font-size: 13px; }
.touching #help-chip { display: none; }
/* a phone on its side: two columns, so the view settings sit beside the buttons instead of below the screen */
@media (max-height: 520px) {
  #pause .menu-col { width: min(900px, 86vw); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 32px; align-items: start; }
  #pause .menu-title, #pause .menu-sub { grid-column: 1 / -1; }
  #pause .menu-sub { margin-bottom: 4px; }
  #pause .menu-items { grid-column: 1; grid-row: 3 / span 3; margin-top: 8px; }
  #pause .menu-item { font-size: 15px; padding: 8px 18px 9px; }
  #pause .pause-sliders { grid-column: 2; grid-row: 3; margin-top: 12px; }
  #pause .pause-players { grid-column: 2; grid-row: 4; margin-top: 14px; }
  #pause .menu-note { grid-column: 2; grid-row: 5; }
}
/* phones: the gameplay buttons sit closer to the edges (into the notch's spare margin, clear of the rounded
   corners), so the middle of the screen is freer */
@media (max-height: 520px), (max-width: 520px) {
  #touch { --sx: max(12px, calc(env(safe-area-inset-left) - 22px)); --sr: max(12px, calc(env(safe-area-inset-right) - 22px)); --sb: max(14px, calc(env(safe-area-inset-bottom) - 8px)); }
  #touch .t-walk { left: var(--sx); bottom: var(--sb); }
  #touch .t-crouch, #touch .t-prone { left: var(--sx); }
  #touch .t-crouch { bottom: calc(var(--sb) + 190px); }
  #touch .t-prone { bottom: calc(var(--sb) + 140px); }
  #touch .t-use { right: var(--sr); bottom: calc(var(--sb) + 4px); }
  #touch .t-jump { right: calc(var(--sr) + 118px); bottom: var(--sb); }
  #touch .t-stand, #touch .t-tickets { right: var(--sr); bottom: calc(var(--sb) + 124px); }
  #touch .t-pause { left: var(--sx); top: max(10px, env(safe-area-inset-top)); }
  #touch .t-gyro { left: calc(var(--sx) + 56px); top: max(10px, env(safe-area-inset-top)); }
  #touch .t-board { left: calc(var(--sx) + 162px); top: max(10px, env(safe-area-inset-top)); }
}
