/* JK 箱庭 2026 — JKGame 2026 house style.
   同 agar-2026/src/client/css/main.css 同一套 token，但唔載入外部字型（design doc §4）：
   display / cjk / mono 全部行系統 stack。深色專用；手機先行，≥900px 轉側邊 rail。 */

:root {
    --bg: #050505;
    --panel: #0a0a0c;
    --fg: #f2f2f2;
    --mute: #9a9aa2;
    --dim: #5c5c66;
    --lime: #c8ff3d;
    --cyan: #4de1ff;
    --warn: #ffb020;
    --bad: #ff6b5e;
    --line: #1c1c1c;
    --line2: rgba(255, 255, 255, 0.16);
    --card: rgba(255, 255, 255, 0.035);
    --display: 'Avenir Next', 'Helvetica Neue', 'PingFang HK', 'Noto Sans CJK HK', system-ui, sans-serif;
    --cjk: 'PingFang HK', 'Noto Sans CJK HK', 'Microsoft JhengHei', system-ui, sans-serif;
    --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    --tabbar: 58px;
    --topbar: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--cjk);
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}

a { color: inherit; text-decoration: none; }
::selection { background: rgba(200, 255, 61, 0.35); }
button { font: inherit; color: inherit; }

.grid-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(255, 255, 255, 0.028) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(120% 90% at 50% 0%, #000 30%, transparent 100%);
}

.mono { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; }
.display { font-family: var(--display); font-weight: 700; letter-spacing: -0.02em; }
.lime { color: var(--lime); }
.dim { color: var(--dim); }
.label { color: var(--mute); margin: 0; }
.huge { font-size: 40px; line-height: 1; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ topbar */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    height: var(--topbar);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    padding-top: env(safe-area-inset-top);
    background: rgba(5, 5, 5, 0.86);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: center; gap: 6px; color: var(--mute); flex: none; }
.topbar .brand img { display: block; border-radius: 6px; }
.game-name { font-size: 16px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* 375px wide, one hand: the brand word, the game name, the language switch and the JK ID
   chip do not all fit. The brand word is the one nobody needs to read. */
@media (max-width: 480px) {
    .topbar { gap: 6px; padding: 0 8px; }
    .topbar .brand .mono { display: none; }
    .game-name { font-size: 15px; }
    .chip { max-width: 30vw; padding: 6px 8px; }
    .langbtn { padding: 0 7px; }
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip {
    max-width: 44vw;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--card);
    color: var(--mute);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: none;
    letter-spacing: 0;
}
.chip a { color: var(--lime); }
.chip .sep { color: var(--dim); margin: 0 5px; }
.langswitch { display: flex; gap: 2px; flex: none; }
.langbtn {
    min-height: 30px;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: none;
    color: var(--dim);
    font-family: var(--mono);
    font-size: 11px;
    letter-spacing: 0.04em;
    cursor: pointer;
    white-space: nowrap;
}
.langbtn.on { color: #050505; background: var(--lime); border-color: var(--lime); }

.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--dim); flex: none;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}
.live-dot.on { background: var(--lime); box-shadow: 0 0 0 3px rgba(200, 255, 61, 0.16); }

/* -------------------------------------------------------------------- main */
#main {
    position: relative;
    z-index: 1;
    padding: 12px 12px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom));
    max-width: 720px;
    margin: 0 auto;
}
.screen { display: flex; flex-direction: column; gap: 12px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; font-size: 20px; }

.ghost {
    background: none;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 10px;
    color: var(--mute);
    cursor: pointer;
}
.ghost:active { border-color: var(--line2); color: var(--fg); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid var(--line2);
    border-radius: 12px;
    background: transparent;
    color: var(--fg);
    font-weight: 600;
    cursor: pointer;
}
.btn.primary { background: var(--lime); border-color: var(--lime); color: #050505; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.45; cursor: default; }

input[type="text"], input[type="number"], input[type="search"] {
    width: 100%;
    min-height: 44px;
    padding: 0 12px;
    background: #0d0d10;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--fg);
    font: inherit;
}
input:focus { outline: none; border-color: var(--lime); }

.warn { margin: 8px 0 0; color: var(--warn); font-size: 13px; }
.err-card { border-color: rgba(255, 107, 94, 0.4); }
.err-card p { margin: 0 0 10px; color: var(--bad); font-size: 14px; }
.empty { color: var(--dim); font-size: 13px; margin: 4px 0; }

/* ------------------------------------------------------------------- lobby */
.turn-row { display: flex; align-items: flex-end; gap: 16px; margin: 6px 0 12px; }
.turn-next { display: flex; flex-direction: column; gap: 2px; }
.turn-next b { font-size: 22px; color: var(--lime); font-variant-numeric: tabular-nums; }
.counts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.counts div { border: 1px solid var(--line); border-radius: 10px; padding: 8px; text-align: center; }
.counts .k { display: block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--mute); }
.counts b { font-family: var(--display); font-size: 19px; }

.hud { display: flex; flex-wrap: wrap; gap: 8px; }
.hud .hchip {
    flex: 1 1 78px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 7px 9px;
}
.hud .hchip span { display: block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--mute); }
.hud .hchip b { font-family: var(--display); font-size: 18px; font-variant-numeric: tabular-nums; }

.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
    font-family: var(--mono); font-size: 10px; letter-spacing: 0.08em;
    padding: 3px 7px; border-radius: 999px;
    border: 1px solid var(--line2); color: var(--mute);
}
.badge.npc { color: var(--cyan); border-color: rgba(77, 225, 255, 0.4); }
.badge.dormant { color: var(--warn); border-color: rgba(255, 176, 32, 0.4); }
.badge.young { color: var(--lime); border-color: rgba(200, 255, 61, 0.4); }

.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.feed li { padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; line-height: 1.5; }
.feed li:first-child { border-top: none; }
.feed .t { font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--dim); margin-right: 8px; }
.feed .who { color: var(--lime); cursor: pointer; }
.feed .txt { color: var(--fg); }

.rank { list-style: none; margin: 0; padding: 0; }
.rank li {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px;
}
.rank li:first-child { border-top: none; }
.rank .no { font-family: var(--mono); font-size: 11px; color: var(--dim); width: 22px; }
.rank .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .val { font-family: var(--display); font-variant-numeric: tabular-nums; }
.rank .prizes { display: flex; gap: 2px; }
.rank .prizes img { width: 16px; height: 16px; image-rendering: pixelated; }

.cta { display: flex; flex-direction: column; gap: 10px; }
.cta h2 { margin: 0; font-size: 20px; }
.cta p { margin: 0; color: var(--mute); font-size: 14px; line-height: 1.6; }

.since { border-color: rgba(200, 255, 61, 0.35); }
.since .card-head { margin-bottom: 6px; }

/* --------------------------------------------------------------------- map */
.map-card { padding: 10px; }
.map-tools { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.map-tools .ghost { min-width: 36px; min-height: 32px; padding: 0 8px; white-space: nowrap; flex: none; }
/* The hint is the only part allowed to shrink: a wrapped toolbar pushes the map down. */
.map-tools .dim {
    margin-left: auto;
    min-width: 0;
    text-transform: none;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.map-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 400 / 384;
    background: #07070a;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
}
.map-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }

/* ------------------------------------------------------------------- plans */
.plans { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plans li {
    display: flex; align-items: center; gap: 10px;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
}
.plans li.drag-over { border-color: var(--lime); }
.plans li.plans-head { background: none; border: none; padding: 0; }
.plans .no { font-family: var(--mono); font-size: 11px; color: var(--dim); width: 24px; flex: none; }
.plans .body { flex: 1; min-width: 0; }
.plans .body b { display: block; font-size: 15px; }
.plans .body .sub { font-family: var(--mono); font-size: 10px; letter-spacing: 0.06em; color: var(--mute); text-transform: none; }
.plans .acts { display: flex; gap: 4px; flex: none; }
.plans .acts button { min-width: 32px; min-height: 36px; padding: 0; font-size: 13px; }
.plans .acts .del { color: var(--bad); }

/* ------------------------------------------------------------------- world */
.subtabs { display: flex; gap: 6px; margin-bottom: 4px; }
.subtab {
    flex: 1; min-height: 40px; border: 1px solid var(--line); border-radius: 10px;
    background: none; color: var(--mute); cursor: pointer;
}
.subtab.active { color: #050505; background: var(--lime); border-color: var(--lime); }

.filters { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.filters input { flex: 1 1 150px; }
.sorts { display: flex; gap: 6px; }
.sorts button { min-height: 44px; }
.sorts button.on { color: #050505; background: var(--lime); border-color: var(--lime); }

.ilist { list-style: none; margin: 0; padding: 0; }
.ilist li {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer;
}
.ilist li:first-child { border-top: none; }
.ilist .nm { flex: 1; min-width: 0; }
.ilist .nm b { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ilist .nm .sub { font-family: var(--mono); font-size: 10px; color: var(--dim); letter-spacing: 0.06em; }
.ilist .val { font-family: var(--display); font-variant-numeric: tabular-nums; text-align: right; }
.ilist .val span { display: block; font-family: var(--mono); font-size: 9px; color: var(--dim); }

/* ------------------------------------------------------------------- sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, 0.6); }
.sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 41;
    max-height: 82vh;
    display: flex;
    flex-direction: column;
    background: var(--panel);
    border-top: 1px solid var(--line2);
    border-radius: 18px 18px 0 0;
    padding: 8px 14px calc(16px + env(safe-area-inset-bottom));
}
.sheet-grip { width: 38px; height: 4px; border-radius: 999px; background: var(--line2); margin: 4px auto 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-body h3 { margin: 0 0 4px; font-size: 18px; font-family: var(--display); }

.kv { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 8px 0 12px; }
.kv div { border: 1px solid var(--line); border-radius: 10px; padding: 7px 9px; }
.kv span { display: block; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; color: var(--mute); }
.kv b { font-family: var(--display); font-size: 16px; }

.cmdgroup { margin: 12px 0 4px; }
.cmdlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cmdlist button {
    width: 100%; min-height: 48px;
    display: flex; align-items: center; gap: 10px;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
    padding: 8px 12px; text-align: left; cursor: pointer;
}
.cmdlist .nm { flex: 1; min-width: 0; }
.cmdlist .nm b { display: block; font-size: 15px; }
.cmdlist .nm .desc { font-size: 12px; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.cmdlist .cost { font-family: var(--mono); font-size: 10px; color: var(--mute); text-align: right; flex: none; }
.cmdlist .free { color: var(--lime); }

.stepper { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.stepper button { min-width: 52px; min-height: 48px; font-size: 20px; }
.stepper input { text-align: center; font-family: var(--display); font-size: 18px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 12px; }
.sheet-actions .btn { flex: 1; }

/* ------------------------------------------------------------------ tabbar */
.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: flex;
    height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(5, 5, 5, 0.92);
    backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
}
.tabbar .tab {
    flex: 1;
    min-height: 44px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--dim);
    font-size: 11px;
    cursor: pointer;
}
.tabbar .tab .ti { font-size: 15px; line-height: 1; }
.tabbar .tab.active { color: var(--lime); }

.toasts {
    position: fixed;
    left: 12px; right: 12px;
    bottom: calc(var(--tabbar) + 14px + env(safe-area-inset-bottom));
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}
.toast {
    background: #101014;
    border: 1px solid var(--line2);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
}
.toast.good { border-color: rgba(200, 255, 61, 0.5); }
.toast.bad { border-color: rgba(255, 107, 94, 0.5); color: #ffd9d5; }

/* ------------------------------------------------------ desktop: side rail */
@media (min-width: 900px) {
    :root { --tabbar: 0px; }
    body { padding-left: 208px; }
    .topbar { padding-left: 220px; }
    .tabbar {
        top: 0; right: auto; bottom: 0;
        width: 208px; height: 100vh;
        flex-direction: column;
        justify-content: flex-start;
        gap: 4px;
        padding: calc(var(--topbar) + 16px) 12px 12px;
        border-top: none;
        border-right: 1px solid var(--line);
    }
    .tabbar .tab {
        flex: none;
        flex-direction: row;
        justify-content: flex-start;
        gap: 10px;
        height: 46px;
        padding: 0 12px;
        border-radius: 10px;
        font-size: 15px;
    }
    .tabbar .tab.active { background: rgba(200, 255, 61, 0.1); }
    #main { max-width: 860px; padding-bottom: 48px; }
    .toasts { left: auto; right: 20px; bottom: 20px; width: 320px; }
    .sheet { left: auto; right: 20px; bottom: 20px; width: 420px; max-height: 76vh; border-radius: 16px; border: 1px solid var(--line2); }
    .kv { grid-template-columns: repeat(3, 1fr); }
    .counts { grid-template-columns: repeat(4, 1fr); }
}
