:root {
  --ink: #1d2226;
  --muted: #5d676f;
  --card: rgba(255, 255, 255, 0.92);
  --glass: rgba(24, 29, 34, 0.62);
  --accent: #e2574c;
  --gold: #f5b83a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #c9d6e2; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; cursor: pointer; border: 0; }
input { font: inherit; }
[hidden] { display: none !important; }

/* loading */
.loading { position: fixed; inset: 0; display: grid; place-content: center; text-align: center; z-index: 30; background: linear-gradient(#c9d6e2, #e7ecef); color: #3a4650; font-weight: 600; }
.loading p:first-child { font-size: 56px; margin: 0; animation: bob 1.6s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.loading-bar-wrap { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 40; pointer-events: none; }
.loading-bar { height: 100%; width: 100%; background: var(--gold); transition: width .3s, opacity .6s; }
.loading-bar[style*="100%"] { opacity: 0; }

/* landing */
.landing { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; z-index: 20; background: linear-gradient(180deg, rgba(20, 28, 36, .15), rgba(20, 28, 36, .45)); overflow: auto; }
.card { width: min(440px, 100%); background: var(--card); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 20px; padding: 22px 22px 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.home { font-size: 13px; color: var(--muted); text-decoration: none; }
.card h1 { margin: 8px 0 6px; font-size: 38px; letter-spacing: -.02em; }
.card h1 span { background: var(--gold); padding: 0 10px; border-radius: 10px; }
.lede { margin: 0 0 16px; color: #3b454d; line-height: 1.45; }
.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 14px; }
.field input { padding: 12px 14px; border-radius: 12px; border: 1.5px solid #d7dde2; font-size: 16px; color: var(--ink); background: #fff; }
.field input:focus { outline: 2px solid var(--gold); border-color: transparent; }
.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .6); }
.swatches button.on { outline: 3px solid var(--ink); outline-offset: 2px; }
.go { display: grid; gap: 8px; margin-top: 4px; }
.go button { padding: 13px; border-radius: 12px; font-weight: 700; font-size: 16px; background: #e9edf0; color: var(--ink); }
.go .primary { background: var(--ink); color: #fff; }
.fine { font-size: 11px; color: var(--muted); margin: 14px 0 0; text-align: center; }
.fine a { color: inherit; }

/* hud */
#hud { display: none; }
body.playing #hud { display: block; }
.where { position: fixed; top: calc(10px + var(--safe-t)); left: 10px; z-index: 5; background: var(--glass); color: #fff; border-radius: 12px; padding: 7px 12px; max-width: calc(100vw - 250px); pointer-events: none; }
.where b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.where span { font-size: 12px; opacity: .8; }
.where b:empty + span { font-size: 14px; }
.top-right { position: fixed; top: calc(10px + var(--safe-t)); right: 10px; z-index: 5; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; max-width: 60vw; }
.icon, .pill { height: 40px; min-width: 40px; border-radius: 12px; background: var(--glass); color: #fff; font-size: 18px; display: grid; place-items: center; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.pill { padding: 0 12px; font-size: 14px; font-weight: 600; }
.icon.on { background: var(--gold); color: var(--ink); }
.conn { font-size: 11px; color: #fff; background: rgba(200, 60, 50, .8); padding: 3px 8px; border-radius: 8px; }
.conn[data-state="online"] { display: none; }
.minimap { position: fixed; right: 10px; bottom: calc(10px + var(--safe-b)); width: 150px; height: 150px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .85); box-shadow: 0 4px 16px rgba(0, 0, 0, .25); z-index: 5; cursor: pointer; }
.modes { position: fixed; right: 170px; bottom: calc(14px + var(--safe-b)); display: flex; gap: 6px; z-index: 5; }

/* chat */
.chat { position: fixed; left: 10px; bottom: calc(10px + var(--safe-b)); width: min(340px, 44vw); z-index: 5; display: grid; gap: 6px; }
.chat-log { list-style: none; margin: 0; padding: 0 4px; max-height: 150px; overflow: auto; font-size: 13px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .8); opacity: 0; transition: opacity .6s; }
.chat.recent .chat-log, .chat:focus-within .chat-log, .chat:hover .chat-log { opacity: 1; }
.chat-log li { margin: 2px 0; overflow-wrap: anywhere; }
.chat-form input { width: 100%; padding: 9px 12px; border-radius: 12px; border: 0; background: var(--glass); color: #fff; font-size: 15px; }
.chat-toggle { display: none; }
@media (pointer: coarse) { .chat-toggle { display: grid; } }
.chat-form input::placeholder { color: rgba(255, 255, 255, .65); }
.emotes { display: flex; gap: 4px; }
.emotes button { background: var(--glass); border-radius: 10px; height: 34px; width: 38px; font-size: 18px; }

/* touch controls */
.stick, .touch-buttons { display: none; }
@media (pointer: coarse) {
  .stick { display: block; position: fixed; left: 22px; bottom: calc(26px + var(--safe-b)); width: 128px; height: 128px; border-radius: 50%; background: rgba(255, 255, 255, .18); border: 2px solid rgba(255, 255, 255, .5); z-index: 6; touch-action: none; }
  .knob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: rgba(255, 255, 255, .85); box-shadow: 0 2px 8px rgba(0, 0, 0, .3); pointer-events: none; }
  .touch-buttons { display: grid; gap: 10px; position: fixed; right: 22px; bottom: calc(180px + var(--safe-b)); z-index: 6; }
  .round { width: 58px; height: 58px; border-radius: 50%; background: rgba(255, 255, 255, .8); font-size: 24px; color: var(--ink); touch-action: none; }
  .fly-only { display: none; }
  body.flying .fly-only { display: block; }
  .chat { left: 160px; width: auto; right: 170px; bottom: calc(12px + var(--safe-b)); }
  .chat .chat-form { display: none; }
  .chat:focus-within .chat-form, .chat.typing .chat-form { display: block; }
  .desk { display: none; }
}
@media (pointer: fine) { .phone { display: none; } }
@media (pointer: coarse) and (max-width: 700px) {
  .minimap { width: 104px; height: 104px; bottom: auto; right: auto; left: 10px; top: calc(66px + var(--safe-t)); }
  .modes { right: 22px; bottom: calc(26px + var(--safe-b)); flex-direction: row; }
  .touch-buttons { bottom: calc(86px + var(--safe-b)); }
  .chat { left: 160px; right: 150px; }
  .emotes { flex-wrap: wrap; }
  .emotes button { width: 32px; height: 30px; font-size: 16px; }
  .where { max-width: calc(100vw - 190px); }
  .top-right { max-width: 180px; }
  .icon { height: 36px; min-width: 36px; font-size: 16px; }
  .pill { height: 36px; font-size: 12px; padding: 0 8px; }
}

/* panels */
.panel { position: fixed; z-index: 10; top: calc(60px + var(--safe-t)); right: 10px; width: min(340px, calc(100vw - 20px)); max-height: calc(100vh - 90px - var(--safe-t) - var(--safe-b)); overflow: auto; background: var(--card); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-radius: 16px; padding: 12px 14px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.panel header { display: flex; justify-content: space-between; align-items: center; }
.panel h2 { margin: 0; font-size: 18px; }
.close { background: #eef1f3; border-radius: 10px; min-width: 32px; height: 32px; }
.list { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.list button { width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; background: #f1f3f5; color: var(--ink); font-size: 15px; }
.list button:hover { background: #e4e8eb; }
.people i { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; }
.people em { color: var(--muted); font-style: normal; font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0; }
.wide { width: 100%; padding: 12px; border-radius: 12px; background: var(--ink); color: #fff; font-weight: 700; margin-top: 8px; }
.help { padding-left: 18px; line-height: 1.5; font-size: 15px; }
.help li { margin: 6px 0; }

/* big map */
.bigmap-wrap { display: none; }
body.map-open .bigmap-wrap { display: block; position: fixed; inset: 0; z-index: 9; background: #9cc3da; }
.bigmap { width: 100%; height: 100%; display: block; touch-action: none; }
.bigmap-hint { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(12px + var(--safe-b)); margin: 0; background: var(--glass); color: #fff; padding: 6px 12px; border-radius: 10px; font-size: 13px; white-space: nowrap; }
body.map-open .top-right { z-index: 11; }

.toast { position: fixed; left: 50%; top: calc(64px + var(--safe-t)); transform: translateX(-50%); z-index: 15; background: var(--ink); color: #fff; padding: 9px 16px; border-radius: 12px; font-weight: 600; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px); text-align: center; }
