:root {
  --slot: 44px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --green: #5fbf4a;
  --green-d: #3b8d32;
  --ink: #0b0d12;
  --panel: rgba(20, 23, 31, 0.84);
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--ink); color: #fff; font-family: var(--sans); overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
canvas#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; background: #8fb4e8; outline: none; image-rendering: auto; }
.hidden { display: none !important; }
button { font-family: inherit; }
input, select { font-family: inherit; -webkit-user-select: text; user-select: text; touch-action: auto; }

/* ---------------------------------------------------------------- screens */
.screen { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: calc(14px + var(--safe-t)) calc(14px + var(--safe-r)) calc(14px + var(--safe-b)) calc(14px + var(--safe-l)); overflow: auto; touch-action: pan-y; background: radial-gradient(ellipse at 50% 40%, rgba(10,14,24,0.34), rgba(6,8,14,0.72)); }
#title { background: radial-gradient(ellipse at 50% 38%, rgba(10,14,24,0.30), rgba(6,8,14,0.70)); }
.card { position: relative; width: min(468px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 2px solid #000; border-radius: 3px; padding: 22px 22px 18px; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.13), inset -2px -2px 0 rgba(0,0,0,0.5), 0 24px 70px rgba(0,0,0,0.55); }
.card.wide { width: min(780px, 100%); }
.card.inv { width: min(520px, 100%); }
.card h2 { margin: 0 0 12px; font-family: var(--mono); font-size: 20px; letter-spacing: 0.08em; text-transform: uppercase; text-align: center; text-shadow: 2px 2px 0 #000; }
.card h3 { margin: 14px 0 8px; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: #9ab; }
.card h3:first-child { margin-top: 0; }

.logo { margin: 4px 0 6px; text-align: center; font-family: var(--mono); font-weight: 900; font-size: clamp(34px, 10vw, 58px); line-height: 0.95; letter-spacing: 0.02em; }
.logo span { display: block; color: #ececec; text-shadow: 0 1px 0 #c9c9c9, 0 2px 0 #a6a6a6, 0 3px 0 #848484, 0 4px 0 #626262, 0 5px 0 #404040, 0 6px 0 #222, 0 12px 18px rgba(0,0,0,0.6); }
.logo span + span { color: #98ea62; text-shadow: 0 1px 0 #7cc84c, 0 2px 0 #62a63a, 0 3px 0 #4a852c, 0 4px 0 #36631f, 0 5px 0 #254515, 0 6px 0 #14260b, 0 12px 18px rgba(0,0,0,0.6); }
.logo.small { font-size: 26px; }
.splash { position: absolute; right: 8px; top: 62px; font-family: var(--mono); font-weight: 800; color: #ffe04a; text-shadow: 2px 2px 0 #3d3200; transform: rotate(-12deg); font-size: 15px; white-space: nowrap; animation: pulse 1.1s ease-in-out infinite; pointer-events: none; }
@keyframes pulse { 0%, 100% { transform: rotate(-12deg) scale(1); } 50% { transform: rotate(-12deg) scale(1.1); } }
.tagline { margin: 10px 4px 16px; text-align: center; color: #b8c2d4; font-size: 14px; line-height: 1.45; }

.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field > span, .slider > span { font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: #9fb0c8; }
input[type="text"], input:not([type]), select { width: 100%; padding: 11px 12px; font-size: 16px; color: #fff; background: #0c0e13; border: 2px solid #000; border-radius: 2px; box-shadow: inset 2px 2px 0 rgba(0,0,0,0.6), 0 1px 0 rgba(255,255,255,0.08); outline: none; }
input:focus, select:focus { border-color: #5fbf4a; }
#swatches { display: flex; gap: 8px; flex-wrap: wrap; }
#swatches i { width: 30px; height: 30px; border: 2px solid #000; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.35), inset -2px -2px 0 rgba(0,0,0,0.35); cursor: pointer; border-radius: 2px; }
#swatches i.sel { outline: 3px solid #fff; outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 14px; color: #dfe6f2; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--green); }
.slider { display: grid; gap: 4px; margin: 9px 0; }
.slider b { float: right; color: #fff; font-family: var(--mono); letter-spacing: 0; }
.slider input { width: 100%; accent-color: var(--green); height: 22px; touch-action: pan-y; }
#title-msg { min-height: 18px; margin: 10px 0 0; text-align: center; font-size: 13px; color: #ffb4a8; }
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.1); font-size: 12px; color: #9fb0c8; }
.keys kbd { display: inline-block; min-width: 20px; padding: 1px 5px; margin-right: 2px; text-align: center; font: 700 11px var(--mono); color: #fff; background: #2a2f3b; border: 1px solid #000; border-bottom-width: 2px; border-radius: 3px; }
@media (pointer: coarse) { .keys { display: none; } }

.mc-btn { display: inline-block; padding: 11px 18px; font: 700 15px var(--mono); letter-spacing: 0.04em; color: #fff; text-shadow: 2px 2px 0 #3a3a3a; background: linear-gradient(#838383, #5f5f5f); border: 2px solid #000; border-radius: 2px; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.45), inset -2px -2px 0 rgba(0,0,0,0.4); cursor: pointer; touch-action: manipulation; }
.mc-btn:hover { background: linear-gradient(#8b98e0, #5d6ab6); color: #ffffa0; }
.mc-btn:active { transform: translateY(1px); }
.mc-btn.primary { background: linear-gradient(#69cc52, #3d8f33); text-shadow: 2px 2px 0 #1d4a18; }
.mc-btn.primary:hover { background: linear-gradient(#80df68, #46a53a); }
.mc-btn.danger { background: linear-gradient(#d65a4c, #9a3026); text-shadow: 2px 2px 0 #4d120c; }
.mc-btn.danger:hover { background: linear-gradient(#ee7466, #b13a2f); }
.mc-btn.big { width: 100%; padding: 14px; font-size: 18px; margin-top: 4px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 28px; }
@media (max-width: 640px), (max-aspect-ratio: 1/1) { .grid2 { grid-template-columns: 1fr; } .card { padding: 18px 16px 14px; } }
.miclevel { margin: 8px 0 4px; }
.miclevel i { display: block; height: 10px; background: #0c0e13; border: 2px solid #000; border-radius: 2px; overflow: hidden; }
.miclevel b { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, #4fd14a, #e8d83a 70%, #e5484d); transition: width 0.06s linear; }
.miclevel small { display: block; margin-top: 6px; color: #8d9bb3; font-size: 11px; line-height: 1.35; }
.hint { margin-top: 10px; text-align: center; color: #9fb0c8; font-size: 13px; min-height: 18px; }

/* ---------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
#hud > * { pointer-events: none; }
#crosshair { position: absolute; left: 50%; top: 50%; width: 22px; height: 22px; transform: translate(-50%, -50%); }
#crosshair::before, #crosshair::after { content: ""; position: absolute; background: #fff; outline: 1px solid rgba(0,0,0,0.55); }
#crosshair::before { left: 10px; top: 0; width: 2px; height: 22px; }
#crosshair::after { top: 10px; left: 0; height: 2px; width: 22px; }
#underwater { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(40,100,220,0.28), rgba(10,40,140,0.55)); opacity: 0; transition: opacity 0.15s; }
#underwater.on { opacity: 1; }

#topbar { position: absolute; left: calc(10px + var(--safe-l)); right: calc(10px + var(--safe-r)); top: calc(10px + var(--safe-t)); display: flex; align-items: center; gap: 8px; }
#topbar > * { pointer-events: auto; }
#topbar .spacer { flex: 1; pointer-events: none; }
.pill { display: flex; align-items: center; gap: 7px; padding: 7px 12px; font: 600 13px var(--sans); background: rgba(14, 17, 24, 0.78); border: 1px solid rgba(255,255,255,0.12); border-radius: 999px; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #5fe36a; box-shadow: 0 0 8px #5fe36a; }
.pill .dot.off { background: #e5484d; box-shadow: 0 0 8px #e5484d; }
.pill .sep { opacity: 0.4; }
.round { position: relative; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; color: #fff; background: rgba(14, 17, 24, 0.78); border: 1px solid rgba(255,255,255,0.14); border-radius: 50%; cursor: pointer; touch-action: manipulation; }
.round:hover { background: rgba(40, 46, 62, 0.8); }
.round .ico { width: 22px; height: 22px; fill: currentColor; }
#micbtn { overflow: hidden; }
#micbtn .mic-off { display: none; }
#micbtn.muted { background: rgba(160, 36, 36, 0.8); border-color: rgba(255,140,140,0.5); }
#micbtn.muted .mic-on { display: none; }
#micbtn.muted .mic-off { display: block; }
#micbtn.live { border-color: rgba(95, 227, 106, 0.5); }
#micbtn.talk { box-shadow: 0 0 0 3px rgba(95, 227, 106, 0.55), 0 0 18px rgba(95,227,106,0.5); }
#micbtn.shout { box-shadow: 0 0 0 3px rgba(255, 190, 60, 0.85), 0 0 22px rgba(255,170,40,0.7); }
#micbtn.nomic { opacity: 0.55; }
#micbtn .meter { position: absolute; left: 6px; right: 6px; bottom: 4px; height: 3px; background: rgba(255,255,255,0.15); border-radius: 2px; overflow: hidden; }
#micbtn .meter b { display: block; height: 100%; width: calc(var(--lvl, 0) * 100%); background: #5fe36a; }
#micbtn.shout .meter b { background: #ffbe3c; }
.touch-only { display: none; }
@media (pointer: coarse) { .touch-only { display: grid; } .pill { font-size: 12px; padding: 6px 10px; } .round { width: 40px; height: 40px; } }

#hotbar { position: absolute; left: 50%; bottom: calc(10px + var(--safe-b)); transform: translateX(-50%); display: flex; padding: 3px; background: rgba(0, 0, 0, 0.5); border: 2px solid #000; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.14), inset -2px -2px 0 rgba(0,0,0,0.4); pointer-events: auto; touch-action: manipulation; }
#hotbar .slot, #invgrid .slot { position: relative; width: var(--slot); height: var(--slot); display: grid; place-items: center; background: rgba(120,120,120,0.28); border: 2px solid rgba(0,0,0,0.55); cursor: pointer; }
#hotbar .slot img, #invgrid .slot img { width: 76%; height: 76%; image-rendering: pixelated; pointer-events: none; }
#hotbar .slot.sel { border-color: #fff; background: rgba(255,255,255,0.18); z-index: 1; outline: 2px solid #000; }
#hotbar .slot i { position: absolute; left: 3px; top: 1px; font: 700 10px var(--mono); color: rgba(255,255,255,0.65); font-style: normal; text-shadow: 1px 1px 0 #000; }
#itemname { position: absolute; left: 50%; bottom: calc(var(--slot) + 26px + var(--safe-b)); transform: translateX(-50%); font: 700 15px var(--mono); text-shadow: 2px 2px 0 #000; opacity: 0; transition: opacity 0.4s; white-space: nowrap; }
#itemname.on { opacity: 1; transition: none; }
#statusbar { position: absolute; left: 50%; top: calc(62px + var(--safe-t)); transform: translateX(-50%); font: 700 13px var(--sans); padding: 5px 12px; border-radius: 999px; background: rgba(14,17,24,0.7); opacity: 0; transition: opacity 0.25s; white-space: nowrap; }
#statusbar.on { opacity: 1; }

#tags { position: absolute; inset: 0; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 5px; padding: 3px 9px 3px 7px; font: 700 13px var(--sans); color: #fff; background: rgba(0, 0, 0, 0.5); border-radius: 4px; white-space: nowrap; will-change: transform; text-shadow: 0 1px 0 #000; }
.tag .c { width: 8px; height: 8px; border-radius: 2px; background: var(--c, #fff); }
.tag svg { width: 12px; height: 12px; fill: #ff7b72; display: none; }
.tag.muted svg { display: block; }
.tag.speaking { background: rgba(20, 90, 36, 0.8); box-shadow: 0 0 0 2px #5fe36a, 0 0 12px rgba(95,227,106,0.6); }
.tag.shouting { background: rgba(130, 78, 8, 0.85); box-shadow: 0 0 0 2px #ffbe3c, 0 0 16px rgba(255,170,40,0.7); }

#chat { position: absolute; left: calc(10px + var(--safe-l)); bottom: calc(var(--slot) + 30px + var(--safe-b)); width: min(560px, 72vw); }
#chatlog { display: flex; flex-direction: column; gap: 2px; }
#chatlog div { align-self: flex-start; max-width: 100%; padding: 3px 8px; font: 500 14px/1.3 var(--sans); background: rgba(0,0,0,0.42); text-shadow: 1px 1px 0 #000; word-break: break-word; transition: opacity 0.6s; }
#chatlog div.old { opacity: 0; }
#chatlog div b { font-weight: 700; }
#chat.typing #chatlog div.old { opacity: 1; }
#chatinput { display: none; width: 100%; margin-top: 6px; pointer-events: auto; background: rgba(0,0,0,0.6); border-color: rgba(255,255,255,0.3); padding: 8px 10px; }
#chat.typing #chatinput { display: block; }
#chat.typing { pointer-events: auto; }

.panel { background: var(--panel); border: 2px solid #000; box-shadow: inset 2px 2px 0 rgba(255,255,255,0.12), inset -2px -2px 0 rgba(0,0,0,0.45); }
#playerlist { position: absolute; left: 50%; top: calc(70px + var(--safe-t)); transform: translateX(-50%); min-width: min(320px, 90vw); max-height: 60vh; overflow: auto; padding: 10px 14px; }
#playerlist .p { display: flex; align-items: center; gap: 10px; padding: 5px 2px; font: 600 14px var(--sans); border-bottom: 1px solid rgba(255,255,255,0.07); }
#playerlist .p:last-child { border: 0; }
#playerlist .c { width: 10px; height: 10px; border-radius: 2px; }
#playerlist .d { margin-left: auto; color: #9fb0c8; font: 600 12px var(--mono); }
#playerlist .s { color: #5fe36a; }
#debug { position: absolute; left: calc(10px + var(--safe-l)); top: calc(62px + var(--safe-t)); padding: 7px 10px; font: 500 12px/1.45 var(--mono); background: rgba(0,0,0,0.55); white-space: pre; border-left: 3px solid var(--green); }
#toast { position: absolute; left: 50%; top: calc(112px + var(--safe-t)); transform: translateX(-50%); max-width: 90vw; padding: 9px 16px; font: 600 14px var(--sans); text-align: center; background: rgba(14,17,24,0.82); border: 1px solid rgba(255,255,255,0.15); border-radius: 8px; opacity: 0; transition: opacity 0.3s; }
#toast.on { opacity: 1; }

/* ---------------------------------------------------------------- inventory */
#invgrid { display: grid; grid-template-columns: repeat(9, var(--slot)); gap: 3px; justify-content: center; max-height: 56vh; overflow: auto; padding: 4px; touch-action: pan-y; }
#invgrid .slot { background: #7d7d7d; border: 2px solid; border-color: #373737 #fff #fff #373737; }
#invgrid .slot:hover { background: #a0a0c8; }
#invgrid .slot.sel { outline: 3px solid #ffe04a; }

/* ---------------------------------------------------------------- touch controls */
#touch { position: fixed; inset: 0; z-index: 12; pointer-events: none; }
#stick { display: none; position: absolute; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.35); background: radial-gradient(circle, rgba(255,255,255,0.10), rgba(255,255,255,0.03)); }
#knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; border-radius: 50%; background: rgba(255,255,255,0.45); border: 2px solid rgba(255,255,255,0.7); transform: translate(-50%, -50%); }
.tbtn { position: absolute; pointer-events: auto; width: 68px; height: 68px; padding: 0; display: grid; place-items: center; border-radius: 50%; border: 2px solid rgba(255,255,255,0.4); background: rgba(14,17,24,0.45); color: #fff; touch-action: none; }
.tbtn svg { width: 30px; height: 30px; fill: #fff; opacity: 0.9; }
.tbtn.small { width: 48px; height: 48px; }
.tbtn.small svg { width: 24px; height: 24px; }
.tbtn.on { background: rgba(95,191,74,0.65); border-color: #fff; }
#t-jump { right: calc(18px + var(--safe-r)); bottom: calc(var(--slot) + 36px + var(--safe-b)); }
#t-fly { right: calc(98px + var(--safe-r)); bottom: calc(var(--slot) + 52px + var(--safe-b)); }
#t-sneak { right: calc(30px + var(--safe-r)); bottom: calc(var(--slot) + 118px + var(--safe-b)); }
@media (pointer: coarse) {
  :root { --slot: min(42px, calc((100vw - 18px - var(--safe-l) - var(--safe-r)) / 9)); }
  #chat { bottom: auto; top: calc(62px + var(--safe-t)); width: min(420px, 62vw); }
  #chatlog { flex-direction: column; }
  #debug { top: calc(62px + var(--safe-t)); }
  #crosshair { opacity: 0.8; }
}
@media (pointer: coarse) and (orientation: landscape) {
  :root { --slot: 38px; }
  #t-jump { right: calc(30px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); }
  #t-fly { right: calc(116px + var(--safe-r)); bottom: calc(30px + var(--safe-b)); }
  #t-sneak { right: calc(44px + var(--safe-r)); bottom: calc(100px + var(--safe-b)); }
  #chat { top: calc(58px + var(--safe-t)); width: min(380px, 40vw); }
  #hotbar { bottom: calc(6px + var(--safe-b)); }
}

/* public address: shown while speaking into a microphone block */
#onair { background: rgba(150, 22, 26, 0.86); border-color: rgba(255, 140, 140, 0.5); letter-spacing: 0.08em; }
#onair .dot { background: #fff; box-shadow: 0 0 8px #fff; animation: onair 1.1s ease-in-out infinite; }
@keyframes onair { 50% { opacity: 0.25; } }

/* accounts + meeting rooms */
#acct { margin: 0 0 12px; padding: 10px 12px; font-size: 13px; line-height: 1.45; color: #cfd8e6; background: rgba(0,0,0,0.28); border: 1px solid rgba(255,255,255,0.1); border-radius: 3px; }
#acct a { color: #9fd0ff; }
#acct .acct-note { margin: 0; }
#acct-form { margin-top: 10px; }
#acct-form .row { margin-top: 0; }
#acct-msg, #room-msg { min-height: 18px; margin-top: 8px; font-size: 13px; color: #ffb4a8; }
#room-text { margin: 0 4px 14px; font-size: 14px; line-height: 1.5; color: #dfe6f2; text-align: center; }
#room .row { justify-content: center; }
#zonepill { border-color: rgba(255, 214, 96, 0.6); color: #ffe9a8; }
#zonepill .lock { width: 9px; height: 8px; border-radius: 2px; background: #ffd660; box-shadow: 0 -5px 0 -2px #0e1118, 0 -5px 0 0 #ffd660; margin-top: 4px; }

#sharepill { border-color: rgba(255, 110, 100, 0.7); color: #ffd0cb; }
#sharepill .rec { width: 9px; height: 9px; border-radius: 50%; background: #ff4a3d; animation: recpulse 1.4s ease-in-out infinite; }
@keyframes recpulse { 50% { opacity: 0.35; } }
#room-linkrow { display: flex; gap: 8px; margin: 0 4px 6px; }
#room-linkrow input { flex: 1; min-width: 0; font-size: 12px; }
