:root {
  --ink: #e9e2cf;
  --muted: #a99f8a;
  --gold: #e6b84c;
  --panel: rgba(18, 20, 26, 0.94);
  --panel-2: rgba(28, 31, 39, 0.96);
  --line: #4b4438;
  --green: #67c96b;
  --red: #e0554b;
  --blue: #5f9fe8;
  --purple: #b382e8;
  --shadow: 0 8px 30px rgba(0,0,0,.55);
}
* { box-sizing: border-box; }
@font-face {
  font-family: "Crimson Text";
  src: url("../data/font/CrimsonText-Regular.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Crimson Text";
  src: url("../data/font/CrimsonText-Bold.ttf") format("truetype");
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}
/* Touch UI: HUD/panel/menu text is chrome, not content. Without this, a long
   press in an Android WebView starts a text selection (highlight plus copy
   handles) over labels like HP, the region name or a chat line. Fields
   re-enable selection below so typing/editing still works normally. */
html, body {
  width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
  background: #07080b; color: var(--ink);
  font-family: "Crimson Text", Georgia, "Times New Roman", serif;
  -webkit-user-select: none; -moz-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea, select, [contenteditable="true"] {
  -webkit-user-select: text; -moz-user-select: text; user-select: text;
  -webkit-touch-callout: default;
}
button { font-family: inherit; color: var(--ink); cursor: pointer; }
#app { position: fixed; inset: 0; }
#canvas-host { position: absolute; inset: 0; }
#canvas-host canvas { display: block; width: 100% !important; height: 100% !important; image-rendering: pixelated; touch-action: none; }
#vignette { position: absolute; inset: 0; pointer-events: none; transition: background .6s; background: radial-gradient(ellipse at center, transparent 42%, rgba(0,0,0,.35) 100%); }
#vignette.cave { background: radial-gradient(circle at 50% 55%, transparent 12%, rgba(0,0,0,.82) 68%); }
#vignette.volcano { background: radial-gradient(ellipse at center, transparent 35%, rgba(80,10,0,.28) 100%); }
#vignette.snow { background: radial-gradient(ellipse at center, transparent 35%, rgba(180,220,255,.14) 100%); }
#vignette.low { background: radial-gradient(ellipse at center, transparent 20%, rgba(140,0,0,.55) 100%); }

.hidden { display: none !important; }
#loading { position: absolute; inset: 0; z-index: 80; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #080a0e; gap: 14px; }
#loading .logo { font-size: 30px; letter-spacing: 4px; color: var(--gold); text-shadow: 0 2px 0 #000; }
#loading .bar { width: min(420px, 70vw); height: 10px; border: 1px solid var(--line); background: #111; }
#loading .bar > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #8a6a2f, var(--gold)); transition: width .15s; }
#loading .hint { color: var(--muted); font-size: 12px; }

#start-screen { position: absolute; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; background: linear-gradient(rgba(5,6,9,.72), rgba(5,6,9,.92)), url('../data/webp/misc/splash_screen.webp') center/cover no-repeat; }
.start-card { width: min(760px, 92vw); padding: 28px 30px; border: 1px solid var(--line); background: rgba(12,14,19,.9); box-shadow: var(--shadow); text-align: center; }
.start-card h1 { margin: 0 0 4px; font-size: clamp(30px, 6vw, 54px); letter-spacing: 6px; color: var(--gold); text-shadow: 0 3px 0 #000; }
.start-card .sub { color: var(--muted); letter-spacing: 2px; margin-bottom: 24px; }
.start-card .actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin: 20px 0; }
.btn { border: 1px solid var(--line); background: linear-gradient(#2a2f3a, #1a1e26); padding: 10px 18px; min-width: 140px; letter-spacing: 1px; box-shadow: inset 0 1px 0 rgba(255,255,255,.08); }
.btn:hover { border-color: var(--gold); color: var(--gold); }
.btn.primary { border-color: #8b6c2c; background: linear-gradient(#5a4621, #33280f); color: #ffe6a1; }
.btn.small { min-width: 0; padding: 5px 9px; font-size: 12px; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.start-controls { margin-top: 18px; color: var(--muted); font-size: 12px; line-height: 1.7; }
.start-controls b { color: var(--ink); }
.credit { margin-top: 18px; color: #6c6557; font-size: 11px; }

#new-game { position: absolute; inset: 0; z-index: 75; display: flex; align-items: center; justify-content: center; background: rgba(4,5,8,.82); }
#delete-character { position: absolute; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; background: rgba(4,5,8,.82); }
.delete-card { text-align: left; }
.delete-card h1 { font-size: clamp(24px, 4vw, 34px); letter-spacing: 2px; margin-bottom: 10px; }
.delete-card .actions { justify-content: flex-end; }
.btn.danger { border-color: #7a2f2f; color: #e8a0a0; }
.ng-card { width: min(760px, 94vw); max-height: 92vh; overflow: auto; padding: 22px; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); }
.ng-card h2 { margin: 0 0 14px; color: var(--gold); letter-spacing: 2px; }
.field { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.field label { width: 92px; color: var(--muted); font-size: 13px; }
.field input { flex: 1; padding: 8px; background: #0d1015; border: 1px solid var(--line); color: var(--ink); font-family: inherit; }
.trait-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.trait-card { border: 1px solid var(--line); background: #151922; padding: 12px; cursor: pointer; text-align: left; }
.trait-card:hover, .trait-card.selected { border-color: var(--gold); background: #201c12; }
.trait-card b { color: var(--gold); display: block; margin-bottom: 4px; }
.trait-card span { color: var(--muted); font-size: 12px; line-height: 1.4; }
.appearance { display: flex; gap: 16px; align-items: center; margin: 12px 0; }
.appearance canvas, .appearance img { width: 108px; height: 156px; image-rendering: pixelated; border: 1px solid var(--line); background: #0b0d12; }
.appearance .opts { flex: 1; display: grid; gap: 8px; }
.appearance .opts label { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; }
.appearance select, .appearance input[type=color] { background: #0d1015; color: var(--ink); border: 1px solid var(--line); font-family: inherit; }
#error-box { position: absolute; left: 10px; bottom: 10px; z-index: 100; max-width: 70vw; padding: 10px 12px; background: #2a0d0d; border: 1px solid #a33; color: #ffd3d3; font-size: 12px; white-space: pre-wrap; display: none; }

/* HUD */
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
#hud > * { pointer-events: auto; }
.hud-left { position: absolute; left: 14px; top: 14px; display: grid; grid-template-columns: 100%; gap: 8px; width: 236px; }
.hud-left-head { display: flex; align-items: flex-start; gap: 4px; width: max-content; max-width: min(360px, 70vw); }
.hud-left.collapsed { width: max-content; }
.hud-left.collapsed > :not(.hud-left-head) { display: none; }
.hud-left.collapsed .hud-left-head .region { display: none; }
.cluster-toggle { flex: none; }
.region {
  display: inline-block;
  flex: 1 1 auto;
  min-width: 0;
  width: max-content;
  max-width: 100%;
  padding: 5px 12px;
  background: linear-gradient(180deg, rgba(28, 33, 44, .96), rgba(9, 11, 15, .96));
  border: 1px solid var(--line);
  border-left: 2px solid var(--gold);
  border-radius: 2px;
  color: var(--gold);
  font-size: 12px;
  line-height: 1.2;
  letter-spacing: 1.6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 #000;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06);
}
.status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: -4px; }
.status-row .save-status { margin-top: 0; }
.save-status { font-size: 10px; letter-spacing: 1px; color: var(--muted); text-shadow: 0 1px 0 #000; margin-top: -4px; }
.save-status.ok { color: var(--green); }
.save-status.bad { color: var(--red); }
#minimap { display: block; width: 100%; height: 100%; border: 1px solid var(--line); background: rgba(8,10,14,.78); image-rendering: pixelated; box-shadow: var(--shadow); }
.minimap-row { display: flex; align-items: flex-start; gap: 6px; }
.location-banner { width: 56px; padding: 7px 8px; display: grid; gap: 6px; background: linear-gradient(180deg, rgba(28, 33, 44, .96), rgba(9, 11, 15, .96)); border: 1px solid var(--line); border-left: 2px solid var(--gold); border-radius: 2px; box-shadow: var(--shadow); color: var(--muted); font-size: 9px; line-height: 1; letter-spacing: 1px; }
.location-banner span { display: flex; align-items: baseline; justify-content: space-between; gap: 4px; }
.location-banner b { color: var(--gold); font-size: 13px; font-weight: 600; letter-spacing: 0; }
.minimap-wrap { position: relative; width: 170px; height: 170px; }
.hud-toggle { padding: 2px 7px; border: 1px solid var(--line); background: rgba(10,12,17,.92); color: var(--gold); font: inherit; font-size: 10px; line-height: 1.4; cursor: pointer; box-shadow: var(--shadow); }
.hud-toggle:hover { border-color: var(--gold); }
.minimap-wrap > .hud-toggle, .quest-wrap > .hud-toggle { position: absolute; right: 4px; top: 4px; z-index: 2; }
.minimap-zoom { position: absolute; left: 4px; bottom: 4px; z-index: 2; display: flex; align-items: center; gap: 1px; background: rgba(10,12,17,.8); border: 1px solid var(--line); padding: 1px; }
.minimap-zoom button { width: 18px; height: 18px; padding: 0; line-height: 1; background: transparent; border: 0; color: var(--ink); font: inherit; font-size: 13px; cursor: pointer; }
.minimap-zoom button:hover { color: var(--gold); }
.minimap-zoom button:disabled { opacity: .35; cursor: default; }
.minimap-zoom span { min-width: 20px; text-align: center; font-size: 9px; color: var(--muted); }
.minimap-wrap.collapsed .minimap-zoom { display: none; }
.minimap-wrap.collapsed { width: max-content; height: auto; justify-self: start; }
.minimap-wrap.collapsed #minimap { display: none; }
.minimap-wrap.collapsed > .hud-toggle { position: static; }
.quest-wrap { position: relative; }
.quest-wrap.collapsed { width: max-content; justify-self: end; }
.quest-wrap.collapsed .quest-tracker { display: none; }
.quest-wrap.collapsed > .hud-toggle { position: static; }
.vitals { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--line); background: rgba(10,12,17,.82); box-shadow: var(--shadow); }
.bar { position: relative; height: 13px; background: #0a0c10; border: 1px solid #232833; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0; transition: width .18s; }
.bar.hp > i { background: linear-gradient(#c13c36, #7d1e1a); }
.bar.hunger > i { background: linear-gradient(#d59a3c, #8a5a1b); }
.bar.xp > i { background: linear-gradient(#4b8bd6, #244a7d); }
.bar span { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 13px; color: #fff; text-shadow: 0 1px 0 #000; }
.stat-line { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.stat-line b { color: var(--ink); }

#zoom-bar { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 24; display: flex; align-items: center; gap: 6px; padding: 4px 9px; background: rgba(10,12,17,.86); border: 1px solid var(--line); font-size: 10px; color: var(--muted); }
#zoom-bar input { width: 120px; accent-color: #c9a55a; }
#zoom-bar b { color: var(--gold); min-width: 34px; text-align: right; }
#zoom-bar button { width: 20px; height: 20px; flex: 0 0 auto; padding: 0; border: 1px solid #4b4438; background: rgba(38, 34, 26, .92); color: #e9e2cf; font-size: 14px; line-height: 1; cursor: pointer; }
#zoom-bar button:hover { border-color: #8b6c2c; }
#zoom-bar button:active { background: #c9a55a; color: #10131a; }
#zoom-bar input#tilt-input { width: 92px; }
#zoom-bar b#tilt-label { min-width: 30px; }
#menu-btn { position: absolute; right: 14px; top: 14px; z-index: 25; padding: 6px 12px; background: rgba(10,12,17,.86); border: 1px solid var(--line); color: var(--gold); font: inherit; font-size: 12px; letter-spacing: 1px; cursor: pointer; box-shadow: var(--shadow); }
#menu-btn:hover { border-color: var(--gold); }
.hud-right { position: absolute; right: 14px; top: 52px; width: 250px; display: grid; gap: 8px; }
.quest-tracker { border: 1px solid var(--line); background: rgba(10,12,17,.88); padding: 8px 10px; box-shadow: var(--shadow); }
.quest-tracker h4 { margin: 0 0 4px; color: var(--gold); font-size: 11px; letter-spacing: 1px; }
.quest-tracker .qtitle { font-size: 12px; margin-bottom: 3px; }
.quest-tracker .qdesc { color: var(--muted); font-size: 10px; line-height: 1.35; }
.quest-tracker .qgoal { margin-top: 5px; font-size: 10px; color: #c8bfa8; }
.currency { display: flex; gap: 14px; justify-content: flex-end; font-size: 12px; color: var(--gold); text-shadow: 0 1px 0 #000; }
.currency span { background: rgba(10,12,17,.72); border: 1px solid var(--line); padding: 3px 8px; }

#ability-bar { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); display: grid; grid-template-columns: repeat(10, auto); gap: 5px; padding: 5px 6px; background: rgba(10,12,17,.82); border: 1px solid var(--line); box-shadow: var(--shadow); }
.ability { width: 42px; height: 42px; border: 1px solid #343946; background: #0c0f14; position: relative; cursor: pointer; touch-action: none; }
.ability:hover { border-color: var(--gold); }
.ability.drag-over { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 8px rgba(230,184,76,.75); }
.ability img { width: 100%; height: 100%; image-rendering: pixelated; padding: 4px; -webkit-user-drag: none; user-drag: none; }
.ability .key { position: absolute; left: 2px; top: 0; font-size: 9px; color: #8f866f; }
.ability .rank { position: absolute; right: 2px; top: 0; font-size: 9px; color: #e6b84c; }
.ability .cd { position: absolute; inset: 0; background: rgba(0,0,0,.68); color: #ffd979; display: flex; align-items: center; justify-content: center; font-size: 11px; }
.ability .uses { position: absolute; left: 2px; bottom: 0; font-size: 9px; color: #a9d6a0; text-shadow: 0 1px 0 #000; pointer-events: none; }
.ability.low { border-color: #8a6a2b; }
.ability.low .uses { color: #e6b84c; }
.ability.empty { opacity: .4; }
.ability.empty::after { content: '—'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #5a5346; }
#command-line { position: absolute; left: 50%; bottom: 130px; transform: translateX(-50%); display: flex; align-items: center; gap: 4px; width: min(390px, 70vw); background: rgba(8,10,14,.94); border: 1px solid var(--gold); padding: 4px 8px; box-shadow: var(--shadow); }
#command-line .chev { color: var(--gold); }
#command-line input { flex: 1; background: transparent; border: 0; color: #e9e2cf; font: inherit; outline: none; }
#hotbar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 5px; padding: 6px; background: rgba(10,12,17,.8); border: 1px solid var(--line); box-shadow: var(--shadow); }
/* Equipment about to break: sits left of the ability + quick slot bars. */
#gear-warn { position: absolute; bottom: 14px; right: 50%; margin-right: 260px; display: flex; flex-direction: column; gap: 4px; padding: 5px; background: rgba(10,12,17,.82); border: 1px solid var(--line); box-shadow: var(--shadow); cursor: pointer; }
#gear-warn.hidden { display: none; }
#gear-warn:hover { border-color: var(--gold); }
#gear-warn .gw-title { font-size: 8px; letter-spacing: .09em; text-transform: uppercase; color: var(--muted); text-align: center; }
#gear-warn .gw-item { position: relative; width: 34px; height: 34px; border: 1px solid #343946; background: #0c0f14; }
#gear-warn .gw-item img { width: 100%; height: 100%; image-rendering: pixelated; padding: 3px; }
#gear-warn .gw-item.warn { border-color: #c9a55a; }
#gear-warn .gw-item.critical { border-color: var(--red); box-shadow: 0 0 6px rgba(224,85,75,.55); animation: gw-pulse 1.4s ease-in-out infinite; }
#gear-warn.above { bottom: 118px; margin-right: 0; transform: translateX(50%); }
#gear-warn .gw-bar { position: absolute; left: 1px; right: 1px; bottom: 1px; height: 3px; background: rgba(0,0,0,.7); }
#gear-warn .gw-bar i { display: block; height: 100%; background: #e6b84c; }
#gear-warn .gw-item.critical .gw-bar i { background: var(--red); }
@keyframes gw-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
.slot { width: 46px; height: 46px; border: 1px solid #343946; background: #0c0f14; position: relative; cursor: pointer; }
.slot:hover { border-color: var(--gold); }
.slot.drag-over { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold), 0 0 8px rgba(230,184,76,.75); }
.slot img { width: 100%; height: 100%; image-rendering: pixelated; padding: 5px; }
.slot .key { position: absolute; left: 2px; top: 0; font-size: 9px; color: #8f866f; }
.slot .qty { position: absolute; right: 2px; bottom: 0; font-size: 10px; color: #fff; text-shadow: 0 1px 0 #000; }
.slot.empty { opacity: .55; }
#action-prompt { position: absolute; left: 50%; bottom: 168px; transform: translateX(-50%); padding: 5px 12px; background: rgba(8,10,14,.82); border: 1px solid var(--line); font-size: 12px; color: #e9e2cf; white-space: nowrap; }
#chat-window { position: absolute; left: 14px; bottom: 14px; width: 360px; background: rgba(8,10,14,.78); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column; }
#chat-window.collapsed { width: auto; }
#chat-window.collapsed .chat-tab { display: none; }
#chat-window.collapsed #log, #chat-window.collapsed .chat-input-row { display: none; }
#chat-window.collapsed .chat-tabs { border-bottom: 0; }
.chat-toggle { margin-left: auto; align-self: center; }
.chat-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.chat-tab { background: transparent; border: 0; color: #8f866f; font: inherit; font-size: 10px; padding: 4px 8px; cursor: pointer; }
#log .whisper { border-left: 2px solid #b382e8; color: #e3d2ff; }
.chat-tab.on { color: var(--gold); background: rgba(201,165,90,.12); }
.chat-input-row { display: flex; border-top: 1px solid var(--line); }
.chat-input-row input { flex: 1; background: #0b0d12; border: 0; color: #e9e2cf; padding: 6px 8px; font: inherit; font-size: 11px; outline: none; }
.chat-input-row button { background: #242936; border: 0; border-left: 1px solid var(--line); color: var(--gold); padding: 4px 10px; cursor: pointer; }
#log { height: 132px; overflow-y: auto; display: flex; flex-direction: column-reverse; gap: 3px; font-size: 11px; color: #cfc6b1; text-shadow: 0 1px 0 #000; padding: 3px; }
#log div { background: rgba(8,10,14,.55); padding: 3px 7px; border-left: 2px solid #4c4435; transition: opacity .4s; }
#log div.good { border-color: var(--green); color: #c9f0c9; }
#log div.bad { border-color: var(--red); color: #ffc9c4; }
#log div.gold { border-color: var(--gold); color: #ffe2a0; }
#buffs { position: absolute; left: 50%; bottom: 200px; transform: translateX(-50%); display: flex; gap: 6px; }
.buff { border: 1px solid var(--gold); background: rgba(40,30,10,.8); color: #ffe2a0; font-size: 10px; padding: 2px 6px; }
#boss-bar { position: absolute; left: 50%; top: 52px; transform: translateX(-50%); width: min(520px, 70vw); display: none; }
#boss-bar .name { text-align: center; color: #ffb0a0; font-size: 12px; letter-spacing: 2px; text-shadow: 0 1px 0 #000; margin-bottom: 3px; }
#boss-bar .bar { height: 12px; }

#toast-layer { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); z-index: 40; display: grid; gap: 8px; pointer-events: none; }
.toast { background: rgba(12,14,19,.92); border: 1px solid var(--line); border-left: 3px solid var(--gold); padding: 7px 14px; font-size: 13px; color: var(--ink); box-shadow: var(--shadow); animation: toastIn .2s ease-out; }
.toast.good { border-left-color: var(--green); }
.toast.bad { border-left-color: var(--red); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
#banner { position: absolute; left: 50%; top: 32%; transform: translateX(-50%); z-index: 35; text-align: center; pointer-events: none; opacity: 0; transition: opacity .5s; }
#banner.on { opacity: 1; }
#banner .big { font-size: clamp(26px, 5vw, 46px); letter-spacing: 8px; color: var(--gold); text-shadow: 0 3px 0 #000, 0 0 30px rgba(230,184,76,.35); }
#banner .small { color: var(--muted); letter-spacing: 3px; font-size: 12px; margin-top: 6px; }

/* Panels */
#panel-layer { position: absolute; inset: 0; z-index: 50; display: none; align-items: center; justify-content: center; background: rgba(3,4,7,.62); }
#panel-layer.on { display: flex; }
.panel { width: min(900px, 94vw); max-height: 90vh; display: flex; flex-direction: column; border: 1px solid var(--line); background: var(--panel); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.panel-head h3 { margin: 0; color: var(--gold); letter-spacing: 2px; font-size: 15px; }
.panel-head .tabs { display: flex; gap: 4px; margin-left: 10px; }
.tab { border: 1px solid transparent; background: transparent; padding: 5px 10px; color: var(--muted); font-size: 12px; }
.tab.on { color: var(--gold); border-color: var(--line); background: #1b1b18; }
.panel-head .close { margin-left: auto; border: 1px solid var(--line); background: #1a1d24; padding: 4px 9px; }
.panel-body { padding: 14px; overflow: auto; }
.recipe, .inv-slot, .equip-slot { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
.panel-foot { padding: 8px 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; display: flex; justify-content: space-between; gap: 12px; }

.inv-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 18px; }
.inv-layout > * { min-width: 0; }
.inv-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 5px; }
.cat-row { display: flex; flex-wrap: wrap; gap: 3px; margin: 6px 0; }
.cat-btn { width: 26px; height: 26px; padding: 0; display: flex; align-items: center; justify-content: center; border: 1px solid #343946; background: #0c0f14; cursor: pointer; }
.cat-btn img { width: 20px; height: 20px; image-rendering: pixelated; pointer-events: none; }
.cat-btn .cat-glyph { color: var(--gold); font-size: 13px; line-height: 1; }
.cat-btn:hover { border-color: var(--gold); }
.cat-btn.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; background: #201c12; }
.inv-pages { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 8px; }
.inv-pages .hint { margin-left: auto; }
.inv-slot { aspect-ratio: 1; border: 1px solid #343946; background: #0c0f14; position: relative; cursor: pointer; }
.inv-slot:hover { border-color: var(--gold); }
.inv-slot img { width: 100%; height: 100%; padding: 12px; image-rendering: pixelated; }
.inv-slot .qty { position: absolute; right: 3px; bottom: 1px; font-size: 10px; color: #fff; text-shadow: 0 1px 0 #000; }
/* Tome rank: the item art is shared per ability, so the numeral is drawn by
   the UI instead of relying on a 3 px glyph baked into a 28 px icon. */
.qty.rank-badge { top: 2px; right: 3px; bottom: auto; color: var(--gold); font-size: 10px; font-weight: 700; letter-spacing: -0.5px; }
.equip-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.equip-slot { border: 1px solid var(--line); background: #10131a; padding: 5px; text-align: center; cursor: pointer; }
.equip-slot .lbl { color: var(--muted); font-size: 9px; letter-spacing: 1px; }
.equip-slot img { width: 38px; height: 38px; image-rendering: pixelated; display: block; margin: 2px auto; }
.stat-block { border: 1px solid var(--line); background: #10131a; padding: 10px; font-size: 12px; line-height: 1.7; }
.stat-block b { color: var(--gold); }
.hint { color: var(--muted); font-size: 11px; line-height: 1.5; }

.recipe-list { display: grid; gap: 6px; }
.recipe { display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; padding: 7px 9px; border: 1px solid #2b303b; background: #11151c; }
.recipe:hover { border-color: #4c5263; }
.recipe img { width: 34px; height: 34px; image-rendering: pixelated; }
.recipe .rname { font-size: 13px; }
.recipe .rneed { font-size: 11px; color: var(--muted); margin-top: 2px; }
.recipe .rneed .miss { color: #e77; }
.recipe .rstation { font-size: 10px; color: var(--purple); }
.recipe .rbtn { display: flex; gap: 5px; align-items: center; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.filter-row .btn.on { border-color: var(--gold); color: var(--gold); background: #201c12; }

.skill-group { margin-bottom: 14px; }
.skill-group h4 { margin: 0 0 6px; color: var(--gold); font-size: 12px; letter-spacing: 1px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.skill-row { display: grid; grid-template-columns: 130px 42px 1fr 42px; gap: 8px; align-items: center; font-size: 12px; padding: 2px 0; }
/* Ability rows have three cells (slot, name, cost), not the four a skill bar
   needs. Reusing the skill grid squeezed names into the 42px level column. */
.skill-row.ability-row { display: flex; gap: 10px; }
.skill-row.ability-row .ability-slot-label { flex: 0 0 130px; color: var(--muted); white-space: nowrap; }
.skill-row.ability-row .ability-name { flex: 1 1 auto; color: var(--gold); }
.skill-row.ability-row .ability-cost { flex: 0 0 auto; color: #a99f8a; font-size: 10px; white-space: nowrap; text-align: right; }
.skill-row.undiscovered { opacity: .38; }
.skill-bar { height: 7px; background: #0a0c10; border: 1px solid #232833; }
.skill-bar > i { display: block; height: 100%; background: linear-gradient(90deg, #5f9fe8, #3b6fb3); }
.skill-row .lvl { color: gold; text-align: right; }

.quest-card { border: 1px solid var(--line); background: #11151c; padding: 12px; margin-bottom: 10px; }
.quest-card h4 { margin: 0 0 4px; color: var(--gold); }
.quest-card p { margin: 0 0 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.quest-goal { font-size: 12px; color: #cfc6b1; }
.quest-goal.done { color: var(--green); }
.quest-done { opacity: .55; }

.upgrade-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; border-bottom: 1px solid #2b303b; padding: 8px 0; }
.upgrade-row .uname { color: var(--ink); }
.upgrade-row .udesc { color: var(--muted); font-size: 11px; }
.trait-pill { display: inline-block; border: 1px solid var(--gold); color: #ffe2a0; padding: 2px 8px; font-size: 11px; margin-right: 6px; }

.chest-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 4px; }
.chest-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
.chest-grid .inv-slot { width: auto; max-width: none; min-width: 0; }
.chest-grid .inv-slot img { padding: 6px; }
.panel h4.section { color: var(--gold); margin: 10px 0 8px; font-size: 12px; letter-spacing: 1px; }

#death-screen { position: absolute; inset: 0; z-index: 65; display: none; align-items: center; justify-content: center; background: radial-gradient(circle, rgba(80,0,0,.35), rgba(2,2,4,.94)); text-align: center; }
#death-screen.on { display: flex; }
#death-screen h2 { font-size: 42px; letter-spacing: 8px; color: #e0554b; text-shadow: 0 3px 0 #000; margin: 0 0 10px; }
#death-screen p { color: var(--muted); }
#death-screen .btn { margin-top: 16px; }

#tooltip { position: fixed; z-index: 70; max-width: 280px; padding: 8px 10px; background: rgba(10,12,17,.97); border: 1px solid var(--gold); color: var(--ink); font-size: 11px; line-height: 1.5; display: none; pointer-events: none; box-shadow: var(--shadow); }
#tooltip b { color: var(--gold); }

#touch-controls { position: absolute; inset: 0; z-index: 25; display: none; pointer-events: none; }
#touch-controls.on { display: block; }
#touch-controls button { touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
#touch-controls button:focus { outline: none; }
.touch-pad { position: absolute; left: 16px; bottom: 90px; width: 132px; height: 132px; pointer-events: auto; }
.touch-pad button { position: absolute; width: 42px; height: 42px; border: 1px solid #4b4438; background: rgba(20,22,28,.7); color: #e9e2cf; font-size: 15px; }
.touch-pad .up { left: 45px; top: 0; } .touch-pad .down { left: 45px; bottom: 0; } .touch-pad .left { left: 0; top: 45px; } .touch-pad .right { right: 0; top: 45px; }
/* Diagonal hints: the corners the joystick already understands. They sit in
   the same 42px boxes as the buttons, stay faint so they read as decoration,
   and never take the pointer away from the pad's drag gesture. The arrow is
   a border triangle rotated into the corner, not a glyph: the page font has
   no diagonal-arrow characters. */
.touch-pad .diag { position: absolute; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center; color: rgba(233,226,207,.45); pointer-events: none; }
.touch-pad .diag::before { content: ''; display: block; width: 0; height: 0; border-left: 6px solid transparent; border-right: 6px solid transparent; border-bottom: 11px solid currentColor; }
.touch-pad .diag.nw { left: 0; top: 0; } .touch-pad .diag.ne { right: 0; top: 0; } .touch-pad .diag.sw { left: 0; bottom: 0; } .touch-pad .diag.se { right: 0; bottom: 0; }
.touch-pad .diag.nw::before { transform: rotate(-45deg); }
.touch-pad .diag.ne::before { transform: rotate(45deg); }
.touch-pad .diag.sw::before { transform: rotate(-135deg); }
.touch-pad .diag.se::before { transform: rotate(135deg); }
/* Build confirmation on touch: a tap parks the ghost on a tile and this pair
   of round buttons asks before the item is spent. The tick and cross are drawn
   with borders and pseudo-elements; the page font ships no ✓/✕
   glyphs, so text marks would render as nothing. */
#place-confirm { position: fixed; z-index: 60; display: none; gap: 12px; transform: translate(-50%, -100%); pointer-events: auto; }
#place-confirm.on { display: flex; }
#place-confirm button { position: relative; width: 54px; height: 54px; padding: 0; border-radius: 50%; border: 2px solid var(--line); background: rgba(12,14,19,.92); box-shadow: var(--shadow); -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
#place-confirm button:focus { outline: none; }
#place-confirm-ok { border-color: var(--green); }
#place-confirm-ok::before { content: ''; position: absolute; left: 16px; top: 10px; width: 14px; height: 25px; border-right: 4px solid var(--green); border-bottom: 4px solid var(--green); transform: rotate(42deg); }
#place-confirm-cancel { border-color: var(--red); }
#place-confirm-cancel::before, #place-confirm-cancel::after { content: ''; position: absolute; left: 11px; top: 24px; width: 28px; height: 4px; border-radius: 2px; background: var(--red); }
#place-confirm-cancel::before { transform: rotate(45deg); }
#place-confirm-cancel::after { transform: rotate(-45deg); }
.touch-actions { position: absolute; right: 16px; bottom: 90px; display: grid; grid-template-columns: repeat(2, 64px); gap: 8px; justify-items: end; pointer-events: auto; }
.touch-actions button { width: 64px; height: 64px; border-radius: 50%; border: 1px solid #4b4438; background: rgba(20,22,28,.75); color: #e9e2cf; font-size: 11px; }
#touch-build { border-color: #8b6c2c; background: rgba(42,36,23,.88); color: #ffe2a0; font-size: 10px; letter-spacing: .5px; }
#touch-inv { width: 48px; height: 48px; font-size: 9px; justify-self: center; align-self: center; }

@media (max-width: 1240px) {
  /* Once the viewport is narrow enough for the chat's right edge to meet the
     centred ability/hotbar stack, lift the chat above it instead of letting
     the two overlap. */
  #chat-window { bottom: 124px; }
}
@media (max-width: 760px) {
  .hud-left { width: 194px; } .minimap-wrap { width: 132px; height: 132px; }
  .hud-right { width: 190px; }
  #chat-window { width: 250px; bottom: 240px; }
  #log { width: 250px; font-size: 10px; height: 100px; }
  .slot { width: 38px; height: 38px; }
  .ability { width: 36px; height: 36px; }
  #ability-bar { bottom: 66px; }
  #command-line { bottom: 104px; }
  #action-prompt { bottom: 142px; }
#menu-btn { top: 10px; padding: 5px 8px; font-size: 11px; }
  .hud-right { top: 44px; }
  #buffs { bottom: 172px; }
  .inv-layout { grid-template-columns: 1fr; }
  .trait-row { grid-template-columns: 1fr; }
  .panel { width: 98vw; max-height: 94vh; }
  #touch-controls.on { display: block; }
}

/* Character creation: appearance picker */
.preview-strip { display: flex; gap: 8px; align-items: flex-end; }
.preview-strip img { width: 72px; height: 104px; image-rendering: pixelated; border: 1px solid var(--line); background: #0b0d12; }
.look-strip { display: flex; gap: 4px; overflow-x: auto; padding: 3px 2px 5px; max-width: 440px; scrollbar-width: thin; }
.look-thumb { flex: 0 0 auto; width: 42px; height: 50px; padding: 0; border: 1px solid #343946; background: #0b0d12; cursor: pointer; }
.look-thumb img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; pointer-events: none; }
.look-thumb:hover { border-color: #8b6c2c; }
.look-thumb.on { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.appearance .opts { display: grid; gap: 8px; }
.app-row { display: grid; grid-template-columns: 120px 28px 32px 28px 1fr; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.app-row > span:first-child { color: var(--ink); }
.app-row .arw { width: 26px; height: 24px; border: 1px solid var(--line); background: #1a1e26; color: var(--ink); font-size: 15px; line-height: 1; }
.app-row .arw:hover { border-color: var(--gold); color: var(--gold); }
.app-row b { text-align: center; color: var(--gold); }
.swatches { display: flex; gap: 5px; align-items: center; flex-wrap: wrap; grid-column: 2 / -1; }
.swatch { width: 24px; height: 24px; border: 1px solid #5a5141; cursor: pointer; padding: 0; }
.swatch:hover { border-color: var(--gold); transform: scale(1.08); }
.app-row input[type=color] { width: 30px; height: 24px; padding: 0; border: 1px solid var(--line); background: #0d1015; }

/* Appearance rotator and gender picker */
.preview-rotator { display: flex; align-items: center; gap: 10px; }
.preview-main { display: grid; justify-items: center; gap: 4px; }
.preview-main img { width: 90px; height: 130px; image-rendering: pixelated; border: 1px solid var(--line); background: radial-gradient(circle at 50% 35%, #1b2130, #0b0d12); }
#ng-view-label { font-size: 10px; letter-spacing: 2px; color: var(--gold); }
.rotate-btn { width: 32px; height: 48px; border: 1px solid var(--line); background: #1a1e26; color: var(--ink); font-size: 22px; line-height: 1; }
.rotate-btn:hover { border-color: var(--gold); color: var(--gold); }
.preview-thumbs { display: flex; gap: 6px; margin: 8px 0 12px; flex-wrap: wrap; }
.view-thumb { display: grid; justify-items: center; gap: 2px; border: 1px solid var(--line); background: #10131a; padding: 3px 7px; color: var(--muted); font-size: 9px; letter-spacing: 1px; }
.view-thumb img { width: 32px; height: 46px; image-rendering: pixelated; }
.view-thumb.on { border-color: var(--gold); color: var(--gold); background: #201c12; }
.gender-row { grid-template-columns: 120px auto auto 1fr; }
.gender { border: 1px solid var(--line); background: #151922; color: var(--muted); padding: 4px 12px; font-size: 12px; }
.gender.on { border-color: var(--gold); color: #ffe2a0; background: #201c12; }

.target-card { border: 1px solid #6b3a38; background: rgba(20,10,12,.9); padding: 8px 10px; box-shadow: var(--shadow); }
.target-card.hidden { display: none; }
.target-card .t-head { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: #ffb0a0; }
.target-card .t-level { color: var(--gold); }
.target-card .t-stats { margin-top: 5px; color: var(--muted); font-size: 10px; letter-spacing: .5px; }
.target-card .bar { margin-top: 5px; }

/* Menu, character hub and appearance editor */
.menu-grid { display: grid; gap: 10px; max-width: 520px; }
.menu-row { display: grid; grid-template-columns: 150px 1fr 36px; align-items: center; gap: 10px; font-size: 12px; color: #c8bfa8; }
.menu-row input[type="range"] { width: 100%; accent-color: #c9a55a; }
.menu-row b { color: var(--gold); text-align: right; }
.char-nav { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--line); }
.char-nav .btn { min-width: 92px; }
.appearance-preview { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px; border: 1px solid var(--line); background: rgba(8,10,14,.5); align-self: start; }
.appearance-preview img { width: 108px; height: auto; image-rendering: pixelated; }
/* The 3D portrait: the canvas is owned by ML.PlayerPreview and re-attached to
   this box after each panel refresh. */
.appearance-3d { width: 260px; height: 340px; }
.appearance-3d canvas { display: block; width: 100% !important; height: 100% !important; }
/* The live portrait's canvas never moves in the DOM (that loses its WebGL
   context); this overlay is positioned over the panel's preview box instead. */
.appearance-3d-live { position: fixed; z-index: 60; pointer-events: none; display: none; }
.appearance-3d-live canvas { display: block; width: 100% !important; height: 100% !important; }

#challenge-modal { position: absolute; inset: 0; z-index: 80; display: flex; align-items: center; justify-content: center; background: rgba(4,6,9,.72); }
#challenge-modal.hidden { display: none; }
.challenge-card { width: min(430px, 92vw); background: #10141b; border: 1px solid var(--gold); box-shadow: var(--shadow); padding: 22px; }
.challenge-card h2 { margin: 0 0 6px; color: var(--gold); font-size: 16px; letter-spacing: 2px; }
.challenge-card .row { display: flex; gap: 8px; margin-top: 10px; }
.challenge-card input { flex: 1; background: #0b0d12; border: 1px solid #4b4438; color: #e9e2cf; padding: 9px; font: inherit; }
.challenge-q { font-size: 24px; color: #ffe2a0; margin: 10px 0; letter-spacing: 2px; }
.challenge-msg { margin-top: 8px; font-size: 12px; color: #ffc9c4; min-height: 16px; }

#item-menu, #ability-menu { position: fixed; z-index: 65; min-width: 140px; background: rgba(10,12,17,.97); border: 1px solid var(--gold); box-shadow: var(--shadow); padding: 4px; display: flex; flex-direction: column; gap: 2px; }
#item-menu.hidden, #ability-menu.hidden { display: none; }
#item-menu .item-menu-title, #ability-menu .item-menu-title { padding: 4px 6px; color: var(--gold); font-size: 11px; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
/* The chest hold menu repeats the tooltip so a long press still reveals the
   item's stats; keep it compact enough to leave the action buttons on screen. */
#item-menu .item-menu-tip { max-width: 240px; max-height: min(45vh, 220px); overflow-y: auto; padding: 2px 6px 6px; color: var(--muted); font-size: 11px; line-height: 1.45; border-bottom: 1px solid var(--line); margin-bottom: 2px; }
#drag-ghost { position: fixed; z-index: 70; pointer-events: none; display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: rgba(10,12,17,.94); border: 1px solid var(--gold); color: var(--ink); font-size: 11px; box-shadow: var(--shadow); opacity: .9; }
#drag-ghost.hidden { display: none; }
#drag-ghost img { width: 24px; height: 24px; image-rendering: pixelated; }
#item-menu button { text-align: left; padding: 7px 8px; background: transparent; border: 0; color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; }
#item-menu button:hover { background: rgba(230,184,76,.14); color: var(--gold); }
#drop-amount-modal, #load-tower-modal { position: fixed; inset: 0; z-index: 90; display: flex; align-items: center; justify-content: center; background: rgba(4,6,9,.62); }
#drop-amount-modal.hidden, #load-tower-modal.hidden { display: none; }
.drop-amount-card, .load-tower-card { width: min(360px, 90vw); background: #10141b; border: 1px solid var(--gold); box-shadow: var(--shadow); padding: 18px; }
.drop-amount-card h3, .load-tower-card h3 { margin: 0 0 4px; color: var(--gold); font-size: 15px; letter-spacing: 1px; }
.drop-amount-card .muted, .load-tower-card .muted { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.drop-amount-card input, .load-tower-card input { width: 100%; background: #0b0d12; border: 1px solid var(--line); color: var(--ink); padding: 9px; font: inherit; font-size: 14px; }
.drop-amount-card .row, .load-tower-card .row { display: flex; gap: 8px; margin-top: 10px; }
.drop-amount-card .row .btn, .load-tower-card .row .btn { flex: 1; min-width: 0; padding: 8px 6px; }
#load-tower-demolish-row .btn { flex: 0 0 auto; min-width: 0; margin-left: auto; }
#ability-menu button.ability-option { display: flex; align-items: center; gap: 8px; text-align: left; padding: 6px 8px; background: transparent; border: 0; color: var(--ink); font: inherit; font-size: 12px; cursor: pointer; }
#ability-menu button.ability-option:hover { background: rgba(230,184,76,.14); color: var(--gold); }
#ability-menu button.ability-option img { width: 24px; height: 24px; image-rendering: pixelated; flex: none; }
#ability-menu button.ability-option span { flex: 1; white-space: nowrap; }
#ability-menu button.ability-option small { color: var(--muted); font-size: 10px; white-space: nowrap; }
#ability-menu .ability-note { padding: 7px 8px; color: var(--muted); font-size: 11px; }

#player-menu { position: absolute; z-index: 60; min-width: 160px; background: rgba(10,12,17,.97); border: 1px solid var(--gold); box-shadow: var(--shadow); padding: 4px; }
#player-menu.hidden { display: none; }
#player-menu .pm-name { padding: 5px 8px; color: var(--gold); border-bottom: 1px solid var(--line); font-size: 12px; }
#player-menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; color: #e9e2cf; padding: 7px 9px; font: inherit; font-size: 12px; cursor: pointer; }
#player-menu button:hover { background: rgba(201,165,90,.15); }
#player-menu.player-menu-modal { left: 50%; top: 50%; transform: translate(-50%, -50%); min-width: 220px; z-index: 90; }
#player-menu.player-menu-modal button { padding: 14px 16px; font-size: 15px; }

#action-buttons { position: absolute; right: 16px; bottom: 18px; display: flex; gap: 10px; z-index: 26; }
#action-buttons button { width: 124px; height: 124px; border-radius: 50%; border: 2px solid #8b6c2c; background: rgba(24,29,39,.92); color: #ffe2a0; font: inherit; font-size: 34px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; box-shadow: var(--shadow); }
#action-buttons button span { font-size: 13px; color: #cfc6b1; }
#action-buttons button:hover { border-color: var(--gold); background: #2a2417; }
@media (max-width: 760px) { #action-buttons button { width: 88px; height: 88px; font-size: 26px; } }

#presence-buttons { position: absolute; right: 278px; top: 52px; z-index: 24; display: grid; gap: 6px; }
#presence-buttons button { padding: 6px 10px; background: rgba(10,12,17,.86); border: 1px solid var(--line); color: var(--gold); font: inherit; font-size: 11px; letter-spacing: 1px; cursor: pointer; box-shadow: var(--shadow); }
#presence-buttons button:hover { border-color: var(--gold); background: #2a2417; }
#presence-buttons #pvp-btn.off { color: #ff9c92; border-color: #7d3a34; }
#presence-buttons #auction-btn.pending { color: #ffe2a0; border-color: var(--gold); box-shadow: var(--shadow), inset 0 0 0 1px var(--gold); }
#chat-chip { display: none; }
#presence-buttons #chat-chip.on { color: #ffe2a0; border-color: var(--gold); background: #2a2417; }
@media (max-width: 760px) { #presence-buttons { right: 214px; top: 44px; } #presence-buttons button { font-size: 10px; padding: 5px 7px; } }

#announcement { position: absolute; left: 50%; top: 16%; transform: translateX(-50%); z-index: 60; max-width: 82vw; padding: 14px 28px; background: rgba(24,8,8,.9); border: 2px solid #c0504a; color: #ffe2a0; font-size: 30px; font-weight: bold; letter-spacing: 1px; text-align: center; text-shadow: 0 2px 0 #000, 0 0 18px #c0504a; box-shadow: 0 0 34px rgba(192,80,74,.65); pointer-events: none; opacity: 0; transition: opacity .25s; }
#announcement.on { opacity: 1; }
#announcement.hidden { display: none; }
@media (max-width: 760px) { #announcement { font-size: 20px; padding: 10px 16px; } }

@media (pointer: coarse) {
  #action-buttons { display: none; }
}

@media (pointer: coarse) {
  .inv-grid { grid-template-columns: repeat(auto-fill, 52px); }
  .inv-slot { width: 52px; max-width: 52px; }
  .inv-slot img { padding: 8px; }
  .equip-slot img { width: 32px; height: 32px; }
}

@media (max-height: 560px) {
  .minimap-wrap { width: 112px; height: 112px; }
  .hud-left { width: 174px; }
  .hud-right { width: 180px; }
  .quest-tracker { padding: 6px 8px; }
  .quest-tracker h4 { font-size: 10px; margin-bottom: 3px; }
  .quest-tracker .qtitle { font-size: 11px; margin-bottom: 2px; }
  .quest-tracker .qdesc { font-size: 9px; line-height: 1.3; max-height: 24px; overflow: hidden; }
  .quest-tracker .qgoal { font-size: 9.5px; margin-top: 4px; }
  #chat-window { width: 220px; }
  #log { width: 220px; height: 72px; font-size: 10px; }
  .touch-pad { left: 12px; bottom: 68px; width: 120px; height: 120px; }
  .touch-pad button { width: 38px; height: 38px; }
  .touch-pad .diag { width: 38px; height: 38px; }
  .touch-pad .up { left: 41px; } .touch-pad .down { left: 41px; } .touch-pad .left { top: 41px; } .touch-pad .right { top: 41px; }
  .touch-actions { right: 12px; bottom: 68px; grid-template-columns: repeat(2, 54px); gap: 6px; }
  .touch-actions button { width: 54px; height: 54px; font-size: 10px; }
}

@media (max-height: 560px) {
  .inv-grid { grid-template-columns: repeat(auto-fill, 52px); }
  .inv-slot { width: 52px; max-width: 52px; }
  .inv-slot img { padding: 8px; }
  .equip-slot img { width: 32px; height: 32px; }
}

.save-status.latency {
  --ping: #c9a55a;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: max-content;
  margin-top: 0;
  padding: 4px 10px 4px 9px;
  background: linear-gradient(180deg, rgba(24, 29, 39, .95), rgba(9, 11, 15, .95));
  border: 1px solid var(--line);
  border-left: 2px solid var(--ping);
  border-radius: 2px;
  color: var(--gold);
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 1.2px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 0 #000;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06);
  transition: border-color .2s, box-shadow .2s;
}
.save-status.latency::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ping);
  box-shadow: 0 0 7px var(--ping);
}
.save-status.latency.ok { --ping: var(--green); border-color: rgba(103, 201, 107, .32); }
.save-status.latency.bad { --ping: var(--red); border-color: rgba(224, 85, 75, .45); box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, .06), 0 0 12px rgba(224, 85, 75, .18); }
.save-status.latency.bad::before { animation: pingPulse 1.1s ease-in-out infinite; }
@keyframes pingPulse {
  50% { opacity: .35; box-shadow: 0 0 12px var(--red); }
}
@media (prefers-reduced-motion: reduce) {
  .save-status.latency.bad::before { animation: none; }
}

/* Touch layout: the phone HUD is tighter, the d-pad owns the bottom-left and
   the chat chip lives under PvP. Keep this block last so it wins over the
   narrow/short-screen rules above. */
@media (pointer: coarse) {
  /* 6px HUD text was half the desktop size and unreadable on a 5-6 inch
     phone; these sizes keep the same boxes but make the numbers legible. */
  .region { font-size: 8px; letter-spacing: .5px; }
  .save-status, .save-status.latency { font-size: 8px; }
  .location-banner { width: 52px; padding: 4px 5px; font-size: 8px; }
  .location-banner b { font-size: 10px; }
  .bar { height: 12px; }
  .bar span { font-size: 8px; line-height: 12px; }
  .stat-line { font-size: 9px; }
  .quest-tracker h4 { font-size: 8px; }
  .quest-tracker .qtitle { font-size: 9px; }
  .quest-tracker .qdesc, .quest-tracker .qgoal { font-size: 8px; }
  .currency { font-size: 9px; }
  .chat-tab { font-size: 8px; }
  .chat-input-row input { font-size: 9px; }
  #log { font-size: 8px; }
  #presence-buttons button { font-size: 8px; }
  .hud-toggle { font-size: 8px; }
  .slot .key, .ability .key, .ability .rank, .ability .uses { font-size: 6px; }
  .minimap-zoom button { width: 14px; height: 14px; font-size: 10px; }
  .minimap-zoom span { min-width: 15px; font-size: 6px; }
  .slot .qty { font-size: 6px; }
  #boss-bar .name { font-size: 8px; }
  #action-prompt { font-size: 9px; }
  #menu-btn { font-size: 9px; }
  /* The zoom bar is the one HUD control a thumb has to hit mid-fight, so it
     keeps readable labels and 28px buttons instead of the 6px HUD text. */
  #zoom-bar { top: 8px; gap: 7px; padding: 5px 9px; font-size: 9px; }
  #zoom-bar b { min-width: 38px; font-size: 10px; }
  #zoom-bar button { width: 28px; height: 28px; font-size: 18px; }
  #zoom-bar input { width: 104px; height: 24px; }
  #zoom-bar input#tilt-input { width: 84px; }
  #zoom-bar b#tilt-label { min-width: 32px; }
  #announcement { font-size: 10px; }
  /* The zone banner was authored for a desktop window: at 46px with 8px
     letter-spacing it spans the whole phone screen for 2.4s. */
  #banner .big { font-size: 22px; letter-spacing: 3px; }
  #banner .small { font-size: 9px; letter-spacing: 2px; }

  /* Character HUD: compact, collapsible, no minimap. */
  .hud-left { width: 190px; gap: 6px; }
  .hud-left .vitals { padding: 6px; gap: 3px; }

  /* The map moved into the right column. Keep the column clear of the touch
     actions: the target card takes over the quest tracker's slot while a
     target is live, and the currency sits under the character HUD. */
  #target-card { position: absolute; left: 0; right: 0; top: 0; z-index: 2; }
  #target-card:not(.hidden) ~ .quest-wrap { visibility: hidden; }
  .hud-right .currency { position: fixed; left: 14px; top: 182px; right: auto; justify-content: flex-start; gap: 6px; font-size: 9px; }
  .touch-actions { right: 12px; bottom: 14px; }

  /* Minimap now lives under the quest tracker; shrink it when a target card
     is visible so the column still fits above the hotbar. */
  .minimap-wrap { width: 104px; height: 104px; }
  .minimap-row { gap: 4px; }
  #target-card:not(.hidden) ~ .minimap-row .minimap-wrap:not(.collapsed) { width: 96px; height: 96px; }

  /* Movement pad: bottom-left corner, clear of the centred hotbar. */
  .touch-pad { left: 8px; bottom: 14px; width: 120px; height: 120px; }
  .touch-pad button { width: 38px; height: 38px; }
  .touch-pad .diag { width: 38px; height: 38px; }
  .touch-pad .up, .touch-pad .down { left: 41px; }
  .touch-pad .left, .touch-pad .right { top: 41px; }
  .slot { width: 36px; height: 36px; }

  /* Chat chip under PvP; the window opens centred above the ability/hotbar
     stack, clear of the d-pad and the touch action buttons. */
  #chat-chip { display: block; }
  #chat-window.collapsed { display: none; }
  #chat-window { left: 50%; right: auto; top: auto; bottom: 156px; transform: translateX(-50%); width: min(400px, 52vw); }
  #log { width: auto; }

  /* Twenty ability slots in two rows of ten must fit a phone: shrink the
     slots and gaps so the bar is about 340px wide. */
  #ability-bar { gap: 3px; padding: 4px; bottom: 66px; }
  .ability { width: 30px; height: 30px; }
  .ability img { padding: 2px; }
  .ability .key { font-size: 5px; }
}

/* Accessibility: a larger text mode for the dense panels. Only type sizes
   grow; no layout box changes, so nothing can overflow the screen. */
body.text-large .panel-body { font-size: 14px; }
body.text-large .panel .hint,
body.text-large .menu-row span,
body.text-large .stat-line { font-size: 13.5px; }
body.text-large .btn.small { font-size: 13px; padding: 7px 11px; }
body.text-large .inv-slot { font-size: 12px; }

/* First-session tips: one dismissible card over the world, shown once per
   browser. */
#first-steps { position: fixed; inset: 0; z-index: 400; display: grid; place-items: center; background: rgba(4, 6, 9, .55); }
#first-steps .fs-card { width: min(420px, 90vw); padding: 18px 20px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
#first-steps h3 { margin: 0 0 10px; color: var(--gold); letter-spacing: 2px; font-size: 15px; }
#first-steps ol { margin: 0 0 14px; padding-left: 20px; color: var(--ink); font-size: 12.5px; line-height: 1.7; }
#first-steps b { color: var(--gold); }
