:root {
  --paper: #f3e7cf;
  --paper-dark: #e4d2ad;
  --ink: #2a2118;
  --ink-soft: #5b4a38;
  --cinnabar: #b3261e;
  --cinnabar-dark: #7e1812;
  --jade: #2f6b5a;
  --gold: #c9a24a;
  --serif: 'Noto Serif TC', 'Songti TC', 'PMingLiU', Georgia, serif;
  --brush: 'LXGW WenKai TC', 'DFKai-SB', 'BiauKai', 'KaiTi', var(--serif);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1b1510; font-family: var(--serif); color: var(--ink); }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
html, body { overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, textarea { -webkit-user-select: text; user-select: text; }
.hidden { display: none !important; }

/* ---------- screens (loading / creation) ---------- */
.screen {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 20;
  background: radial-gradient(ellipse at center, rgba(40, 28, 18, 0.35), rgba(15, 10, 6, 0.85));
  /* no backdrop-filter here: blurring the live 3D canvas every frame makes the background flash on some GPUs */
  padding: 16px;
}
.scroll {
  position: relative; width: min(460px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 34px 36px 30px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.25), rgba(0, 0, 0, 0.03)),
    repeating-linear-gradient(90deg, rgba(120, 90, 50, 0.035) 0 2px, transparent 2px 7px),
    var(--paper);
  border-top: 14px solid #5a3a22;
  border-bottom: 14px solid #5a3a22;
  border-radius: 4px;
  box-shadow: 0 0 0 1px #3a2412, 0 24px 60px rgba(0, 0, 0, 0.6), inset 0 0 60px rgba(140, 100, 50, 0.25);
  text-align: center;
}
.scroll.small { width: min(340px, 100%); }
.seal {
  position: absolute; top: 18px; right: 20px; width: 40px; height: 40px;
  display: grid; place-items: center; color: #fbe9d7; background: var(--cinnabar);
  font-family: var(--brush); font-size: 26px; border-radius: 4px; transform: rotate(6deg);
  box-shadow: inset 0 0 0 2px rgba(255, 230, 210, 0.5);
}
.brush { font-family: var(--brush); font-weight: 400; font-size: 48px; margin: 0 0 18px; letter-spacing: 6px; color: var(--ink); }
html[lang='en'] .brush { font-size: 27px; letter-spacing: 0; padding: 8px 36px 0; }
#loading-text { color: var(--ink-soft); font-size: 14px; }

form { text-align: left; }
.field { display: block; margin-bottom: 18px; }
.lbl { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
input#cf-name, input.text-in {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 16px; color: var(--ink);
  background: rgba(255, 252, 244, 0.7); border: 1px solid #b59b72; border-radius: 3px; outline: none;
}
input#cf-name:focus, input.text-in:focus { border-color: var(--cinnabar); box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.15); }
.hint { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 5px; }
.hint.ok { color: var(--jade); }
.hint.bad { color: var(--cinnabar); }

.choice { display: flex; gap: 10px; }
.choice button {
  flex: 1; padding: 10px; font: inherit; font-size: 15px; cursor: pointer; color: var(--ink);
  background: rgba(255, 252, 244, 0.6); border: 1px solid #b59b72; border-radius: 3px;
}
.choice button.sel { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.avatar-row { display: flex; gap: 16px; align-items: center; }
#cf-avatar, .avatar-preview {
  width: 96px; height: 96px; border-radius: 50%; object-fit: cover; flex: none;
  border: 3px solid var(--gold); box-shadow: 0 0 0 2px var(--ink), 0 4px 12px rgba(0, 0, 0, 0.25); background: #ddd;
}
.avatar-btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.btn { display: inline-block; font: inherit; font-size: 14px; cursor: pointer; border-radius: 3px; padding: 8px 14px; text-align: center; }
.btn.ghost { background: transparent; border: 1px solid var(--ink-soft); color: var(--ink); }
.btn.ghost:hover { background: rgba(0, 0, 0, 0.05); }
.btn.primary {
  width: 100%; padding: 13px; font-size: 18px; letter-spacing: 2px; color: #fff3e6; border: none;
  background: linear-gradient(var(--cinnabar), var(--cinnabar-dark));
  box-shadow: 0 3px 0 #4f0e0a, 0 6px 14px rgba(0, 0, 0, 0.3);
}
.btn.primary:disabled { opacity: 0.55; cursor: wait; }
.error { color: var(--cinnabar); min-height: 1.2em; font-size: 13px; margin: 0 0 10px; }
.btn.wide { width: 100%; padding: 11px; margin-top: 6px; }

/* ---------- sign in ---------- */
#auth-mode { margin-bottom: 18px; }
.field.hidden { display: none; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-soft); margin: -6px 0 10px; cursor: pointer; }
.account-line { margin: -10px 0 0; font-size: 13px; color: var(--ink-soft); }
.account-line b { color: var(--ink); }
.link { border: none; background: none; padding: 0 0 0 8px; font: inherit; font-size: 13px; color: var(--cinnabar); cursor: pointer; text-decoration: underline; }
#select-empty { margin: 16px 0 4px; }

/* ---------- character select ---------- */
#select-list { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 8px; }
.char-card {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 14px; font: inherit; color: var(--ink);
  text-align: left; cursor: pointer; background: rgba(255, 252, 244, 0.6); border: 1px solid #b59b72;
  border-left: 4px solid var(--cinnabar); border-radius: 36px 4px 4px 36px; transition: background 0.15s, transform 0.15s;
}
.char-card:hover, .char-card:focus-visible { background: rgba(255, 246, 225, 0.95); transform: translateX(3px); outline: none; }
.char-card:disabled { opacity: 0.6; cursor: wait; }
.char-card img { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); flex: none; }
.char-card .cc-name { font-weight: 700; font-size: 18px; }
.char-card .cc-sub { font-size: 12px; color: var(--ink-soft); }
.char-card .cc-go { margin-left: auto; color: var(--cinnabar); font-size: 15px; white-space: nowrap; }

.card-btns { display: flex; flex-direction: column; gap: 6px; margin-left: 4px; }
#hud-switch, .card-btns .lang-btn {
  padding: 0; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; font: inherit; font-size: 14px;
  color: var(--paper); background: var(--ink); border: 1px solid var(--gold);
}
#hud-switch:hover, .lang-btn:hover { background: var(--cinnabar) !important; }
.card-btns .lang-btn { font-size: 12px; }
/* on the loading, sign-in, select and create screens the language button sits in the corner */
#lang-btn {
  display: none; position: fixed; top: 14px; right: 16px; z-index: 25; padding: 7px 14px; font: inherit; font-size: 14px; cursor: pointer;
  color: var(--paper); background: rgba(30, 22, 15, 0.8); border: 1px solid var(--gold); border-radius: 3px;
}
body:has(.screen:not(.hidden)) #lang-btn { display: block; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }

#profile-card {
  position: absolute; top: 14px; left: 14px; display: flex; gap: 10px; align-items: center;
  padding: 8px 16px 8px 8px; background: rgba(243, 231, 207, 0.92); border: 1px solid #5a3a22;
  border-left: 4px solid var(--cinnabar); border-radius: 40px 6px 6px 40px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
}
#hud-avatar:hover { border-color: var(--cinnabar); }
#portrait { width: min(340px, calc(100vw - 24px)); }
#portrait .error { margin: 8px 0 6px; }
#hud-avatar { cursor: pointer; width: 52px; height: 52px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); }
#hud-name { font-weight: 700; font-size: 17px; }
#hud-place { font-size: 12px; color: var(--ink-soft); }
#hud-level { margin-left: 8px; padding: 0 7px; border-radius: 9px; background: var(--cinnabar); color: #fbe9d7; font-size: 12px; font-weight: 700; vertical-align: 2px; }
.plate .tag .lv:not(:empty) { margin-left: 5px; font-size: 0.8em; color: #ffd76a; }
#hud-hp { display: flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--cinnabar-dark); }
#hud-exp { display: flex; align-items: center; gap: 6px; margin-top: 3px; font-size: 12px; color: #7a5a1c; }
#hud-hp .track, #hud-exp .track { position: relative; width: 130px; height: 14px; border-radius: 7px; overflow: hidden; background: rgba(60, 30, 20, 0.75); box-shadow: 0 0 0 1px #5a3a22; }
#hud-exp i { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(#e0b04c, #b07d1e); transition: width 0.3s; }
#hud-hp i { position: absolute; inset: 0 auto 0 0; width: 100%; background: linear-gradient(#57a583, var(--jade)); transition: width 0.2s; }
#hud-hp b, #hud-exp b { position: absolute; inset: 0; font-size: 10px; line-height: 14px; text-align: center; color: #fff; text-shadow: 0 1px 1px #000; }
#hud-hp.low i { background: linear-gradient(#e0503f, var(--cinnabar)); }
#hud-hp.low .track { animation: hp-low 0.9s infinite alternate; }
@keyframes hp-low { to { box-shadow: 0 0 0 1px #5a3a22, 0 0 9px 2px rgba(224, 60, 40, 0.8); } }
/* red edges when a claw lands */
#hurt { position: fixed; inset: 0; pointer-events: none; opacity: 0; background: radial-gradient(ellipse at center, transparent 45%, rgba(170, 10, 10, 0.6)); }
#hurt.on { animation: hurt 0.5s ease-out; }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }
.plate .hp-bar { width: 74px; height: 6px; margin: 3px auto 0; border-radius: 3px; overflow: hidden; background: rgba(0, 0, 0, 0.75); box-shadow: 0 0 0 1px rgba(255, 120, 100, 0.5); }
.plate .hp-bar i { display: block; width: 100%; height: 100%; background: linear-gradient(#ff7a66, #c4281c); transition: width 0.15s; }
#hud-coins { display: flex; align-items: center; gap: 5px; margin-top: 2px; font-size: 13px; color: #7a5a1c; }
#hud-coins b { font-size: 15px; color: #5c3f0e; transition: color 0.3s; }
#hud-coins.gain b { color: var(--cinnabar); }
/* a square-holed copper cash coin */
.coin {
  width: 14px; height: 14px; border-radius: 50%; flex: none; position: relative;
  background: radial-gradient(circle at 35% 35%, #f6d77a, #c8952e 60%, #8a5f16);
  box-shadow: 0 0 0 1px #6b4a12;
}
.coin::after { content: ''; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; transform: translate(-50%, -50%); background: rgba(243, 231, 207, 0.95); box-shadow: 0 0 0 1px #6b4a12; }

/* "+12 文" rising from a slain jiangshi */
.coin-pop {
  position: absolute; left: 0; top: 0; display: flex; align-items: center; gap: 5px; white-space: nowrap;
  font-weight: 700; font-size: 20px; color: #ffd76a; letter-spacing: 1px;
  text-shadow: 0 0 6px rgba(120, 60, 0, 0.9), 0 2px 0 #5a3608;
  will-change: transform, opacity;
}
.coin-pop .coin { width: 18px; height: 18px; }
.coin-pop.dmg { color: #fff; text-shadow: 0 0 5px rgba(0, 0, 0, 0.9), 0 2px 0 #222; }
.coin-pop.hurt { color: #ff5a48; text-shadow: 0 0 5px rgba(0, 0, 0, 0.9), 0 2px 0 #400; }
.coin-pop.levelup { font-size: 26px; color: #fff0b0; }
.coin-pop.loot { color: #fff3dc; font-size: 17px; }
.coin-pop .item-icon {
  display: grid; place-items: center; width: 22px; height: 22px; border-radius: 3px; color: #fff3e6;
  font-family: var(--brush); font-size: 15px; text-shadow: none; box-shadow: 0 0 0 1px rgba(255, 240, 200, 0.6), 0 0 8px rgba(255, 210, 120, 0.7);
}

#online-count {
  position: absolute; top: 18px; right: 16px; padding: 6px 12px; font-size: 13px;
  background: rgba(30, 22, 15, 0.7); color: var(--paper); border: 1px solid rgba(201, 162, 74, 0.6); border-radius: 3px;
}

#chat {
  position: absolute; left: 14px; bottom: 14px; width: min(400px, calc(100vw - 28px));
  background: rgba(24, 18, 12, 0.62); border: 1px solid rgba(201, 162, 74, 0.45); border-radius: 4px;
  color: #f1e6cf; font-size: 14px;
}
#chat-log { height: 180px; overflow-y: auto; padding: 8px 10px; line-height: 1.45; scrollbar-width: thin; }
#chat-log .msg { margin: 2px 0; word-wrap: break-word; }
#chat-log .who { color: #f0c46a; font-weight: 600; cursor: default; }
#chat-log .who.me { color: #8fd3b6; }
#chat-log .who.npc { color: #e59a8f; }
#chat-log .sys { color: #b8a98c; font-style: italic; }
#chat-log .time { color: #8c7c62; font-size: 11px; margin-right: 4px; }
#chat-input {
  width: 100%; padding: 9px 10px; border: none; border-top: 1px solid rgba(201, 162, 74, 0.35); outline: none;
  background: rgba(0, 0, 0, 0.35); color: #fff7e6; font: inherit; font-size: 14px; border-radius: 0 0 4px 4px;
}
#chat-input::placeholder { color: #9d8d72; }

#help {
  position: absolute; right: 16px; bottom: 14px; font-size: 12px; color: rgba(255, 245, 225, 0.85);
  background: rgba(24, 18, 12, 0.5); padding: 6px 10px; border-radius: 3px; pointer-events: none;
}
#toast {
  position: absolute; top: 18%; left: 50%; transform: translateX(-50%); padding: 12px 26px;
  background: rgba(243, 231, 207, 0.95); border: 1px solid #5a3a22; border-top: 3px solid var(--cinnabar);
  font-size: 16px; opacity: 0; transition: opacity 0.4s; pointer-events: none; text-align: center; max-width: 80vw;
  white-space: pre-line;
}
#toast.show { opacity: 1; }

/* ---------- land deeds ---------- */
#bag-btn {
  position: absolute; top: 54px; right: 14px; display: flex; align-items: center; gap: 6px; cursor: pointer;
  padding: 5px 12px 5px 6px; font: inherit; font-size: 13px; color: var(--ink);
  background: rgba(243, 231, 207, 0.92); border: 1px solid #5a3a22; border-radius: 3px;
}
#bag-btn::before {
  content: '囊'; display: grid; place-items: center; width: 22px; height: 22px; border-radius: 3px;
  background: #6b4a2f; color: #fff3e6; font-family: var(--brush); font-size: 15px;
}
#bag-btn b { padding: 0 6px; border-radius: 9px; background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 600; }
#bag-btn:hover { background: #fff6e2; }
body.in-maze #bag-btn { top: 268px; } /* below the maze map */

#gear-slots {
  display: flex; align-items: center; gap: 12px; padding: 8px 10px; margin-bottom: 12px;
  background: rgba(255, 252, 244, 0.65); border: 1px solid #c4ab80; border-left: 4px solid var(--gold); border-radius: 3px;
}
#gear-slots .tile { flex: none; width: 46px; height: 46px; display: grid; place-items: center; border-radius: 4px; color: #fff3e6; font-family: var(--brush); font-size: 24px; }
#gear-slots .tile.none { color: #8a7350; border: 1px dashed #b59b72; }
#gear-slots .slot-name { font-size: 12px; color: var(--ink-soft); }
#gear-slots .nm { font-weight: 700; }
#gear-slots button { margin-left: auto; padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; border-radius: 3px; border: 1px solid var(--ink-soft); background: transparent; color: var(--ink); }
#bag-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
#bag-grid .slot {
  position: relative; aspect-ratio: 1; padding: 4px; cursor: pointer;
  background: rgba(90, 58, 34, 0.12); border: 1px solid #b59b72; border-radius: 4px;
}
#bag-grid .slot.empty { cursor: default; background: rgba(90, 58, 34, 0.06); border-style: dashed; }
#bag-grid .slot.sel { outline: 3px solid var(--cinnabar); outline-offset: -1px; }
#bag-grid .slot:not(.empty):hover { background: rgba(255, 246, 225, 0.9); }
#bag-grid .tile {
  display: grid; place-items: center; width: 100%; height: 100%; border-radius: 3px; color: #fff3e6;
  font-family: var(--brush); font-size: 24px; box-shadow: inset 0 0 0 2px rgba(255, 240, 200, 0.35), 0 1px 2px rgba(0, 0, 0, 0.3);
}
#bag-grid .n {
  position: absolute; right: 3px; bottom: 1px; font-size: 12px; font-weight: 700; color: #fff;
  text-shadow: 0 0 3px #000, 0 0 2px #000;
}
#bag-detail { min-height: 92px; margin-top: 12px; padding-top: 10px; border-top: 1px solid #c4ab80; }
#bag-detail .nm { font-weight: 700; font-size: 16px; }
#bag-detail .ds { font-size: 13px; color: var(--ink-soft); margin: 3px 0 10px; }
#bag-detail .acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
#bag-detail button {
  padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; border-radius: 3px;
  border: 1px solid var(--ink-soft); background: transparent; color: var(--ink);
}
#bag-detail button.go { border: none; color: #fff; background: linear-gradient(#3f8a6f, var(--jade)); }
#bag-detail button.go:disabled { opacity: 0.45; cursor: not-allowed; }
#bag-detail button.drop[data-armed] { background: var(--cinnabar); color: #fff; border-color: var(--cinnabar); }
#bag-detail .why { font-size: 12px; color: var(--cinnabar); }
#bag-detail .hint { margin: 0; }

body.in-maze #shop, body.in-home #shop, body.in-maze #pawn, body.in-home #pawn, body.in-maze #smith, body.in-home #smith { display: none; }
.pawn-row .seal { color: #fff; }
.deed-row .btns { flex: none; display: flex; flex-direction: column; gap: 4px; }
.pawn-row .btns button, .deed-row .btns .sell { max-width: 128px; padding: 5px 10px; font-size: 13px; background: linear-gradient(#3f8a6f, var(--jade)); }

/* ---------- house access ---------- */
#access-btn {
  position: absolute; top: 92px; right: 14px; padding: 6px 12px; cursor: pointer; font: inherit; font-size: 13px;
  color: #fff3e6; background: linear-gradient(var(--jade), #1f4a3e); border: 1px solid #7fc7a8; border-radius: 3px;
}
#access-btn:hover { filter: brightness(1.15); }
#access .choice { margin: 6px 0 14px; }
#access .choice button { font-size: 13px; padding: 9px 6px; }
#guest-box .lbl { font-weight: 700; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
#guest-box .lbl .hint { display: inline; margin: 0; font-weight: 400; }
#guest-box.off { opacity: 0.55; }
#guest-list { list-style: none; margin: 8px 0; padding: 0; max-height: 180px; overflow-y: auto; }
#guest-list:empty::before { content: 'No one yet.'; display: block; padding: 6px 0; color: var(--ink-soft); font-style: italic; font-size: 13px; }
#guest-list li {
  display: flex; align-items: center; justify-content: space-between; padding: 5px 8px; margin-bottom: 4px;
  background: rgba(255, 252, 244, 0.65); border: 1px solid #c4ab80; border-radius: 3px; font-size: 14px;
}
#guest-list li button { border: none; background: none; cursor: pointer; color: var(--cinnabar); font-size: 13px; }
#guest-form { display: flex; gap: 8px; }
#guest-form input {
  flex: 1; min-width: 0; padding: 7px 9px; font: inherit; font-size: 14px; color: var(--ink);
  background: rgba(255, 252, 244, 0.8); border: 1px solid #b59b72; border-radius: 3px;
}
#guest-form button {
  padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; border-radius: 3px; border: none;
  color: #fff; background: linear-gradient(#3f8a6f, var(--jade));
}
#access-msg { margin: 8px 0 0; }

.mini-card { width: 300px; transform: none; padding: 12px 14px 10px; }
.mini-card .panel-head { font-size: 17px; margin-bottom: 6px; }
.mini-card .who { display: flex; align-items: center; gap: 8px; }
.mini-card .who img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); }
#pc-houses .row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; margin-bottom: 6px;
  background: rgba(255, 252, 244, 0.65); border: 1px solid #c4ab80; border-radius: 3px; font-size: 14px;
}
#pc-houses .row small { display: block; color: var(--ink-soft); font-size: 11px; }
#pc-houses button {
  flex: none; padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; border-radius: 3px; border: none;
  color: #fff; background: linear-gradient(#3f8a6f, var(--jade));
}
#pc-houses button.on { color: var(--cinnabar); background: transparent; border: 1px solid var(--cinnabar); }
.seal-sm {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 4px; transform: rotate(-4deg);
  background: var(--cinnabar); color: #fff3e6; font-family: var(--brush); font-size: 18px;
}
#ec-body .row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 8px; margin-bottom: 6px;
  background: rgba(255, 252, 244, 0.65); border: 1px solid #c4ab80; border-radius: 3px; font-size: 14px;
}
#ec-body .row small { display: block; color: var(--ink-soft); font-size: 11px; }
#ec-body button {
  flex: none; padding: 5px 10px; font: inherit; font-size: 13px; cursor: pointer; border-radius: 3px; border: none;
  color: #fff; background: linear-gradient(#3f8a6f, var(--jade));
}
#ec-body button.danger { color: var(--cinnabar); background: transparent; border: 1px solid var(--cinnabar); }
#ec-body button.danger[data-armed] { color: #fff; background: var(--cinnabar); }
#ec-body .name-form { display: flex; gap: 6px; margin-bottom: 2px; }
#ec-body .name-form input {
  flex: 1; min-width: 0; padding: 6px 8px; font: inherit; font-size: 14px; color: var(--ink);
  background: rgba(255, 252, 244, 0.85); border: 1px solid #b59b72; border-radius: 3px;
}
#ec-body .name-hint { min-height: 0; margin: 0 0 6px; }
#ec-body .warn { margin: 2px 0 4px; font-size: 12px; color: var(--cinnabar); min-height: 1.2em; }
#pc-houses .none { margin: 4px 0; font-size: 13px; color: var(--ink-soft); font-style: italic; }

.panel {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 15;
  width: min(440px, calc(100vw - 24px)); max-height: calc(100vh - 40px); overflow-y: auto;
  padding: 16px 18px 12px; background: linear-gradient(#f6ecd6, #ead9b5); color: var(--ink);
  border: 1px solid #5a3a22; border-top: 4px solid var(--cinnabar); border-radius: 4px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; font-size: 19px; font-weight: 700; margin-bottom: 8px; }
.panel .x { border: none; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--ink-soft); }
.panel .hint { margin: 10px 0 2px; }
.shop-coins { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; font-size: 14px; }
.shop-coins b { font-size: 16px; color: #5c3f0e; }
.deed-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 10px; margin-bottom: 8px;
  background: rgba(255, 252, 244, 0.65); border: 1px solid #c4ab80; border-left: 4px solid var(--gold); border-radius: 3px;
}
.deed-row .seal {
  position: static; flex: none; width: 38px; height: 38px; display: grid; place-items: center; transform: rotate(-4deg);
  background: var(--cinnabar); color: #fff3e6; font-family: var(--brush); font-size: 22px; border-radius: 4px;
}
.deed-row .info { flex: 1; min-width: 0; }
.deed-row .nm { font-weight: 700; font-size: 16px; }
.deed-row .ds { font-size: 12px; color: var(--ink-soft); }
.deed-row .price { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #5c3f0e; margin-top: 2px; }
.deed-row button {
  flex: none; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; border-radius: 3px;
  color: #fff3e6; border: none; background: linear-gradient(var(--cinnabar), var(--cinnabar-dark));
}
.deed-row button:disabled { opacity: 0.45; cursor: not-allowed; }
.deed-row .owned { font-size: 12px; color: var(--jade); margin-top: 2px; }

#build-bar {
  position: absolute; left: 50%; bottom: 60px; transform: translateX(-50%); z-index: 12; text-align: center;
  width: min(520px, calc(100vw - 24px)); padding: 10px 14px; background: rgba(30, 20, 12, 0.86); color: #f6dcae;
  border: 1px solid rgba(201, 162, 74, 0.7); border-top: 3px solid var(--gold); border-radius: 4px;
}
#build-title { font-size: 16px; font-weight: 700; }
#build-msg { font-size: 13px; min-height: 1.3em; margin: 3px 0 8px; color: #b8e0c4; }
#build-msg.bad { color: #ff9a86; }
.build-btns { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.build-btns button {
  padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; border-radius: 3px;
  background: rgba(243, 231, 207, 0.12); color: #f6dcae; border: 1px solid rgba(243, 231, 207, 0.4);
}
.build-btns button.go { background: linear-gradient(#3f8a6f, var(--jade)); border-color: #7fc7a8; color: #fff; }
.build-btns button.go:disabled { opacity: 0.45; cursor: not-allowed; }
.build-btns kbd { font: inherit; font-size: 11px; opacity: 0.7; border: 1px solid rgba(243, 231, 207, 0.4); border-radius: 2px; padding: 0 3px; }
body.touch .build-btns kbd { display: none; }
.plate.estate .tag { padding-left: 9px; background: rgba(70, 40, 16, 0.82); color: #ffe3a6; border-color: rgba(201, 162, 74, 0.8); }

#quest {
  position: absolute; top: 148px; left: 14px; padding: 7px 14px; font-size: 14px; font-weight: 600;
  background: rgba(30, 14, 12, 0.78); color: #f6dcae; border: 1px solid rgba(201, 162, 74, 0.6);
  border-left: 4px solid var(--cinnabar); border-radius: 3px; pointer-events: none;
}
/* ---------- touch controls (shown once a touch screen is detected) ---------- */
#attack-btn, #touch-help { display: none; }
body.touch #attack-btn {
  display: grid; place-items: center; position: absolute;
  right: calc(18px + env(safe-area-inset-right)); bottom: calc(22px + env(safe-area-inset-bottom));
  width: 78px; height: 78px; border-radius: 50%; border: 3px solid var(--gold);
  background: radial-gradient(circle at 35% 30%, #d94a3a, var(--cinnabar) 55%, var(--cinnabar-dark));
  color: #fff3e6; font-family: var(--brush); font-size: 38px; line-height: 1;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35), 0 6px 16px rgba(0, 0, 0, 0.45);
  touch-action: none; -webkit-tap-highlight-color: transparent; cursor: pointer;
}
body.touch #attack-btn:active { transform: scale(0.92); filter: brightness(1.15); }
body.touch #help { display: none; }
body.touch #touch-help {
  display: block; position: absolute; left: 14px; max-width: calc(100vw - 130px); overflow: hidden; text-overflow: ellipsis;
  bottom: calc(8px + env(safe-area-inset-bottom));
  font-size: 11px; color: rgba(255, 245, 225, 0.75); background: rgba(24, 18, 12, 0.45);
  padding: 3px 8px; border-radius: 3px; pointer-events: none; white-space: nowrap;
}
body.touch #chat { bottom: calc(30px + env(safe-area-inset-bottom)); width: min(300px, calc(100vw - 130px)); }
body.touch #chat-log { height: 96px; font-size: 13px; }
@media (max-width: 640px) {
  body.touch #minimap { top: 52px; }
  #profile-card { transform: scale(0.85); transform-origin: top left; }
  #quest { top: 126px; font-size: 12px; }
}

#minimap {
  position: absolute; top: 54px; right: 16px; padding: 6px; pointer-events: none;
  background:
    radial-gradient(ellipse at center, rgba(40, 46, 52, 0.55), rgba(14, 16, 20, 0.85)),
    rgba(14, 16, 20, 0.8);
  border: 1px solid rgba(201, 162, 74, 0.7); border-top: 6px solid #5a3a22; border-bottom: 6px solid #5a3a22;
  border-radius: 3px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
#minimap canvas { display: block; }
#minimap .title {
  position: absolute; top: -2px; left: -2px; width: 26px; height: 26px; display: grid; place-items: center;
  background: var(--cinnabar); color: #fbe9d7; font-family: var(--brush); font-size: 15px; border-radius: 3px;
  transform: rotate(-6deg); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
#minimap::after {
  content: 'Explored ' attr(data-explored); position: absolute; right: 8px; bottom: 6px;
  font-size: 11px; color: rgba(243, 231, 207, 0.8); text-shadow: 0 1px 2px #000;
}
html[lang='zh-Hant'] #minimap::after { content: '已探 ' attr(data-explored); }
html[lang='en'] #minimap .title { font-size: 11px; }
@media (max-width: 640px) {
  #minimap canvas { width: 130px !important; height: 130px !important; }
}

#fade {
  position: fixed; inset: 0; z-index: 30; pointer-events: none; opacity: 0; transition: opacity 0.4s;
  background: radial-gradient(circle, #1f3a34 0%, #060908 75%);
}
#fade.on { opacity: 1; }

/* ---------- floating labels ---------- */
/* name tags and speech bubbles stay out of sight behind the sign-in, select and create screens */
body:has(.screen:not(.hidden)) #labels { visibility: hidden; }
#labels { position: fixed; inset: 0; pointer-events: none; z-index: 5; overflow: hidden; }
.plate {
  position: absolute; left: 0; top: 0; display: flex; flex-direction: column; align-items: center;
  transform: translate(-50%, -100%); white-space: nowrap; will-change: transform;
}
.plate .tag {
  display: flex; align-items: center; gap: 5px; padding: 2px 9px 2px 2px; border-radius: 14px;
  background: rgba(24, 18, 12, 0.6); color: #fff3dc; font-size: 13px; text-shadow: 0 1px 2px #000;
}
.plate .tag img { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; border: 1px solid var(--gold); }
.plate.me .tag { color: #a9f0d1; }
.plate.npc .tag { background: rgba(126, 24, 18, 0.65); padding-left: 9px; }
.plate.monster .tag { background: rgba(10, 10, 14, 0.75); color: #ff8a7a; padding-left: 9px; border: 1px solid rgba(255, 80, 60, 0.5); }
.plate .bubble {
  position: relative; max-width: 240px; white-space: normal; margin-bottom: 8px; padding: 7px 11px;
  background: var(--paper); color: var(--ink); border: 1px solid #5a3a22; border-radius: 6px;
  font-size: 13px; line-height: 1.4; box-shadow: 0 3px 10px rgba(0, 0, 0, 0.35);
  opacity: 0; transition: opacity 0.25s; text-align: center;
}
.plate .bubble.show { opacity: 1; }
.plate .bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -7px; margin-left: -6px;
  border: 6px solid transparent; border-top-color: var(--paper); border-bottom: 0;
}

@media (max-width: 640px) {
  #help { display: none; }
  #chat-log { height: 120px; }
  .brush { font-size: 38px; }
  .scroll { padding: 28px 20px 22px; }
}
