:root {
  --bg: #0d0c10;
  --panel: #1b1812;
  --panel2: #252017;
  --edge: #4a3f2c;
  --text: #eadfc8;
  --dim: #9a8f7a;
  --gold: #e8c060;
  --hp: #c8322a;
  --xp: #d8b040;
  --rest: #4ac85a;
  --recover: #a060e0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.35 "Trebuchet MS", Verdana, sans-serif; overflow: hidden; }
#app { display: flex; height: 100vh; }
#stage { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #050507; }
#view { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
#overlay { position: absolute; pointer-events: none; }
#banner { position: absolute; top: 12%; left: 50%; transform: translateX(-50%); font-size: 28px; font-weight: bold; color: #ffe9b0;
  text-shadow: 0 2px 0 #000, 0 0 12px #000; opacity: 0; pointer-events: none; letter-spacing: 1px; white-space: nowrap; }
#banner.show { animation: banner 3.2s ease-out; }
@keyframes banner { 0% { opacity: 0; transform: translate(-50%, 10px); } 12% { opacity: 1; transform: translate(-50%, 0); } 75% { opacity: 1; } 100% { opacity: 0; } }

#chatwrap { position: absolute; left: 10px; bottom: 10px; width: min(560px, 60%); pointer-events: none; }
#chatlog { max-height: 190px; overflow-y: auto; padding: 4px 6px; scrollbar-width: none; pointer-events: auto; }
#chatlog::-webkit-scrollbar { display: none; }
#chatlog .line { text-shadow: 0 1px 0 #000, 0 0 3px #000; padding: 1px 0; transition: opacity 1.5s; }
#chatlog .line.old { opacity: 0.35; }
#chatwrap:hover .line.old { opacity: 1; }
.line.sys { color: #d8d0c0; } .line.you { color: #9ad8ff; } .line.npc { color: #ffe28a; } .line.bad { color: #ff7a6a; }
.line.loot { color: #e8c060; } .line.level { color: #7aff8a; font-weight: bold; } .line.quest { color: #d8a0ff; } .line.sign { color: #c8b890; font-style: italic; }
#chat { display: none; width: 100%; margin-top: 4px; padding: 6px 8px; background: rgba(10, 8, 6, 0.9); border: 1px solid var(--edge); color: var(--text); font: inherit; pointer-events: auto; outline: none; }
#chat.open { display: block; }

#panel { width: 280px; min-width: 280px; background: var(--panel); border-left: 2px solid var(--edge); display: flex; flex-direction: column; padding: 10px; gap: 8px; overflow-y: auto; }
.hdr { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
#zone { font-weight: bold; color: var(--gold); font-size: 14px; }
#time { color: var(--dim); font-size: 12px; white-space: nowrap; }
.hp { position: relative; height: 18px; background: #2a0d0b; border: 1px solid #5a2a20; }
#hpfill { height: 100%; background: linear-gradient(#e0483a, #9a2018); width: 100%; transition: width 0.15s; }
#hptext { position: absolute; inset: 0; text-align: center; font-size: 12px; line-height: 16px; text-shadow: 0 1px 0 #000; }
#focus .skname { font-size: 12px; color: var(--text); margin-bottom: 2px; }
#status { color: #9ad8ff; font-size: 12px; min-height: 15px; }
.xpbar { height: 6px; background: #1a160f; border: 1px solid #3a3222; }
.xpbar > div { height: 100%; background: var(--xp); }
.xpbar.rested > div { background: var(--rest); }
.xpbar.recover > div { background: var(--recover); }
.tabs { display: flex; gap: 2px; }
.tabs button { flex: 1; background: var(--panel2); color: var(--dim); border: 1px solid var(--edge); padding: 5px 0; font: inherit; cursor: pointer; }
.tabs button.active { color: var(--text); background: #3a3020; }
.tab { display: none; }
.tab.show { display: block; }
.label { color: var(--dim); font-size: 11px; margin: 6px 0 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
#bag { grid-template-columns: repeat(4, 1fr); }
.cell { position: relative; aspect-ratio: 1; background: #120f0a; border: 1px solid #3a3222; display: flex; align-items: center; justify-content: center; cursor: pointer; }
.cell:hover { border-color: var(--gold); }
.cell img { width: 90%; height: 90%; image-rendering: pixelated; }
.cell.empty { cursor: default; }
.cell.empty[data-label]::after { content: attr(data-label); font-size: 8px; color: #5a5040; text-align: center; }
.cell .warn { position: absolute; top: 0; right: 2px; color: #ff6a4a; font-weight: bold; }
.cell .key { position: absolute; bottom: 0; left: 2px; font-size: 9px; color: #7a6a50; }
.stats { display: flex; justify-content: space-between; margin-top: 6px; color: var(--dim); }
.stats b { color: var(--gold); }
.skill { padding: 6px; border: 1px solid #3a3222; margin-bottom: 4px; background: #16130d; }
.skill.focus { border-color: var(--gold); }
.skill.locked { opacity: 0.55; }
.sktop { display: flex; justify-content: space-between; margin-bottom: 3px; }
.skdesc { font-size: 11px; color: var(--dim); margin-top: 2px; }
.skinfo { font-size: 11px; color: var(--dim); margin-top: 8px; }
.quest { border: 1px solid #3a3222; padding: 6px; margin-bottom: 6px; background: #16130d; }
.quest.done { border-color: #7aff8a; }
.qt { font-weight: bold; color: #d8a0ff; } .qg { color: var(--dim); font-weight: normal; }
.qd { font-size: 11px; color: var(--dim); margin: 3px 0; }
.qp { font-size: 12px; color: var(--gold); }
.mapgrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; }
.mapcell { aspect-ratio: 1; background: #120f0a; border: 1px solid #3a3222; font-size: 8px; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--dim); padding: 1px; overflow: hidden; }
.mapcell.none { visibility: hidden; }
.mapcell.seen { background: #2a3a20; color: var(--text); }
.mapcell.here { outline: 2px solid var(--gold); }
.dim { color: var(--dim); } .small { font-size: 11px; }
.ok { color: #7aff8a; } .bad { color: #ff7a6a; }
.foot { margin-top: auto; }
.foot button, .modal button { background: #3a3020; color: var(--text); border: 1px solid var(--edge); padding: 5px 12px; font: inherit; cursor: pointer; }
.modal button.link { background: none; border: none; color: #c89a6a; text-decoration: underline; padding: 0; }
#tooltip { position: fixed; display: none; width: 180px; background: rgba(12, 10, 8, 0.96); border: 1px solid var(--edge); padding: 6px 8px; font-size: 12px; pointer-events: none; z-index: 40; }
.modal { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.65); z-index: 30; }
.modal.show { display: flex; }
.modal-body { max-width: 760px; width: 92%; max-height: 92%; overflow-y: auto; background: var(--panel); border: 2px solid var(--edge); padding: 18px 22px; }
.modal h1 { margin: 0; color: var(--gold); letter-spacing: 2px; }
.modal .sub { margin: 2px 0 10px; color: var(--dim); }
.modal .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.modal h3 { margin: 6px 0; color: #d8c8a0; }
.modal table { border-collapse: collapse; width: 100%; }
.modal td { padding: 2px 4px; border-bottom: 1px solid #2a2418; vertical-align: top; }
.modal td:first-child { color: var(--gold); white-space: nowrap; }
.modal ul { padding-left: 16px; margin: 0; }
.modal li { margin-bottom: 5px; }
.modal .start { margin-top: 14px; font-size: 14px; }
@media (max-width: 800px) { .modal .cols { grid-template-columns: 1fr; } }

#netstatus { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(90, 20, 10, 0.9); border: 1px solid #c85a3a; padding: 4px 12px; display: none; z-index: 4; }
#netstatus.show { display: block; }
#campbar { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); background: rgba(20, 16, 10, 0.88); border: 1px solid var(--gold); color: var(--text); padding: 6px 14px; display: none; z-index: 7; white-space: nowrap; pointer-events: none; }
#campbar.show { display: block; }
.line.other { color: #c8f0ff; }
.modal a, .foot a { color: #e8c060; }
.foot { display: flex; flex-wrap: wrap; gap: 4px; }
.foot .btn { background: #3a3020; color: var(--text); border: 1px solid var(--edge); padding: 5px 10px; text-decoration: none; }
.modal ol { padding-left: 18px; margin: 0; } .modal ol li { margin-bottom: 5px; }
.login-body { max-width: 380px; display: flex; flex-direction: column; gap: 10px; }
.login-body label { display: flex; flex-direction: column; gap: 3px; color: var(--dim); }
.login-body input { padding: 7px 8px; background: #120f0a; border: 1px solid var(--edge); color: var(--text); font: inherit; }
.loginbtns { display: flex; gap: 8px; } .loginbtns button { flex: 1; padding: 8px; }
#loginerr { min-height: 16px; }
#login { background: radial-gradient(circle at 50% 40%, rgba(40, 30, 16, 0.7), rgba(0, 0, 0, 0.92)); }
#rankcat { width: 100%; padding: 4px; background: #120f0a; color: var(--text); border: 1px solid var(--edge); margin-bottom: 6px; }
table.ranks { width: 100%; border-collapse: collapse; font-size: 12px; }
table.ranks td { padding: 2px 4px; border-bottom: 1px solid #2a2418; }
table.ranks td:first-child { color: var(--dim); width: 22px; } table.ranks td:last-child { text-align: right; color: var(--gold); }
table.ranks tr.me td { color: #9ad8ff; }
.tabs button { font-size: 12px; }

table.binds { width: 100%; border-collapse: collapse; margin: 8px 0; }
table.binds td { padding: 3px 4px; border-bottom: 1px solid #2a2418; }
table.binds td:first-child { color: var(--text); }
button.bind { width: 100%; min-width: 64px; background: #120f0a; border: 1px solid var(--edge); color: var(--gold); padding: 4px; cursor: pointer; font: inherit; }
button.bind:hover { border-color: var(--gold); }
button.bind.capturing { background: #3a3020; color: #fff; }

button.bind.shared { color: #ffd28a; }
.share { font-size: 10px; color: #ff9a5a; margin-left: 2px; }
.line.guild { color: #8affc8; } .line.whisper { color: #f0a0ff; font-style: italic; }

/* bank tab */
#bank .bkrow { display: flex; justify-content: space-between; align-items: center; gap: 4px; margin: 3px 0; flex-wrap: wrap; }
#bank .bkrow > span { flex: 1; min-width: 0; }
#bank button { background: #3a3020; color: var(--text); border: 1px solid var(--edge); padding: 3px 7px; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
#bank button:hover:not(:disabled) { border-color: var(--gold); }
#bank button:disabled { opacity: 0.45; cursor: default; }
#bank input, #bank select { flex: 1; min-width: 0; padding: 3px 5px; background: #120f0a; border: 1px solid var(--edge); color: var(--text); font: inherit; font-size: 12px; }
#bank input.tag { flex: 0 0 56px; text-transform: uppercase; }
#bank select { flex: 0 0 128px; }
.bkrooms { border: 1px solid #3a3222; background: #16130d; padding: 2px 5px; margin: 4px 0; max-height: 170px; overflow-y: auto; }
.bkroom { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 2px 0; font-size: 12px; }
.bkroom.here { color: var(--gold); }
.bkmembers { border: 1px solid #3a3222; background: #16130d; padding: 2px 5px; margin: 4px 0; max-height: 160px; overflow-y: auto; }
.bkmembers button { padding: 1px 5px !important; font-size: 11px !important; }

.tabs button.hidden { display: none; }
.helptabs { display: flex; gap: 4px; margin: 6px 0 10px; }
.helptabs button.active { border-color: var(--gold); color: var(--gold); }
.helppane { display: none; } .helppane.show { display: block; }
#cmdtable td:first-child { font-family: Consolas, monospace; }
.setting { display: flex; gap: 8px; align-items: center; margin: 8px 0; cursor: pointer; }
.camp-body { max-width: 440px; text-align: center; }
.hidden { display: none !important; }
.forgot { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid #2a2418; padding-top: 8px; }
.accountbox .acsec { border-top: 1px solid #2a2418; padding: 8px 0; }
.accountbox .acrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.accountbox input { flex: 1; min-width: 130px; padding: 5px 7px; background: #120f0a; border: 1px solid var(--edge); color: var(--text); font: inherit; }
.accountbox .acqr svg { width: 180px; height: 180px; display: block; margin: 6px 0; }
.accountbox .ackey { user-select: all; }
.accountbox .accodes { display: grid; grid-template-columns: repeat(2, max-content); gap: 4px 18px; margin: 6px 0; font-size: 14px; }
#remembered .accrow { display: flex; gap: 8px; align-items: center; margin: 3px 0; }
#remembered .accrow button:first-child { flex: 1; padding: 6px; }
#social .row { display: flex; gap: 4px; align-items: center; justify-content: space-between; margin: 4px 0; }
#social input { flex: 1; min-width: 0; padding: 3px 5px; background: #120f0a; border: 1px solid var(--edge); color: var(--text); font: inherit; font-size: 12px; }
#social button { background: #3a3020; color: var(--text); border: 1px solid var(--edge); padding: 3px 8px; font: inherit; font-size: 12px; cursor: pointer; }
#social button.on { border-color: #ff7a5a; color: #ffb09a; }

.volumes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 18px; margin: 6px 0 8px; }
.volumes label { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text); }
.volumes input[type=range] { flex: 1; max-width: 170px; accent-color: var(--gold); }

.voicepick { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0; }
.voicepick select { padding: 4px; background: #120f0a; color: var(--text); border: 1px solid var(--edge); }

/* ---------------- phones, tablets and narrow windows ---------------- */
html, body { overscroll-behavior: none; }
#app { height: 100dvh; }
#stage, #view, #overlay { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.menuclose { display: none; }
#touchui { display: none; }

/* the side panel becomes a drawer on small screens and touch devices */
@media (max-width: 900px) {
  #panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: min(320px, 88vw); min-width: 0; transform: translateX(105%); transition: transform 0.2s ease; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.6); padding-top: max(10px, env(safe-area-inset-top)); }
  #panel.open { transform: none; }
  .menuclose { display: block; align-self: flex-end; background: none; border: 0; color: var(--text); font-size: 20px; padding: 0 4px; cursor: pointer; }
  body:not(.touch) #stage::after { content: 'Menu: Tab'; position: absolute; top: 6px; right: 8px; color: var(--dim); font-size: 11px; pointer-events: none; }
}
body.touch #panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; width: min(340px, 90vw); min-width: 0; transform: translateX(105%); transition: transform 0.2s ease; box-shadow: -8px 0 24px rgba(0, 0, 0, 0.6); padding-top: max(10px, env(safe-area-inset-top)); }
body.touch #panel.open { transform: none; }
body.touch .menuclose { display: block; align-self: flex-end; background: none; border: 0; color: var(--text); font-size: 22px; padding: 0 4px; }

/* on-screen controls */
body.touch #touchui { display: block; position: absolute; inset: 0; pointer-events: none; z-index: 6; }
#touchui .joy { position: absolute; left: max(18px, env(safe-area-inset-left)); bottom: max(18px, env(safe-area-inset-bottom)); width: 128px; height: 128px; border-radius: 50%; background: rgba(255, 240, 210, 0.08); border: 2px solid rgba(255, 240, 210, 0.22); pointer-events: auto; touch-action: none; }
#touchui .joy-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(232, 192, 96, 0.45); border: 2px solid rgba(255, 230, 170, 0.6); pointer-events: none; }
#touchui .tbtns { position: absolute; right: max(16px, env(safe-area-inset-right)); bottom: max(16px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: auto auto; gap: 10px; align-items: end; pointer-events: none; }
#touchui .ttop { position: absolute; right: max(10px, env(safe-area-inset-right)); top: max(10px, env(safe-area-inset-top)); display: flex; gap: 8px; pointer-events: none; }
#touchui .tb { pointer-events: auto; touch-action: none; border-radius: 50%; width: 62px; height: 62px; font-size: 24px; color: #fff3d8; background: rgba(40, 30, 16, 0.55); border: 2px solid rgba(232, 192, 96, 0.55); -webkit-user-select: none; user-select: none; }
#touchui .tb.big { width: 84px; height: 84px; font-size: 34px; grid-row: span 2; }
#touchui .tb.small { width: auto; height: 38px; border-radius: 19px; font-size: 13px; padding: 0 12px; }
#touchui .tb.down, #touchui .tb.on { background: rgba(232, 192, 96, 0.6); color: #1b1408; }
#touchui #tb-respawn { display: none; position: absolute; left: 50%; top: 58%; transform: translateX(-50%); font-size: 16px; height: 46px; padding: 0 22px; }
#touchui #tb-respawn.show { display: block; }
body.touch #chatwrap { bottom: 160px; width: min(420px, 55%); }
body.touch #chatlog { max-height: 110px; font-size: 12px; }
body.touch #banner { font-size: 20px; }
body.touch .foot { flex-wrap: wrap; }
body.touch #chat { font-size: 16px; } /* 16px stops iOS from zooming into the chat box */
/* dialogs (help, settings, camp...) cover the controls, so hide them while one is open */
body.touch #stage:has(.modal.show) #touchui { display: none; }
/* upright phones: a narrower chat, and the dialogs use the whole width */
@media (orientation: portrait) {
  body.touch #chatwrap { width: calc(100% - 20px); bottom: 170px; }
  body.touch .modal-body { width: 96%; padding: 14px 14px; }
}
