/* SVIM - Närmast vinner - Dark Professional Theme */
:root {
    --bg-darkest: #0a0a0f;
    --bg-dark: #12121a;
    --bg-card: #1a1a26;
    --bg-card-hover: #222233;
    --bg-input: #15151f;
    --border: #2a2a3a;
    --border-focus: #4a6cf7;
    --accent: #4a6cf7;
    --accent-hover: #5b7bf8;
    --accent-glow: rgba(74, 108, 247, 0.3);
    --success: #34d399;
    --warning: #fbbf24;
    --danger: #f87171;
    --text-primary: #e8e8ef;
    --text-secondary: #9ca3b0;
    --text-muted: #5a5f6e;
    --team-gold: #f59e0b;
    --team-silver: #94a3b8;
    --team-bronze: #d97706;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

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

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-darkest);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Login screen */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow);
}

.login-box h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    text-align: center;
}

.login-box .subtitle {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 28px;
    font-size: 0.9rem;
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea { resize: vertical; min-height: 80px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-success {
    background: var(--success);
    color: #000;
}
.btn-success:hover { opacity: 0.9; }

.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover { opacity: 0.9; }

.btn-secondary {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1.1rem;
}

.btn-block { width: 100%; }

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Admin layout */
.admin-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 80px;
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.admin-header h1 {
    font-size: 1.2rem;
    font-weight: 700;
}

/* Cards & Sections */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.card-header h2 {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    padding: 12px 0 8px;
    margin-bottom: 12px;
    border-bottom: 2px solid var(--accent);
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Question list */
.question-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    border: 1px solid var(--border);
}

.question-item .name {
    font-weight: 600;
    flex: 1;
}

.question-item .actions {
    display: flex;
    gap: 6px;
}

/* Team row */
.team-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
    padding: 10px;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.team-row label {
    font-size: 0.75rem;
    margin-bottom: 4px;
}

/* Status badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-open {
    background: rgba(52, 211, 153, 0.2);
    color: var(--success);
}

.badge-closed {
    background: rgba(248, 113, 113, 0.2);
    color: var(--danger);
}

.badge-phase {
    background: rgba(74, 108, 247, 0.2);
    color: var(--accent);
}

/* Results table */
.results-list {
    width: 100%;
}

.result-row {
    display: grid;
    grid-template-columns: 40px 24px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--bg-dark);
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 0.85rem;
    border: 1px solid transparent;
}

.result-row.team-row-result {
    border-color: var(--team-gold);
    background: rgba(245, 158, 11, 0.1);
}

.result-row.team-row-result .alias {
    font-size: 1rem;
    font-weight: 800;
    color: var(--team-gold);
}

.result-row.team-row-result .pin-dot {
    width: 20px;
    height: 20px;
    border-width: 3px;
    border-color: #000;
}

.result-row .rank {
    font-weight: 700;
    color: var(--accent);
    text-align: center;
}

.result-row .pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #000;
}

.result-row .alias {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.result-row .distance {
    color: var(--text-secondary);
    font-weight: 500;
    text-align: right;
    white-space: nowrap;
}

.result-row .total-rank {
    color: var(--text-muted);
    font-weight: 500;
    text-align: right;
    min-width: 40px;
    padding-left: 8px;
    border-left: 1px solid var(--border);
}

/* Header row for results */
.result-header {
    display: grid;
    grid-template-columns: 40px 24px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Map containers */
.map-container {
    width: 100%;
    height: 300px;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.map-container-large {
    height: 50vh;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 2000;
    padding: 20px;
    overflow-y: auto;
}

.modal-overlay.active { display: flex; align-items: flex-start; justify-content: center; padding-top: 40px; }

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow);
}

.modal-content h2 {
    margin-bottom: 16px;
    font-size: 1.1rem;
}

/* Player view */
.player-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-darkest);
}

.player-header {
    padding: 10px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.player-header .title {
    font-weight: 700;
    font-size: 0.95rem;
}

.player-body {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

/* Lobby screen */
.lobby-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 24px;
    text-align: center;
}

.lobby-screen .icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

.lobby-screen .status {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.lobby-screen .count {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}

/* Timer */
.timer-display {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 1.3rem;
    font-weight: 700;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.timer-display.urgent {
    background: var(--danger);
    animation: pulse 0.5s infinite alternate;
}

/* Circular timer (projector) */
.circular-timer {
    position: relative;
    width: 200px;
    height: 200px;
}

.circular-timer svg {
    transform: rotate(-90deg);
    width: 200px;
    height: 200px;
}

.circular-timer .track {
    fill: none;
    stroke: var(--border);
    stroke-width: 8;
}

.circular-timer .progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 8;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.5s linear;
}

.circular-timer .progress.urgent {
    stroke: var(--danger);
}

.circular-timer .time-text {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    font-size: 3.5rem;
    font-weight: 700;
}

/* Projector layout */
.projector-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-darkest);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.projector-phase {
    display: none;
    flex: 1;
    flex-direction: column;
}

.projector-phase.active {
    display: flex;
}

/* Projector lobby */
.proj-lobby {
    align-items: center;
    justify-content: center;
    gap: 40px;
    text-align: center;
}

.proj-lobby .qr-wrapper {
    background: #fff;
    padding: 24px;
    border-radius: var(--radius);
    display: inline-block;
}

.proj-lobby .url-display {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 1px;
}

.proj-lobby .pin-display {
    font-size: 3rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-top: 12px;
}

.proj-lobby .pin-label {
    font-size: 1.2rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 2px;
}

/* Projector playing */
.proj-playing {
    align-items: center;
    justify-content: center;
    gap: 30px;
    padding: 40px;
    text-align: center;
}

.proj-playing .question-title {
    font-size: 2.5rem;
    font-weight: 700;
    white-space: pre-wrap;
}

.proj-playing .question-clue {
    font-size: 1.6rem;
    color: var(--text-secondary);
    max-width: 900px;
    line-height: 1.6;
    white-space: pre-wrap;
}

/* Projector results */
.proj-results {
    flex-direction: row;
    gap: 0;
}

.proj-results .map-side {
    flex: 2;
    position: relative;
}

.proj-results .list-side {
    flex: 1;
    background: var(--bg-card);
    padding: 24px;
    overflow-y: auto;
    border-left: 1px solid var(--border);
}

.proj-results .clue-bar {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    background: rgba(10, 10, 15, 0.9);
    padding: 20px 28px;
    z-index: 1000;
}

.proj-results .clue-bar .clue-text {
    color: var(--text-secondary);
    font-size: 1.5rem;
    line-height: 1.5;
    white-space: pre-wrap;
    margin-bottom: 6px;
}

.proj-results .clue-bar .answer-text {
    color: var(--success);
    font-weight: 700;
    font-size: 1.8rem;
    white-space: pre-wrap;
}

/* Projector factslide */
.proj-factslide {
    position: relative;
    padding: 0;
}

.proj-factslide img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Player results view */
.player-results {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.player-results .results-map {
    height: 40vh;
    flex-shrink: 0;
}

.player-results .results-info {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

/* Factslide player */
.player-factslide {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 8px;
    background: #000;
}

.player-factslide img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Map instruction overlay */
.map-instruction {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius);
    z-index: 1000;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    box-shadow: var(--shadow);
    pointer-events: none;
}

/* Animations */
@keyframes pulse {
    from { opacity: 1; }
    to { opacity: 0.6; }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-darkest); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-accent { color: var(--accent); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* Leaflet overrides */
.leaflet-container {
    background: var(--bg-dark) !important;
}
