:root {
  --bg: #02040a;
  --glass: rgba(12, 20, 34, 0.72);
  --glass-strong: rgba(14, 24, 40, 0.92);
  --line: rgba(160, 200, 255, 0.14);
  --text: #e6eef8;
  --muted: #8ea3bb;
  --accent: #4fa3ff;
  --accent-2: #7cd4ff;
  --danger: #ff6b6b;
  --radius: 12px;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }

#globe { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

.label {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -50%);
  text-align: center; white-space: nowrap; pointer-events: none;
  color: #fff; text-shadow: 0 1px 3px #000, 0 0 8px rgba(0,0,0,.7);
  font-weight: 600; letter-spacing: .02em; line-height: 1.1;
  transition: opacity .15s;
}
.label small { display: block; font-weight: 500; font-size: .75em; opacity: .8; }
.label.walled::before { content: '🧱 '; }
.cursor {
  position: absolute; left: 0; top: 0; pointer-events: none; font-size: 12px; font-weight: 700;
  white-space: nowrap; text-shadow: 0 1px 3px #000;
}
.cursor i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; margin-right: 4px; vertical-align: -1px; box-shadow: 0 0 8px currentColor; }
.float-text {
  position: absolute; left: 0; top: 0; font-weight: 800; font-size: 18px; pointer-events: none;
  text-shadow: 0 2px 6px #000; transform: translate(-50%, -50%);
}

/* screens */
.screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; }
#loading { background: var(--bg); z-index: 50; text-align: center; color: var(--muted); }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 1s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

#menu { background: radial-gradient(ellipse at 30% 50%, transparent 30%, rgba(2,4,10,.65) 75%); z-index: 20; overflow-y: auto; justify-items: end; }
.menu-card {
  width: min(560px, 100%); background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line); border-radius: 18px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
  margin-right: max(0px, 6vw);
}
@media (max-width: 900px) { #menu { justify-items: center; } .menu-card { margin-right: 0; } }
.menu-card h1 { margin: 0 0 6px; font-size: 34px; letter-spacing: -.02em; }
.menu-card h2 { font-size: 15px; margin: 0 0 10px; color: var(--accent-2); text-transform: uppercase; letter-spacing: .08em; }
.menu-card h3 { font-size: 12px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.tagline { color: var(--muted); margin: 0 0 20px; line-height: 1.5; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 16px; }
@media (max-width: 560px) { .menu-grid { grid-template-columns: 1fr; } }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input:not([type]), input[type=text] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(0,0,0,.35); outline: none;
}
input:focus { border-color: var(--accent); }
#join-code { text-transform: uppercase; letter-spacing: .3em; font-weight: 700; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; color: var(--muted); margin-bottom: 12px; }

button {
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,.06);
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
}
button:hover { background: rgba(255,255,255,.12); border-color: rgba(160,200,255,.3); }
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(180deg, #4fa3ff, #2f7fe0); border-color: transparent; font-weight: 600; width: 100%; }
button.primary:hover { background: linear-gradient(180deg, #62afff, #3a8af0); }
#btn-join { width: 100%; }
.error { color: var(--danger); font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }

.public-list ul { list-style: none; padding: 0; margin: 0; max-height: 160px; overflow-y: auto; }
.public-list li.lobby { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.public-list li.lobby small { color: var(--muted); display: block; }
.public-list li.lobby button { padding: 5px 10px; font-size: 13px; }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
.panel { background: var(--glass); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.panel h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }

.topbar {
  position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); left: 12px; right: 12px;
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; pointer-events: none;
}
.topbar > * { pointer-events: auto; }
.lobby-info { display: flex; align-items: center; gap: 10px; background: var(--glass); backdrop-filter: blur(12px); border: 1px solid var(--line); padding: 6px 6px 6px 14px; border-radius: 999px; }
.view-toggles { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 999px; padding: 6px 12px; font-size: 13px; background: var(--glass); backdrop-filter: blur(12px); }
.chip.toggle.active { background: rgba(79,163,255,.25); border-color: var(--accent); }
.chip.danger { color: #ffb3b3; }
button.danger { color: #ffb3b3; border-color: rgba(255,107,107,.3); }
button.danger:hover { background: rgba(255,107,107,.15); }
button.danger.armed { background: rgba(255,107,107,.35); color: #fff; border-color: var(--danger); }
#hud-code { letter-spacing: .15em; color: var(--accent-2); }

.toolbar {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 6px; padding: 6px; background: var(--glass);
  backdrop-filter: blur(12px); border: 1px solid var(--line); border-radius: 16px;
}
.toolbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 64px; padding: 8px 4px; border-radius: 12px; background: transparent; border-color: transparent; }
.toolbar button span { font-size: 22px; }
.toolbar button em { font-style: normal; font-size: 11px; color: var(--muted); }
.toolbar button.active { background: rgba(79,163,255,.22); border-color: var(--accent); }
.toolbar button.active em { color: var(--text); }

.hint {
  position: absolute; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  background: var(--glass-strong); border: 1px solid var(--line); border-radius: 999px; padding: 8px 16px; font-size: 13px;
  color: var(--muted); max-width: calc(100% - 24px); text-align: center; pointer-events: none !important;
}
.hint b { color: var(--text); }
.tool-options { position: absolute; bottom: calc(60px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); display: flex; gap: 6px; }
button:disabled { opacity: .45; cursor: default; }

.side { position: absolute; right: 12px; top: 64px; width: 260px; display: flex; flex-direction: column; gap: 10px; max-height: calc(100% - 340px); overflow-y: auto; scrollbar-width: none; pointer-events: none; }
.side > * { pointer-events: auto; }
#players { list-style: none; margin: 0; padding: 0; font-size: 14px; }
#players li { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
#players li i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#players li .you { color: var(--muted); font-size: 12px; }
#ranking { margin: 0; padding-left: 20px; font-size: 13px; }
#ranking li { padding: 2px 0; cursor: pointer; }
#ranking li span { color: var(--muted); float: right; }
#ranking li:hover { color: var(--accent-2); }

.piece-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
#piece-color { width: 34px; height: 34px; border: none; padding: 0; background: none; border-radius: 8px; cursor: pointer; flex: none; }
#piece-name { font-weight: 700; font-size: 16px; min-width: 0; }
button.icon { padding: 6px 8px; flex: none; }
input[type=number] { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.35); outline: none; font-variant-numeric: tabular-nums; }
.color-field { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.color-field span { margin: 0; }
#found-color { width: 44px; height: 30px; border: none; padding: 0; background: none; cursor: pointer; }
#found-presets { margin-top: -4px; }
.stats { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; font-size: 13px; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; gap: 6px; margin-top: 6px; }
.row button { flex: 1; font-size: 13px; padding: 8px 6px; }

.feed { position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); width: 320px; padding: 8px; }
#log { list-style: none; margin: 0 0 6px; padding: 0 4px; max-height: 170px; overflow-y: auto; font-size: 13px; line-height: 1.4; }
#log li { padding: 2px 0; }
#log li.chat b { margin-right: 4px; }
#chat-input { padding: 8px 10px; font-size: 13px; }

.legend { position: absolute; left: 50%; transform: translateX(-50%); bottom: 60px; background: var(--glass); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 11px; color: var(--muted); width: 240px; }
.legend .ramp { height: 8px; border-radius: 4px; margin: 4px 0; background: linear-gradient(90deg, #1b3a4b, #2a7f62, #c8d44e, #f39c3d, #e5383b); }
.legend .ticks { display: flex; justify-content: space-between; }

/* modals & toasts */
.modal { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); z-index: 40; padding: 16px; }
.modal-card { background: var(--glass-strong); border: 1px solid var(--line); border-radius: 16px; padding: 22px; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal-card h2 { margin: 0 0 8px; }
.route { font-size: 15px; }
#mig-range { width: 100%; accent-color: var(--accent); }
.mig-amount { font-variant-numeric: tabular-nums; }
.presets { display: flex; gap: 6px; }
.presets button { flex: 1; padding: 6px; font-size: 12px; }

#toasts { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; pointer-events: none; }
.toast { background: var(--glass-strong); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px; font-size: 14px; animation: toast-in .2s ease-out; }
.toast.error { border-color: rgba(255,107,107,.5); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

@media (max-width: 760px) {
  .side { top: auto; bottom: 170px; width: calc(100% - 100px); max-height: 45%; }
  #players-panel, #rank-panel { display: none; }
  .feed { width: calc(100% - 100px); }
  #log { max-height: 80px; }
  .toolbar button { width: 56px; }
  .hint { bottom: auto; top: 110px; }
  .tool-options { bottom: auto; top: 160px; }
}
