:root {
    --bg: #09111a;
    --panel: #101d2b;
    --line: #274057;
    --text: #eef4fb;
    --muted: #9fb1c5;
    --accent: #3b82f6;
    --danger: #dc2626;
    --roman: #b45309;
    --tribe: #166534;
    --contested: #b91c1c;
    --neutral: #334155;
    --table-wood: #4b3826;
    --table-felt: #23301d;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: radial-gradient(circle at top, #17314a 0%, var(--bg) 45%);
    color: var(--text);
}

.shell {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

.topbar,
.workspace,
.button-row,
.map-header,
.legend,
.minimap-controls {
    display: flex;
}

.topbar,
.workspace {
    gap: 20px;
}

.topbar {
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
}

.topbar h1,
.map-header h2,
.card h2 {
    margin: 0 0 8px;
}

.lede,
.hint {
    color: var(--muted);
}

.topbar-actions,
.sidebar,
.main,
.stack {
    display: flex;
    flex-direction: column;
}

.topbar-actions,
.stack {
    gap: 10px;
}

.workspace {
    align-items: flex-start;
}

.sidebar {
    width: 360px;
    gap: 16px;
}

.main {
    flex: 1;
    gap: 16px;
    min-width: 0;
}

.card {
    background: color-mix(in srgb, var(--panel) 85%, black 15%);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 18px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}

label {
    display: block;
    font-size: 14px;
}

input,
select,
button {
    width: 100%;
    margin-top: 6px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #08121d;
    color: var(--text);
    padding: 11px 12px;
}

button {
    cursor: pointer;
    background: var(--accent);
    border-color: var(--accent);
    font-weight: 700;
}

button.secondary {
    background: #162638;
    border-color: #35516d;
}

button.danger {
    background: color-mix(in srgb, var(--danger) 80%, #162638 20%);
    border-color: var(--danger);
}

.button-row {
    gap: 10px;
}

.checkbox {
    display: flex;
    gap: 10px;
    align-items: center;
}

.checkbox input {
    width: auto;
    margin: 0;
}

.toolbar-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(120px, 1fr));
    gap: 12px;
}

.nav-row {
    margin-top: 12px;
}

.tile-list,
.compact-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.tile-list li,
.compact-list li {
    margin-bottom: 8px;
}

.tile-button,
.region-button {
    width: 100%;
    text-align: left;
    background: #0b1622;
    border: 1px solid #21364b;
}

.tile-button.active {
    outline: 2px solid #7fb4ff;
}

.tile-line {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

.map-header {
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 12px;
}

.legend {
    gap: 12px;
    flex-wrap: wrap;
    color: var(--muted);
}

.legend-swatch {
    width: 12px;
    height: 12px;
    display: inline-block;
    border-radius: 999px;
    margin-right: 6px;
}

.legend-swatch.roman { background: var(--roman); }
.legend-swatch.tribe { background: var(--tribe); }
.legend-swatch.contested { background: var(--contested); }
.legend-swatch.neutral { background: var(--neutral); }
.legend-swatch.player { background: #22c55e; }

.map-stage {
    overflow: auto;
    max-width: 100%;
    max-height: 72vh;
    border: 12px solid color-mix(in srgb, var(--table-wood) 80%, #1b130d 20%);
    border-radius: 18px;
    background:
        radial-gradient(circle at center, rgba(255, 245, 207, 0.05), transparent 55%),
        linear-gradient(180deg, color-mix(in srgb, var(--table-felt) 80%, #0f1b16 20%), #0b1521);
    box-shadow:
        inset 0 0 0 1px rgba(255, 244, 214, 0.06),
        0 18px 30px rgba(0, 0, 0, 0.3);
}

.map-viewport {
    position: relative;
    min-width: 640px;
    min-height: 420px;
}

.map-canvas {
    position: absolute;
    inset: 0;
    image-rendering: pixelated;
}

.overlay-canvas {
    cursor: crosshair;
}

.overlay-canvas.dragging {
    cursor: grabbing;
}

.map-floating-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 3;
    width: 250px;
    padding: 12px;
    border: 1px solid rgba(255, 244, 214, 0.12);
    border-radius: 14px;
    background: rgba(8, 15, 23, 0.84);
    backdrop-filter: blur(8px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.32);
}

.minimap-header h3 {
    margin: 0 0 4px;
}

#minimap-canvas {
    width: 220px;
    height: 220px;
    display: block;
    margin: 0 auto;
    border-radius: 12px;
    border: 1px solid rgba(255, 244, 214, 0.08);
    background: #0f1710;
    cursor: crosshair;
}

.player-tooltip {
    position: absolute;
    z-index: 4;
    pointer-events: none;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(8, 15, 23, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text);
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    transform: translate(10px, -24px);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

@media (max-width: 1200px) {
    .workspace {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
    }

    .toolbar-grid {
        grid-template-columns: repeat(2, minmax(140px, 1fr));
    }
}
