:root {
  --ui-bg: rgba(18, 20, 28, 0.92);
  --ui-bg-2: rgba(30, 33, 46, 0.96);
  --ui-border: #3a4053;
  --ui-fg: #e8e9ee;
  --ui-dim: #9aa1b5;
  --ui-accent: #f0b429;
  --ui-accent-2: #46a2ff;
  --ui-danger: #ff5a5a;
  --ui-ok: #4fd27a;
  --font: "Segoe UI", system-ui, sans-serif;
  --mono: Consolas, "Courier New", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: var(--ui-fg); font-family: var(--font); font-size: 14px; overflow: hidden; }
#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; background: #000; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
#fade { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: none; z-index: 900; }
#boot { position: absolute; inset: 0; display: grid; place-items: center; background: #0c0e14; color: var(--ui-dim); z-index: 1000; font-size: 18px; }
#boot.hidden { display: none; }

/* windows */
.win { position: absolute; background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 6px; box-shadow: 0 8px 30px rgba(0,0,0,.6); min-width: 220px; user-select: none; display: flex; flex-direction: column; }
.win.hidden { display: none; }
.win > .title { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: var(--ui-bg-2); border-bottom: 1px solid var(--ui-border); border-radius: 6px 6px 0 0; cursor: move; font-weight: 600; }
.win > .title .close { cursor: pointer; color: var(--ui-dim); padding: 0 4px; }
.win > .title .close:hover { color: var(--ui-danger); }
.win > .body { padding: 8px 10px; overflow: auto; }
.win.modal { left: 50%; top: 50%; transform: translate(-50%, -50%); }
.dim { position: absolute; inset: 0; background: rgba(0,0,0,.55); }

button, .btn { font: inherit; color: var(--ui-fg); background: #2b3042; border: 1px solid var(--ui-border); border-radius: 4px; padding: 5px 12px; cursor: pointer; }
button:hover, .btn:hover { background: #363c52; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--ui-accent); color: #1a1500; border-color: #c48f10; font-weight: 600; }
button.danger { background: #5a2323; }
input, select, textarea { font: inherit; color: var(--ui-fg); background: #11131b; border: 1px solid var(--ui-border); border-radius: 4px; padding: 5px 8px; }
input:focus, select:focus { outline: 1px solid var(--ui-accent-2); }
label { color: var(--ui-dim); font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 6px; }
.grow { flex: 1; }
.muted { color: var(--ui-dim); }
.hidden { display: none !important; }
.err { color: var(--ui-danger); min-height: 1.2em; }

/* menu stage */
#menu-bg { position: absolute; inset: 0; background: radial-gradient(1200px 600px at 50% 110%, #1d2a44, #0b0e16 70%); }
#menu-bg h1 { position: absolute; top: 10vh; width: 100%; text-align: center; font-size: 52px; letter-spacing: 6px; color: var(--ui-accent); text-shadow: 0 2px 0 #000, 0 0 30px rgba(240,180,41,.4); margin: 0; }
#menu-bg .status { position: absolute; bottom: 12px; left: 12px; color: var(--ui-dim); font-size: 12px; }
.menu-win { width: 340px; }
.menu-win .body { padding: 14px 16px; }
.menu-win .col { gap: 10px; }
.char-card { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px; border: 1px solid var(--ui-border); border-radius: 6px; background: #161a26; min-width: 160px; }
.char-card canvas { image-rendering: pixelated; width: 64px; height: 96px; }

/* game HUD */
#hud-player { left: 8px; top: 8px; width: 260px; }
#hud-target { left: 280px; top: 8px; width: 260px; }
.entitybox .row { align-items: stretch; }
.entitybox .portrait { width: 64px; height: 64px; background: #11131b; border: 1px solid var(--ui-border); border-radius: 4px; image-rendering: pixelated; }
.bar { position: relative; height: 14px; background: #1b1e29; border: 1px solid #000; border-radius: 3px; overflow: hidden; margin: 2px 0; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; width: 0; transition: width .15s linear; }
.bar.hp > i { background: linear-gradient(#6fdc6f, #2e8b2e); }
.bar.mp > i { background: linear-gradient(#6fa8ff, #2a5cc6); }
.bar.exp > i { background: linear-gradient(#f0d060, #b58a0f); }
.bar.shield > i { background: rgba(255,255,255,.35); }
.bar > b { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 12px; font-weight: 600; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.statuses { display: flex; gap: 3px; flex-wrap: wrap; margin-top: 3px; }
.statuses .st { width: 22px; height: 22px; border: 1px solid var(--ui-border); background: #11131b; position: relative; image-rendering: pixelated; }
.statuses .st span { position: absolute; right: 0; bottom: 0; font-size: 9px; background: rgba(0,0,0,.7); padding: 0 2px; }

#hotbar, #menu-buttons, #chat, #announcement { position: absolute; }
#hotbar { left: 50%; bottom: 8px; transform: translateX(-50%); display: flex; gap: 4px; padding: 4px; background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 6px; }
.slot { width: 40px; height: 40px; border: 1px solid var(--ui-border); background: #11131b; position: relative; border-radius: 3px; image-rendering: pixelated; }
.slot canvas, .slot img { width: 100%; height: 100%; image-rendering: pixelated; display: block; }
.slot.drop-target { outline: 2px solid var(--ui-accent-2); }
.slot .qty { position: absolute; right: 2px; bottom: 1px; font-size: 10px; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.slot .key { position: absolute; left: 2px; top: 0; font-size: 9px; color: var(--ui-dim); }
.slot .cd { position: absolute; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; font-size: 11px; color: #fff; }
.slot .eq { position: absolute; left: 2px; bottom: 1px; font-size: 9px; color: var(--ui-accent); font-weight: 700; }
.slot.selected { outline: 2px solid var(--ui-accent); }
.grid-slots { display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: 4px; }

#menu-buttons { right: 8px; bottom: 8px; display: flex; gap: 4px; padding: 4px; background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 6px; }
#menu-buttons button { width: 36px; height: 36px; padding: 0; font-size: 15px; }

#chat { left: 8px; bottom: 8px; width: 420px; height: 220px; display: flex; flex-direction: column; background: rgba(18,20,28,.75); border: 1px solid var(--ui-border); border-radius: 6px; }
#chat .tabs { display: flex; gap: 2px; padding: 4px 4px 0; }
#chat .tabs button { padding: 2px 8px; font-size: 12px; background: transparent; border-color: transparent; color: var(--ui-dim); }
#chat .tabs button.active { background: var(--ui-bg-2); color: var(--ui-fg); border-color: var(--ui-border); }
#chat .log { flex: 1; overflow-y: auto; padding: 4px 8px; font-size: 13px; line-height: 1.35; word-break: break-word; }
#chat .log .line { white-space: pre-wrap; }
#chat .log .line .name { cursor: pointer; text-decoration: underline dotted; }
#chat .input { display: flex; gap: 4px; padding: 4px; }
#chat .input select { width: 84px; }
#chat .input input { flex: 1; }
#chat.unfocused .log { opacity: .9; }

.tooltip { position: absolute; z-index: 800; background: var(--ui-bg-2); border: 1px solid var(--ui-border); border-radius: 4px; padding: 8px 10px; pointer-events: none; max-width: 280px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.6); }
.tooltip h4 { margin: 0 0 4px; font-size: 13px; }
.tooltip .kv { display: flex; justify-content: space-between; gap: 12px; color: var(--ui-dim); }
.ctx-menu { position: absolute; z-index: 850; background: var(--ui-bg-2); border: 1px solid var(--ui-border); border-radius: 4px; min-width: 140px; padding: 4px 0; }
.ctx-menu div { padding: 4px 12px; cursor: pointer; }
.ctx-menu div:hover { background: #363c52; }

/* event dialog */
#event-dialog { bottom: 240px; left: 50%; transform: translateX(-50%); width: 560px; }
#event-dialog .body { display: flex; gap: 12px; }
#event-dialog .face { width: 128px; height: 128px; image-rendering: pixelated; background: #11131b; border: 1px solid var(--ui-border); flex: none; }
#event-dialog .text { flex: 1; font-size: 15px; line-height: 1.4; min-height: 100px; white-space: pre-wrap; }
#event-dialog .options { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
#event-dialog .options button { text-align: left; }

#announcement { top: 12%; left: 50%; transform: translateX(-50%); font-size: 26px; color: var(--ui-accent); text-shadow: 0 2px 0 #000, 0 0 12px rgba(0,0,0,.8); pointer-events: none; }
#picture { position: absolute; inset: 0; display: grid; place-items: center; z-index: 700; }
#picture img { image-rendering: pixelated; }
.quest-list .q { padding: 4px 6px; cursor: pointer; border-radius: 3px; }
.quest-list .q:hover, .quest-list .q.active { background: #2b3042; }
.list { max-height: 260px; overflow: auto; }
.list .item { padding: 3px 6px; display: flex; justify-content: space-between; gap: 8px; cursor: default; }
.list .item:hover { background: #2b3042; }
.online { color: var(--ui-ok); }
.offline { color: var(--ui-dim); }
.settings .tab-row { display: flex; gap: 4px; margin-bottom: 8px; }
.settings .tab-row button.active { background: var(--ui-accent); color: #000; }
.settings .opt { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; gap: 10px; }
.settings .opt input[type=range] { width: 160px; }
.bind { min-width: 110px; text-align: center; }
.bind.listening { outline: 2px solid var(--ui-accent); }
.debug { font: 11px var(--mono); position: absolute; right: 8px; top: 8px; background: rgba(0,0,0,.6); padding: 6px 8px; border-radius: 4px; white-space: pre; pointer-events: none; }
.craft .recipe { padding: 4px 6px; cursor: pointer; border-radius: 3px; }
.craft .recipe:hover, .craft .recipe.active { background: #2b3042; }
.progress { height: 10px; background: #1b1e29; border: 1px solid #000; border-radius: 3px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ui-accent-2); width: 0; }
.trade-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.input-box { width: 360px; }
.input-box input[type=range] { width: 100%; }
kbd { font: 11px var(--mono); background: #0b0e16; border: 1px solid var(--ui-border); border-radius: 3px; padding: 0 4px; }
@media (max-width: 900px) {
  #chat { width: calc(100vw - 16px); height: 150px; }
  #hud-target { left: 8px; top: 120px; }
  #event-dialog { width: calc(100vw - 16px); }
}

/* touch screens: on-screen stick and buttons (ui/touch.js), body.touch while they are active */
#menu-buttons .menu-toggle { display: none; }
#touch { position: absolute; inset: auto 0 0 0; height: 0; pointer-events: none; }
#touch .stick, #touch .tbtns { pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
#touch .stick { position: absolute; left: 20px; bottom: 20px; width: 124px; height: 124px; border-radius: 50%; background: rgba(18,20,28,.45); border: 2px solid rgba(255,255,255,.18); }
#touch .stick.on { border-color: rgba(240,180,41,.6); }
#touch .knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(232,233,238,.35); border: 2px solid rgba(255,255,255,.4); pointer-events: none; }
#touch .tbtns { position: absolute; right: 12px; bottom: 16px; width: 164px; height: 150px; }
#touch .tbtn { position: absolute; width: 50px; height: 50px; padding: 0; border-radius: 50%; font-size: 20px; background: rgba(43,48,66,.7); border: 2px solid rgba(255,255,255,.2); touch-action: none; }
#touch .tbtn.on { background: rgba(240,180,41,.55); border-color: var(--ui-accent); }
#touch .tbtn.act { right: 0; bottom: 0; width: 76px; height: 76px; font-size: 30px; }
#touch .tbtn.block { right: 86px; bottom: 0; }
#touch .tbtn.pick { right: 84px; bottom: 58px; }
#touch .tbtn.target { right: 12px; bottom: 88px; }
#touch .tbtn.chat { right: 112px; bottom: 112px; width: 40px; height: 40px; font-size: 16px; }
#touch .tbtn.chat.unread::after { content: ""; position: absolute; right: 2px; top: 2px; width: 9px; height: 9px; border-radius: 50%; background: var(--ui-danger); }
body.touch #game { touch-action: none; }
body.touch .win > .title { touch-action: none; }
body.touch #chat { display: none; }
body.touch.chat-open #chat { display: flex; left: 8px; top: 8px; bottom: auto; width: min(420px, calc(100vw - 16px)); height: min(45vh, 260px); z-index: 60; }
body.touch #menu-buttons { top: 8px; bottom: auto; flex-wrap: wrap; justify-content: flex-end; max-width: calc(100vw - 284px); min-width: 48px; }
body.touch #menu-buttons button { width: 40px; height: 40px; }
body.touch #menu-buttons .menu-toggle { display: block; }
body.touch #menu-buttons:not(.open) button:not(.menu-toggle) { display: none; }
body.touch #hotbar { gap: 3px; padding: 3px; }
body.touch #hotbar .slot { width: 34px; height: 34px; }
body.touch #event-dialog { bottom: 180px; }
@media (max-width: 600px) {
  body.touch #hotbar { bottom: 180px; flex-wrap: wrap; justify-content: center; width: 200px; }
  body.touch #menu-buttons { flex-direction: column; flex-wrap: nowrap; }
  body.touch #event-dialog { bottom: 250px; }
}

/* minimap and quest tracker (top right) */
#minimap { position: absolute; right: 8px; top: 8px; padding: 4px; width: max-content; min-width: 0; cursor: pointer; user-select: none; }
#minimap canvas { display: block; border: 1px solid var(--ui-border); }
#minimap .mm-name { font-size: 11px; text-align: center; margin-bottom: 2px; color: var(--ui-accent); }
#tracker { position: absolute; right: 8px; top: 140px; width: 190px; padding: 6px 8px; cursor: pointer; font-size: 12px; }
#tracker .tq + .tq { margin-top: 6px; }
body.touch #minimap { top: 56px; }
body.touch #tracker { top: 190px; }
@media (max-width: 760px) { #minimap, #tracker { transform: scale(.8); transform-origin: top right; } }

/* live edit mode: the editor docked beside the game (ui/editmode.js) */
body.editing #app { right: var(--dock, 55%); }
#editdock { position: fixed; top: 0; right: 0; bottom: 0; width: var(--dock, 55%); display: flex; flex-direction: column; background: #14161d; border-left: 1px solid var(--ui-border); z-index: 950; }
/* the dock's tool bar shares the class name of the vital bars (.bar above): undo their height, clipping and centred label */
#editdock .bar { display: flex; align-items: center; gap: 10px; padding: 4px 8px; font-size: 12px; border-bottom: 1px solid var(--ui-border);
  position: static; height: auto; overflow: visible; margin: 0; background: none; border-width: 0 0 1px; border-radius: 0; }
#editdock .bar > b { position: static; font-size: inherit; line-height: inherit; text-shadow: none; }
#editdock .bar .grow { flex: 1; }
#editdock .bar label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#editdock .bar button { padding: 2px 8px; font-size: 12px; }
#editdock iframe { flex: 1; width: 100%; border: 0; background: #14161d; }
#editdock .grip { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; cursor: col-resize; z-index: 2; }
body.dock-drag #editdock iframe { pointer-events: none; }
body.dock-drag { cursor: col-resize; user-select: none; }
#editbadge { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); padding: 3px 10px; font-size: 12px; border-radius: 10px; background: rgba(70,162,255,.2); border: 1px solid var(--ui-accent-2); color: var(--ui-fg); pointer-events: none; }
#menu-buttons button.on { background: var(--ui-accent-2); color: #000; }

/* packaged apps: the first-start "which server" form (core/server.js askForServer) */
#boot .server-ask { display: flex; flex-direction: column; gap: 10px; width: min(420px, calc(100vw - 32px)); padding: 20px; background: var(--ui-bg); border: 1px solid var(--ui-border); border-radius: 8px; font-size: 14px; color: var(--ui-fg); }
#boot .server-ask h2 { margin: 0; font-size: 18px; color: var(--ui-accent); }
#boot .server-ask p { margin: 0; color: var(--ui-dim); }
#boot .server-ask input { font-size: 16px; padding: 8px; }
#boot .server-ask .err { min-height: 1.2em; color: var(--ui-danger); }
