:root {
  --bg: #0b0a0d;
  --panel: #15131a;
  --panel-2: #1d1a24;
  --line: #3a3344;
  --text: #d9d2c5;
  --muted: #8a8295;
  --accent: #c89468;
  --gold: #e8c45a;
  --exp: #d8c23a;
  --train: #8e5bd1;
  --hp: #b83a3a;
  --good: #6fbf73;
  --bad: #e06c5f;
  --war: #e0b84a;
  --shout: #7fb6e8;
  --auction: #66c48a;
  font-family: Verdana, Tahoma, "Segoe UI", sans-serif;
  font-size: 13px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg) radial-gradient(ellipse at top, #241b2e 0%, #0b0a0d 60%) fixed;
  color: var(--text); min-height: 100vh;
}
a { color: var(--accent); }
button, select, input, textarea {
  font: inherit; color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 3px; padding: 4px 8px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); color: #fff; }
button:disabled { opacity: .45; cursor: default; }
button.big { padding: 9px 18px; font-size: 15px; background: #3b2a1f; border-color: var(--accent); }
input[type=number] { width: 7.5em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.gold { color: var(--gold); }

.logo { font-family: Georgia, "Times New Roman", serif; color: var(--accent); letter-spacing: 3px; text-shadow: 0 0 12px rgba(200,148,104,.4); }
h1.logo { font-size: 48px; margin: 0 0 4px; text-align: center; }
.small-logo { font-size: 22px; }
h2 { font-size: 15px; margin: 0 0 8px; color: var(--accent); font-family: Georgia, serif; }
h3 { font-size: 12px; margin: 10px 0 4px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 10px; }

/* title screen */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.title-card { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 12px; }
.title-card .tag { text-align: center; color: var(--muted); margin: 0; }
.title-card form { display: flex; flex-direction: column; gap: 10px; }
.title-card label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
.title-card .row2 { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.title-card textarea { width: 100%; }
.or { text-align: center; color: var(--muted); margin-top: 6px; }
#continue-box { text-align: center; }
.race-info { background: var(--panel-2); border: 1px solid var(--line); padding: 8px; border-radius: 3px; }
.mods { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-top: 6px; text-align: center; font-size: 11px; }
.mods b { display: block; color: var(--muted); font-weight: normal; }

/* top bar */
header.top { display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); background: rgba(0,0,0,.35); }
.bars { display: grid; gap: 3px; }
.bar { position: relative; height: 14px; background: #000; border: 1px solid var(--line); border-radius: 2px; overflow: hidden; }
.bar .fill { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .25s; }
.bar .fill.exp { background: linear-gradient(#f0dc5a, #a8941e); }
.bar .fill.train { background: linear-gradient(#b17ff0, #5d2f99); }
.bar .fill.hp { background: linear-gradient(#e05a5a, #7d1f1f); }
.bar span { position: relative; font-size: 10px; padding-left: 6px; line-height: 14px; color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.clock { text-align: right; }

/* main layout */
.grid { display: grid; grid-template-columns: 230px minmax(0, 1fr) 250px; gap: 8px; padding: 8px; }
.actions, .chat { margin: 0 8px 8px; }
table.kv { width: 100%; border-collapse: collapse; }
table.kv th { text-align: left; color: var(--muted); font-weight: normal; padding: 2px 6px 2px 0; width: 42%; }
table.kv td { padding: 2px 0; text-align: right; }
table.stats td button { padding: 0 6px; margin-left: 6px; font-weight: bold; color: var(--train); }
.train-note { margin: 8px 0 4px; color: var(--train); min-height: 1em; font-weight: bold; }

table.forts { width: 100%; border-collapse: collapse; text-align: center; font-size: 12px; }
table.forts th { color: var(--muted); font-weight: normal; }
table.forts td, table.forts th { padding: 2px; }

/* tabs */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs button { border-radius: 3px 3px 0 0; }
.tabs button.active { background: #3b2a1f; border-color: var(--accent); color: #fff; }
.tab-body { min-height: 430px; }

/* target pane */
.monster-card { display: grid; grid-template-columns: 1fr; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); padding: 12px; border-radius: 4px; }
.monster-card .name { font-size: 18px; font-family: Georgia, serif; color: #fff; }
.monster-card .bar { height: 18px; }
.monster-card .bar span { line-height: 18px; font-size: 11px; }
.attack-btn { font-size: 20px; padding: 14px; background: #4a1f1f; border-color: #b84a3a; }
.attack-btn:disabled { opacity: .6; }
.mlist { width: 100%; border-collapse: collapse; margin-top: 6px; }
.mlist td, .mlist th { padding: 4px 6px; border-bottom: 1px solid #241f2b; text-align: left; }
.mlist th { color: var(--muted); font-weight: normal; }
.lvl-easy { color: var(--muted); }
.lvl-even { color: var(--good); }
.lvl-hard { color: var(--war); }
.lvl-deadly { color: var(--bad); }
.beast-box { margin-top: 10px; border: 1px solid #7a3a1a; background: #24130d; padding: 8px; border-radius: 4px; }

/* map */
.map-wrap { display: grid; grid-template-columns: 36px auto 36px; grid-template-rows: 30px auto 30px; justify-content: center; align-items: center; gap: 4px; }
.map-wrap canvas { grid-column: 2; grid-row: 2; width: 100%; max-width: 390px; aspect-ratio: 1; background: #000; border: 1px solid var(--line); image-rendering: pixelated; cursor: crosshair; }
.cmp.n { grid-column: 2; grid-row: 1; justify-self: center; }
.cmp.s { grid-column: 2; grid-row: 3; justify-self: center; }
.cmp.w { grid-column: 1; grid-row: 2; }
.cmp.e { grid-column: 3; grid-row: 2; }
.map-under { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 6px; flex-wrap: wrap; }

/* inventory etc */
.items { width: 100%; border-collapse: collapse; }
.items td, .items th { padding: 4px 6px; border-bottom: 1px solid #241f2b; text-align: left; }
.items th { color: var(--muted); font-weight: normal; }
.items td.btns { text-align: right; white-space: nowrap; }
.items td.btns button { padding: 1px 6px; font-size: 11px; }
.ench { color: #b98cf0; }
.help-body p, .help-body li { line-height: 1.5; }
.help-body kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 11px; }

/* actions */
.actions { display: grid; gap: 6px; }
.action-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.action-row label { color: var(--muted); display: flex; gap: 6px; align-items: center; }
.action-row .fields { display: contents; }
.action-row .hint { color: var(--muted); font-size: 11px; }

/* chat */
.chat-filters { display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.chat-filters label { display: flex; gap: 3px; align-items: center; }
.log { height: 210px; overflow-y: auto; background: #000; border: 1px solid var(--line); padding: 6px; font-size: 12px; line-height: 1.45; }
.log div { overflow-wrap: anywhere; }
.log .h { color: #555; margin-right: 4px; }
.log .ch-sys { color: var(--text); }
.log .ch-fight { color: #b5aca0; }
.log .ch-loot { color: var(--gold); }
.log .ch-war { color: var(--war); }
.log .ch-kingdom { color: #f08a5d; }
.log .ch-shout { color: var(--shout); }
.log .ch-auction { color: var(--auction); }
.log .ch-you { color: #fff; }
.chat-row { display: flex; gap: 6px; margin-top: 6px; }
.chat-row input { flex: 1; min-width: 0; }

@media (max-width: 980px) {
  .grid { grid-template-columns: 1fr 1fr; }
  #view-panel { grid-column: 1 / -1; order: -1; }
}
@media (max-width: 620px) {
  :root { font-size: 14px; }
  header.top { grid-template-columns: 1fr; padding: 8px 16px; }
  .small-logo { display: none; }
  .clock { text-align: left; }
  .grid { grid-template-columns: 1fr; padding: 8px 16px; }
  .actions, .chat { margin: 0 16px 8px; }
  .tab-body { min-height: 0; }
  .map-wrap { grid-template-columns: 30px minmax(0, 1fr) 30px; }
  .cmp { padding: 4px 2px; }
}

/* in-page dialog */
.dialog { background: rgba(0,0,0,.6); z-index: 30; }
.dialog-card { width: 100%; max-width: 420px; display: grid; gap: 10px; }
.dialog-card p { margin: 0; line-height: 1.5; }
.dialog-card textarea { width: 100%; font-size: 11px; }
.dialog-btns { display: flex; gap: 8px; justify-content: flex-end; }
.dialog-btns button.big { padding: 6px 16px; font-size: 13px; }
textarea[hidden], button[hidden] { display: none; }

/* shared world */
.mp-box { display: grid; gap: 6px; justify-items: center; text-align: center; }
.mp-status { margin: 0; color: var(--shout); line-height: 1.5; }
button.linkish { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 0; font-size: 12px; }

/* portraits, tavern, quests, social */
.char-title { margin: -6px 0 6px; font-style: italic; }
.monster-card .portrait-row { display: flex; gap: 12px; align-items: center; }
.monster-card canvas.portrait { width: 96px; height: 96px; border: 1px solid var(--line); border-radius: 4px; flex: none; }
.monster-card .who { min-width: 0; display: grid; gap: 4px; }
.mlist canvas.mini { width: 32px; height: 32px; vertical-align: middle; border-radius: 3px; margin-right: 6px; }
.place-box { margin-top: 10px; border: 1px solid #2f4a63; background: #0f1a24; padding: 8px; border-radius: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.cards { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.card { width: 64px; height: 90px; border-radius: 6px; background: #f5efe0; color: #111; border: 2px solid #bba98a; display: flex; flex-direction: column; justify-content: space-between; padding: 4px 6px; font-family: Georgia, serif; font-size: 20px; cursor: pointer; user-select: none; }
.card.red { color: #b3261e; }
.card.held { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold); transform: translateY(-6px); }
.card.back { background: repeating-linear-gradient(45deg, #3b2a1f 0 6px, #2a1d15 6px 12px); border-color: var(--accent); cursor: default; }
.card .big { font-size: 28px; text-align: center; }
.card .held-tag { font-size: 10px; text-align: center; font-family: Verdana, sans-serif; color: var(--gold); min-height: 12px; }
.paytable { border-collapse: collapse; font-size: 12px; }
.paytable td { padding: 1px 10px 1px 0; }
.quest { border: 1px solid var(--line); background: var(--panel-2); border-radius: 4px; padding: 8px; margin-bottom: 8px; display: grid; gap: 4px; }
.quest .prog { height: 8px; background: #000; border-radius: 4px; overflow: hidden; }
.quest .prog div { height: 100%; background: var(--exp); }
.deed { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 6px 0; border-bottom: 1px solid #241f2b; }
.deed.locked { opacity: .5; }
.social-grid { display: grid; gap: 14px; }
.social-grid section { border: 1px solid var(--line); border-radius: 4px; padding: 10px; background: var(--panel-2); }
.social-grid h3 { margin-top: 0; }
.row-form { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 6px; }
.row-form input[type=text] { width: 12em; }
.log .ch-guild { color: #c9a7ff; }
.bracket { display: flex; gap: 10px; overflow-x: auto; font-size: 11px; padding-bottom: 6px; }
.bracket .round { display: grid; gap: 4px; align-content: start; min-width: 130px; }
.bracket .match { border: 1px solid var(--line); border-radius: 3px; padding: 2px 4px; }
.bracket .w { color: var(--gold); }

.mlist-wrap { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 4px; }
.mlist-wrap .mlist { margin-top: 0; }
.mlist-wrap th { position: sticky; top: 0; background: var(--panel); z-index: 1; }

/* player's guide */
.char-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.char-head h2 { margin-bottom: 8px; min-width: 0; }
.guide-btn { padding: 2px 10px; font-size: 11px; border-color: var(--accent); color: var(--accent); flex: none; }
.guide-overlay { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.7); display: flex; justify-content: center; padding: 16px; }
.guide-panel { width: 100%; max-width: 1050px; background: var(--panel); border: 1px solid var(--accent); border-radius: 6px; display: flex; flex-direction: column; min-height: 0; }
.guide-top { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.guide-top h1 { font-size: 22px; margin: 0; flex: 1; }
.guide-content { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: start; }
.g-toc { position: sticky; top: 0; display: grid; gap: 2px; padding: 14px 10px; border-right: 1px solid var(--line); font-size: 12px; }
.g-toc a { color: var(--text); text-decoration: none; padding: 3px 6px; border-radius: 3px; }
.g-toc a:hover, .g-toc a:focus-visible { background: var(--panel-2); color: var(--accent); }
.g-body { padding: 6px 22px 40px; line-height: 1.6; max-width: 72ch; }
.g-body section { padding-top: 12px; }
.g-body h2 { font-size: 18px; margin: 10px 0 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.g-body p, .g-body li { margin: 6px 0; }
.g-table { overflow-x: auto; margin: 8px 0; }
.g-table table { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.g-table th { text-align: left; color: var(--muted); font-weight: normal; border-bottom: 1px solid var(--line); padding: 4px 8px; }
.g-table td { padding: 4px 8px; border-bottom: 1px solid #241f2b; vertical-align: top; }
.g-tip { border-left: 3px solid var(--good); padding: 6px 10px; background: rgba(111,191,115,.08); }
.g-warn { border-left: 3px solid var(--war); padding: 6px 10px; background: rgba(224,184,74,.08); }
.g-up { color: var(--good); } .g-down { color: var(--bad); }
.g-easy { color: var(--muted); } .g-even { color: var(--good); } .g-hard { color: var(--war); } .g-deadly { color: var(--bad); }
.g-body kbd { background: var(--panel-2); border: 1px solid var(--line); border-radius: 3px; padding: 0 4px; font-size: 11px; }
.g-body details { margin: 8px 0; } .g-body summary { cursor: pointer; color: var(--accent); }
@media (max-width: 700px) {
  .guide-overlay { padding: 0; }
  .guide-panel { border-radius: 0; }
  .guide-content { grid-template-columns: minmax(0, 1fr); }
  .g-toc a { overflow-wrap: anywhere; }
  .g-toc { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); border-right: none; border-bottom: 1px solid var(--line); padding: 10px 16px; }
  .g-body { padding: 4px 16px 32px; }
}
.guide-content:focus { outline: none; }

/* race portraits */
.char-portrait { display: block; width: 128px; height: 128px; margin: 2px auto 10px; border-radius: 6px; box-shadow: 0 0 0 1px var(--line), 0 6px 18px rgba(0,0,0,.45); }
.race-pick { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 10px; align-items: start; }
.race-portrait { width: 112px; height: 112px; border-radius: 6px; max-width: 100%; }
@media (max-width: 420px) { .race-pick { grid-template-columns: 1fr; justify-items: center; } }

.respec-row { text-align: right; margin: 2px 0 6px; }
.social-grid section.danger { border-color: #6b2a2a; }
button.bad { border-color: var(--bad); color: var(--bad); }

/* admin panel */
.admin-btn { padding: 2px 10px; font-size: 11px; border-color: var(--accent); color: var(--accent); margin-right: 6px; }
.motd { padding: 6px 12px; background: #2a2116; border-bottom: 1px solid var(--accent); color: var(--gold); font-size: 13px; text-align: center; }
.admin-tabs { margin: 0; }
.admin-content { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px; }
.admin-content:focus { outline: none; }
.admin-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); align-items: start; }
.admin-grid input[type=number] { width: 8em; }
.admin-grid input.n6 { width: 5.5em; }
.admin-grid input.wide { width: min(100%, 24em); }
.admin-grid .row-form label { display: inline-flex; gap: 4px; align-items: center; }
.admin-grid select { max-width: 100%; }

/* town, market, dungeons, events */
.motd { white-space: pre-line; }
#dialog-msg { white-space: pre-line; max-height: 60vh; overflow-y: auto; }
.log .ch-whisper { color: #ff9ad5; }
.town-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); align-items: start; }
.town-grid h4 { margin: 10px 0 4px; }
.town-grid input[type=number] { width: 7em; }
.dungeon-box { border-color: #8a7a5c; background: #1d1912; }
.merchant-box { border-color: var(--gold); }
.merchant-box table { margin-top: 6px; }
.merchant-box { display: block; margin: 0 0 10px; }
.dungeon-box { display: block; margin: 0 0 10px; line-height: 1.9; }

/* abilities and loot rarity */
.fight-btns { display: flex; gap: 8px; }
.fight-btns .attack-btn { flex: 1; }
.ability-btn { flex: none; min-width: 9em; border-color: #6b5a2a; color: #b9a46a; }
.ability-btn.ready { border-color: var(--gold); color: var(--gold); box-shadow: 0 0 6px rgba(255, 210, 90, .35); }
.rar-rare b, .rar-rare { color: #5aa9ff; }
.rar-epic b, .rar-epic { color: #c08bff; }
.rar-legendary b, .rar-legendary { color: #ffa53a; }
.rar-common b { color: inherit; }
td .aff { color: #c9c3b8; font-weight: normal; }
.small-tabs button { font-size: 12px; padding: 3px 10px; }
.dice-row { display: flex; gap: 10px; align-items: center; margin: 8px 0; }
.die { display: inline-flex; width: 40px; height: 40px; align-items: center; justify-content: center; font-size: 22px; font-weight: bold; background: #f3ead8; color: #222; border-radius: 6px; }
.quest.done { opacity: .7; }
.gather-box { margin: 0 0 10px; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 25; max-width: min(92vw, 560px); background: #2a2116; border: 1px solid var(--gold); color: var(--gold); padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 18px rgba(0,0,0,.6); font-size: 14px; cursor: pointer; }

/* profiles, charts, arena, raids, tutorial */
.clickable { cursor: pointer; }
.clickable:hover { text-decoration: underline; }
.profile-panel { max-width: 860px; }
.profile-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.profile-head canvas { width: 120px; height: 120px; border: 1px solid var(--line); border-radius: 4px; }
.profile-head h2 { margin: 0 0 4px; }
.profile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 14px; margin-top: 10px; }
.profile-grid .gear td { text-align: left; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: 14px; }
.chart { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; }
.chart h4 { margin: 0 0 4px; color: var(--text); }
.chart svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart .series { fill: none; stroke: #3987e5; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .enddot, .chart .hoverdot { fill: #3987e5; stroke: var(--panel); stroke-width: 2; }
.chart .ax, .chart .grid { stroke: #2a2632; stroke-width: 1; }
.chart .cross { stroke: var(--muted); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 10px; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hidden { display: none; }
.chart-tip { position: absolute; top: 4px; background: #000; border: 1px solid var(--line); color: var(--text); font-size: 12px; padding: 2px 6px; border-radius: 3px; pointer-events: none; white-space: nowrap; }
.raid-box { border-color: #8a2a7a; background: #1e0f1c; margin: 0 0 10px; }
.raid-next { margin: 0 0 8px; }
.tutorial { position: fixed; right: 16px; top: 76px; z-index: 15; width: min(340px, calc(100vw - 32px)); background: #1b1626; border: 1px solid var(--accent); border-radius: 6px; padding: 10px 14px; box-shadow: 0 4px 18px rgba(0,0,0,.6); }
.tutorial p { margin: 4px 0 8px; }
.tut-glow { outline: 2px solid var(--gold) !important; outline-offset: 2px; box-shadow: 0 0 12px rgba(255, 210, 90, .6) !important; }
.filebtn { display: inline-flex; align-items: center; padding: 4px 10px; border: 1px solid var(--line); border-radius: 3px; cursor: pointer; background: #241f2b; }
.filebtn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.filebtn:focus-within { outline: 2px solid var(--accent); }
.whatsnew-card { max-width: 560px; max-height: 85vh; overflow-y: auto; }
.whatsnew-card h2 { margin: 0; }
ul.whatsnew { padding-left: 18px; line-height: 1.6; margin: 6px 0; }
#whatsnew { z-index: 28; }
.log .chatname { color: inherit; text-decoration: underline dotted; font: inherit; padding: 0; }
.town-grid select { max-width: 100%; }
.npc-box { display: block; margin: 0 0 10px; line-height: 1.7; border-color: #c9a227; background: #1f1a0e; }
.npc-box i { color: #e8dcb5; }
.npc-box td.gold { white-space: nowrap; }
.siege-box { border-color: #ff5050; }
