:root {
    --bg: #0f172a;
    --panel: #1e293b;
    --text: #e2e8f0;
    --accent: #38bdf8;
    --accent2: #22c55e;
    --danger: #ef4444;
}

* { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    padding: 12px 20px;
    background: var(--panel);
    border-bottom: 1px solid #334155;
}

.brand {
    font-weight: 700;
    font-size: 20px;
}

.level-picker {
    display: flex;
    align-items: center;
    gap: 8px;
}

.level-picker select {
    background: #0f172a;
    color: var(--text);
    border: 1px solid #334155;
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 15px;
}

.stats {
    display: flex;
    gap: 16px;
    margin-left: auto;
}

.stat {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.btn {
    background: #334155;
    color: var(--text);
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s;
}

.btn:hover { background: #475569; }

.btn.primary { background: var(--accent); color: #0f172a; }
.btn.primary:hover { background: #7dd3fc; }

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 6px;
}

.zoom-label {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    min-width: 44px;
    text-align: center;
    color: var(--accent);
}

.content {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    flex-wrap: wrap;
}

#board {
    display: flex;
    gap: 24px;
    justify-content: center;
    align-items: flex-start;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.panel {
    background: var(--panel);
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.35);
    flex-shrink: 0;
}

.img-wrap {
    position: relative;
    display: inline-block;
    line-height: 0;
    cursor: crosshair;
    border-radius: 8px;
    overflow: hidden;
}

.img-wrap img {
    display: block;
    max-width: min(46vw, 720px);
    height: auto;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

.img-wrap canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto;
    touch-action: manipulation; /* allow pinch-zoom, no double-tap zoom */
}

.panel-label {
    text-align: center;
    margin-top: 8px;
    font-weight: 600;
    color: #94a3b8;
}

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.overlay.hidden { display: none; }

.modal {
    background: var(--panel);
    border-radius: 16px;
    padding: 32px 40px;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0,0,0,0.5);
}

.modal h2 { margin-top: 0; }

.modal p { color: #cbd5e1; font-size: 16px; }

.hidden { display: none !important; }

.link-btn {
    background: transparent;
    border: 1px solid #334155;
    color: var(--text);
    text-decoration: none;
}

.link-btn:hover { background: #334155; }

.auth-area {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

.user-label {
    color: var(--accent);
    font-weight: 700;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 260px;
    margin-top: 12px;
}

.auth-form input {
    background: #0f172a;
    color: var(--text);
    border: 1px solid #334155;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 15px;
}

.auth-form input:focus { outline: 1px solid var(--accent); }

.auth-error {
    color: #fca5a5;
    font-size: 13px;
    text-align: center;
}

.leaderboard {
    background: var(--panel);
    border-radius: 12px;
    padding: 16px 20px;
    min-width: 240px;
    max-width: 280px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.leaderboard h3 { margin-top: 0; color: #fbbf24; }

.lb-list {
    margin: 0;
    padding-left: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.lb-list li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    font-variant-numeric: tabular-nums;
}

.lb-list .lb-name { font-weight: 600; }

.lb-list .lb-meta { color: #94a3b8; font-size: 13px; }

.lb-empty { color: #64748b; font-size: 14px; }

/* ---------- mobile ---------- */

@media (max-width: 820px) {
    .topbar {
        gap: 10px 14px;
        padding: 10px 12px;
        position: sticky;
        top: 0;
        z-index: 20;
    }

    .brand { font-size: 17px; }

    .stats {
        gap: 10px;
        margin-left: 0;
        order: 10;
        width: 100%;
        justify-content: space-between;
    }

    .auth-area { margin-left: 0; }

    .content {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 12px;
    }

    #board {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .panel { padding: 8px; }

    .img-wrap img {
        max-width: 100%;
        width: 100%;
    }

    .leaderboard {
        min-width: 0;
        max-width: none;
        width: 100%;
    }

    .btn {
        padding: 11px 16px;
        font-size: 15px;
        min-height: 44px;
    }

    .level-picker {
        flex: 1;
    }

    .level-picker select {
        flex: 1;
        padding: 10px;
        font-size: 16px;
        min-height: 44px;
    }

    .modal { padding: 24px 20px; margin: 12px; }
}
