:root {
  --ink: #3b2a1e;
  --text: #4a2e19;
  --muted: #8a6a3f;
  --paper: #f6e7c1;
  --paper-2: #ecd9a8;
  --paper-3: #e0c890;
  --wood: #b97a41;
  --gold: #f4c53c;
  --good: #3f8f3a;
  --bad: #c8473a;
  --panel-w: 404px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2b72b8; color: var(--text); font: 13px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
img.px, .px { image-rendering: pixelated; }
[hidden] { display: none !important; }

#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; cursor: grab; user-select: none; }

/* ---------- pixel frames (images are generated at runtime) ---------- */
.frame { border-style: solid; border-color: transparent; image-rendering: pixelated; }
.frame.wood { border-width: 14px; border-image: var(--f-wood) 7 fill / 14px; }
.frame.paper { border-width: 8px; border-image: var(--f-paper) 4 fill / 8px; }
.frame.slot { border-width: 6px; border-image: var(--f-slot) 3 fill / 6px; }
.frame.dark { border-width: 6px; border-image: var(--f-dark) 3 fill / 6px; color: #fff3da; }
.frame.btn { border-width: 8px; border-image: var(--f-btn) 4 fill / 8px; color: #fff6e2; font-weight: 800; text-shadow: 0 1px 0 rgba(60, 30, 10, .8); background: none; padding: 0 4px; min-width: 40px; height: 36px; line-height: 20px; }
.frame.btn:hover { filter: brightness(1.08); }
.frame.btn:active, .frame.btn.on { border-image: var(--f-btn-on) 4 fill / 8px; color: #4a2e19; text-shadow: none; }

/* ---------- top HUD ---------- */
#hud-title { position: fixed; left: 12px; top: 12px; display: flex; align-items: center; gap: 10px; padding: 0 6px 0 2px; z-index: 5; }
#hud-title h1 { margin: 0; font-size: 18px; line-height: 1.15; letter-spacing: 1px; font-weight: 900; color: #5a3113; }
#hud-title p { margin: 1px 0 0; font-size: 11px; color: var(--muted); font-weight: 600; white-space: nowrap; }
#live-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; background: #d99a2b; box-shadow: 0 0 0 2px rgba(59, 42, 30, .25); }
#live-dot.on { background: #4faa3f; animation: blink 1.6s steps(2) infinite; }
#live-dot.warn { background: #e0a030; animation: blink 1.2s steps(2) infinite; }
#live-dot.off { background: var(--bad); }
@keyframes blink { 50% { opacity: .35; } }

#hud-stats { position: fixed; left: 12px; top: 82px; display: flex; flex-direction: row; flex-wrap: wrap; gap: 5px; max-width: calc(100vw - var(--panel-open, 0px) - 24px); z-index: 4; pointer-events: none; }
.stat { display: flex; align-items: center; gap: 6px; padding: 2px 9px 2px 5px; background: rgba(42, 26, 14, .78); color: #fff3da; font-weight: 700; font-size: 12px; box-shadow: 0 0 0 2px rgba(20, 12, 6, .85); width: max-content; }
.stat img { width: 18px; height: 18px; object-fit: contain; }
.stat small { color: #d9c08c; font-weight: 600; margin-right: 2px; }

#location { position: fixed; top: 14px; left: calc((100vw - var(--panel-open, 0px)) / 2); transform: translateX(-50%); padding: 1px 12px; font-weight: 800; font-size: 14px; z-index: 4; white-space: nowrap; display: flex; align-items: center; gap: 8px; pointer-events: none; }
#location small { font-weight: 600; color: var(--muted); font-size: 12px; }
#location img { width: 18px; height: 18px; object-fit: contain; }

#clock { position: fixed; top: 12px; right: calc(var(--panel-open, 0px) + 12px); display: flex; align-items: center; gap: 8px; padding: 0 4px; z-index: 5; cursor: pointer; user-select: none; transition: right .18s steps(4); }
#clock-day { font-size: 11px; color: var(--muted); font-weight: 700; line-height: 1.2; }
#clock-time { font-size: 19px; font-weight: 900; line-height: 1.05; letter-spacing: 1px; color: #5a3113; font-variant-numeric: tabular-nums; }
#clock-mode { font-size: 10px; font-weight: 800; padding: 1px 5px; background: var(--paper-3); box-shadow: 0 0 0 2px var(--ink); margin-left: 2px; }

#toolbar { position: fixed; left: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 5; }
#toolbar .btn { font-size: 13px; }
#toolbar .btn[data-act="zoom-in"], #toolbar .btn[data-act="zoom-out"] { font-size: 18px; }

/* ---------- side panel ---------- */
#panel { position: fixed; top: 12px; right: 12px; bottom: 12px; width: calc(var(--panel-w) - 24px); display: flex; flex-direction: column; z-index: 6; transition: transform .18s steps(5); }
body.panel-closed #panel { transform: translateX(calc(100% + 30px)); }
#tabs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 3px; margin: -2px -2px 8px; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 0 3px; background: var(--paper-2); box-shadow: 0 0 0 2px var(--ink), inset 0 -3px 0 rgba(120, 80, 30, .22); font-size: 11px; font-weight: 800; border: 0; color: var(--muted); position: relative; }
.tab img { width: 22px; height: 22px; object-fit: contain; }
.tab:hover { background: #f3e0b4; }
.tab.on { background: #fff3cf; color: #5a3113; box-shadow: 0 0 0 2px var(--ink), inset 0 3px 0 var(--gold); }
.tab .dot { position: absolute; top: 2px; right: 6px; width: 8px; height: 8px; background: var(--bad); box-shadow: 0 0 0 2px var(--ink); }

#panel-body { flex: 1; overflow-y: auto; overflow-x: hidden; margin: 0 -6px -4px 0; padding-right: 6px; scrollbar-width: thin; scrollbar-color: #b08a55 transparent; }
#panel-body::-webkit-scrollbar { width: 8px; }
#panel-body::-webkit-scrollbar-thumb { background: #b08a55; box-shadow: inset 0 0 0 2px var(--paper); }

h2.sec { margin: 12px 0 6px; font-size: 13px; font-weight: 900; color: #5a3113; display: flex; align-items: center; gap: 6px; }
h2.sec:first-child { margin-top: 0; }
h2.sec::after { content: ""; flex: 1; height: 2px; background: repeating-linear-gradient(90deg, #c9a66b 0 4px, transparent 4px 8px); }
h2.sec img { width: 18px; height: 18px; object-fit: contain; }
h2.sec small { font-weight: 600; color: var(--muted); font-size: 11px; }

.card { background: #fff6dc; box-shadow: 0 0 0 2px #c9a66b; padding: 8px 10px; margin: 2px 2px 8px; }
.card.hl { box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px var(--gold); }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; padding: 6px 2px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num { font-variant-numeric: tabular-nums; font-weight: 800; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 2px; }
.tile { background: #fff6dc; box-shadow: 0 0 0 2px #c9a66b; padding: 5px 7px; }
.tile b { display: block; font-size: 15px; font-weight: 900; color: #5a3113; font-variant-numeric: tabular-nums; line-height: 1.25; }
.tile span { font-size: 11px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 3px; }
.tile img { width: 14px; height: 14px; object-fit: contain; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 0 6px; font-size: 11px; font-weight: 700; background: var(--paper-2); box-shadow: 0 0 0 1px #b08a55; white-space: nowrap; line-height: 18px; }
.chip img { width: 14px; height: 14px; object-fit: contain; }
.chip i { width: 8px; height: 8px; display: inline-block; box-shadow: 0 0 0 1px var(--ink); }
.chip.t0 { background: #d8efc8; } .chip.t1 { background: #f8e2a8; } .chip.t2 { background: #f6c6bc; }
.chip.act-high { background: #f8dfa0; } .chip.act-medium { background: #d8efc8; } .chip.act-low { background: #e3edf5; } .chip.act-quiet, .chip.act-warming_up { background: var(--paper-2); }
.chip.fog-tag { background: #dce8f4; color: #314b68; box-shadow: 0 0 0 1px #7c97b5; }
.chip.paid { background: #ffe07a; } .chip.free { background: #d8efc8; }
.chip.closed { background: #dfd5c2; color: #6e6253; box-shadow: 0 0 0 1px #9e907a; }
.chip.tag-chip { background: #e3edf5; color: #2f5b88; box-shadow: 0 0 0 1px #8aa4bf; border: 0; cursor: pointer; }
.chip.tag-chip:hover { background: #cde0f0; }
.chip.buff { background: #ffe9c2; color: #7a3e10; box-shadow: 0 0 0 1px #d48e3a; }
.item.closed-post { opacity: 0.72; }

.link { background: none; border: 0; padding: 0; color: #2f6a9c; font-weight: 800; text-decoration: underline dotted; text-underline-offset: 2px; cursor: pointer; text-align: left; }
.link:hover { color: #1f4a70; }

.list { margin: 2px; display: flex; flex-direction: column; }
.item { display: flex; gap: 8px; align-items: flex-start; padding: 6px 4px; border-bottom: 2px dotted #d9bf8a; }
.item:last-child { border-bottom: 0; }
.item .ico { width: 22px; height: 22px; flex: none; object-fit: contain; margin-top: 1px; }
.item .meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.item p { margin: 1px 0 0; word-break: break-word; overflow-wrap: anywhere; }
.item.good p b { color: var(--good); } .item.err p { color: var(--bad); }
.tag { font-size: 10px; font-weight: 900; color: #fff; padding: 0 5px; line-height: 16px; }

.avatar { width: 48px; height: 45px; flex: none; background: #cfe9f5; box-shadow: 0 0 0 2px var(--ink); object-fit: cover; }
.avatar.sm { width: 26px; height: 24px; box-shadow: 0 0 0 1px var(--ink); }

.subtabs { display: flex; gap: 4px; margin: 2px 2px 8px; flex-wrap: wrap; }
.subtab { border: 0; padding: 2px 9px; font-weight: 800; font-size: 12px; background: var(--paper-2); box-shadow: 0 0 0 2px #b08a55; color: var(--muted); }
.subtab.on { background: #5a3113; color: #fff3da; box-shadow: 0 0 0 2px var(--ink); }

.rank { display: grid; grid-template-columns: 26px 26px 1fr auto; gap: 7px; align-items: center; padding: 5px 4px; border-bottom: 2px dotted #d9bf8a; }
.rank .n { font-weight: 900; text-align: center; color: var(--muted); }
.rank .n.m1 { color: #c8922a; } .rank .n.m2 { color: #7f8894; } .rank .n.m3 { color: #a8623a; }
.rank .v { text-align: right; font-weight: 900; font-variant-numeric: tabular-nums; }
.rank .v small { display: block; font-weight: 600; color: var(--muted); font-size: 10px; }

.bar { height: 10px; background: #d9c08c; box-shadow: 0 0 0 2px var(--ink); position: relative; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: #6cbf48; box-shadow: inset 0 3px 0 rgba(255, 255, 255, .35), inset 0 -3px 0 rgba(0, 0, 0, .15); }
.bar.warn > i { background: #e0a030; } .bar.low > i { background: var(--bad); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 12px; margin: 4px 0 0; }
.kv dt { color: var(--muted); font-weight: 600; } .kv dd { margin: 0; font-weight: 700; text-align: right; }

.paper-doc { background: #fffaf0; box-shadow: 0 0 0 2px var(--ink), 4px 4px 0 rgba(60, 40, 20, .18); padding: 10px 12px; margin: 2px 4px 10px 2px; font-family: "Songti SC", "Noto Serif SC", "SimSun", serif; }
.paper-doc h3 { margin: 0 0 4px; font-size: 17px; text-align: center; letter-spacing: 2px; border-bottom: 3px double var(--ink); padding-bottom: 5px; }
.paper-doc h4 { margin: 10px 0 3px; font-size: 13px; background: var(--ink); color: #fffaf0; padding: 1px 7px; display: inline-block; }
.paper-doc p { margin: 3px 0; } .paper-doc ul { margin: 3px 0; padding-left: 18px; } .paper-doc li { margin: 2px 0; }
.paper-doc code { font-family: ui-monospace, Menlo, monospace; background: #f0e2be; padding: 0 3px; font-size: 12px; }
.paper-doc .headline { font-weight: 900; font-size: 14px; margin: 6px 0; }

.post-body { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; background: #fffaf0; box-shadow: 0 0 0 2px #c9a66b; padding: 8px 10px; margin: 6px 0 2px; font-size: 12.5px; max-height: 340px; overflow-y: auto; }

/* ---------- hotbar (my agent) ---------- */
#hotbar { position: fixed; bottom: 12px; left: calc((100vw - var(--panel-open, 0px)) / 2); transform: translateX(-50%); display: flex; align-items: flex-end; gap: 8px; z-index: 5; }
.hb-wallet { display: flex; flex-direction: column; gap: 4px; }
.hb-wallet .stat { pointer-events: auto; }
.hb-slots { display: flex; gap: 0; padding: 0 2px; }
.slot { width: 48px; height: 48px; position: relative; display: flex; align-items: center; justify-content: center; margin: 0 -1px; }
.slot img { width: 30px; height: 30px; object-fit: contain; }
.slot.empty img { opacity: .28; filter: grayscale(1); }
.slot b { position: absolute; right: 1px; bottom: -3px; font-size: 13px; font-weight: 900; color: #fff; text-shadow: -1px -1px 0 var(--ink), 1px -1px 0 var(--ink), -1px 1px 0 var(--ink), 1px 1px 0 var(--ink), 0 2px 0 var(--ink); font-variant-numeric: tabular-nums; }
.slot u { position: absolute; left: 0; top: -5px; font-size: 9px; font-weight: 800; text-decoration: none; color: var(--muted); }
.hb-sep { width: 6px; }
.hb-energy { width: 48px; height: 108px; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; position: relative; margin-left: -2px; }
.hb-energy .tube { width: 14px; flex: 1; background: #5a3c26; box-shadow: 0 0 0 2px var(--ink); position: relative; margin-top: 2px; }
.hb-energy .tube i { position: absolute; left: 0; right: 0; bottom: 0; background: #6cbf48; box-shadow: inset 3px 0 0 rgba(255, 255, 255, .35); }
.hb-energy .tube.warn i { background: #e0a030; } .hb-energy .tube.low i { background: var(--bad); }
.hb-energy b { font-size: 12px; font-weight: 900; line-height: 15px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.hb-energy img { width: 16px; height: 16px; }
.hb-load { font-size: 10px; font-weight: 800; color: #fff3da; background: rgba(42, 26, 14, .78); box-shadow: 0 0 0 2px rgba(20, 12, 6, .85); padding: 0 6px; position: absolute; top: -20px; left: 50%; transform: translateX(-50%); white-space: nowrap; }

/* ---------- dialogue ---------- */
#dialogue { position: fixed; bottom: 96px; left: calc((100vw - var(--panel-open, 0px)) / 2); transform: translateX(-50%); width: min(560px, calc(100vw - var(--panel-open, 0px) - 140px)); display: flex; gap: 12px; align-items: flex-start; z-index: 5; cursor: pointer; padding: 0 4px; }
body.no-hotbar #dialogue { bottom: 16px; }
#dlg-portrait { width: 80px; height: 75px; flex: none; background: #cfe9f5; box-shadow: 0 0 0 2px var(--ink); }
#dlg-main { flex: 1; min-width: 0; }
#dlg-head { display: flex; align-items: baseline; gap: 8px; }
#dlg-name { font-size: 14px; font-weight: 900; color: #5a3113; }
#dlg-where { font-size: 11px; color: var(--muted); font-weight: 600; }
#dlg-text { margin: 2px 0 0; font-size: 13.5px; font-weight: 600; min-height: 60px; max-height: 84px; overflow: hidden; word-break: break-word; overflow-wrap: anywhere; }

/* ---------- misc ---------- */
#tooltip { position: fixed; z-index: 20; pointer-events: none; padding: 0 4px; font-size: 12px; max-width: 280px; }
#tooltip b { display: block; font-weight: 800; } #tooltip span { color: #e3cfa6; font-size: 11px; }
#toast { position: fixed; top: 58px; left: calc((100vw - var(--panel-open, 0px)) / 2); transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; align-items: center; z-index: 8; pointer-events: none; }
.toast { background: rgba(42, 26, 14, .9); color: #fff3da; padding: 4px 12px; font-weight: 700; box-shadow: 0 0 0 2px #1b120b, 0 0 0 4px var(--gold); max-width: min(560px, 70vw); text-align: center; animation: toast-in .25s steps(4); }
@keyframes toast-in { from { transform: translateY(-10px); opacity: 0; } }
#fatal { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 50; background: #3a0d0d; color: #ffd9d9; padding: 8px 12px; font: 12px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; box-shadow: 0 0 0 2px #ff6b6b; }

@media (max-width: 1180px) {
  .hb-wallet { position: absolute; left: 0; top: -58px; flex-direction: row; }
  #dialogue { bottom: 150px; }
}
@media (max-width: 860px) {
  :root { --panel-w: min(404px, 100vw); }
  #hud-stats { display: none; }
  #hud-title { max-width: calc(100vw - 150px); }
  #hud-title h1 { font-size: 15px; }
  #hud-title div { min-width: 0; }
  #hud-title p { overflow: hidden; text-overflow: ellipsis; }
  #clock { right: 12px; }
  #clock-day, #clock-mode { display: none; }
  #location { display: none !important; }
  #toolbar { bottom: 124px; }
  body.no-hotbar #toolbar { bottom: 12px; }
  #hotbar { gap: 4px; }
  .hb-wallet { position: absolute; left: 0; top: -58px; flex-direction: row; }
  .slot { width: 40px; height: 40px; }
  .slot img { width: 26px; height: 26px; }
  .hb-energy { height: 100px; }
  #dialogue { width: calc(100vw - 24px); bottom: 190px; }
  #dlg-portrait { width: 64px; height: 60px; }
}
@media (prefers-reduced-motion: reduce) {
  #live-dot.on, .toast { animation: none; }
  #panel, #clock { transition: none; }
}
