:root {
  --bg: #14111c; --panel: rgba(20, 17, 28, 0.88); --line: #3b3350; --gold: #f4d35e;
  --text: #ece6d8; --muted: #a49cb3; --err: #ff7b7b; --accent: #8e52e0;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --serif: "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 var(--mono); overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: #2a2338; border: 1px solid var(--line); border-radius: 4px; padding: 6px 10px; }
button:hover { border-color: var(--gold); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: linear-gradient(#6b3fb0, #4d2b85); border-color: #9a6be8; font-weight: bold; }
input, select { background: #0e0c14; border: 1px solid var(--line); border-radius: 4px; padding: 7px 8px; min-width: 0; }
input:focus, select:focus { outline: 1px solid var(--gold); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; margin: 8px 0 0; }
.swatch { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 1px solid #000; image-rendering: pixelated; vertical-align: -1px; }
.screen { position: fixed; inset: 0; }

/* auth */
#auth { display: grid; place-items: center; overflow-y: auto; padding: 16px;
  background: radial-gradient(ellipse at 50% 20%, #2c1f47 0%, #14111c 60%), #14111c; }
.auth-card { width: min(520px, 100%); background: var(--panel); border: 2px solid var(--line); border-radius: 6px; padding: 22px; box-shadow: 0 0 0 4px #0b0910, 0 20px 60px #000a; }
.logo { font: bold 40px/1 var(--serif); letter-spacing: 3px; text-align: center; color: var(--gold); margin: 6px 0 4px; text-shadow: 3px 3px 0 #5b3f8c; }
.crown { display: block; width: 48px; height: 32px; margin: 0 auto 10px; background: url(/icon.svg) center / contain no-repeat; image-rendering: pixelated; }
.tagline { text-align: center; color: var(--muted); margin: 0 0 16px; font-family: var(--serif); font-style: italic; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tabs button { flex: 1; }
.tabs button.active, .class-btn.active { border-color: var(--gold); background: #3a2d55; }
.auth-form { display: grid; gap: 10px; }
.auth-form label { display: grid; gap: 4px; color: var(--muted); }
.auth-form label input { color: var(--text); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset { border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px 10px; margin: 0; }
legend { color: var(--muted); padding: 0 4px; }
.picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
#kingdom-select { width: 100%; }
.kingdom-info { margin-top: 8px; color: var(--muted); font-size: 12px; }
.kingdom-info b { color: var(--text); }
.online-line { text-align: center; color: var(--muted); font-size: 12px; margin: 10px 0 0; }

/* game */
#map { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; touch-action: none; cursor: pointer; }
.hud-top { position: fixed; top: 0; left: 0; right: 0; display: flex; gap: 8px; align-items: flex-start; padding: 8px; padding-top: max(8px, env(safe-area-inset-top)); pointer-events: none; flex-wrap: wrap; }
.hud-top > * { pointer-events: auto; }
.hud-block { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 5px 9px; }
.world-name { color: var(--gold); font: bold 16px var(--serif); letter-spacing: 1px; }
.clock { font-size: 12px; color: var(--muted); }
.hero-block { font-size: 12px; }
.hero-block b { font-size: 13px; }
.online { font-size: 12px; color: var(--muted); }
.hud-buttons { margin-left: auto; display: flex; gap: 4px; }
.hud-buttons button { width: 36px; height: 36px; padding: 0; background: var(--panel); font-size: 16px; }
.actions { position: fixed; right: 8px; top: 64px; display: grid; gap: 6px; }
.action { background: linear-gradient(#6b3fb0, #4d2b85); border-color: #9a6be8; font-weight: bold; }
.hex-info { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(10px, env(safe-area-inset-bottom)); background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 4px 10px; font-size: 12px; color: var(--muted); pointer-events: none; max-width: calc(100% - 20px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast { position: fixed; left: 50%; top: 80px; transform: translate(-50%, -10px); background: #2a1f3d; border: 1px solid var(--gold); border-radius: 4px; padding: 8px 14px; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 30; max-width: 90%; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* chat */
.chat { position: fixed; left: 8px; bottom: 40px; width: min(440px, calc(100% - 16px)); height: min(340px, 45vh); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; z-index: 10; }
.chat.collapsed { height: auto; }
.chat.collapsed .chat-log, .chat.collapsed .chat-form { display: none; }
.chat-head { display: flex; border-bottom: 1px solid var(--line); }
.chat-tabs { display: flex; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chat-tab { border: 0; border-radius: 0; background: none; padding: 6px 8px; font-size: 12px; color: var(--muted); white-space: nowrap; position: relative; }
.chat-tab.active { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
.badge { background: #c0392b; color: #fff; border-radius: 8px; font-size: 10px; padding: 0 5px; margin-left: 4px; }
.chat-toggle { border: 0; border-left: 1px solid var(--line); border-radius: 0; background: none; width: 36px; }
.chat-toggle.ping { color: var(--gold); animation: ping 1s infinite alternate; }
@keyframes ping { to { background: #4d2b85; } }
.chat-log { list-style: none; margin: 0; padding: 6px 8px; overflow-y: auto; flex: 1; font-size: 13px; overscroll-behavior: contain; }
.msg { padding: 1px 0; word-wrap: break-word; }
.msg .time { color: #6d6580; font-size: 11px; margin-right: 6px; }
.msg .tag { display: inline-block; min-width: 18px; font-size: 10px; text-align: center; border-radius: 3px; padding: 0 3px; margin-right: 5px; background: #333; color: #ddd; }
.ch-global .tag { background: #2f5d8a; } .ch-world .tag { background: #5b3f8c; } .ch-kingdom .tag { background: #8a6d1f; }
.ch-local .tag { background: #2f7a4d; } .ch-whisper .tag { background: #8a2f6d; } .ch-whisper .text { color: #f3b6e2; }
.msg .name { background: none; border: 0; padding: 0; margin-right: 6px; font-weight: bold; }
.msg .name::after { content: ':'; color: var(--muted); }
.ch-sys .text { color: var(--muted); font-style: italic; } .ch-err .text { color: var(--err); }
.chat-form { display: flex; gap: 4px; padding: 6px; border-top: 1px solid var(--line); }
#chat-channel { flex: 0 0 auto; }
#chat-to { width: 90px; flex: 0 0 auto; }
#chat-input { flex: 1; }

/* popups & modals */
.popup { position: fixed; z-index: 20; background: var(--panel); border: 1px solid var(--gold); border-radius: 4px; padding: 8px 10px; min-width: 170px; }
.popup-buttons { display: flex; gap: 6px; margin-top: 8px; }
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-card { background: var(--bg); border: 2px solid var(--line); border-radius: 6px; padding: 18px 20px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-card h2 { font: bold 22px var(--serif); color: var(--gold); margin: 0 0 10px; }
.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.gate-worlds { display: grid; gap: 8px; }
.help { padding-left: 18px; } .help li { margin-bottom: 6px; }
code { background: #2a2338; padding: 0 4px; border-radius: 3px; }

@media (max-width: 700px) {
  .hero-block .muted:not(div) { display: none; }
  .online { display: none; }
  .chat { bottom: 36px; height: 42vh; }
  .row2 { grid-template-columns: 1fr; }
  .picker { grid-template-columns: repeat(2, 1fr); }
  #chat-channel { max-width: 82px; }
}

/* legal, moderation, deletion */
a { color: #c9a8ff; }
.legal { text-align: center; color: var(--muted); font-size: 11px; margin: 10px 0 0; }
.menu-legal { text-align: left; margin-top: 14px; }
button.link { background: none; border: 0; padding: 0; text-decoration: underline; font-size: inherit; }
.danger { color: var(--err); }
.danger-btn { background: #5a1e26; border-color: #a33a48; }
.stack { display: grid; gap: 4px; color: var(--muted); }
.modal-card.wide { width: min(720px, 100%); }
.reports { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.report { border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px; }
blockquote { margin: 6px 0; padding: 4px 8px; border-left: 3px solid var(--line); color: var(--text); word-wrap: break-word; }
.popup select { width: 100%; margin: 6px 0; }
.popup { max-width: 260px; }
.small { font-size: 11px; margin-bottom: 6px; }
#btn-menu { position: relative; }
.dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: #e74c3c; }
.hud-block:empty { display: none; }
