:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #64748b;
    --secondary-hover: #475569;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-light: #64748b;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.app-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Top Bar */
.top-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    z-index: 20;
    position: relative;
}

.logo {
    font-weight: 800;
    font-size: 1.5rem;
    color: var(--text);
    letter-spacing: -0.5px;
    margin-right: 20px;
}

.controls-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.common-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    padding-right: 0;
    flex: 0 0 auto;
    /* Prevent growing, keep flush right */
}

.github-link {
    color: var(--text-light);
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
}

.github-link:hover {
    color: var(--text);
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* Bottom Controls */
.bottom-controls {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 10;
}

.zoom-controls {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    border: 1px solid var(--border);
}

.zoom-controls .btn {
    border-radius: 0;
    width: 40px;
    height: 40px;
    border-bottom: 1px solid var(--border);
}

.zoom-controls .btn:last-child {
    border-bottom: none;
}

#center-view-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
}

.hidden {
    display: none !important;
}

/* Buttons & Inputs */
.btn {
    border: none;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.btn.icon-only {
    padding: 0;
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
    background: transparent;
    color: var(--text);
}

.btn.icon-only:hover {
    background: var(--bg);
}

.btn.text-btn {
    width: 100%;
    justify-content: flex-start;
    background: transparent;
    color: var(--text);
    font-weight: 500;
}

.btn.text-btn:hover {
    background: var(--bg);
}

.btn.text-btn.danger {
    color: var(--danger);
}

.btn.text-btn.danger:hover {
    background: #fef2f2;
}

.btn.primary {
    background-color: var(--primary);
    color: white;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

.btn.primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.3);
}

.btn.primary:active {
    transform: translateY(0);
}

.btn.primary:disabled {
    background-color: var(--border);
    color: var(--text-light);
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

.btn.secondary {
    background-color: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn.secondary:hover {
    background-color: var(--bg);
    border-color: var(--secondary);
}

.btn.icon {
    padding: 8px;
    font-size: 1.2rem;
    background: transparent;
    color: var(--text-light);
}

.btn.icon:hover {
    color: var(--text);
    background: var(--bg);
}

input[type="text"] {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

input[type="text"]:focus {
    border-color: var(--primary);
}

.divider {
    width: 1px;
    height: 24px;
    background-color: var(--border);
    margin: 0 10px;
}

.instruction {
    font-size: 0.9rem;
    color: var(--text-light);
    font-weight: 500;
}

.status-text {
    font-size: 1rem;
    font-weight: 600;
}

/* Toggle */
.toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-light);
    user-select: none;
}

.select-small {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    background: var(--bg);
}

.control-group-vertical {
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: flex-end;
}

/* Player Bar */
.player-bar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 10px 20px;
    display: flex;
    gap: 15px;
    overflow-x: auto;
    min-height: 50px;
    align-items: center;
}

.player-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--bg);
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid var(--border);
    white-space: nowrap;
}

.player-chip.active {
    border-color: var(--primary);
    background: #eff6ff;
    color: var(--primary);
}

.player-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

/* Canvas */
.canvas-container {
    flex: 1;
    background-color: #e5e5e5;
    /* Neutral background for canvas area */
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

canvas {
    background: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    border-radius: 4px;
    cursor: crosshair;
}

@media print {

    .top-bar,
    .player-bar {
        display: none;
    }

    .canvas-container {
        padding: 0;
        background: white;
    }

    canvas {
        box-shadow: none;
        border: 1px solid #000;
    }
}

/* Global Input Styling */
input[type="checkbox"],
input[type="range"] {
    accent-color: #475569;
    cursor: pointer;
}

/* Racing Mode Header Overrides */
.top-bar.racing-mode {
    color: white;
    transition: background-color 0.3s ease;
}

.top-bar.racing-mode .logo {
    color: white;
}

.top-bar.racing-mode .toggle,
.top-bar.racing-mode .instruction,
.top-bar.racing-mode .btn.icon,
.top-bar.racing-mode .status-text,
.top-bar.racing-mode .github-link {
    color: rgba(255, 255, 255, 0.9);
}

.top-bar.racing-mode .github-link:hover {
    color: white;
}

.top-bar.racing-mode input[type="checkbox"],
.top-bar.racing-mode input[type="range"] {
    accent-color: white;
}

.top-bar.racing-mode .btn.secondary {
    color: white;
    border-color: rgba(255, 255, 255, 0.4);
}

.top-bar.racing-mode .btn.secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.top-bar.racing-mode .divider {
    background-color: rgba(255, 255, 255, 0.3);
}