:root {
    --bg: #1b1e24;
    --surface: #23272e;
    --surface-2: #2b3038;
    --border: #353b45;
    --text: #c8ccd4;
    --heading: #eceff4;
    --muted: #7a8291;
    --red: #e06c75;
    --red-dim: rgba(224, 108, 117, 0.14);
    --green: #98c379;
    --green-dim: rgba(152, 195, 121, 0.14);
    --yellow: #e5c07b;
    --yellow-dim: rgba(229, 192, 123, 0.14);
    --blue: #61afef;
    --blue-dim: rgba(97, 175, 239, 0.14);
    --orange: #d19a66;
    --radius: 8px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

h1, h2, h3 { color: var(--heading); margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; margin-bottom: 12px; }
h3 { font-size: 14px; }

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--heading); font-size: 16px; }
.brand-large { font-size: 22px; margin-bottom: 4px; }
.brand-mark {
    display: inline-grid; place-items: center;
    width: 28px; height: 28px; border-radius: 7px;
    background: var(--red); color: #1b1e24; font-weight: 800; font-size: 15px;
}

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: 1px solid transparent; border-radius: 6px;
    padding: 7px 14px; font: inherit; font-weight: 500;
    cursor: pointer; color: var(--heading); background: var(--surface-2);
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--border); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.btn-primary { background: var(--blue); color: #10151c; }
.btn-primary:hover { background: #7cbdf2; }
.btn-danger { background: var(--red); color: #1b1e24; }
.btn-danger:hover { background: #e8858c; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-small { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

input, select {
    width: 100%; padding: 8px 10px; margin-top: 4px;
    border: 1px solid var(--border); border-radius: 6px;
    background: var(--bg); color: var(--heading); font: inherit;
}
input::placeholder { color: var(--muted); }
label { display: block; margin-bottom: 14px; font-weight: 500; color: var(--text); }

.form-error {
    margin: 0 0 14px; padding: 8px 10px; border-radius: 6px;
    background: var(--red-dim); color: var(--red);
}

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
    width: 100%; max-width: 380px; padding: 28px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.login-card p.muted { margin: 0 0 20px; }
.login-card h2 { margin: 16px 0 6px; }
.login-card p.small { margin: -6px 0 14px; }
.setup-back { margin-top: 8px; }

.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 24px;
    padding: 20px 14px; background: var(--surface); border-right: 1px solid var(--border);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
    padding: 8px 12px; border-radius: 6px; color: var(--text); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--blue-dim); color: var(--blue); }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.staff-name { color: var(--heading); font-weight: 600; }
.sidebar-buttons { display: flex; flex-wrap: wrap; gap: 6px; }

.main { min-width: 0; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 18px 28px; border-bottom: 1px solid var(--border);
}
.page { padding: 24px 28px 48px; max-width: 1280px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-header h2 { margin: 0; }

.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { color: var(--heading); font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }

.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.grid-2 > .card + .card { margin-top: 0; }
.grid-2 + .card { margin-top: 16px; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-auto > .card + .card { margin-top: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar input, .toolbar select { margin-top: 0; width: auto; }
.toolbar input[type="search"] { flex: 1 1 220px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
td.reason { max-width: 320px; overflow-wrap: anywhere; }
td.actions { text-align: right; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.player { display: inline-flex; align-items: center; gap: 8px; color: var(--heading); font-weight: 500; }
.player img { width: 22px; height: 22px; border-radius: 4px; background: var(--surface-2); }
a.player:hover { text-decoration: none; color: var(--blue); }

.badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
    background: var(--surface-2); color: var(--text);
}
.badge-red { background: var(--red-dim); color: var(--red); }
.badge-green { background: var(--green-dim); color: var(--green); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-blue { background: var(--blue-dim); color: var(--blue); }
.badge-orange { background: rgba(209, 154, 102, 0.14); color: var(--orange); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: none; }

.log-line { display: flex; flex-direction: column; gap: 2px; }

.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 12px; color: var(--muted); }

.profile { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.profile img { width: 64px; height: 64px; border-radius: 10px; background: var(--surface-2); }
.profile-name { font-size: 22px; font-weight: 700; color: var(--heading); }
.profile-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.profile-actions { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.dialog {
    width: min(460px, calc(100vw - 32px)); padding: 24px;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: 12px;
}
.dialog-small { width: min(380px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-row label { flex: 1 1 160px; margin-bottom: 0; }
.form-row .btn { margin-bottom: 1px; }
td select { width: auto; margin-top: 0; padding: 4px 8px; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
    padding: 10px 14px; border-radius: 8px; max-width: 360px;
    background: var(--surface-2); border: 1px solid var(--border); color: var(--heading);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.toast-error { border-color: var(--red); }
.toast-success { border-color: var(--green); }

.loading { color: var(--muted); padding: 20px 0; }

@media (max-width: 1200px) {
    .stats { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 960px) {
    .grid-2 { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 800px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: static; height: auto; flex-direction: row; flex-wrap: wrap;
        align-items: center; gap: 12px; padding: 12px 16px;
        border-right: none; border-bottom: 1px solid var(--border);
    }
    .nav { flex-direction: row; overflow-x: auto; width: 100%; order: 3; }
    .nav a { white-space: nowrap; }
    .sidebar-footer { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
    .sidebar-footer .muted { display: none; }
    .topbar { padding: 14px 16px; }
    .page { padding: 16px 16px 40px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .profile { flex-wrap: wrap; }
    .profile-actions { margin-left: 0; }
}

.mc, .mc-stage {
    --px: 2px;
    font-family: "Pixelify Sans", ui-monospace, monospace;
    -webkit-font-smoothing: none;
    font-smooth: never;
}
@media (min-width: 1280px) { .mc-stage, .mc-tooltip { --px: 3px; } }
@media (max-width: 420px) { .mc-stage, .mc-tooltip { --px: 1.6px; } }

.btn-ghost.active { background: var(--blue-dim); color: var(--blue); border-color: transparent; }

.mc-stage { padding: 6px 4px; overflow-x: auto; min-height: 60px; }
.mc-stage > .mc-gui { margin: 0 auto; }

.mc-gui {
    position: relative;
    background: #C6C6C6;
    border-radius: calc(3 * var(--px));
    box-shadow:
        0 0 0 var(--px) #000000,
        inset calc(2 * var(--px)) calc(2 * var(--px)) 0 0 #FFFFFF,
        inset calc(-2 * var(--px)) calc(-2 * var(--px)) 0 0 #555555;
    font-family: "Pixelify Sans", ui-monospace, monospace;
    user-select: none;
}

.mc-slot, .mc-model {
    position: absolute;
    background: #8B8B8B;
    box-shadow: inset var(--px) var(--px) 0 0 #373737, inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 0 #FFFFFF;
}
.mc-slot { width: calc(18 * var(--px)); height: calc(18 * var(--px)); }
.mc-slot-filled { cursor: default; }
.mc-slot-filled:hover::after {
    content: ""; position: absolute; z-index: 3;
    left: var(--px); top: var(--px); width: calc(16 * var(--px)); height: calc(16 * var(--px));
    background: rgba(255, 255, 255, 0.5);
}

.mc-model { background: #000000; overflow: hidden; }
.mc-model img {
    position: absolute; left: 50%; bottom: calc(6 * var(--px)); transform: translateX(-50%);
    height: calc(56 * var(--px)); width: calc(28 * var(--px));
    image-rendering: pixelated;
}

.mc-item {
    position: absolute; left: var(--px); top: var(--px);
    width: calc(16 * var(--px)); height: calc(16 * var(--px));
    display: grid; place-items: center;
}
.mc-item img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.mc-empty-icon img { opacity: 1; }
.mc-missing { font-size: calc(6 * var(--px)); color: #373737; text-transform: uppercase; }

.mc-item img.mc-glint-layer {
    position: absolute; inset: 0;
    filter: brightness(0) invert(1) sepia(1) saturate(7) hue-rotate(225deg) brightness(1.1);
    mix-blend-mode: screen;
    animation: mc-glint 2.8s ease-in-out infinite;
    pointer-events: none;
}
@keyframes mc-glint {
    0%, 100% { opacity: 0.12; }
    50% { opacity: 0.5; }
}

.mc-count {
    position: absolute; z-index: 2; right: 0; bottom: calc(-1 * var(--px));
    font-size: calc(9 * var(--px)); line-height: 1; color: #FFFFFF;
    text-shadow: var(--px) var(--px) 0 #3F3F3F;
}

.mc-durability {
    position: absolute; z-index: 2;
    left: calc(3 * var(--px)); top: calc(14 * var(--px));
    width: calc(13 * var(--px)); height: calc(2 * var(--px));
    background: #000000;
}
.mc-durability-fill { height: var(--px); }

.mc-label {
    position: absolute; font-size: calc(8 * var(--px)); line-height: 1;
    color: #404040; white-space: nowrap;
}

.mc-arrow {
    position: absolute; width: calc(16 * var(--px)); height: calc(13 * var(--px));
    background: #8B8B8B;
    clip-path: polygon(0 38%, 56% 38%, 56% 0, 100% 50%, 56% 100%, 56% 62%, 0 62%);
}

.mc-tooltip {
    position: fixed; z-index: 100; pointer-events: none;
    padding: calc(4 * var(--px)) calc(4 * var(--px)) calc(3 * var(--px));
    background: rgba(16, 0, 16, 0.94);
    clip-path: polygon(
        var(--px) 0, calc(100% - var(--px)) 0, calc(100% - var(--px)) var(--px), 100% var(--px),
        100% calc(100% - var(--px)), calc(100% - var(--px)) calc(100% - var(--px)), calc(100% - var(--px)) 100%,
        var(--px) 100%, var(--px) calc(100% - var(--px)), 0 calc(100% - var(--px)), 0 var(--px), var(--px) var(--px));
    font-size: calc(8 * var(--px)); line-height: calc(10 * var(--px));
    white-space: pre; max-width: min(90vw, 640px);
}
.mc-tooltip::before {
    content: ""; position: absolute; inset: var(--px);
    border: var(--px) solid transparent;
    border-image: linear-gradient(to bottom, rgba(80, 0, 255, 0.4), rgba(40, 0, 127, 0.4)) 1;
}
.mc-tooltip-line { position: relative; min-height: calc(10 * var(--px)); }
.mc-tooltip-line:first-child { margin-bottom: calc(2 * var(--px)); }
