:root {
  --bg: #14161b; --panel: #1b1e25; --panel-2: #222631; --panel-3: #2a2f3c; --border: #303644;
  --text: #e6e9ef; --muted: #8f97a8; --accent: #4fb46c; --blue: #5b9cf5; --yellow: #e5b84a; --orange: #e88a3c; --red: #e5534b;
  --mono: "Cascadia Mono", Consolas, ui-monospace, Menlo, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif; }
body { min-height: 100vh; min-height: 100dvh; }
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.btn { border: 1px solid var(--border); background: var(--panel-2); border-radius: 10px; padding: 10px 14px; cursor: pointer; font-weight: 600; min-height: 44px; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.4; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1a11; }
.btn.danger { color: var(--red); }
.btn.block { width: 100%; }
.icon-btn { background: none; border: 0; font-size: 22px; width: 44px; height: 44px; border-radius: 10px; cursor: pointer; color: var(--muted); }
.icon-btn.danger { color: var(--red); font-size: 18px; }
.icon-btn:active { background: var(--panel-2); }

/* 登入 */
.login { max-width: 360px; margin: 0 auto; padding: 12vh 20px 20px; text-align: center; }
.login-icon { width: 72px; height: 72px; image-rendering: pixelated; border-radius: 14px; }
.login h1 { margin: 14px 0 2px; font-size: 22px; }
.login form { margin-top: 26px; display: grid; gap: 12px; }
.login input, .con-input input { width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel); min-height: 46px; outline: none; }
.login input:focus, .con-input input:focus { border-color: var(--accent); }
.err { color: var(--red); min-height: 1.4em; font-size: 14px; }

/* 頂部 */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(20, 22, 27, 0.92); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); min-height: 56px; }
.top img { width: 26px; height: 26px; image-rendering: pixelated; border-radius: 5px; }
.summary { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.offline { background: #4a2a12; color: var(--orange); padding: 8px 16px; font-size: 14px; }

/* 伺服器卡片 */
main { padding: 12px 12px calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 12px; max-width: 760px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head h2 { margin: 0; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { color: var(--muted); font-size: 13px; margin: 2px 0 0 20px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #5a6070; flex: none; }
.dot.running { background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.dot.starting, .dot.stopping { background: var(--yellow); }
.dot.crashed { background: var(--red); }
.badge { font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--panel-3); color: var(--muted); white-space: nowrap; }
.badge.running { background: rgba(79, 180, 108, 0.16); color: var(--accent); }
.badge.starting, .badge.stopping { background: rgba(229, 184, 74, 0.16); color: var(--yellow); }
.badge.crashed { background: rgba(229, 83, 75, 0.16); color: var(--red); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }
.stats div { background: var(--panel-2); border-radius: 10px; padding: 8px 10px; font-size: 12px; color: var(--muted); }
.stats b { display: block; color: var(--text); font-size: 15px; font-variant-numeric: tabular-nums; }
.players { font-size: 13px; color: var(--muted); margin: -4px 0 12px; overflow-wrap: anywhere; }
.err-line { color: var(--red); font-size: 13px; margin: 8px 0; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.actions .btn.wide { grid-column: span 2; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* 主控台 */
.console-view { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); z-index: 10; }
.con-actions { display: flex; gap: 8px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.con-actions .btn { min-height: 38px; padding: 6px 14px; font-size: 14px; white-space: nowrap; }
.con-log { flex: 1; overflow-y: auto; padding: 8px 12px; font: 12.5px/1.5 var(--mono); white-space: pre-wrap; word-break: break-word; background: #0f1115; }
.con-log .l-sys { color: var(--blue); }
.con-log .l-cmd { color: var(--accent); }
.con-log .l-err { color: var(--red); }
.con-log .l-warn { color: var(--yellow); }
.con-log .l-join { color: #7fd6a0; }
.con-input { display: flex; gap: 8px; padding: 8px 12px; padding-bottom: max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--panel); }
.con-input input { flex: 1; font-family: var(--mono); font-size: 16px; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 20;
  background: var(--panel-3); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.toast.error { border-color: var(--red); color: #ffb3ae; }
.stats-gap { height: 12px; }
.small-btn { min-height: 34px; padding: 4px 12px; font-size: 13px; font-weight: 500; }
.setup-note { font-size: 14px; margin: 0 0 4px; text-align: left; }

/* 卡片 */
.stats.four { grid-template-columns: repeat(4, 1fr); gap: 6px; }
.stats.four div { padding: 7px 8px; }
.stats b.warn { color: var(--yellow); }
.stats b.bad { color: var(--red); }
.actions { grid-template-columns: repeat(2, 1fr); }
.actions .btn.full { grid-column: 1 / -1; }
.links { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.link-btn { background: var(--panel-2); border: 1px solid var(--border); border-radius: 9px; min-height: 38px; font-size: 13px; cursor: pointer; color: var(--text); padding: 4px 6px; }
.link-btn:active { background: var(--panel-3); }

/* 詳細頁 */
.d-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dtabs { display: flex; border-bottom: 1px solid var(--border); background: var(--panel); flex: none; }
.dtabs button { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; min-height: 44px; color: var(--muted); font-weight: 600; cursor: pointer; }
.dtabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.pane { flex: 1; min-height: 0; }
.pane-console:not([hidden]) { display: flex; flex-direction: column; }
.pane.scroll { overflow-y: auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); max-width: 760px; width: 100%; margin: 0 auto; }
.sec-title { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 16px 2px 8px; }
.sec-title:first-child { margin-top: 2px; }
.sec-title .note { font-size: 12px; font-weight: 400; }
.text-in { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); min-height: 44px; outline: none; font-size: 16px; }
.text-in:focus { border-color: var(--accent); }
.grid-btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.grid-btns .btn { min-height: 40px; padding: 6px 8px; font-size: 14px; }
.inline-form { display: flex; gap: 8px; }
.inline-form .text-in { flex: 1; }
.empty-sm { padding: 10px 4px; font-size: 14px; }
.player { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 8px; padding: 4px 10px; }
.player.open { padding-bottom: 10px; }
.player-row { display: flex; align-items: center; gap: 10px; width: 100%; background: none; border: 0; padding: 8px 0; cursor: pointer; text-align: left; }
.avatar { width: 30px; height: 30px; border-radius: 7px; background: var(--panel-3); display: grid; place-items: center; font-weight: 700; color: var(--accent); flex: none; }
.name-list { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.name-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--border); gap: 8px; }
.name-row:last-child { border-bottom: 0; }
.name-row span { overflow: hidden; text-overflow: ellipsis; }
.name-row .link-btn { min-height: 34px; flex: none; }
.bk-top { display: flex; align-items: center; gap: 10px; }
.bk-top .muted { flex: 1; font-size: 13px; }
.bar { height: 8px; background: var(--panel-3); border-radius: 4px; overflow: hidden; margin-top: 12px; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.bk-pt { font-size: 12px; margin-top: 4px; }
.bk-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; }
.bk-row .muted { font-size: 12px; }

/* 圖表 */
.seg { display: flex; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; min-height: 38px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--panel-3); color: var(--text); }
.ch-note { font-size: 12px; margin: 8px 2px 12px; }
.ch-empty { background: var(--panel); border: 1px dashed var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.ch-card { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; padding: 10px 10px 6px; margin-bottom: 12px; }
.ch-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin: 0 4px 6px; }
.ch-sum { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ch-sum b { color: var(--text); font-weight: 600; }
.ch-card canvas { display: block; width: 100%; height: 140px; touch-action: pan-y; }

/* 公開網站設定 */
.row-check { display: flex; align-items: center; gap: 10px; padding: 10px 2px; font-size: 15px; }
.row-check input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.text-in.area { min-height: 120px; resize: vertical; font: inherit; }
.pub-srv { margin-bottom: 8px; padding: 6px 12px 12px; }
.save-btn { margin-top: 18px; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; color: var(--text); }
