:root {
  --bg: #0b0f1a;
  --panel: rgba(14, 20, 34, 0.88);
  --line: rgba(140, 170, 220, 0.22);
  --text: #e3e9f3;
  --muted: #8b98ad;
  --accent: #5ef0d0;
  --gold: #ffd76a;
  --bad: #ff6b6b;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", sans-serif; overflow: hidden; }
#view { position: fixed; inset: 0; }
#view canvas { display: block; }
#view .overlay { position: absolute; inset: 0; pointer-events: none; }
[hidden] { display: none !important; }
kbd { font: 11px ui-monospace, monospace; padding: 0 4px; border: 1px solid var(--line); border-radius: 3px; background: rgba(255,255,255,0.06); color: var(--muted); }
button { font: inherit; color: var(--text); background: rgba(255,255,255,0.07); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover { background: rgba(255,255,255,0.14); }
button.primary { background: #1f8f78; border-color: #3ed7b4; font-weight: 700; padding: 8px 22px; font-size: 16px; }
button.primary:hover { background: #26a88d; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.screen { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 30%, rgba(40, 70, 90, 0.55), rgba(5, 8, 15, 0.92)); z-index: 20; padding: 16px; }
.card { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px 26px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); }
.card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 2px; }
.sub { color: var(--muted); margin: 0 0 16px; }
.ver { font-size: 13px; color: #9fb3d1; font-weight: 600; letter-spacing: 0; background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 4px; padding: 1px 6px; vertical-align: middle; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.field select, .field input { font: inherit; color: var(--text); background: #0f1626; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.role { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; color: var(--text); }
.role input { display: none; }
.role small { color: var(--muted); }
.role:has(input:checked) { border-color: var(--accent); background: rgba(94, 240, 208, 0.08); }
#loading { margin-top: 12px; display: flex; align-items: center; gap: 10px; color: var(--muted); }
.bar { flex: 1; height: 6px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; }
#load-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.help { margin-top: 14px; color: var(--muted); }
.help summary { cursor: pointer; color: var(--text); }
.help ul { padding-left: 18px; margin: 6px 0 0; }
.help li { margin: 3px 0; }
.credit { margin: 12px 0 0; font-size: 12px; color: var(--muted); }

#top { position: fixed; top: 0; left: 0; right: 0; height: 42px; display: flex; align-items: center; gap: 18px; padding: 0 14px; background: linear-gradient(rgba(8, 12, 22, 0.92), rgba(8, 12, 22, 0.75)); border-bottom: 1px solid var(--line); z-index: 5; }
#top .brand { font-weight: 800; letter-spacing: 2px; color: var(--accent); }
#top .stat b { font-size: 16px; }
#top .spacer { flex: 1; }
#hud-creature { color: #ff9fe0; }
#hud-day { color: #ffe08a; }
#hud-day.night { color: #9fb4ff; }
#hud-beacon { color: #ffd76a; animation: flash 1.2s infinite; }
.flash { animation: flash 0.35s; }
@keyframes flash { 50% { color: var(--bad); transform: scale(1.15); } }

#log { position: fixed; top: 52px; left: 12px; width: min(420px, 40vw); margin: 0; padding: 0; list-style: none; z-index: 4; pointer-events: none; }
#log li { background: rgba(8, 12, 22, 0.62); border-left: 3px solid currentColor; padding: 3px 8px; margin-bottom: 3px; border-radius: 0 4px 4px 0; font-size: 13px; animation: logIn 0.25s; }
@keyframes logIn { from { opacity: 0; transform: translateX(-10px); } }

#toast { position: fixed; bottom: 210px; left: 50%; transform: translateX(-50%); background: rgba(80, 20, 28, 0.92); border: 1px solid #ff6b6b; padding: 6px 14px; border-radius: 6px; z-index: 6; pointer-events: none; }
#banner { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); font-size: 30px; font-weight: 800; letter-spacing: 3px; color: #ff6bb5; text-shadow: 0 0 20px rgba(255, 60, 160, 0.7); z-index: 6; pointer-events: none; animation: bannerIn 0.4s; }
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -12px) scale(1.2); } }

#bottom { position: fixed; left: 0; right: 0; bottom: 0; height: 200px; display: grid; grid-template-columns: 200px 1fr minmax(260px, 420px); gap: 10px; padding: 4px 10px 8px; background: linear-gradient(rgba(8, 12, 22, 0), rgba(8, 12, 22, 0.9) 18%); z-index: 5; pointer-events: none; }
#bottom > * { pointer-events: auto; }
#minimap { align-self: end; width: 192px; height: 192px; border: 1px solid var(--line); border-radius: 6px; background: #000; image-rendering: pixelated; cursor: crosshair; }
#info { align-self: end; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; min-height: 120px; max-width: 520px; justify-self: center; width: 100%; }
#info h3 { margin: 0 0 4px; font-size: 16px; }
#info .muted { color: var(--muted); font-size: 13px; }
#info .hpbar, #info .xpbar { height: 8px; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; margin: 6px 0; }
#info .hpbar > div { height: 100%; background: #5dff7a; }
#info .xpbar > div { height: 100%; background: #ff5fd2; }
#cmd { align-self: end; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
#cmd button { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 6px 8px; text-align: left; min-height: 64px; position: relative; }
#cmd button .nm { font-weight: 700; }
#cmd button .cost { font-size: 12px; color: var(--gold); }
#cmd button .ds { font-size: 11px; color: var(--muted); }
#cmd button kbd { position: absolute; top: 4px; right: 4px; }
#cmd button.active { border-color: var(--accent); background: rgba(94, 240, 208, 0.15); }
#cmd .wide { grid-column: span 3; min-height: 0; }
#cmd .tip { grid-column: span 3; color: var(--muted); font-size: 12px; }

#end-stats { width: 100%; border-collapse: collapse; margin: 6px 0 16px; font-size: 13px; }
#end-stats th, #end-stats td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: right; }
#end-stats th:first-child, #end-stats td:first-child { text-align: left; }

@media (max-width: 900px) {
  #bottom { grid-template-columns: 140px 1fr; height: auto; }
  #minimap { width: 136px; height: 136px; }
  #cmd { grid-column: span 2; }
  #log { width: 70vw; }
}

.online { padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 16px; background: rgba(94, 240, 208, 0.05); }
.card h2 { font-size: 15px; margin: 0 0 8px; }
.solo-title { color: var(--muted); }
.muted { color: var(--muted); font-size: 13px; }
#join-msg { margin-left: 10px; }
.card.wide { width: min(860px, 100%); }
.code { font-family: ui-monospace, monospace; color: var(--accent); letter-spacing: 3px; }
.lobby-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.members { list-style: none; padding: 0; margin: 0 0 12px; }
.members li { display: flex; justify-content: space-between; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 5px; }
.members li .tag { font-size: 12px; color: var(--muted); }
.members li.off { opacity: 0.5; }
.prefs { display: flex; gap: 6px; }
.prefs button.on { border-color: var(--accent); background: rgba(94, 240, 208, 0.18); }
#btn-go { margin-right: 8px; }
.lb-chat { display: flex; flex-direction: column; min-height: 320px; }
.chat { list-style: none; margin: 0 0 8px; padding: 8px; flex: 1; overflow-y: auto; max-height: 340px; border: 1px solid var(--line); border-radius: 6px; background: rgba(0,0,0,0.25); }
.chat li { margin: 2px 0; word-break: break-word; }
.chat li.sys { color: var(--muted); font-size: 12px; }
#lb-chat-input, #chat-input { font: inherit; color: var(--text); background: #0f1626; border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
#chat-input { position: fixed; left: 50%; bottom: 214px; transform: translateX(-50%); width: min(520px, 80vw); z-index: 7; }
#net-banner { position: fixed; top: 50px; left: 50%; transform: translateX(-50%); background: rgba(120, 60, 10, 0.92); border: 1px solid #ffb347; padding: 6px 16px; border-radius: 6px; z-index: 8; }
@media (max-width: 760px) { .lobby-grid { grid-template-columns: 1fr; } }

#hud-res { display: flex; gap: 14px; }
#top .stat.bad b { color: var(--bad); animation: flash 0.8s infinite; }
#cmd { max-height: 190px; overflow-y: auto; }
#cmd .tabs { grid-column: span 3; display: flex; gap: 4px; }
#cmd .tabs button { min-height: 0; padding: 2px 10px; flex: 1; align-items: center; }
#cmd .tabs button.on { border-color: var(--accent); background: rgba(94, 240, 208, 0.18); }
#cmd .skills { grid-column: span 3; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#cmd .skills button { min-height: 44px; }
#cmd .cdtext { position: absolute; right: 8px; bottom: 4px; font-size: 12px; color: var(--gold); }
#cmd button.done { border-color: #5dff7a; opacity: 0.7; }
#cmd button { min-height: 58px; }
