:root {
    color-scheme: dark;
    --ink: #f3f5ef;
    --muted: #98a298;
    --ground: #090d0c;
    --surface: #111816;
    --surface-2: #17211d;
    --line: #28372f;
    --green: #5fe096;
    --green-deep: #143e2b;
    --gold: #d8b66a;
    --red: #ff7e76;
    --shadow: 0 24px 70px rgba(0, 0, 0, .38);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--ground); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--ground); font-size: 16px; line-height: 1.5; }
button, input, select { font: inherit; }
button, summary { -webkit-tap-highlight-color: transparent; }

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 18% 12%, rgba(95, 224, 150, .14), transparent 28rem),
        radial-gradient(circle at 85% 90%, rgba(216, 182, 106, .08), transparent 34rem),
        linear-gradient(145deg, #070a09, #0d1411 65%, #090d0c);
}

.login-shell { width: min(100%, 430px); }
.login-card { padding: 42px; border: 1px solid var(--line); border-radius: 22px; background: rgba(17, 24, 22, .94); box-shadow: var(--shadow); }
.brand-mark { display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 30px; border: 1px solid #4d6b5a; border-radius: 15px; color: #07110c; background: linear-gradient(135deg, var(--green), #9af2bc); font-weight: 900; letter-spacing: -.06em; }
.brand-mark.small { width: 38px; height: 38px; margin: 0; border-radius: 10px; font-size: .82rem; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: .76rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, h4, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(2rem, 8vw, 2.7rem); line-height: 1.05; letter-spacing: -.055em; }
h2 { margin-bottom: 0; font-size: clamp(1.45rem, 4vw, 2rem); letter-spacing: -.035em; }
h3 { margin: 0; font-size: 1.3rem; letter-spacing: -.02em; }
h4 { margin-bottom: 10px; }
.login-copy, .muted { color: var(--muted); }
.login-copy { margin-bottom: 28px; }
.login-form, .compact-form { display: grid; gap: 14px; }
label span { display: block; margin-bottom: 7px; color: #c8d0ca; font-size: .88rem; font-weight: 700; }
input, select { width: 100%; min-height: 46px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 10px; outline: 0; color: var(--ink); background: #0b110f; }
input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(95, 224, 150, .12); }
button { min-height: 44px; padding: 9px 16px; border: 0; border-radius: 10px; color: #07110c; background: var(--green); font-weight: 800; cursor: pointer; }
button:hover { filter: brightness(1.07); }
button:focus-visible, summary:focus-visible { outline: 3px solid rgba(95, 224, 150, .5); outline-offset: 2px; }
.button-secondary { border: 1px solid var(--line); color: var(--ink); background: var(--surface-2); }
.full { width: 100%; }
.form-message { padding: 10px 12px; border-radius: 8px; font-size: .88rem; }
.form-message.error { color: #ffd1cd; background: rgba(255, 126, 118, .12); border: 1px solid rgba(255, 126, 118, .3); }
.form-message.success { color: #caffdd; background: rgba(95, 224, 150, .1); border: 1px solid rgba(95, 224, 150, .25); }

.topbar { position: sticky; z-index: 10; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 12px max(20px, calc((100vw - 1240px) / 2)); border-bottom: 1px solid rgba(40, 55, 47, .8); background: rgba(9, 13, 12, .88); backdrop-filter: blur(18px); }
.brand { display: flex; gap: 12px; align-items: center; color: var(--ink); text-decoration: none; }
.brand strong, .brand small { display: block; }
.brand strong { line-height: 1.15; }
.brand small { color: var(--muted); font-size: .75rem; }
.topbar-actions { display: flex; gap: 12px; align-items: center; }
.connection { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .88rem; }
.connection i { width: 9px; height: 9px; border-radius: 50%; background: #77817a; box-shadow: 0 0 0 4px rgba(119, 129, 122, .1); }
.connection i.online { background: var(--green); box-shadow: 0 0 0 4px rgba(95, 224, 150, .12); }
.connection i.warning { background: var(--gold); }
.connection i.offline { background: var(--red); }
.account-menu { position: relative; }
.account-menu summary { padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; list-style: none; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-popover { position: absolute; top: calc(100% + 10px); right: 0; width: min(330px, calc(100vw - 32px)); padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); }
.account-popover form + form { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.compact-form input { min-height: 42px; }

.app-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 64px; }
.tabs { display: flex; gap: 4px; width: max-content; max-width: 100%; margin-bottom: 32px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.tab { min-height: 40px; padding: 7px 15px; color: var(--muted); background: transparent; }
.tab.active { color: var(--ink); background: var(--surface-2); box-shadow: inset 0 0 0 1px rgba(95, 224, 150, .14); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 38px; }
.summary-card { min-height: 150px; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: linear-gradient(145deg, var(--surface), #0d1412); }
.summary-card.accent { border-color: rgba(95, 224, 150, .28); background: linear-gradient(145deg, rgba(20, 62, 43, .85), var(--surface)); }
.summary-card > span, .summary-card > small, .metric span { display: block; color: var(--muted); }
.summary-card > strong { display: block; margin: 18px 0 7px; font-size: 1.55rem; letter-spacing: -.035em; }
.summary-card > small { font-size: .82rem; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.filter-row { display: flex; gap: 9px; }
.filter-row select { width: auto; min-width: 150px; }
.players-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.player-card { padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.player-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.player-head small { color: var(--muted); }
.online-badge { padding: 5px 9px; border: 1px solid rgba(95, 224, 150, .25); border-radius: 99px; color: var(--green); background: rgba(95, 224, 150, .08); font-size: .75rem; font-weight: 800; }
.vitals { display: grid; gap: 13px; margin: 24px 0; }
.meter-heading { display: flex; justify-content: space-between; margin-bottom: 5px; color: var(--muted); font-size: .78rem; }
.meter-track { height: 7px; overflow: hidden; border-radius: 99px; background: #25312b; }
.meter-fill { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #43bd77, var(--green)); }
.metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.metric { padding: 9px; border: 1px solid var(--line); border-radius: 9px; background: #0c1210; }
.metric span { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; }
.metric strong { display: block; margin-top: 4px; font-size: .88rem; }
.player-details { margin-top: 18px; border-top: 1px solid var(--line); }
.player-details summary { padding-top: 16px; color: var(--gold); cursor: pointer; font-weight: 700; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding-top: 16px; }
.data-list { max-height: 260px; margin: 0; padding: 0; overflow: auto; list-style: none; }
.data-list li { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid rgba(40, 55, 47, .55); font-size: .8rem; }
.data-list span { overflow: hidden; color: var(--muted); text-overflow: ellipsis; }
.data-list strong { white-space: nowrap; }
.empty-state { grid-column: 1 / -1; padding: 44px 24px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); text-align: center; background: rgba(17, 24, 22, .55); }
.empty-state.error { color: #ffc0bb; }

.activity-list { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.activity-row { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 14px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.event-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: var(--green); background: var(--green-deep); font-weight: 900; }
.event-icon.event-chat { color: var(--gold); background: rgba(216, 182, 106, .12); }
.activity-heading { display: flex; justify-content: space-between; gap: 14px; }
.activity-heading strong { text-transform: capitalize; }
.activity-heading time, .activity-body small { color: var(--muted); font-size: .77rem; }
.activity-body p { margin: 2px 0; color: #cdd5cf; }
blockquote { margin: 9px 0; padding: 9px 12px; border-left: 2px solid var(--gold); color: #f5e6c2; background: rgba(216, 182, 106, .06); }
.runtime-log { min-height: 520px; max-height: 70vh; margin: 18px 0 0; padding: 18px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; color: #b8d4c2; background: #050807; font: .8rem/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.last-refresh { margin-top: 20px; color: #68736b; font-size: .76rem; text-align: right; }

.player-identity { min-height: 0; padding: 0; color: inherit; background: transparent; text-align: left; }
.player-identity:hover h3 { color: var(--green); }
.player-identity .eyebrow { margin-bottom: 6px; }
.meter.unavailable .meter-value { color: #78827b; }
.meter.unavailable .meter-track { opacity: .45; }
.button-danger { border: 1px solid rgba(255, 126, 118, .35); color: #ffd0cc; background: rgba(255, 126, 118, .12); }
.button-small { min-height: 34px; padding: 5px 10px; font-size: .78rem; }
button:disabled { cursor: wait; opacity: .55; }
button.busy::after { content: '…'; }
.hidden { display: none !important; }
.small-copy { font-size: .8rem; }

.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.admin-card { min-width: 0; padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); }
.admin-card-wide { grid-column: 1 / -1; }
.admin-card > p { margin: 12px 0 18px; color: var(--muted); font-size: .88rem; }
.admin-card-heading, .action-buttons, .console-controls, .dialog-actions { display: flex; align-items: center; gap: 9px; }
.admin-card-heading { justify-content: space-between; }
.action-buttons { flex-wrap: wrap; }
.risk-badge { padding: 4px 8px; border: 1px solid rgba(216, 182, 106, .25); border-radius: 99px; color: var(--gold); font-size: .7rem; }
.admin-form { display: grid; gap: 13px; }
.admin-form label small { color: var(--muted); font-weight: 400; }
.config-flags { padding: 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #0b110f; font-size: .76rem; }
.save-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 22px; }
.file-list { display: grid; gap: 7px; max-height: 360px; overflow: auto; }
.file-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 11px; border: 1px solid var(--line); border-radius: 9px; background: #0b110f; }
.file-row > div { min-width: 0; }
.file-row strong, .file-row small { display: block; overflow: hidden; text-overflow: ellipsis; }
.file-row strong { white-space: nowrap; font-size: .8rem; }
.file-row small { color: var(--muted); font-size: .68rem; }
.console-controls select { flex: 1; }
.command-output { min-height: 230px; max-height: 420px; margin: 14px 0 0; padding: 13px; overflow: auto; border: 1px solid var(--line); border-radius: 10px; color: #b8d4c2; background: #050807; font: .75rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.command-output.compact { min-height: 80px; max-height: 180px; }

.modal { width: min(760px, calc(100% - 28px)); max-height: calc(100vh - 40px); padding: 24px; overflow: auto; border: 1px solid var(--line); border-radius: 18px; color: var(--ink); background: var(--surface); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(0, 0, 0, .72); backdrop-filter: blur(4px); }
.modal-heading { display: flex; justify-content: space-between; gap: 20px; }
.icon-button { width: 40px; min-height: 40px; padding: 0; border: 1px solid var(--line); color: var(--ink); background: var(--surface-2); font-size: 1.4rem; }
.dialog-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 22px 0 14px; }
.dialog-actions { margin: 14px 0 24px; }
.dialog-actions.end { justify-content: flex-end; margin-bottom: 0; }
.player-timeline { max-height: 430px; margin-top: 14px; }
.confirm-modal { width: min(500px, calc(100% - 28px)); }
.toast { position: fixed; z-index: 40; right: 20px; bottom: 20px; max-width: min(420px, calc(100% - 40px)); padding: 13px 16px; border: 1px solid rgba(95, 224, 150, .3); border-radius: 11px; color: #d9ffe7; background: #153526; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(12px); transition: opacity .18s ease, transform .18s ease; }
.toast.visible { opacity: 1; transform: none; }
.toast.error { border-color: rgba(255, 126, 118, .35); color: #ffd0cc; background: #3a1c1a; }

@media (max-width: 800px) {
    .app-shell { width: min(100% - 24px, 680px); padding-top: 22px; }
    .summary-grid, .players-grid, .admin-grid { grid-template-columns: 1fr; }
    .admin-card-wide { grid-column: auto; }
    .save-columns { grid-template-columns: 1fr; }
    .summary-card { min-height: 125px; }
    .tabs { position: sticky; z-index: 8; top: 78px; width: 100%; }
    .tab { flex: 1; padding-inline: 9px; }
    .section-heading { align-items: flex-start; }
    .filter-row { width: 100%; }
    .filter-row select { flex: 1; min-width: 0; }
    .detail-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .login-card { padding: 30px 22px; }
    .topbar { padding-inline: 12px; }
    .brand small, .connection span { display: none; }
    .app-shell { width: min(100% - 20px, 480px); }
    .section-heading { display: grid; }
    .metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .activity-row { padding: 14px 12px; }
    .activity-heading { display: grid; gap: 2px; }
    .runtime-log { min-height: 60vh; padding: 12px; font-size: .74rem; }
    .tabs { overflow-x: auto; }
    .tab { flex: 0 0 auto; }
    .admin-card { padding: 17px; }
    .dialog-summary { grid-template-columns: 1fr; }
    .dialog-actions { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
