/* 9Bot Web Dashboard — Mobile-First CSS */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Thin dark scrollbars (Chromium/Edge) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0c0c18;
    color: #e0e0f0;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
}

/* Navigation */
nav {
    background: #14142a;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid rgba(100,216,255,0.08);
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.nav-brand {
    display: inline-flex;
    align-items: stretch;
    gap: 8px;
    color: #64d8ff;
    text-decoration: none;
}

.logo-line {
    display: flex;
    gap: 3px;
}

.logo-line::before,
.logo-line::after {
    content: '';
    width: 1px;
}

.logo-line::before {
    background: linear-gradient(180deg, #64d8ff22, #64d8ff88, #64d8ff22);
}

.logo-line::after {
    background: linear-gradient(180deg, #64d8ff44, #64d8ff, #64d8ff44);
}

.logo-group {
    display: flex;
    flex-direction: column;
}

.logo-main {
    display: flex;
    align-items: baseline;
}

.logo-nine {
    font-family: 'Bodoni Moda', serif;
    font-style: italic;
    font-weight: 700;
    font-size: 28px;
    line-height: 1;
    text-shadow: 0 0 15px rgba(100, 216, 255, 0.3);
}

.logo-text {
    font-family: system-ui, sans-serif;
    font-weight: 300;
    font-size: 11px;
    letter-spacing: 4px;
    margin-left: 1px;
}

.logo-sub {
    font-family: system-ui, sans-serif;
    font-size: 7px;
    letter-spacing: 4px;
    color: rgba(100, 216, 255, 0.25);
    margin-top: 1px;
}

.nav-links {
    display: flex;
    gap: 4px;
}

.nav-links a {
    color: #889;
    text-decoration: none;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.nav-links a.active {
    color: #fff;
    background: #1e3a5f;
}

/* Main content */
main {
    max-width: 960px;
    margin: 0 auto;
    padding: 12px;
}

/* Device cards grid — side by side on wider screens */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 10px;
}

.device-grid > .device-card {
    margin-bottom: 0;
}

h1 { font-size: 24px; margin-bottom: 16px; color: #fff; }
h2 { font-size: 18px; margin: 24px 0 12px; color: #ddd; }
h3 { font-size: 15px; margin-bottom: 12px; color: #64d8ff; }

/* Cards */
.card {
    background: #181830;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
}

.muted { color: #778; font-size: 14px; }

/* Access card */
/* Compact access strip */
.access-strip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    margin-bottom: 10px;
    border-radius: 6px;
    background: rgba(255,255,255,0.02);
}
.access-strip-btns {
    margin-left: auto;
    display: flex;
    gap: 4px;
}
.access-strip-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.06);
    color: #556;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}
.access-strip-btn:hover { color: #889; border-color: rgba(255,255,255,0.12); }
.access-strip-btn:active { color: #64d8ff; border-color: rgba(100,216,255,0.25); }

/* (access-btn removed — replaced by access-strip-btn) */

/* QR code modal overlay */
.qr-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.qr-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.qr-modal {
    background: #1a1a30;
    border: 1px solid rgba(100,216,255,0.15);
    border-radius: 16px;
    padding: 24px;
    text-align: center;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.qr-title {
    font-size: 12px;
    color: #64d8ff;
    font-weight: 600;
    margin-bottom: 16px;
    word-break: break-all;
}

.qr-img {
    width: 200px;
    height: 200px;
    border-radius: 8px;
    background: #fff;
    padding: 8px;
}

.qr-close {
    margin-top: 16px;
    padding: 8px 24px;
    background: #141428;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: #889;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.qr-close:active {
    background: #1e3a5f;
    color: #dde;
}

.share-modal-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
}

/* Share modal tab bar */
.share-tab-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 14px;
    background: rgba(0,0,0,0.25);
    border-radius: 8px;
    padding: 3px;
}

.share-tab {
    flex: 1;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 600;
    color: #667;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.share-tab.active {
    color: #fff;
    background: rgba(100,216,255,0.15);
}

.share-tab:active {
    opacity: 0.7;
}

.share-url {
    font-size: 11px;
    color: #64d8ff;
    word-break: break-all;
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 8px 10px;
    margin-bottom: 14px;
    font-family: monospace;
}
.share-url a {
    color: #64d8ff;
    text-decoration: none;
}
.share-url a:hover {
    text-decoration: underline;
}

.share-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 14px;
}

.share-action-btn {
    padding: 10px 24px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    background: #141428;
    border: 1px solid rgba(255,255,255,0.08);
    color: #889;
}

.share-action-btn:active {
    background: #1e3a5f;
    color: #dde;
}

.share-action-btn.share-action-primary {
    background: rgba(100,216,255,0.12);
    border-color: rgba(100,216,255,0.25);
    color: #64d8ff;
}

.share-action-btn.share-action-primary:active {
    background: rgba(100,216,255,0.22);
}

/* Tunnel status indicator (inside remote banner) */
.tunnel-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 8px;
    flex-shrink: 0;
}

.tunnel-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}

.tunnel-label {
    font-size: 11px;
    font-weight: 600;
}

/* Connected — green, pulsing */
.tunnel-connected {
    background: #4caf50;
    box-shadow: 0 0 8px rgba(76,175,80,0.7);
    animation: pulse-glow 2s ease-in-out infinite;
}

.tunnel-label-connected {
    color: #66bb6a;
}

/* Connecting — amber, pulsing */
.tunnel-connecting {
    background: #ffb74d;
    box-shadow: 0 0 8px rgba(255,183,77,0.6);
    animation: pulse-amber 2s ease-in-out infinite;
}

.tunnel-label-connecting {
    color: #ffb74d;
}

@keyframes pulse-amber {
    0%, 100% { box-shadow: 0 0 4px rgba(255,183,77,0.3); }
    50% { box-shadow: 0 0 12px rgba(255,183,77,0.7); }
}

/* Disconnected — red, static */
.tunnel-disconnected {
    background: #ef5350;
}

.tunnel-label-disconnected {
    color: #ef5350;
}

/* Disabled — gray, static */
.tunnel-disabled {
    background: #444;
}

.tunnel-label-disabled {
    color: #556;
}

/* Device cards */
.device-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-left: 2px solid rgba(100,216,255,0.25);
    padding-left: 14px;
    background: #181830;
}

.device-top {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    row-gap: 2px;
    column-gap: 12px;
}

.device-name-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.device-name-row strong {
    font-size: 16px;
    color: #f0f0ff;
    letter-spacing: 0.2px;
}

.device-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-self: end;
}

.share-btn {
    padding: 3px 10px;
    font-size: 10px;
    font-weight: 600;
    color: #778;
    background: none;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.share-btn:active {
    color: #99a;
    border-color: rgba(255,255,255,0.15);
}

.device-troops {
    font-size: 12px;
    color: #889;
    font-weight: 600;
}

/* Device status bar */
.device-status-bar {
    grid-column: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 0;
}

.status-indicator {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2a2a40;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.status-indicator.active {
    background: #4caf50;
    box-shadow: 0 0 8px rgba(76,175,80,0.5);
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 4px rgba(76,175,80,0.2); }
    50% { box-shadow: 0 0 10px rgba(76,175,80,0.5); }
}

.status-text {
    font-size: 13px;
    color: #667;
    font-weight: 600;
    transition: color 0.3s ease;
}

.status-text.status-active {
    color: #5cc8e8;
}

.status-text.status-waiting {
    color: #e8a94e;
}

.status-text.status-navigating {
    color: #8899aa;
}

.status-text.status-stopping {
    color: #e06060;
}

.status-text.status-error {
    color: #e05555;
    font-weight: 700;
}

.status-text.status-offline {
    color: #556;
}

/* Section labels inside cards */
.section-label {
    font-size: 9px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 6px;
    margin-bottom: 2px;
}

/* Section headers for task groups */
.section-header {
    font-size: 10px;
    font-weight: 700;
    color: #778;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 24px;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

/* Troop slots */
.troop-slots {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-top: 4px;
    align-items: center;
    justify-content: center;
}

.mithril-time {
    color: #ce93d8;
    font-weight: 700;
}

/* Troop summary pills */
.troop-summary {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 12px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    flex: 1 1 auto;
    text-align: center;
}

.troop-home       { color: #667; }
.troop-returning  { color: #4caf50; border-color: rgba(76,175,80,0.35); box-shadow: 0 0 8px rgba(76,175,80,0.15); }
.troop-rallying   { color: #42a5f5; border-color: rgba(66,165,245,0.35); box-shadow: 0 0 8px rgba(66,165,245,0.15); }
.troop-defending  { color: #ab47bc; border-color: rgba(171,71,188,0.35); box-shadow: 0 0 8px rgba(171,71,188,0.15); }
.troop-marching   { color: #e8a94e; border-color: rgba(232,169,78,0.35); box-shadow: 0 0 8px rgba(232,169,78,0.15); }
.troop-gathering  { color: #ffa726; border-color: rgba(255,167,38,0.35); box-shadow: 0 0 8px rgba(255,167,38,0.15); }
.troop-deployed   { color: #5cc8e8; border-color: rgba(92,200,232,0.35); box-shadow: 0 0 8px rgba(92,200,232,0.15); }
.troop-battling   { color: #ef5350; border-color: rgba(239,83,80,0.35); box-shadow: 0 0 8px rgba(239,83,80,0.15); }
.troop-occupying  { color: #ffa726; border-color: rgba(255,167,38,0.35); box-shadow: 0 0 8px rgba(255,167,38,0.15); }
.troop-stationing { color: #42a5f5; border-color: rgba(66,165,245,0.35); box-shadow: 0 0 8px rgba(66,165,245,0.15); }
.troop-adventuring { color: #66bb6a; border-color: rgba(102,187,106,0.35); box-shadow: 0 0 8px rgba(102,187,106,0.15); }

.troop-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.troop-age {
    font-size: 9px;
    color: #445;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}

.quest-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.quest-age {
    font-size: 9px;
    color: #445;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}

/* Quest tracking */
.quest-tracking { padding-top: 4px; }

.dp-quests {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
}

.dp-quests .quest-pill {
    flex: 1 1 0;
    min-width: 0;
}

/* 4+ pills: force 2 per row */
.dp-quests.quests-wrap .quest-pill {
    flex-basis: 40%;
}

.quest-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 4px 10px;
    font-size: 11px;
}

.quest-complete-msg {
    grid-column: 1 / -1;
    font-size: 11px;
    font-weight: 600;
    color: #4caf50;
    text-align: center;
    padding: 2px 0;
}

.quest-label { font-weight: 600; }
.quest-val { color: #e8e8f0; font-weight: 700; font-variant-numeric: tabular-nums; }
.quest-pend { color: #ffb74d; font-weight: 700; margin-left: 2px; }

/* Quest type colors */
.quest-titan       { border-color: rgba(255,167,38,0.3); box-shadow: 0 0 8px rgba(255,167,38,0.12); }
.quest-evil_guard  { border-color: rgba(239,83,80,0.3); box-shadow: 0 0 8px rgba(239,83,80,0.12); }
.quest-pvp         { border-color: rgba(171,71,188,0.3); box-shadow: 0 0 8px rgba(171,71,188,0.12); }
.quest-gather      { border-color: rgba(255,167,38,0.3); box-shadow: 0 0 8px rgba(255,167,38,0.12); }
.quest-tower       { border-color: rgba(66,165,245,0.3); box-shadow: 0 0 8px rgba(66,165,245,0.12); }
.quest-titan .quest-label        { color: #ffa726; }
.quest-evil_guard .quest-label   { color: #ef5350; }
.quest-pvp .quest-label          { color: #ab47bc; }
.quest-gather .quest-label       { color: #ffa726; }
.quest-tower .quest-label        { color: #42a5f5; }

/* Auto mode columns (side-by-side groups) */
.auto-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 8px;
}

.auto-column .section-header {
    margin-top: 0;
}

/* Auto mode list */
.auto-list {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    overflow: hidden;
}

.auto-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    min-height: 48px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.auto-row:last-child { border-bottom: none; }

.auto-label {
    font-size: 13px;
    font-weight: 600;
    color: #ccd;
}

/* Toggle switch */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: #252540;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s ease;
    flex-shrink: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.toggle::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    background: #556;
    border-radius: 50%;
    transition: all 0.25s ease;
}

.toggle:active {
    transform: scale(0.92);
}

.toggle.on {
    background: rgba(76,175,80,0.15);
    border-color: rgba(76,175,80,0.3);
}

.toggle.on::after {
    background: #4caf50;
    left: 23px;
    box-shadow: 0 0 8px rgba(76,175,80,0.5);
}

/* Running tasks list */
.running-list {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    overflow: hidden;
}

.running-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.running-row:last-child { border-bottom: none; }

.running-name {
    font-size: 12px;
    color: #99a;
    word-break: break-all;
}

.running-stop {
    background: none;
    border: 1px solid rgba(239,83,80,0.2);
    color: #ef5350;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
    margin-left: 10px;
}

.running-stop:active {
    background: rgba(239,83,80,0.15);
    border-color: rgba(239,83,80,0.4);
}

/* Device selector */
.device-select {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.device-option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.device-option:active { background: #1e3a5f; }
.device-option input[type="checkbox"] { width: 20px; height: 20px; }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    background: #1e3a5f;
    color: #fff;
    min-height: 44px;
    line-height: 24px;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.15s ease;
}

.btn:active {
    transform: scale(0.97);
    filter: brightness(0.85);
}

.btn-sm {
    padding: 7px 16px;
    font-size: 13px;
    min-height: 34px;
    border-radius: 8px;
}

.btn-primary {
    background: #1565c0;
    color: #fff;
}

.btn-start {
    background: #2e7d32;
    color: #fff;
}

.btn-stop {
    background: #c62828;
    color: #fff;
}

.btn-danger {
    background: #b71c1c;
    color: #fff;
}

.btn-full {
    display: block;
    width: 100%;
    margin-top: 8px;
}

.inline-form { display: inline; }

/* Collapsible actions section */
.actions-section {
    margin-top: 24px;
}
.actions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(100,216,255,0.15);
    margin-bottom: 8px;
    -webkit-tap-highlight-color: transparent;
}

/* Action chips (quick actions grid) */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 5px;
}

.action-chip {
    width: 100%;
    padding: 10px 6px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    color: #99a;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.action-chip:active {
    border-color: rgba(100,216,255,0.35);
    box-shadow: 0 0 8px rgba(100,216,255,0.12);
    color: #dde;
    transform: scale(0.97);
}

.action-chip-war {
    border-color: rgba(239,83,80,0.12);
}

.action-chip-war:active {
    border-color: rgba(239,83,80,0.35);
    box-shadow: 0 0 8px rgba(239,83,80,0.12);
    color: #e0c0c0;
}

.action-chip-debug {
    border-color: rgba(171,122,224,0.15);
}

.action-chip-debug:active {
    border-color: rgba(171,122,224,0.35);
    box-shadow: 0 0 8px rgba(171,122,224,0.12);
    color: #d8c8f0;
}

/* Debug page */
.debug-result {
    margin-top: 16px;
    padding: 12px 16px;
    background: rgba(180,130,255,0.04);
    border: 1px solid rgba(180,130,255,0.1);
    border-radius: 10px;
    font-size: 12px;
    color: #aab;
    white-space: pre-wrap;
    font-family: 'SF Mono', 'Fira Code', monospace;
    max-height: 400px;
    overflow-y: auto;
}

/* Bottom bar */
.bottom-bar {
    display: flex;
    gap: 6px;
    margin-top: 28px;
    padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.bottom-bar form {
    display: flex;
}

.bottom-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    color: #889;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.bottom-btn:active {
    transform: scale(0.97);
}

.bottom-btn-danger {
    color: #e06060;
    border-color: rgba(239,83,80,0.25);
}

.bottom-btn-danger:active {
    border-color: rgba(239,83,80,0.4);
    box-shadow: 0 0 10px rgba(239,83,80,0.15);
}

.bottom-btn-restart {
    color: #e8a94e;
    border-color: rgba(232,169,78,0.25);
}

.bottom-btn-restart:active {
    border-color: rgba(232,169,78,0.4);
    box-shadow: 0 0 10px rgba(232,169,78,0.15);
}

.bottom-btn-quit {
    color: #667;
    border-color: rgba(255,255,255,0.06);
}

.bottom-btn-quit:active {
    color: #99a;
    border-color: rgba(255,255,255,0.15);
}

.bottom-btn-bugreport {
    color: #ab7ae0;
    border-color: rgba(171,122,224,0.25);
}

.bottom-btn-bugreport:active {
    border-color: rgba(171,122,224,0.4);
    box-shadow: 0 0 10px rgba(171,122,224,0.15);
}

/* Bug report modal */
.bugreport-modal {
    max-width: 380px;
}

.bugreport-notes {
    width: 100%;
    min-height: 100px;
    padding: 10px 12px;
    background: #0c0c18;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #e0e0f0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
}

.bugreport-notes::placeholder {
    color: #556;
}

.bugreport-notes:focus {
    outline: none;
    border-color: rgba(100,216,255,0.3);
}

.bugreport-hint {
    font-size: 11px;
    color: #556;
    margin-top: 8px;
    margin-bottom: 4px;
}

/* Settings */
.setting-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    font-size: 15px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.setting-row:last-child { border-bottom: none; }
.setting-row.indent { padding-left: 28px; }

.setting-row input[type="checkbox"] {
    width: 22px;
    height: 22px;
    cursor: pointer;
}

.input-sm {
    width: 70px;
    padding: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    background: #141428;
    color: #fff;
    font-size: 15px;
    text-align: center;
}

.select-sm {
    padding: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    background: #141428;
    color: #fff;
    font-size: 15px;
}

.unit { color: #889; font-size: 13px; }

/* Settings page (redesigned) */
.settings-card {
    padding: 0;
    overflow: hidden;
    border-top: 2px solid rgba(100,216,255,0.25);
}
/* Section divider — fieldset legend style */
.settings-section-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 16px 0;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
.settings-section-divider::before,
.settings-section-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255,255,255,0.06);
}
.settings-section-divider-label {
    font-size: 10px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.settings-section-chevron {
    font-size: 10px;
    color: #556;
    transition: transform 0.3s ease;
    display: inline-block;
}
.settings-section-chevron.collapsed {
    transform: rotate(-90deg);
}
/* Collapsible sub-sections */
.settings-collapse {
    max-height: 500px;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    opacity: 1;
}
.settings-collapse.collapsed {
    max-height: 0;
    opacity: 0;
}
.settings-card-header {
    font-size: 12px;
    font-weight: 700;
    color: #778;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 14px 16px 8px;
}
.settings-card-subheader {
    font-size: 10px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 16px;
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    min-height: 48px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-indent { padding-left: 32px; }
.settings-row-label {
    font-size: 14px;
    color: #ccd;
    font-weight: 500;
    flex: 1;
    min-width: 0;
}
.settings-row-hint {
    display: block;
    font-size: 11px;
    color: #556;
    font-weight: 400;
    margin-top: 2px;
}
.settings-row-inline {
    /* Row with inline input/select on right */
}
.settings-row-input {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.settings-select {
    padding: 8px 12px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 10px;
    background: #141428;
    color: #dde;
    font-size: 14px;
    -webkit-appearance: none;
    appearance: none;
}
.settings-checkbox {
    width: 20px;
    height: 20px;
    accent-color: #4caf50;
    cursor: pointer;
    flex-shrink: 0;
}

/* Override row (per-device settings) */
.settings-override-hint {
    font-size: 12px;
    color: #667;
    margin: 8px 0 16px;
}
.settings-override-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.setting-overridden {
    border-left: 2px solid rgba(100,216,255,0.3);
}
.override-reset {
    background: none;
    border: none;
    color: #5b9bd5;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.override-reset:hover {
    opacity: 1;
}
/* Dependency: disabled children */
.setting-disabled {
    opacity: 0.35;
    pointer-events: none;
}
/* Save indicator */
.save-indicator {
    font-size: 14px;
    font-weight: 700;
    margin-left: 6px;
    animation: saveFlash 0.3s ease;
    flex-shrink: 0;
}
.save-ok { color: #4caf50; }
.save-err { color: #ef5350; }
@keyframes saveFlash {
    0% { opacity: 0; transform: scale(0.5); }
    50% { opacity: 1; transform: scale(1.2); }
    100% { opacity: 1; transform: scale(1); }
}
.toggle.toggle-disabled {
    opacity: 0.3;
    cursor: default;
}
.settings-permissions-hint {
    font-size: 12px;
    color: #667;
    margin: 0 16px 10px;
}
.settings-permissions-group {
    font-size: 10px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    padding: 0 16px;
}
.btn-territory {
    display: block;
    text-align: center;
    margin-top: 12px;
    background: rgba(100,216,255,0.06);
    color: #64d8ff;
    border: 1px solid rgba(100,216,255,0.25);
    text-decoration: none;
    border-radius: 10px;
    transition: background 0.15s ease;
}
.btn-territory:hover {
    background: rgba(100,216,255,0.12);
}
.btn-territory:active {
    background: rgba(100,216,255,0.18);
}
.btn-reset-overrides {
    background: rgba(239,83,80,0.06);
    color: #e06060;
    border: 1px solid rgba(239,83,80,0.15);
}

/* Logs */
.log-controls {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
}

.log-viewer {
    background: #0a0a16;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 12px;
    height: 70vh;
    overflow-y: auto;
    font-family: "SF Mono", "Menlo", "Courier New", monospace;
    font-size: 11px;
    line-height: 1.5;
    -webkit-overflow-scrolling: touch;
}

.log-line {
    padding: 1px 0;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================================
   Territory Grid Manager
   ============================================================ */

/* Allow territory page to use full screen width for bigger tap targets */
.territory-page main {
    max-width: 100%;
    padding: 12px 8px;
}
.terr-grid-container {
    max-width: 540px;
}

.terr-grid-wrap {
    display: flex;
    align-items: flex-end;
    margin-bottom: 1px;
}

.terr-grid-corner {
    width: 24px;
    flex-shrink: 0;
}

.terr-col-headers {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    flex: 1;
    min-width: 0;
}

.terr-header-cell {
    font-size: 9px;
    color: #556;
    text-align: center;
    line-height: 16px;
    user-select: none;
}

.terr-row-num {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}

.terr-grid-body {
    display: flex;
}

.terr-row-headers {
    width: 24px;
    flex-shrink: 0;
    display: grid;
    grid-template-rows: repeat(24, 1fr);
}

.terr-grid {
    flex: 1;
    min-width: 0;
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    grid-template-rows: repeat(24, 1fr);
    gap: 1px;
    background: rgba(255,255,255,0.03);
    aspect-ratio: 1 / 1;
}

.terr-cell {
    background: #1a1a30;
    border-radius: 2px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-width: 0;
    min-height: 0;
}

.terr-cell:active {
    filter: brightness(1.3);
}

.terr-cell.terr-attack {
    background: #2e7d32;
    box-shadow: inset 0 0 0 1px rgba(76,175,80,0.3);
}

.terr-cell.terr-ignore {
    background: #c62828;
    box-shadow: inset 0 0 0 1px rgba(239,83,80,0.3);
}

.terr-cell.terr-throne {
    background: #333355;
    cursor: default;
}

.terr-cell.terr-throne:active {
    filter: none;
}

.terr-throne-label {
    font-size: 8px;
    font-weight: 700;
    color: #667;
    line-height: 1;
    user-select: none;
}

/* Mutual zone (frontline) colors */
.terr-mutual-1 { background: rgba(255, 112, 67, 0.45); }  /* Fire-Earth — deep orange */
.terr-mutual-2 { background: rgba(171, 71, 188, 0.45); }  /* Fire-Ice — purple */
.terr-mutual-3 { background: rgba(38, 166, 154, 0.45); }  /* Earth-Forest — teal */
.terr-mutual-4 { background: rgba(120, 144, 156, 0.45); } /* Forest-Ice — blue-grey */
/* Safe zone colors */
.terr-safe-yellow { background: rgba(255, 235, 59, 0.35); }
.terr-safe-green  { background: rgba(76, 175, 80, 0.35); }
.terr-safe-red    { background: rgba(244, 67, 54, 0.35); }
.terr-safe-blue   { background: rgba(33, 150, 243, 0.35); }

/* Pass zone editor controls */
.terr-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 12px;
}
.terr-tab {
    flex: 1;
    padding: 8px 0;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    color: #889;
    cursor: pointer;
    transition: all 0.15s;
}
.terr-tab.active {
    background: rgba(0, 188, 212, 0.12);
    border-color: rgba(0, 188, 212, 0.3);
    color: #00bcd4;
}
.terr-controls {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: 10px;
}
.terr-controls select,
.terr-controls input[type="text"] {
    background: #14142a;
    border: 1px solid rgba(255,255,255,0.1);
    color: #e0e0f0;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12px;
    outline: none;
}
.terr-controls select { min-width: 140px; }
.terr-controls input[type="text"] { width: 120px; }
/* Zone picker buttons */
.zone-picker { margin-bottom: 10px; }
.zone-section-label {
    font-size: 10px;
    font-weight: 600;
    color: #667;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.zone-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}
.zone-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 8px;
    border-radius: 6px;
    font-size: 11px;
    color: #aab;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    cursor: pointer;
    user-select: none;
    transition: all 0.12s;
}
.zone-btn:active { filter: brightness(1.2); }
.zone-btn.active {
    background: rgba(0, 188, 212, 0.15);
    border-color: rgba(0, 188, 212, 0.4);
    color: #e0e0f0;
}
.zone-swatch {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}
.zone-label { white-space: nowrap; }
.zone-count {
    font-size: 9px;
    opacity: 0.6;
}
.zone-owned-cb {
    width: 14px;
    height: 14px;
    margin: 0 0 0 4px;
    cursor: pointer;
    accent-color: #4dd0e1;
}
.zone-vis-toggle {
    margin-left: auto;
    padding: 0 2px;
    font-size: 10px;
    cursor: pointer;
    color: #667;
    user-select: none;
    line-height: 1;
}
.zone-vis-toggle:hover { color: #aab; }
.zone-front-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.zone-pass-toggles {
    display: flex;
    gap: 6px;
    margin-left: 4px;
}
.zone-pass-cb {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    color: #778;
    cursor: pointer;
    white-space: nowrap;
}
.zone-pass-cb input {
    width: 13px;
    height: 13px;
    margin: 0;
    accent-color: #4dd0e1;
    cursor: pointer;
}
.zone-btn.zone-hidden {
    opacity: 0.35;
}
.zone-btn.zone-hidden .zone-label {
    text-decoration: line-through;
}

/* Home zone colors (visual reference only — no blocking) */
.terr-home-yellow { background: rgba(255, 241, 118, 0.35); }
.terr-home-green  { background: rgba(165, 214, 167, 0.35); }
.terr-home-red    { background: rgba(239, 154, 154, 0.35); }
.terr-home-blue   { background: rgba(144, 202, 249, 0.35); }

/* Background image behind grid — dimmed so painted zones pop */
.terr-grid.has-bg {
    background-size: 100% 100%;
    background-position: top left;
    position: relative;
}
.terr-grid.has-bg::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 0;
    pointer-events: none;
}
.terr-grid.has-bg .terr-cell {
    background: transparent;
    position: relative;
    z-index: 1;
}
/* Painted zones stay visible over background — high opacity + outline */
.terr-grid.has-bg .terr-cell.terr-attack { background: rgba(46, 125, 50, 0.75); box-shadow: inset 0 0 0 1px #4caf50; }
.terr-grid.has-bg .terr-cell.terr-ignore { background: rgba(198, 40, 40, 0.75); box-shadow: inset 0 0 0 1px #ef5350; }
.terr-grid.has-bg .terr-cell.terr-mutual-1 { background: rgba(255, 112, 67, 0.7); box-shadow: inset 0 0 0 1px #ff7043; }
.terr-grid.has-bg .terr-cell.terr-mutual-2 { background: rgba(171, 71, 188, 0.7); box-shadow: inset 0 0 0 1px #ab47bc; }
.terr-grid.has-bg .terr-cell.terr-mutual-3 { background: rgba(38, 166, 154, 0.7); box-shadow: inset 0 0 0 1px #26a69a; }
.terr-grid.has-bg .terr-cell.terr-mutual-4 { background: rgba(120, 144, 156, 0.7); box-shadow: inset 0 0 0 1px #78909c; }
.terr-grid.has-bg .terr-cell.terr-safe-yellow { background: rgba(255, 235, 59, 0.6); box-shadow: inset 0 0 0 1px #ffeb3b; }
.terr-grid.has-bg .terr-cell.terr-safe-green  { background: rgba(76, 175, 80, 0.6); box-shadow: inset 0 0 0 1px #4caf50; }
.terr-grid.has-bg .terr-cell.terr-safe-red    { background: rgba(244, 67, 54, 0.6); box-shadow: inset 0 0 0 1px #f44336; }
.terr-grid.has-bg .terr-cell.terr-safe-blue   { background: rgba(33, 150, 243, 0.6); box-shadow: inset 0 0 0 1px #2196f3; }
.terr-grid.has-bg .terr-cell.terr-home-yellow { background: rgba(255, 241, 118, 0.5); box-shadow: inset 0 0 0 1px #fff176; }
.terr-grid.has-bg .terr-cell.terr-home-green  { background: rgba(165, 214, 167, 0.5); box-shadow: inset 0 0 0 1px #a5d6a7; }
.terr-grid.has-bg .terr-cell.terr-home-red    { background: rgba(239, 154, 154, 0.5); box-shadow: inset 0 0 0 1px #ef9a9a; }
.terr-grid.has-bg .terr-cell.terr-home-blue   { background: rgba(144, 202, 249, 0.5); box-shadow: inset 0 0 0 1px #90caf9; }
.terr-grid.has-bg .terr-cell.terr-throne {
    background: rgba(51, 51, 85, 0.5);
}

/* Pass toggles panel (territory page — Passes tab) */
.pass-group {
    background: rgba(255,255,255,0.02);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    padding: 10px 12px;
    margin-bottom: 8px;
}
.pass-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}
.pass-group-label {
    font-size: 12px;
    font-weight: 600;
    color: #ccd;
}
.pass-status {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 8px;
    border-radius: 4px;
}
.pass-status-open {
    color: #4caf50;
    background: rgba(76,175,80,0.1);
}
.pass-status-blocked {
    color: #ef5350;
    background: rgba(239,83,80,0.1);
}
.pass-status-partial {
    color: #ffb74d;
    background: rgba(255,183,77,0.1);
}
.pass-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    border-top: 1px solid rgba(255,255,255,0.04);
}
.pass-team-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
.pass-toggle-name {
    font-size: 13px;
    color: #aab;
}

/* Footer debug link */
.page-footer {
    text-align: center;
    padding: 24px 0 8px;
}

.footer-debug-link {
    font-size: 11px;
    color: #445;
    text-decoration: none;
    letter-spacing: 0.3px;
}

.footer-debug-link:active {
    color: #778;
}

.footer-kofi {
    display: block;
    margin-top: 10px;
    font-size: 11px;
    color: #334;
    text-decoration: none;
}
.footer-kofi:hover {
    color: #ffb74d;
}

/* Inline auto-modes inside device card */
.device-auto-modes {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255,255,255,0.04);
}

/* Collapsible events section (per-device card) */
.device-events-section {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid rgba(255,255,255,0.04);
}
.events-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 4px 0;
    -webkit-tap-highlight-color: transparent;
}
.events-label {
    font-size: 9px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.events-body {
    padding: 4px 0;
}

/* Collapsible controls header */
.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    padding: 8px 0 10px;
    min-height: 36px;
    -webkit-tap-highlight-color: transparent;
}

.controls-label {
    font-size: 9px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.controls-arrow {
    font-size: 10px;
    color: #556;
    transition: transform 0.15s ease;
}

/* Collapsed pills — only show active ones */
.controls-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding-bottom: 2px;
}

.controls-pills .control-pill:not(.pill-on) {
    display: none;
}

.control-pill {
    font-size: 10px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 12px;
    color: #556;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    white-space: nowrap;
    transition: all 0.2s ease;
}

.control-pill.pill-on {
    color: #4caf50;
    border-color: rgba(76,175,80,0.35);
    box-shadow: 0 0 8px rgba(76,175,80,0.15);
}

/* Mithril timer (device-top grid, row 2 col 2) */
.mithril-timer {
    justify-self: end;
    font-size: 10px;
    font-weight: 600;
    color: #ce93d8;
    font-variant-numeric: tabular-nums;
    padding: 2px 8px;
    background: transparent;
    border: 1px solid rgba(206,147,216,0.3);
    border-radius: 12px;
    box-shadow: 0 0 8px rgba(206,147,216,0.1);
}

.auto-subheader {
    font-size: 9px;
    font-weight: 700;
    color: #556;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

/* Live View section */
.live-view-section {
    margin-top: 6px;
    padding-top: 6px;
}

.live-view-buttons {
    display: flex;
    gap: 6px;
}

/* Shared style for device card action buttons */
.live-view-toggle,
.manual-control-toggle,
.chat-view-toggle,
.restart-game-btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 600;
    color: #889;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.live-view-toggle:hover,
.manual-control-toggle:hover,
.chat-view-toggle:hover,
.restart-game-btn:hover {
    color: #bbc;
    border-color: rgba(255,255,255,0.18);
}

.live-view-toggle:active,
.manual-control-toggle:active,
.chat-view-toggle:active,
.restart-game-btn:active {
    transform: scale(0.97);
}

.live-view-toggle.live-view-on {
    color: #64d8ff;
    border-color: rgba(100,216,255,0.35);
    box-shadow: 0 0 8px rgba(100,216,255,0.15);
}

.manual-control-toggle.manual-control-on {
    color: #ffab40;
    border-color: rgba(255,171,64,0.4);
    box-shadow: 0 0 10px rgba(255,171,64,0.2);
    background: rgba(255,171,64,0.06);
}

.device-card.manual-mode {
    border-left-color: #ffab40;
}

.device-card.manual-mode .auto-row .toggle {
    opacity: 0.3;
    pointer-events: none;
}

.restart-game-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* Offline device card */
.device-card-offline {
    border-left-color: #555;
}

/* Emulator step buttons (two side-by-side numbered steps on both offline and online cards) */
.emu-steps {
    display: flex;
    gap: 8px;
    margin-top: 6px;
}

/* Compact variant for online cards — unobtrusive at bottom */
.emu-steps-compact {
    margin-top: 8px;
    opacity: 0.55;
    transition: opacity 0.2s ease;
}
.emu-steps-compact:hover {
    opacity: 1;
}
.emu-steps-compact .emu-step-btn {
    padding: 5px 10px;
    font-size: 11px;
}
.emu-steps-compact .emu-step-num {
    display: none;
}

.emu-step-btn {
    flex: 1;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    border: 1px solid;
    text-align: center;
    background: transparent;
}

.emu-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    font-size: 11px;
    font-weight: 800;
    margin-right: 4px;
    vertical-align: middle;
    line-height: 1;
}

/* Step 1: Start Emulator (green) */
.emu-step-emu {
    color: #4caf50;
    border-color: rgba(76,175,80,0.3);
    box-shadow: 0 0 8px rgba(76,175,80,0.1);
}
.emu-step-emu .emu-step-num {
    background: rgba(76,175,80,0.15);
    color: #4caf50;
}
.emu-step-emu:hover {
    border-color: rgba(76,175,80,0.45);
    box-shadow: 0 0 12px rgba(76,175,80,0.15);
}
.emu-step-emu:active {
    transform: scale(0.97);
}
.emu-step-emu.emu-starting {
    color: #e8a94e;
    border-color: rgba(232,169,78,0.3);
    box-shadow: 0 0 8px rgba(232,169,78,0.1);
    animation: emu-pulse 1.5s ease-in-out infinite;
}
.emu-step-emu.emu-starting .emu-step-num {
    background: rgba(232,169,78,0.15);
    color: #e8a94e;
}

/* Step 2: Start Game / Restart Game (amber) */
.emu-step-game {
    color: #e8a94e;
    border-color: rgba(232,169,78,0.3);
    box-shadow: 0 0 8px rgba(232,169,78,0.1);
}
.emu-step-game .emu-step-num {
    background: rgba(232,169,78,0.15);
    color: #e8a94e;
}
.emu-step-game:hover:not(:disabled) {
    border-color: rgba(232,169,78,0.45);
    box-shadow: 0 0 12px rgba(232,169,78,0.15);
}
.emu-step-game:disabled {
    color: #556;
    border-color: rgba(255,255,255,0.06);
    box-shadow: none;
    opacity: 0.5;
    cursor: default;
}
.emu-step-game:disabled .emu-step-num {
    background: rgba(255,255,255,0.05);
    color: #556;
}

/* Step 2 ready: Start Game available (green) */
.emu-step-game.emu-step-game-ready {
    color: #4caf50;
    border-color: rgba(76,175,80,0.3);
    box-shadow: 0 0 8px rgba(76,175,80,0.1);
}
.emu-step-game.emu-step-game-ready .emu-step-num {
    background: rgba(76,175,80,0.15);
    color: #4caf50;
}
.emu-step-game.emu-step-game-ready:hover {
    border-color: rgba(76,175,80,0.45);
    box-shadow: 0 0 12px rgba(76,175,80,0.15);
}

/* Step 1 online: Stop Emulator (red) */
.emu-step-stop {
    color: #ef5350;
    border-color: rgba(239,83,80,0.3);
    box-shadow: 0 0 8px rgba(239,83,80,0.1);
}
.emu-step-stop .emu-step-num {
    background: rgba(239,83,80,0.15);
    color: #ef5350;
}
.emu-step-stop:hover {
    border-color: rgba(239,83,80,0.45);
    box-shadow: 0 0 12px rgba(239,83,80,0.15);
}
.emu-step-stop:active {
    transform: scale(0.97);
}

@keyframes emu-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.live-view-container {
    margin-top: 8px;
    position: relative;
}

.live-view-img {
    width: 100%;
    border-radius: 8px;
    background: #111;
    min-height: 80px;
    cursor: crosshair;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.tap-ripple {
    position: absolute;
    width: 28px;
    height: 28px;
    margin-left: -14px;
    margin-top: -14px;
    border-radius: 50%;
    background: rgba(0, 200, 255, 0.5);
    pointer-events: none;
    animation: tap-fade 0.4s ease-out forwards;
}
@keyframes tap-fade {
    0%   { transform: scale(0.5); opacity: 1; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Settings device tabs */
.settings-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
}

.settings-tab {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    color: #889;
    background: #1a1a30;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 8px;
    text-decoration: none;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.settings-tab.active {
    color: #64d8ff;
    background: rgba(100,216,255,0.1);
    border-color: rgba(100,216,255,0.25);
}

.settings-tab:active {
    opacity: 0.7;
}

/* Per-device override rows */
.override-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 4px 0;
}

.override-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    padding-top: 2px;
    cursor: pointer;
}

.override-toggle .override-cb {
    accent-color: #64d8ff;
}

.override-label {
    font-size: 10px;
    font-weight: 600;
    color: #64d8ff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.override-row .setting-row {
    flex: 1;
    padding: 0;
}

.global-hint {
    font-size: 11px;
    color: #556;
    font-style: italic;
    margin-left: 4px;
}

/* ============================================================
   Quick Start Guide
   ============================================================ */

.guide {
    max-width: 640px;
    margin: 0 auto;
    padding-bottom: 40px;
}

.guide-title {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 4px;
}

.guide-subtitle {
    font-size: 14px;
    color: #778;
    margin-bottom: 28px;
}

.guide-step {
    display: flex;
    gap: 14px;
    margin-bottom: 28px;
}

.guide-step-num {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: rgba(100,216,255,0.12);
    border: 1px solid rgba(100,216,255,0.25);
    color: #64d8ff;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
}

.guide-step-body h2 {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin: 0 0 6px;
}

.guide-step-body p {
    font-size: 14px;
    color: #bbc;
    line-height: 1.5;
    margin: 0 0 10px;
}

.guide-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 12px;
    background: rgba(100,216,255,0.08);
    border: 1px solid rgba(100,216,255,0.15);
    border-radius: 4px;
    padding: 1px 6px;
    color: #64d8ff;
}

.guide-checklist {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.guide-check {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 14px;
    color: #ccd;
    line-height: 1.4;
}

.guide-check-icon {
    font-size: 16px;
    color: #556;
    flex-shrink: 0;
    margin-top: 1px;
}

.guide-hint {
    font-size: 12px;
    color: #667;
    margin-top: 2px;
    line-height: 1.4;
}

.guide-note {
    font-size: 13px;
    color: #889;
    background: rgba(255,255,255,0.03);
    border-left: 2px solid rgba(100,216,255,0.2);
    padding: 8px 12px;
    border-radius: 0 6px 6px 0;
    line-height: 1.5;
}

.guide-modes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 12px;
}

.guide-mode {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 14px;
    color: #ccd;
    line-height: 1.4;
}

.guide-mode-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    border-radius: 50%;
    margin-top: 5px;
}

.guide-mode-farming {
    background: #4caf50;
    box-shadow: 0 0 6px rgba(76,175,80,0.4);
}

.guide-mode-combat {
    background: #ef5350;
    box-shadow: 0 0 6px rgba(239,83,80,0.4);
}

.guide-markers {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 12px;
}

.guide-marker-row {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    font-size: 14px;
    color: #ccd;
    line-height: 1.4;
}

.guide-marker-img {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    flex-shrink: 0;
    margin-top: 1px;
}

.guide-divider {
    height: 1px;
    background: rgba(255,255,255,0.06);
    margin: 32px 0 24px;
}

.guide-section-title {
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    margin: 0 0 16px;
}

.guide-tips {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.guide-tip {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    font-size: 14px;
    color: #bbc;
    line-height: 1.5;
}

.guide-tip-icon {
    font-size: 16px;
    flex-shrink: 0;
    margin-top: 1px;
}

/* ------------------------------------------------------------------ */
/* Calibrate Page                                                      */
/* ------------------------------------------------------------------ */

.calibrate-page main { max-width: 600px; margin: 0 auto; padding: 16px 12px; }

.cal-toolbar {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px;
}
.cal-toolbar select, .cal-toolbar button {
    background: #1e1e3a; border: 1px solid #333; color: #e0e0f0;
    padding: 8px 12px; border-radius: 6px; font-size: 14px;
}
.cal-toolbar select { flex: 1; min-width: 0; }
.cal-toolbar button { cursor: pointer; white-space: nowrap; }
.cal-toolbar button:active { opacity: 0.7; }
.cal-btn-capture { background: #1a3a5c !important; border-color: #2a6 !important; }
.cal-btn-record { position: relative; }
.cal-btn-record.active { background: #5a1a1a !important; border-color: #c44 !important; }
.cal-btn-record.active::before {
    content: ''; position: absolute; top: 6px; right: 6px;
    width: 8px; height: 8px; border-radius: 50%; background: #f44;
    animation: cal-pulse 1s infinite;
}
@keyframes cal-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.cal-canvas-wrap {
    position: relative; width: 100%; background: #111;
    border-radius: 8px; overflow: hidden; cursor: crosshair;
    touch-action: none; -webkit-touch-callout: none; user-select: none;
}
.cal-canvas-wrap canvas { display: block; width: 100%; height: auto; }
.cal-placeholder {
    aspect-ratio: 9 / 16; display: flex; align-items: center; justify-content: center;
    color: #555; font-size: 14px;
}

.cal-coords, .cal-region {
    display: flex; align-items: center; gap: 8px; margin-top: 8px;
    background: #14142a; border-radius: 6px; padding: 8px 12px;
    font-family: "SF Mono", "Consolas", monospace; font-size: 14px; color: #0ff;
}
.cal-coords .cal-label, .cal-region .cal-label { color: #888; font-size: 12px; }
.cal-coords .cal-value, .cal-region .cal-value { flex: 1; }
.cal-note-input {
    background: transparent; border: none; border-bottom: 1px solid #333;
    color: #aab; font-size: 13px; padding: 2px 4px; width: 100px; outline: none;
    font-family: "SF Mono", "Consolas", monospace;
}
.cal-note-input:focus { border-color: #0ff; color: #e0e0f0; }
.cal-note-input::placeholder { color: #444; }
.cal-log-note { color: #888; margin-left: 6px; font-size: 12px; }
.cal-log-note::before { content: '— '; }
.cal-copy-btn {
    background: #1e1e3a; border: 1px solid #333; color: #aab; border-radius: 4px;
    padding: 4px 10px; cursor: pointer; font-size: 12px;
}
.cal-copy-btn:active { background: #2a6; color: #fff; }

.cal-region-actions {
    display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap;
}
.cal-region-actions input[type="text"] {
    background: #1e1e3a; border: 1px solid #333; color: #e0e0f0;
    padding: 6px 10px; border-radius: 4px; font-size: 13px; flex: 1; min-width: 100px;
}
.cal-region-actions button {
    background: #1a3a5c; border: 1px solid #2a6; color: #e0e0f0;
    padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.cal-region-actions button:active { opacity: 0.7; }
.cal-region-actions .cal-overwrite { font-size: 11px; color: #888; display: flex; align-items: center; gap: 4px; }
.cal-region-actions .cal-overwrite input { accent-color: #2a6; }

.cal-section-title {
    font-size: 13px; color: #888; margin-top: 16px; margin-bottom: 6px;
    text-transform: uppercase; letter-spacing: 0.5px;
}

.cal-log {
    max-height: 200px; overflow-y: auto; background: #14142a;
    border-radius: 6px; padding: 6px;
}
.cal-log-entry {
    display: flex; align-items: center; gap: 8px; padding: 4px 6px;
    font-family: "SF Mono", "Consolas", monospace; font-size: 13px; color: #bbc;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.cal-log-entry:last-child { border-bottom: none; }
.cal-log-entry .cal-idx { color: #555; font-size: 11px; min-width: 20px; }
.cal-log-entry .cal-value { flex: 1; color: #0ff; }

.cal-timeline {
    display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
    max-height: 400px; overflow-y: auto;
}
.cal-step {
    display: flex; align-items: center; gap: 10px; background: #14142a;
    border-radius: 6px; padding: 8px 10px;
}
.cal-step-num {
    width: 24px; height: 24px; border-radius: 50%; background: #2a6;
    color: #fff; font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.cal-step-info { flex: 1; font-size: 13px; color: #bbc; }
.cal-step-info strong { color: #0ff; }
.cal-step-thumb {
    width: 36px; height: 64px; border-radius: 4px; object-fit: cover; flex-shrink: 0;
}

.cal-export-row {
    display: flex; gap: 8px; align-items: center; margin-top: 10px;
}
.cal-export-row input[type="text"] {
    background: #1e1e3a; border: 1px solid #333; color: #e0e0f0;
    padding: 6px 10px; border-radius: 4px; font-size: 13px; flex: 1;
}
.cal-export-row button {
    background: #1a3a5c; border: 1px solid #2a6; color: #e0e0f0;
    padding: 6px 14px; border-radius: 4px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
.cal-toast {
    position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
    background: #2a6; color: #fff; padding: 8px 18px; border-radius: 6px;
    font-size: 13px; opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 100;
}
.cal-toast.show { opacity: 1; }

/* ============================================================
   Chat Viewer (modal overlay + standalone page)
   ============================================================ */

/* (chat-view-toggle styled via shared .live-view-buttons rule above) */

/* --- Mini chat feed (inline in device card) --- */
.chat-feed {
    margin-top: 4px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.chat-feed:active .chat-feed-well { opacity: 0.7; }

.chat-feed-well {
    position: relative;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 12px;
    padding: 6px 10px;
    overflow: hidden;
    max-height: 56px;
    transition: opacity 0.15s;
}
.chat-feed-fade {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 14px;
    background: linear-gradient(180deg, rgba(12,12,24,0.7) 0%, transparent 100%);
    pointer-events: none;
}
.chat-feed-messages {
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.chat-feed-msg {
    display: flex;
    gap: 5px;
    font-size: 11px;
    line-height: 1.5;
    overflow: hidden;
}
.chat-feed-sender {
    font-weight: 600;
    flex-shrink: 0;
    white-space: nowrap;
}
.chat-feed-text {
    color: rgba(255,255,255,0.35);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}
.chat-feed-empty {
    font-size: 11px;
    color: #334;
}

/* --- Chat overlay (slide-up modal container) --- */
.chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(4,4,12,0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 200;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.chat-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* --- Chat modal panel (slides up from bottom) --- */
.chat-modal {
    width: 100%;
    max-width: 560px;
    height: 88vh;
    max-height: 88vh;
    background: #0e0e20;
    border: 1px solid rgba(255,255,255,0.06);
    border-bottom: none;
    border-radius: 18px 18px 0 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
}
.chat-overlay.visible .chat-modal {
    transform: translateY(0);
}

/* --- Chat header --- */
.chat-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.chat-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #e0e0f0;
    letter-spacing: 0.3px;
}
.chat-modal-device {
    font-size: 12px;
    color: #556;
    margin-left: 8px;
    font-weight: 400;
}
.chat-modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,0.05);
    border: none;
    color: #778;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}
.chat-modal-close:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* --- Channel tabs (shared between modal + standalone) --- */
.chat-tabs {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.chat-tab {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #556;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 20px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}
.chat-tab:hover { color: #889; border-color: rgba(255,255,255,0.12); }
.chat-tab.active {
    color: #e0e0f0;
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.15);
}

/* Channel-specific active tab colors */
.chat-tab[data-channel="SERVER"].active { color: #5b9bd5; border-color: rgba(91,155,213,0.3); background: rgba(91,155,213,0.08); }
.chat-tab[data-channel="UNION"].active { color: #66bb6a; border-color: rgba(102,187,106,0.3); background: rgba(102,187,106,0.08); }
.chat-tab[data-channel="FACTION"].active { color: #ab7ae0; border-color: rgba(171,122,224,0.3); background: rgba(171,122,224,0.08); }
.chat-tab[data-channel="WORLD"].active { color: #e8a94e; border-color: rgba(232,169,78,0.3); background: rgba(232,169,78,0.08); }
.chat-tab[data-channel="PRIVATE"].active { color: #e07090; border-color: rgba(224,112,144,0.3); background: rgba(224,112,144,0.08); }

/* --- Message area --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    scroll-behavior: smooth;
    min-height: 0;
}

.chat-messages-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #334;
    text-align: center;
    padding: 40px 20px;
}
.chat-messages-empty-icon {
    font-size: 36px;
    margin-bottom: 12px;
    opacity: 0.3;
}
.chat-messages-empty-text {
    font-size: 13px;
    line-height: 1.8;
    max-width: 260px;
    white-space: pre-line;
}

/* --- Date separator --- */
.chat-date-sep {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px 8px;
}
.chat-date-line {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}
.chat-date-label {
    font-size: 10px;
    font-weight: 600;
    color: #445;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

/* --- Individual message --- */
.chat-msg {
    padding: 5px 16px 5px 14px;
    border-left: 2px solid transparent;
    transition: background 0.12s ease;
}
.chat-msg:hover {
    background: rgba(255,255,255,0.015);
}

/* Channel left-border colors */
.chat-msg.ch-server  { border-left-color: rgba(91,155,213,0.5); }
.chat-msg.ch-union   { border-left-color: rgba(102,187,106,0.5); }
.chat-msg.ch-faction { border-left-color: rgba(171,122,224,0.5); }
.chat-msg.ch-world   { border-left-color: rgba(232,169,78,0.5); }
.chat-msg.ch-private { border-left-color: rgba(224,112,144,0.5); }
.chat-msg.ch-system  { border-left-color: rgba(200,140,60,0.3); }

/* Message header row */
.chat-msg-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    flex-wrap: wrap;
}
.chat-time {
    font-size: 10px;
    color: rgba(255,255,255,0.18);
    font-variant-numeric: tabular-nums;
    min-width: 32px;
    font-family: "SF Mono", "Menlo", "Courier New", monospace;
}

/* Channel badge */
.chat-channel-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    line-height: 1.5;
}
.badge-server  { color: #5b9bd5; background: rgba(91,155,213,0.1); }
.badge-union   { color: #66bb6a; background: rgba(102,187,106,0.1); }
.badge-faction { color: #ab7ae0; background: rgba(171,122,224,0.1); }
.badge-world   { color: #e8a94e; background: rgba(232,169,78,0.1); }
.badge-private { color: #e07090; background: rgba(224,112,144,0.1); }
.badge-system  { color: #c8963c; background: rgba(200,150,60,0.1); }

/* Union tag + sender */
.chat-union-tag {
    font-size: 10px;
    color: #445;
    font-weight: 500;
}
.chat-sender {
    font-size: 13px;
    font-weight: 600;
}
.chat-sender-server  { color: #7db8e8; }
.chat-sender-union   { color: #81c784; }
.chat-sender-r4      { color: #e06060; }
.chat-sender-faction { color: #bb8de8; }
.chat-sender-world   { color: #e8bc6e; }
.chat-sender-private { color: #e08aa8; }
.chat-sender-system  { color: #c8963c; }

/* Message content */
.chat-content {
    font-size: 13px;
    color: rgba(255,255,255,0.75);
    line-height: 1.5;
    padding: 1px 0 3px 38px;
    word-break: break-word;
}
.chat-content-system {
    font-size: 12px;
    color: rgba(200,150,60,0.5);
    font-style: italic;
    padding: 1px 0 3px 38px;
    word-break: break-word;
}
.chat-content-coord {
    color: #8be9fd;
}
.chat-content-translated {
    font-size: 12px;
    font-style: italic;
    color: rgba(100, 216, 255, 0.7);
    padding: 0 0 3px 38px;
    word-break: break-word;
}
.chat-content-translated::before {
    content: "\21B3 ";
}

/* --- Chat footer --- */
.chat-modal-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid rgba(255,255,255,0.04);
    flex-shrink: 0;
}
.chat-system-toggle {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    color: #445;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.chat-system-toggle:hover { color: #667; border-color: rgba(255,255,255,0.12); }
.chat-system-toggle.active {
    color: #c8963c;
    border-color: rgba(200,150,60,0.3);
    background: rgba(200,150,60,0.08);
}
.chat-system-count {
    font-size: 11px;
    color: #334;
}
.chat-status-text {
    margin-left: auto;
    font-size: 11px;
    color: #445;
    font-variant-numeric: tabular-nums;
}

/* --- Standalone chat page --- */
.chat-page main {
    max-width: 700px;
}
.chat-page-wrap {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
}
.chat-page-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.chat-page-select {
    background: #141428;
    color: #ccc;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 13px;
}
.chat-page-body {
    flex: 1;
    background: #0e0e20;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* APK Patch modal */
.patch-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.patch-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.patch-modal {
    background: #1a1a30;
    border: 1px solid rgba(100,216,255,0.15);
    border-radius: 16px;
    padding: 20px;
    max-width: 480px;
    width: 92%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.5);
}

.patch-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin-bottom: 12px;
}

.patch-desc {
    font-size: 12px;
    color: #889;
    line-height: 1.5;
    margin-bottom: 16px;
}

.patch-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.patch-btn {
    flex: 1;
    min-width: 100px;
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    background: #141428;
    border: 1px solid rgba(255,255,255,0.08);
    color: #889;
}

.patch-btn:active {
    background: #1e3a5f;
    color: #dde;
}

.patch-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

.patch-btn-primary {
    background: rgba(100,216,255,0.12);
    border-color: rgba(100,216,255,0.25);
    color: #64d8ff;
}

.patch-btn-primary:active {
    background: rgba(100,216,255,0.22);
}

.patch-step {
    font-size: 12px;
    font-weight: 600;
    color: #64d8ff;
    margin-bottom: 8px;
}

.patch-log {
    background: #0c0c18;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 8px;
    padding: 10px;
    font-family: "SF Mono", "Cascadia Code", "Consolas", monospace;
    font-size: 11px;
    line-height: 1.5;
    color: #aab;
    overflow-y: auto;
    max-height: 50vh;
    min-height: 200px;
    margin-bottom: 12px;
}

.patch-log-line {
    white-space: pre-wrap;
    word-break: break-all;
}

/* Schedule rows */
.schedule-row { gap: 8px; }
.schedule-mode-label { font-weight: 500; }
.schedule-delete {
    background: none; border: none; color: var(--text-secondary);
    font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.schedule-delete:hover { color: var(--danger, #e74c3c); }
.schedule-add-form { border-top: 1px solid var(--border-color, #333); }

/* Safe area for notched iPhones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    main {
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
}

/* ================================================================
   Protocol Visualizer
   ================================================================ */

.viz-page main { padding: 0; max-width: none; }

.viz-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    background: #14142a;
    border-bottom: 1px solid rgba(100,216,255,0.08);
}
.viz-header select {
    background: #1a1a2e;
    color: #e0e0f0;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 13px;
}
.viz-conn {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
}
.viz-conn-on { color: #4caf50; }
.viz-conn-off { color: #ef5350; }
.viz-server-time { font-size: 11px; color: #667; margin-left: auto; }

.viz-main {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 90px);
    overflow: hidden;
}
.viz-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.viz-map-wrap {
    flex: 7;
    position: relative;
    min-width: 0;
    background: #0a0a1a;
}
.viz-map-wrap canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: crosshair;
}

.viz-map-controls {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    gap: 4px;
    z-index: 2;
}
.viz-map-controls button {
    background: rgba(20,20,42,0.85);
    color: #aab;
    border: 1px solid #333;
    border-radius: 4px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}
.viz-map-controls button:hover { background: #1a1a2e; color: #e0e0f0; }
.viz-btn-active { background: #1a2a3e !important; color: #64d8ff !important; border-color: #64d8ff !important; }

.viz-entity-filters {
    position: absolute;
    bottom: 8px;
    left: 8px;
    right: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 3px;
    z-index: 2;
}
.viz-filter-btn {
    background: rgba(20,20,42,0.8);
    color: #667;
    border: 1px solid #333;
    border-radius: 3px;
    padding: 2px 6px;
    font-size: 10px;
    cursor: pointer;
    transition: all 0.15s;
    border-left-width: 3px;
}
.viz-filter-btn:hover { color: #aab; }
.viz-filter-active { color: #e0e0f0; background: rgba(20,20,42,0.95); }

.viz-legend {
    position: absolute;
    top: 40px;
    left: 8px;
    background: rgba(20,20,42,0.92);
    border: 1px solid #333;
    border-radius: 6px;
    padding: 8px 12px;
    z-index: 3;
    min-width: 140px;
}
.viz-legend-title { font-size: 11px; font-weight: 600; color: #aab; margin-bottom: 6px; }
.viz-legend-item { display: flex; align-items: center; gap: 6px; font-size: 11px; color: #ccc; padding: 2px 0; }
.viz-legend-swatch { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

.viz-tooltip {
    position: absolute;
    background: rgba(20,20,42,0.95);
    color: #e0e0f0;
    border: 1px solid #444;
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    font-family: monospace;
    pointer-events: none;
    z-index: 10;
    white-space: nowrap;
}

/* Sidebar */
.viz-sidebar {
    flex: 3;
    min-width: 240px;
    max-width: 340px;
    overflow-y: auto;
    background: #0c0c18;
    border-left: 1px solid rgba(100,216,255,0.08);
    padding: 6px;
}

.viz-panel {
    background: #14142a;
    border: 1px solid rgba(255,255,255,0.04);
    border-radius: 6px;
    margin-bottom: 6px;
    overflow: hidden;
}
.viz-panel-head {
    font-size: 11px;
    font-weight: 600;
    color: #8899aa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 6px 10px;
    background: rgba(255,255,255,0.02);
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.viz-panel-toggle { cursor: pointer; user-select: none; }
.viz-panel-toggle:hover { color: #aab; }
.viz-chevron { float: right; font-size: 9px; }
.viz-panel-body { padding: 6px 10px; font-size: 12px; color: #ccd; }
.viz-collapsed { display: none; }

.viz-panel-alert { border-color: rgba(239, 83, 80, 0.4) !important; }
.viz-panel-alert .viz-panel-head { color: #ef5350; }

/* AP bar */
.viz-ap-bar-wrap {
    height: 14px;
    background: #1a1a2e;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 4px;
}
.viz-ap-bar {
    height: 100%;
    background: #64d8ff;
    border-radius: 3px;
    transition: width 0.3s ease;
}
.viz-ap-low { background: #ef5350; }
.viz-ap-text { font-size: 12px; color: #aab; text-align: center; }

/* Alert */
.viz-alert {
    background: rgba(239, 83, 80, 0.15);
    color: #ef5350;
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
    text-align: center;
    animation: pulse-red 1.5s ease-in-out infinite;
}
@keyframes pulse-red {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Troop cards */
.viz-troop-card {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.viz-troop-card:last-child { border-bottom: none; }
.viz-troop-badge {
    font-size: 9px;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 3px;
    color: #fff;
    min-width: 50px;
    text-align: center;
}
.viz-troop-power { color: #aab; font-size: 11px; }
.viz-troop-time { color: #ffb74d; font-size: 11px; margin-left: auto; }

/* Rallies */
.viz-rally-item {
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 11px;
}
.viz-rally-item:last-child { border-bottom: none; }
.viz-rally-owner { color: #ffa726; }
.viz-rally-state { color: #667; }
.viz-rally-count { color: #aab; }
.viz-rally-time { color: #ffb74d; float: right; }

/* Attacks */
.viz-atk-item {
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    font-size: 11px;
}
.viz-atk-name { color: #ef5350; }
.viz-atk-act { color: #667; }
.viz-atk-eta { color: #ef5350; font-weight: 600; float: right; }

/* Resources */
.viz-res-group-head { color: #64d8ff; font-size: 10px; font-weight: 600; padding: 4px 0 2px; text-transform: uppercase; border-bottom: 1px solid rgba(100,216,255,0.1); }
.viz-res-item { display: flex; gap: 6px; padding: 1px 0; font-size: 10px; align-items: baseline; }
.viz-res-id { color: #667; min-width: 70px; font-family: monospace; }
.viz-res-name { color: #bbc; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-res-val { color: #aab; font-weight: 600; white-space: nowrap; }
.viz-res-cap { color: #556; white-space: nowrap; }

/* Quests */
.viz-quest-item { display: flex; gap: 6px; padding: 2px 0; font-size: 11px; color: #aab; align-items: baseline; }
.viz-quest-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-quest-cnt { color: #64d8ff; font-weight: 600; }
.viz-quest-state { color: #667; font-size: 10px; }

/* Buffs */
.viz-buff-item { padding: 2px 0; font-size: 10px; color: #667; word-break: break-all; }

/* Battles */
.viz-battle-item { padding: 2px 0; font-size: 11px; color: #aab; }

/* PVP battles */
.viz-pvp-count { color: #667; font-size: 10px; font-weight: 400; }
.viz-pvp-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 10px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.viz-pvp-result { font-weight: 700; font-size: 9px; padding: 1px 4px; border-radius: 2px; min-width: 14px; text-align: center; }
.viz-pvp-win { color: #4caf50; background: rgba(76,175,80,0.15); }
.viz-pvp-loss { color: #ef5350; background: rgba(239,83,80,0.15); }
.viz-pvp-names { color: #aab; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-pvp-power { color: #667; font-size: 9px; white-space: nowrap; }
.viz-pvp-age { color: #556; font-size: 9px; white-space: nowrap; }

/* March intelligence */
.viz-march-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 3px 0; font-size: 10px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.viz-march-act { font-weight: 600; font-size: 9px; padding: 1px 4px; border-radius: 2px; min-width: 32px; text-align: center; color: #fff; background: rgba(255,255,255,0.1); }
.viz-act-1 { color: #ef5350; background: rgba(239,83,80,0.15); }
.viz-act-7, .viz-act-8 { color: #ffa726; background: rgba(255,167,38,0.15); }
.viz-act-9, .viz-act-10 { color: #42a5f5; background: rgba(66,165,245,0.15); }
.viz-act-2 { color: #66bb6a; background: rgba(102,187,106,0.15); }
.viz-act-11 { color: #7e57c2; background: rgba(126,87,194,0.15); }
.viz-march-names { color: #aab; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-march-eta { color: #ffb74d; font-size: 9px; font-weight: 600; white-space: nowrap; }

/* Alliance gifts */
.viz-gift-row { padding: 3px 0; font-size: 10px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.viz-gift-from { color: #64d8ff; margin-right: 6px; }
.viz-gift-name { color: #aab; }
.viz-gift-rewards { color: #667; font-size: 9px; padding-left: 8px; margin-top: 1px; }

/* Heroes */
.viz-hero-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; font-size: 10px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.viz-hero-cfg { color: #667; font-family: monospace; }
.viz-hero-name { color: #aab; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-hero-level { color: #64d8ff; font-weight: 600; }
.viz-hero-star { color: #ffd54f; }

/* Mail */
.viz-mail-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; font-size: 10px; border-bottom: 1px solid rgba(255,255,255,0.03); }
.viz-mail-title { color: #aab; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-mail-from { color: #64d8ff; font-size: 9px; }
.viz-mail-time { color: #556; font-size: 9px; white-space: nowrap; }

/* Alliance altar */
.viz-altar-item { display: flex; justify-content: space-between; padding: 2px 0; font-size: 11px; color: #aab; }
.viz-altar-id { color: #667; }
.viz-altar-val { color: #64d8ff; font-weight: 600; }

/* Explore atlas */
.viz-explore-item { display: flex; gap: 8px; padding: 2px 0; font-size: 10px; color: #aab; }
.viz-explore-cfg { color: #667; font-family: monospace; }
.viz-explore-pos { color: #aab; }
.viz-explore-sta { color: #4caf50; font-weight: 600; }

/* Entity counts */
.viz-ec-item { display: flex; justify-content: space-between; padding: 2px 0; font-size: 11px; color: #aab; }
.viz-ec-count { color: #64d8ff; font-weight: 600; }

/* Freshness dots */
.viz-fresh-item { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.viz-fresh-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.viz-dot-green { background: #4caf50; }
.viz-dot-yellow { background: #ffb74d; }
.viz-dot-red { background: #ef5350; }
.viz-dot-gray { background: #444; }
.viz-fresh-cat { font-size: 11px; color: #aab; min-width: 65px; }
.viz-fresh-age { font-size: 10px; color: #667; margin-left: auto; }

/* Message type rows in sidebar */
.viz-msgtype-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 3px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 10px;
}
.viz-msgtype-name { color: #aab; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-msgtype-count { color: #64d8ff; font-weight: 600; min-width: 24px; text-align: right; }
.viz-msgtype-age { color: #556; min-width: 28px; text-align: right; }
.viz-msgtype-fields { width: 100%; color: #556; font-size: 9px; padding-left: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viz-msgtypes-toolbar { display: flex; align-items: center; gap: 4px; padding: 4px 8px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.viz-sort-btn { background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.08); color: #667; padding: 1px 6px; border-radius: 3px; font-size: 9px; cursor: pointer; }
.viz-sort-btn:hover { background: rgba(100,216,255,0.1); color: #aab; }
.viz-sort-btn.viz-sort-active { background: rgba(100,216,255,0.15); border-color: rgba(100,216,255,0.3); color: #64d8ff; }
.viz-msgtypes-total { color: #556; font-size: 9px; margin-left: auto; }

/* Clickable items */
.viz-clickable { cursor: pointer; }
.viz-clickable:hover { background: rgba(100,216,255,0.05); }

/* Protocol message feed panel */
.viz-feed-panel {
    height: 300px;
    min-height: 150px;
    border-top: 2px solid rgba(100,216,255,0.15);
    background: #0c0c18;
    display: flex;
    flex-direction: column;
}
.viz-feed-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 10px;
    background: #14142a;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    flex-shrink: 0;
}
.viz-feed-title {
    font-size: 11px;
    font-weight: 600;
    color: #8899aa;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.viz-feed-stats {
    font-size: 10px;
    color: #667;
}
.viz-feed-auto {
    font-size: 10px;
    color: #667;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    user-select: none;
}
.viz-feed-auto input { width: 12px; height: 12px; cursor: pointer; }
.viz-feed-filter {
    background: #1a1a2e;
    color: #e0e0f0;
    border: 1px solid #333;
    border-radius: 3px;
    padding: 2px 8px;
    font-size: 11px;
    font-family: monospace;
    width: 180px;
    margin-left: auto;
}
.viz-feed-clear {
    background: rgba(239,83,80,0.15);
    color: #ef5350;
    border: 1px solid rgba(239,83,80,0.3);
    border-radius: 3px;
    padding: 2px 8px;
    font-size: 10px;
    cursor: pointer;
}
.viz-feed-clear:hover { background: rgba(239,83,80,0.25); }
.viz-feed-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}
.viz-feed-list {
    flex: 1;
    overflow-y: auto;
    font-size: 11px;
    font-family: monospace;
    padding: 2px;
}
.viz-feed-detail {
    width: 45%;
    min-width: 300px;
    overflow-y: auto;
    border-left: 1px solid rgba(100,216,255,0.08);
    padding: 6px 10px;
    background: #0a0a14;
}
.viz-detail-title {
    font-size: 11px;
    font-weight: 600;
    color: #8899aa;
    margin-bottom: 6px;
    text-transform: uppercase;
}
.viz-detail-json {
    font-size: 11px;
    color: #ccd;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    line-height: 1.4;
}

/* Message feed rows */
.viz-msg-row {
    display: flex;
    gap: 6px;
    padding: 2px 6px;
    border-bottom: 1px solid rgba(255,255,255,0.02);
    cursor: pointer;
    align-items: baseline;
}
.viz-msg-row:hover { background: rgba(100,216,255,0.04); }
.viz-msg-row.viz-msg-selected { background: rgba(100,216,255,0.08); }
.viz-msg-row.viz-msg-hidden { display: none; }
.viz-msg-ts { color: #445; flex-shrink: 0; font-size: 10px; }
.viz-msg-dir { flex-shrink: 0; font-size: 9px; font-weight: 700; width: 16px; text-align: center; }
.viz-msg-dir-in { color: #4caf50; }
.viz-msg-dir-out { color: #ffb74d; }
.viz-msg-name { color: #64d8ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viz-msg-preview { color: #556; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* JSON syntax highlighting in detail panel */
.viz-json-key { color: #64d8ff; }
.viz-json-str { color: #66bb6a; }
.viz-json-num { color: #ffb74d; }
.viz-json-bool { color: #ce93d8; }
.viz-json-null { color: #667; }

/* Responsive: sidebar below map on narrow screens */
@media (max-width: 768px) {
    .viz-layout { flex-direction: column; }
    .viz-map-wrap { flex: none; height: 50vh; }
    .viz-sidebar { flex: none; max-width: none; border-left: none; border-top: 1px solid rgba(100,216,255,0.08); }
    .viz-feed-panel { height: 250px; }
    .viz-feed-detail { width: 40%; min-width: 200px; }
}
