:root {
    --bg: #030712;
    --panel: rgba(15, 23, 42, 0.82);
    --panel-solid: #0f172a;
    --border: rgba(255, 255, 255, 0.1);
    --text: #f8fafc;
    --muted: #94a3b8;
    --dim: #64748b;
    --accent: #3b82f6;
    --accent-2: #2563eb;
    --glow: rgba(59, 130, 246, 0.45);
    --danger: #ef4444;
    --warn: #f59e0b;
    --ok: #10b981;
    --gold: #fbbf24;
    --radius: 12px;
    --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, sans-serif; overflow: hidden; user-select: none; -webkit-user-select: none; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.small { font-size: 0.8rem; }
kbd { display: inline-block; padding: 1px 6px; border-radius: 4px; background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.18); font-size: 0.75em; font-family: inherit; }

/* ---------- Screens ---------- */
.screen { position: absolute; inset: 0; }
#screen-menu, #screen-lobby { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; overflow-y: auto;
    background: radial-gradient(1200px 600px at 30% -10%, rgba(37, 99, 235, 0.18), transparent 60%), radial-gradient(800px 500px at 90% 110%, rgba(16, 185, 129, 0.12), transparent 60%), var(--bg); }
.menu-card { width: min(760px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); backdrop-filter: blur(16px); }
.menu-card.narrow { width: min(520px, 100%); }
.menu-head { text-align: center; margin-bottom: 18px; }
.menu-head h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); font-weight: 800; letter-spacing: -0.02em; color: #fff; text-shadow: 0 0 28px rgba(96, 165, 250, 0.45); }
.menu-head h1 span { font-weight: 400; color: var(--muted); font-size: 0.6em; }
.tagline { color: var(--muted); margin-top: 6px; }
.version { color: var(--dim); font-size: 0.75rem; margin-top: 14px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { background: none; border: none; padding: 10px 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px 16px; margin-bottom: 18px; }
.field-grid.compact { gap: 8px 12px; margin-bottom: 12px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 0.85rem; color: var(--muted); font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
input[type=text], input[type=number], select { width: 100%; padding: 8px 10px; background: rgba(0,0,0,0.35); border: 1px solid #334155; border-radius: 8px; color: var(--text); outline: none; transition: border-color 0.15s; }
input:focus, select:focus { border-color: var(--accent); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.subcard { background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.06); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.subcard h3 { font-size: 1rem; color: #cbd5e1; }
.hint { color: var(--muted); font-size: 0.82rem; margin-top: 12px; line-height: 1.4; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- Buttons ---------- */
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border: 1px solid rgba(255,255,255,0.2); padding: 10px 18px; border-radius: 8px; font-weight: 600; cursor: pointer; box-shadow: 0 4px 15px var(--glow); transition: transform 0.12s var(--ease), box-shadow 0.12s, filter 0.12s; }
button.primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px var(--glow); filter: brightness(1.08); }
button.primary:active { transform: translateY(0) scale(0.98); }
button.primary.big { width: 100%; padding: 13px; font-size: 1.05rem; }
button.primary.alt { background: linear-gradient(135deg, #10b981, #059669); box-shadow: 0 4px 15px rgba(16,185,129,0.35); }
button.primary.danger { background: linear-gradient(135deg, #ef4444, #b91c1c); box-shadow: 0 4px 15px rgba(239,68,68,0.35); }
button.primary.warn { background: linear-gradient(135deg, #f97316, #c2410c); box-shadow: 0 4px 15px rgba(249,115,22,0.35); }
button.ghost { background: rgba(255,255,255,0.08); color: var(--text); border: 1px solid rgba(255,255,255,0.14); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; transition: background 0.12s, transform 0.12s; }
button.ghost:hover { background: rgba(255,255,255,0.16); }
button.ghost:active { transform: scale(0.98); }
button.ghost.small { padding: 5px 10px; font-size: 0.8rem; }
button.icon-btn { width: 38px; padding: 8px 0; }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none !important; box-shadow: none !important; filter: none !important; }
button.x { background: none; border: none; color: var(--muted); font-size: 1.5rem; cursor: pointer; line-height: 1; padding: 0 6px; }
button.x:hover { color: #fff; }
.action-btn { width: 100%; background: rgba(255,255,255,0.08); color: #fff; border: 1px solid rgba(255,255,255,0.16); padding: 9px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 8px; text-align: left; display: flex; justify-content: space-between; align-items: center; transition: background 0.12s; }
.action-btn:hover:not(:disabled) { background: rgba(255,255,255,0.16); }
.action-btn.pillage { background: rgba(234, 88, 12, 0.3); border-color: rgba(234, 88, 12, 0.6); }
.action-btn.pillage:hover:not(:disabled) { background: rgba(234, 88, 12, 0.45); }
.action-btn kbd { opacity: 0.7; }

/* ---------- Lobby ---------- */
.code-row { display: flex; align-items: center; gap: 12px; margin: 12px 0 16px; }
.code { font-size: 2.6rem; font-family: ui-monospace, monospace; letter-spacing: 0.3rem; font-weight: 800; background: rgba(0,0,0,0.3); padding: 8px 16px; border-radius: 10px; border: 1px dashed rgba(255,255,255,0.25); flex: 1; text-align: center; }
.settings-summary { color: var(--muted); font-size: 0.85rem; margin-bottom: 14px; display: flex; gap: 14px; flex-wrap: wrap; }
.players { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 8px; padding: 6px 8px; background: rgba(255,255,255,0.04); border-radius: 6px; }
.players .dot, .faction .dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- Game ---------- */
#screen-game { background: var(--bg); }
#game-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: default; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#top-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 16px; background: var(--panel); backdrop-filter: blur(16px); border-bottom: 1px solid var(--border); box-shadow: 0 4px 30px rgba(0,0,0,0.5); pointer-events: auto; padding-top: max(10px, env(safe-area-inset-top)); }
.tb-group { display: flex; align-items: center; gap: 18px; }
.tb-group.right { gap: 8px; }
.tb-stat { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 0.95rem; text-shadow: 0 2px 4px rgba(0,0,0,0.8); white-space: nowrap; }
.tb-stat .icon { font-size: 1.05rem; }
.tb-stat.warn { color: var(--warn); }
.tb-stat.danger { color: var(--danger); animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: 0.55; } }
.faction { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.player-dots { display: flex; gap: 5px; margin-left: 6px; }
.player-dots .pd { width: 16px; height: 16px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 800; color: #fff; border: 1px solid rgba(255,255,255,0.3); }
.player-dots .pd.dead { opacity: 0.3; }

.turn-banner { position: absolute; top: 66px; left: 50%; transform: translateX(-50%); padding: 7px 20px; border-radius: 24px; font-weight: 600; font-size: 0.9rem; z-index: 50; backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.1); white-space: nowrap; }
.turn-banner.active { background: rgba(16, 185, 129, 0.25); color: #6ee7b7; }
.turn-banner.waiting { background: rgba(245, 158, 11, 0.25); color: #fcd34d; }
.turn-banner.over { background: rgba(148, 163, 184, 0.25); color: #e2e8f0; }

#side-panel { position: absolute; right: 16px; top: 70px; width: 330px; max-height: calc(100% - 90px); overflow-y: auto; background: var(--panel); backdrop-filter: blur(20px); border: 1px solid var(--border); border-radius: 14px; padding: 16px; pointer-events: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.7); transition: transform 0.3s var(--ease), opacity 0.3s; }
#side-panel.panel-hidden { transform: translateX(120%); opacity: 0; pointer-events: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); margin-bottom: 10px; padding-bottom: 8px; }
.panel-head h2 { font-size: 1.1rem; }
.panel-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 5px; font-size: 0.9rem; }
.panel-row .k { color: var(--muted); }
.panel-row.warn .v { color: var(--warn); font-weight: 600; }
.panel-row.danger .v { color: var(--danger); font-weight: 600; }
.panel-row.good .v { color: #6ee7b7; }
.panel-sep { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.army-title { font-weight: 800; margin: 6px 0 6px; display: flex; align-items: center; gap: 8px; }
.army-title .idx { font-size: 0.75rem; color: var(--muted); font-weight: 600; }
.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 0.72rem; font-weight: 700; }
.badge.rout { background: rgba(239,68,68,0.25); color: #fca5a5; }
.badge.engaged { background: rgba(251,191,36,0.25); color: #fde68a; }
.badge.starve { background: rgba(249,115,22,0.25); color: #fdba74; }
.badge.enemy { background: rgba(255,255,255,0.1); color: #cbd5e1; }
.bar { height: 6px; background: rgba(255,255,255,0.08); border-radius: 4px; overflow: hidden; margin: 2px 0 8px; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--ok); transition: width 0.3s var(--ease); }
.bar.morale > i { background: linear-gradient(90deg, #ef4444, #f59e0b 35%, #10b981 55%); }
.odds { background: rgba(0,0,0,0.3); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin: 8px 0; font-size: 0.85rem; }
.odds .oddsbar { height: 10px; border-radius: 5px; overflow: hidden; display: flex; margin: 6px 0; }
.odds .tt-row, .modal .tt-row { display: flex; justify-content: space-between; gap: 12px; }
.odds .oddsbar i { display: block; height: 100%; }
.stack-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.stack-item { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; background: rgba(255,255,255,0.04); cursor: pointer; font-size: 0.85rem; }
.stack-item:hover { background: rgba(255,255,255,0.1); }
.stack-item.sel { outline: 1px solid var(--gold); }
.stack-item .dot { width: 10px; height: 10px; border-radius: 50%; }
#panel-actions { margin-top: 10px; }
.t3r-wrap { margin-top: 8px; font-size: 0.8rem; color: var(--muted); }
.t3r-wrap .vals { display: flex; justify-content: space-between; margin-top: 2px; }

#tooltip { position: absolute; z-index: 60; background: rgba(15, 23, 42, 0.95); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 0.8rem; max-width: 260px; pointer-events: none; box-shadow: 0 8px 24px rgba(0,0,0,0.6); line-height: 1.35; }
#tooltip b { color: #fff; }
#tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }
#tooltip .tt-army { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
#tooltip .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
#tooltip .tt-note { color: var(--muted); margin-top: 4px; }

#hintbar { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: rgba(15, 23, 42, 0.75); border: 1px solid var(--border); border-radius: 999px; padding: 6px 16px; font-size: 0.8rem; color: #cbd5e1; pointer-events: none; backdrop-filter: blur(10px); white-space: nowrap; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; transition: opacity 0.2s; }
#hintbar:empty { opacity: 0; }

.dock { position: absolute; bottom: 14px; left: 14px; pointer-events: auto; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.dock.right { left: auto; right: 14px; align-items: flex-end; }
.dock-toggle { background: rgba(15, 23, 42, 0.8); border: 1px solid var(--border); color: var(--muted); padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; cursor: pointer; font-weight: 600; }
.dock-toggle:hover { color: #fff; }
.dock-body { background: rgba(15, 23, 42, 0.85); backdrop-filter: blur(10px); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 0.75rem; color: #cbd5e1; width: 240px; }
.dock.collapsed .dock-body { display: none; }
.legend-row { display: flex; align-items: center; gap: 7px; margin-bottom: 3px; }
.legend-row i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; border: 1px solid rgba(255,255,255,0.15); }
.legend-note { margin-top: 6px; color: var(--muted); line-height: 1.35; }
#log-list { list-style: none; max-height: 190px; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; width: 100%; }
#log-list li { padding: 3px 0; border-bottom: 1px solid rgba(255,255,255,0.05); line-height: 1.3; }
#log-list li .t { color: var(--dim); margin-right: 5px; font-variant-numeric: tabular-nums; }
#log-list li.battle { color: #fde68a; } #log-list li.rout, #log-list li.disband, #log-list li.desertion, #log-list li.eliminated { color: #fca5a5; } #log-list li.pillage { color: #86efac; } #log-list li.dread { color: #fdba74; } #log-list li.resolve { color: #93c5fd; }

/* ---------- Modals ---------- */
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.45); backdrop-filter: blur(3px); z-index: 300; display: flex; align-items: center; justify-content: center; pointer-events: auto; padding: 16px; animation: fadein 0.12s var(--ease); }
@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
.modal { background: var(--panel-solid); border: 1px solid rgba(255,255,255,0.12); border-radius: 14px; padding: 22px 24px; width: 440px; max-width: 100%; max-height: 88vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.85); animation: pop 0.14s var(--ease); }
@keyframes pop { from { transform: scale(0.96); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.modal.wide { width: 620px; }
.modal h2 { font-size: 1.25rem; margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.modal .body { overflow-y: auto; color: #cbd5e1; font-size: 0.92rem; line-height: 1.45; }
.modal .body p { margin-bottom: 8px; }
.modal .buttons { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.modal .buttons .spacer { flex: 1; }
.card { background: rgba(0,0,0,0.25); border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }
.card .outcome { font-size: 1.1rem; font-weight: 800; margin-bottom: 2px; }
.card .outcome.victory { color: var(--gold); } .card .outcome.defeat { color: var(--danger); } .card .outcome.neutral { color: #cbd5e1; }
.card .summary { color: var(--muted); font-size: 0.88rem; margin-bottom: 6px; }
.brow { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; font-size: 0.86rem; padding: 4px 0; border-top: 1px solid rgba(255,255,255,0.06); }
.brow .who { display: flex; align-items: center; gap: 6px; min-width: 0; } .brow .who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.brow .str { color: var(--muted); font-size: 0.78rem; } .brow .loss { text-align: right; font-variant-numeric: tabular-nums; }
.brow .bad { color: var(--danger); font-weight: 600; } .brow .good { color: #6ee7b7; }
.score-table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.score-table td { padding: 5px 4px; border-bottom: 1px solid rgba(255,255,255,0.06); font-size: 0.9rem; }
.score-table td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.score-table td .d { display: block; color: var(--muted); font-size: 0.76rem; font-weight: 400; }
.score-total { display: flex; justify-content: space-between; font-size: 1.3rem; font-weight: 800; padding: 8px 4px; }
.rank { text-align: center; padding: 10px; background: linear-gradient(135deg, rgba(251,191,36,0.15), rgba(59,130,246,0.1)); border: 1px solid rgba(251,191,36,0.3); border-radius: 10px; margin-bottom: 10px; }
.rank .r-name { font-size: 1.35rem; font-weight: 800; color: var(--gold); }
.rank .r-blurb { color: var(--muted); font-size: 0.85rem; font-style: italic; margin-top: 2px; }
.go-title { font-size: 2.2rem; text-align: center; margin-bottom: 4px; }
.go-title.win { color: var(--gold); } .go-title.lose { color: var(--danger); } .go-title.draw { color: #cbd5e1; }
.go-sub { text-align: center; color: var(--muted); margin-bottom: 14px; }
.shortcuts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.86rem; }
.shortcuts kbd { justify-self: start; }
.tune-grid { display: grid; grid-template-columns: 1fr; gap: 8px; }
.tune-row { display: grid; grid-template-columns: 1fr 90px; gap: 10px; align-items: center; font-size: 0.82rem; }
.tune-row .k { color: var(--muted); } .tune-row .k b { color: #e2e8f0; display: block; }
.tune-row input { padding: 5px 8px; }
.howto h3 { margin: 12px 0 4px; font-size: 1rem; color: #e2e8f0; }
.howto p, .howto li { color: #cbd5e1; font-size: 0.9rem; line-height: 1.5; }
.howto ul { padding-left: 18px; }
.fame table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.fame td, .fame th { padding: 6px 6px; border-bottom: 1px solid rgba(255,255,255,0.06); text-align: left; }
.fame th { color: var(--muted); font-weight: 600; }
.fame .empty { color: var(--muted); padding: 12px 0; }

/* ---------- Toasts ---------- */
#toasts { position: absolute; top: 76px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 6px; z-index: 400; pointer-events: none; }
.toast { background: rgba(15, 23, 42, 0.95); border: 1px solid var(--border); border-left: 3px solid var(--accent); padding: 8px 14px; border-radius: 8px; font-size: 0.85rem; box-shadow: 0 8px 24px rgba(0,0,0,0.6); animation: slidein 0.18s var(--ease); max-width: 90vw; }
.toast.error { border-left-color: var(--danger); } .toast.warn { border-left-color: var(--warn); } .toast.good { border-left-color: var(--ok); }
@keyframes slidein { from { transform: translateY(-8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .tb-group.center .tb-stat:nth-child(5), #tb-players { display: none; }
    .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    #top-bar { padding: 6px 8px; gap: 4px 6px; flex-wrap: wrap; } .tb-group { gap: 8px; } .tb-group.right { margin-left: auto; } .tb-stat { font-size: 0.8rem; gap: 3px; } .tb-stat .icon { font-size: 0.9rem; }
    .faction .name { display: none; } #tb-turn { font-size: 0.8rem; }
    .tb-group.center .tb-stat:nth-child(3), .tb-group.center .tb-stat:nth-child(4), .tb-group.center .tb-stat:nth-child(5), #tb-players { display: none; }
    #btn-undo, #btn-next { padding: 7px 9px; font-size: 0.85rem; } #btn-undo { font-size: 0; } #btn-undo::before { content: '↶'; font-size: 1rem; } #btn-next { font-size: 0; } #btn-next::before { content: '▸'; font-size: 1rem; }
    #btn-end-turn { padding: 8px 12px; font-size: 0.9rem; } #btn-menu { width: 32px; }
    #side-panel { top: auto; bottom: 0; right: 0; left: 0; width: 100%; max-height: 45vh; border-radius: 16px 16px 0 0; }
    #side-panel.panel-hidden { transform: translateY(120%); }
    .dock, #hintbar { display: none; }
    .modal { padding: 16px; }
    .menu-card { padding: 18px; }
}

/* ---- Army composition + tooth/tail rat ---- */
.comp { display: flex; gap: 10px; align-items: center; margin: 6px 0 4px; }
.rat-wrap { flex: 0 0 auto; width: 128px; text-align: center; }
.rat { width: 128px; height: auto; display: block; }
.rat-cap { font-size: 0.78rem; line-height: 1.25; margin-top: 2px; }
.units { flex: 1; border-collapse: collapse; font-size: 0.82rem; }
.units td { padding: 1px 4px; }
.units td.n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.units td.r { color: var(--muted, #94a3b8); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; }
.units tr.tooth td:first-child { color: #fca5a5; }
.units tr.tail td:first-child { color: #fcd34d; }
.comp-note, .speed-why { margin: 2px 0 6px; line-height: 1.3; }
.bar.food { height: 5px; }
.bar.food i { background: #f59e0b; }
.split-grid { display: grid; grid-template-columns: 86px 1fr 84px; gap: 6px 8px; align-items: center; margin: 8px 0; }
.split-grid .lbl { font-size: 0.85rem; }
.split-grid .num { width: 100%; box-sizing: border-box; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; font-size: inherit; color: inherit; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.18); border-radius: 6px; padding: 3px 6px; }
.split-grid .num:hover { border-color: rgba(255,255,255,0.4); }
.split-grid .num:focus { outline: none; border-color: var(--gold, #facc15); background: rgba(255,255,255,0.12); }
.split-prev { display: flex; gap: 10px; }
.split-prev > div { flex: 1; background: rgba(148,163,184,0.1); border-radius: 8px; padding: 6px 8px; font-size: 0.8rem; }
.split-prev .rat { width: 90px; margin: 0 auto; }
.merge-list { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 6px; }
.merge-list label.stack-item { flex-direction: row; flex-wrap: nowrap; }
.merge-list label.stack-item input { width: auto; flex: none; }

.food-alert { cursor: pointer; }
.food-alert.crit { outline: 1px solid rgba(248, 113, 113, 0.7); background: rgba(248, 113, 113, 0.12); }

/* =====================================================================
   Touch-first mode (html.mobile, set by src/client/Mobile.js).
   Desktop is unaffected: every rule here is scoped to .mobile.
   ===================================================================== */
.mobile-only, .m-summary { display: none; }
.mobile { --bar-h: calc(64px + env(safe-area-inset-bottom)); --top-h: calc(50px + env(safe-area-inset-top)); }
.mobile, .mobile body { overscroll-behavior: none; }
.mobile body { position: fixed; inset: 0; -webkit-tap-highlight-color: transparent; }
.mobile #game-canvas { touch-action: none; }
.mobile button, .mobile .stack-item, .mobile select, .mobile input { touch-action: manipulation; }
.mobile kbd { display: none; }
.mobile .action-btn kbd, .mobile .modal .buttons kbd { display: none; }

/* Top bar: one compact row of status; controls moved to the bottom */
.mobile #top-bar { flex-wrap: nowrap; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); gap: 8px; min-height: var(--top-h); }
.mobile .tb-group { gap: 10px; }
.mobile .tb-group.center { flex: 1; justify-content: center; overflow: hidden; }
.mobile .tb-stat { font-size: 0.82rem; gap: 3px; }
.mobile .faction .name { display: none; }
.mobile #btn-menu { width: 40px; height: 40px; padding: 0; }

/* Bottom bar: the turn controls, in thumb reach */
.mobile #bottom-bar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--bar-h); display: flex; gap: 8px; align-items: center; padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); background: var(--panel-solid); border-top: 1px solid var(--border); pointer-events: auto; z-index: 20; box-shadow: 0 -6px 24px rgba(0,0,0,0.5); }
.mobile #bottom-bar.hidden { display: none; }
.mobile #bottom-bar button { height: 48px; min-width: 48px; font-size: 0.95rem; padding: 0 12px; border-radius: 12px; }
.mobile #bottom-bar #btn-undo, .mobile #bottom-bar #btn-next { font-size: 0.95rem; }
.mobile #bottom-bar #btn-undo::before, .mobile #bottom-bar #btn-next::before { content: none; }
.mobile #bottom-bar #btn-end-turn { flex: 1; font-size: 1.05rem; padding: 0 14px; }
.mobile #btn-log.mobile-only { display: inline-block; }

/* Army panel: a bottom sheet that peeks above the bar; tap/swipe its title to expand */
.mobile #side-panel { top: auto; left: 0; right: 0; bottom: var(--bar-h); width: 100%; max-height: 42vh; border-radius: 18px 18px 0 0; padding: 4px 14px 10px; display: flex; flex-direction: column; overflow: hidden; z-index: 15; transition: transform 0.25s var(--ease), opacity 0.25s, max-height 0.25s var(--ease); }
.mobile #side-panel.panel-hidden { transform: translateY(130%); }
.mobile #side-panel.expanded { max-height: calc(100% - var(--top-h) - var(--bar-h) - 10px); }
.mobile #side-panel .panel-head { flex-direction: column; align-items: stretch; padding: 0 0 6px; margin-bottom: 6px; cursor: pointer; position: relative; }
.mobile #side-panel .panel-head::before { content: ''; display: block; width: 42px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.28); margin: 4px auto 6px; }
.mobile #side-panel .panel-head h2 { font-size: 1rem; padding-right: 40px; }
.mobile #side-panel .panel-head .x { position: absolute; right: -6px; top: 6px; width: 44px; height: 40px; }
.mobile #panel-content, .mobile #panel-actions { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.mobile #panel-content { flex: 0 1 auto; }
.mobile #side-panel.expanded #panel-content { flex: 1 1 auto; }
.mobile .m-summary { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 0.84rem; margin: 2px 0 6px; }
.mobile .m-summary b { font-variant-numeric: tabular-nums; }
.mobile .m-summary .warn { color: var(--warn); } .mobile .m-summary .danger { color: var(--danger); }
/* Peek: just the summary and the actions; the full breakdown is one swipe up */
.mobile #side-panel:not(.expanded) #panel-content:has(.army-title) > :is(.panel-row, .comp, .comp-note, .speed-why, .bar, .muted, hr) { display: none; }
.mobile #side-panel:not(.expanded) #panel-content:has(.army-title) > hr + .army-title { margin-top: 0; }
.mobile #side-panel .army-title { margin: 2px 0 4px; }
.mobile .stack-item { min-height: 40px; }
.mobile #panel-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; margin-top: 6px; flex: none; }
.mobile .action-btn { margin: 0; min-height: 48px; justify-content: center; text-align: center; border-radius: 12px; font-weight: 600; }
.mobile .action-btn .muted { display: block; font-size: 0.75rem; font-weight: 500; }
.mobile .action-btn.confirm { grid-column: 1 / -1; flex-direction: column; gap: 2px; min-height: 58px; background: linear-gradient(135deg, #0ea5e9, #0369a1); border-color: rgba(255,255,255,0.25); font-size: 1.02rem; box-shadow: 0 4px 16px rgba(14,165,233,0.4); }
.mobile .action-btn.confirm.attack { background: linear-gradient(135deg, #ef4444, #991b1b); box-shadow: 0 4px 16px rgba(239,68,68,0.4); }
.mobile .action-btn.confirm.merge { background: linear-gradient(135deg, #ca8a04, #854d0e); box-shadow: 0 4px 16px rgba(202,138,4,0.4); }
.mobile .action-btn.confirm .sub { font-size: 0.75rem; font-weight: 500; opacity: 0.9; }

/* Dialogs become bottom sheets over a live map: no dimming, no blocking.
   Tap the title (or the map) to tuck one down to its title bar. */
.mobile .modal-backdrop.sheet { background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; pointer-events: none; align-items: flex-end; padding: 0; z-index: 300; }
.mobile .sheet .modal { pointer-events: auto; width: 100%; max-width: 100%; max-height: 72vh; border-radius: 18px 18px 0 0; padding: 4px 16px calc(12px + env(safe-area-inset-bottom)); animation: sheetup 0.2s var(--ease); box-shadow: 0 -12px 40px rgba(0,0,0,0.7); }
@keyframes sheetup { from { transform: translateY(40px); opacity: 0 } to { transform: none; opacity: 1 } }
.mobile .sheet-grip { width: 42px; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.28); margin: 6px auto 8px; cursor: pointer; flex: none; }
.mobile .sheet .modal h2 { font-size: 1.08rem; cursor: pointer; }
.mobile .sheet .modal.min { margin-bottom: var(--bar-h); padding-bottom: 6px; border-radius: 18px 18px 0 0; }
.mobile .sheet .modal.min .body, .mobile .sheet .modal.min .buttons { display: none; }
.mobile .sheet .modal.min h2 { border-bottom: 0; margin-bottom: 0; }
.mobile .sheet .modal.min h2::after { content: ' · tap to open'; color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.mobile .modal .buttons { gap: 8px; }
.mobile .modal .buttons button { min-height: 46px; flex: 1 1 auto; border-radius: 12px; }
.mobile .modal .buttons .spacer { display: none; }
.mobile .two-col, .mobile .split-prev { flex-direction: column; }
.mobile .split-grid { grid-template-columns: 72px 1fr 76px; }
.mobile .split-grid input[type=range] { height: 32px; }
.mobile .merge-list .stack-item { min-height: 48px; }
.mobile .m-log { list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 0.86rem; }
.mobile .m-log li { padding: 4px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.mobile .m-legend .legend-row { font-size: 0.85rem; }
.mobile .m-legend .legend-note { font-size: 0.8rem; }

/* Low-food warning chip: a reminder, not a popup */
.alert-chip { position: absolute; top: calc(var(--top-h, 60px) + 8px); left: 50%; transform: translateX(-50%); z-index: 40; pointer-events: auto; background: rgba(245, 158, 11, 0.92); color: #1c1917; border: 0; border-radius: 999px; padding: 9px 16px; font-weight: 700; font-size: 0.85rem; box-shadow: 0 6px 20px rgba(0,0,0,0.5); white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
.alert-chip.crit { background: rgba(239, 68, 68, 0.95); color: #fff; animation: blink 1.4s infinite; }
.mobile .turn-banner { top: calc(var(--top-h) + 52px); font-size: 0.8rem; padding: 6px 14px; }
.mobile #toasts { top: calc(var(--top-h) + 56px); width: 92vw; align-items: center; }
.mobile .toast { text-align: center; }
.mobile #tooltip { max-width: min(280px, 86vw); font-size: 0.85rem; }

/* Menu and lobby on phones */
.mobile .menu-card { padding: 16px; }
.mobile .tab { padding: 12px 12px; }
.mobile input[type=text], .mobile select { min-height: 44px; font-size: 16px; } /* 16px stops iOS zooming into fields */
