:root {
  --bg: #0f1115; --panel: #171a21; --panel2: #1f232d; --line: #2a2f3a; --fg: #e6e4dc; --muted: #8b90a0;
  --accent: #d4a94a; --accent2: #7aa2ff; --hp: #c84b4b; --mp: #3f7bd9; --cp: #c9a227; --xp: #6cae5c; --danger: #b43b3b; --ok: #4caf7d;
  --radius: 12px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overscroll-behavior: none; }
body { padding-top: var(--safe-t); }
#app { height: 100%; }
.view { height: 100%; display: flex; flex-direction: column; }
[hidden] { display: none !important; }
button { font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 14px; cursor: pointer; }
button:active { transform: translateY(1px); filter: brightness(1.15); }
button.primary { background: var(--accent); color: #1a1405; border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
button.link { background: none; border: none; color: var(--accent2); padding: 4px 8px; }
button.icon-btn { padding: 4px 10px; font-size: 18px; }
input, select { font: inherit; color: var(--fg); background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent2); outline-offset: -1px; }
h1 { font-size: 24px; margin: 8px 0; } h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 8px; } h3 { font-size: 16px; margin: 10px 0 6px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .error { color: #ff8a8a; margin: 8px 0; } .row { display: flex; gap: 8px; margin: 8px 0; flex-wrap: wrap; }

/* login */
#view-login { align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px 20px; text-align: center; }
.login-card .logo { width: 72px; height: 72px; }
.login-card form { display: grid; gap: 12px; text-align: left; margin-top: 12px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }

/* lists */
.bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel); }
.bar .title { font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; overflow: auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; display: flex; align-items: center; gap: 10px; }
.card.clickable { cursor: pointer; } .card.clickable:active { background: var(--panel2); }
.card .grow { flex: 1; min-width: 0; } .card .name { font-weight: 600; } .card .sub { color: var(--muted); font-size: 12px; }
.card .actions { display: flex; gap: 6px; } .card .actions button { padding: 6px 10px; font-size: 13px; }
.tag { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--panel2); color: var(--muted); }
.tag.mob { color: #ff9c9c; } .tag.npc { color: #9cc9ff; } .tag.player { color: #ffd98a; } .tag.item { color: #b4e7a3; }
.hpmini { height: 4px; background: #333; border-radius: 2px; overflow: hidden; margin-top: 4px; } .hpmini i { display: block; height: 100%; background: var(--hp); }

/* game hud */
#view-game { background: var(--bg); }
.hud { background: var(--panel); border-bottom: 1px solid var(--line); padding: 8px 12px 6px; }
.hud-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hud-right { display: flex; align-items: center; gap: 8px; min-width: 0; } .hud-right span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
.bars { display: grid; gap: 3px; margin-top: 6px; }
.bar-line { position: relative; height: 14px; background: #262a33; border-radius: 4px; overflow: hidden; }
.bar-line.small { height: 10px; }
.bar-line i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .3s; }
.bar-line.hp i { background: var(--hp); } .bar-line.mp i { background: var(--mp); } .bar-line.cp i { background: var(--cp); } .bar-line.xp i { background: var(--xp); }
.bar-line span { position: absolute; inset: 0; font-size: 10px; line-height: 14px; text-align: center; color: #fff; text-shadow: 0 0 2px #000; }
.bar-line.small span { line-height: 10px; font-size: 9px; }
.target { margin-top: 8px; padding: 8px 10px; background: var(--panel2); border-radius: 10px; }
.target-name { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; margin-bottom: 4px; }
.target-actions { display: flex; gap: 6px; margin-top: 8px; } .target-actions button { flex: 1; padding: 8px 6px; font-size: 13px; } .target-actions .ghost { flex: 0 0 40px; }
.notice { margin-top: 8px; padding: 8px 10px; background: #3a1f1f; border-radius: 10px; display: flex; justify-content: space-between; align-items: center; }

main#panels { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; }
.panel { padding: 8px 12px calc(16px + var(--safe-b)); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; display: flex; justify-content: space-between; }
.stat b { font-variant-numeric: tabular-nums; }
.stat.wide { grid-column: 1 / -1; }
.skills { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.skill { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; text-align: center; font-size: 11px; cursor: pointer; display: grid; gap: 4px; justify-items: center; }
.skill img, .cell img { width: 40px; height: 40px; image-rendering: auto; border-radius: 6px; background: #000; }
.skill.passive { opacity: .55; }
.skill .lvl { position: absolute; } .skill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.adena { margin: 6px 0 10px; color: var(--accent); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 8px; }
.cell { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: grid; justify-items: center; gap: 4px; font-size: 11px; cursor: pointer; }
.cell.equipped { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cell .cnt { position: absolute; right: 6px; top: 6px; background: rgba(0,0,0,.7); border-radius: 4px; padding: 0 4px; font-size: 10px; }
.cell .ench { position: absolute; left: 6px; top: 6px; color: var(--accent); font-size: 10px; font-weight: 600; }
.cell span.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* chat */
.chat-panel { display: flex; flex-direction: column; height: 100%; padding-bottom: calc(8px + var(--safe-b)); }
.chat-log { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 3px; font-size: 14px; padding: 4px 0; }
.chat-log .line b { margin-right: 4px; } .chat-log .line .ch { font-size: 11px; color: var(--muted); margin-right: 4px; }
.c0 { color: #e6e4dc; } .c1 { color: #ff9a6a; } .c2 { color: #e39bff; } .c3 { color: #7dd87d; } .c4 { color: #b8c8ff; } .c8 { color: #ffd37a; } .c9 { color: #9ee6d8; } .c10 { color: #ffb0b0; } .c15 { color: #ffe08a; } .c16 { color: #ffe08a; }
.sys-log { max-height: 30%; overflow: auto; border-top: 1px solid var(--line); padding-top: 4px; font-size: 12px; color: var(--muted); display: flex; flex-direction: column-reverse; gap: 2px; }
.chat-form { display: flex; gap: 6px; padding-top: 6px; } .chat-form select { width: auto; padding: 8px; } .chat-form input#chat-target { width: 90px; } .chat-form button { padding: 8px 12px; }

/* world */
.seg { display: flex; gap: 2px; background: var(--panel2); border-radius: 10px; padding: 2px; } .seg button { padding: 5px 8px; font-size: 12px; border: none; background: transparent; border-radius: 8px; } .seg button.on { background: var(--panel); }
.dpad { display: grid; justify-items: center; gap: 6px; margin: 8px 0; } .dpad button { width: 64px; height: 48px; font-size: 20px; } .dpad-mid { display: flex; gap: 6px; }
.dpad label { display: flex; gap: 6px; align-items: center; } .dpad select { width: auto; padding: 4px 8px; }

/* npc */
.npc-html { background: #1c1a16; color: #e8dcc0; border: 1px solid #3a3426; border-radius: 10px; padding: 12px; font-size: 14px; line-height: 1.45; }
.npc-html a, .npc-html .lnk { display: block; color: var(--accent2); text-decoration: none; padding: 7px 10px; margin: 4px 0; background: rgba(122,162,255,.08); border-radius: 8px; cursor: pointer; }
.npc-html img { max-width: 100%; }
.npc-html table { border-collapse: collapse; width: 100%; } .npc-html td { padding: 2px 4px; vertical-align: top; }
.npc-html font { }
.shop-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; position: sticky; bottom: 0; background: var(--bg); }
.qty { display: flex; align-items: center; gap: 4px; } .qty input { width: 64px; padding: 6px; text-align: center; } .qty button { padding: 6px 10px; }

/* map */
.map-panel { display: flex; flex-direction: column; height: 100%; padding: 0 0 var(--safe-b); }
.map-wrap { position: relative; flex: 0 0 56vh; background: #0a0c10; overflow: hidden; touch-action: none; }
.map-wrap canvas { width: 100%; height: 100%; display: block; }
.map-ctl { position: absolute; right: 8px; top: 8px; display: grid; gap: 6px; } .map-ctl button { width: 40px; height: 40px; padding: 0; font-size: 20px; background: rgba(23,26,33,.9); }
.map-hint { position: absolute; left: 8px; bottom: 8px; font-size: 11px; color: var(--muted); background: rgba(15,17,21,.7); padding: 3px 8px; border-radius: 8px; }
.map-panel .panel-head, .map-panel .list { padding-left: 12px; padding-right: 12px; }
.map-panel .list { max-height: none; }
.gk-opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; } .gk-opts button { padding: 5px 9px; font-size: 12px; }

/* tabs */
.tabs { display: flex; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; position: relative; background: none; border: none; border-radius: 0; padding: 10px 2px 8px; font-size: 12px; color: var(--muted); }
.tabs button.on { color: var(--accent); }
.badge { position: absolute; top: 6px; right: 18%; min-width: 16px; height: 16px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; line-height: 16px; font-style: normal; padding: 0 4px; }

/* overlays */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 20; }
.sheet-body { width: 100%; background: var(--panel); border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); display: grid; gap: 8px; max-height: 80vh; overflow: auto; }
.sheet-body .item-head { display: flex; gap: 10px; align-items: center; } .sheet-body .item-head img { width: 48px; height: 48px; border-radius: 8px; background: #000; }
.toast { position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); background: #2b2f3a; color: #fff; padding: 10px 14px; border-radius: 10px; z-index: 30; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.5); }
.conn { position: fixed; top: var(--safe-t); left: 0; right: 0; background: #7a2e2e; color: #fff; text-align: center; font-size: 12px; padding: 4px; z-index: 40; }
