@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@400;600;700&family=Share+Tech+Mono&display=swap');

:root {
    --bg: #0a0a0b;
    --bg2: #111113;
    --surface: #18181c;
    --surface2: #1e1e24;
    --border: rgba(255, 255, 255, 0.07);

    --red-off: #1a0505;
    --red-dim: #3d0a0a;
    --red-on: #ff1e00;
    --red-glow: rgba(255, 30, 0, 0.6);
    --red-glow2: rgba(255, 30, 0, 0.15);

    --text: #e8e8f0;
    --dim: #5a5a6a;
    --accent: #ff1e00;
    --gold: #ffd700;

    --penalty: #ff6b00;
    --success: #00d4aa;

    --font-display: 'Rajdhani', sans-serif;
    --font-mono: 'Share Tech Mono', monospace;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

html,
body {
    touch-action: none;
    overscroll-behavior: none;
    position: fixed;
    width: 100%;
    height: 100%;
}

body {
    font-family: var(--font-display);
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    width: 100vw;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── GRAIN OVERLAY ─── */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    opacity: 0.03;
    pointer-events: none;
    z-index: 999;
}

/* ─── HUD ─── */
.hud {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(16px, 4vw, 48px);
    padding: 10px 100px 10px 60px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    z-index: 10;
    min-height: 58px;
}

.hud-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.hud-item .label {
    font-size: 9px;
    letter-spacing: 2px;
    color: var(--dim);
    text-transform: uppercase;
    font-family: var(--font-mono);
}

.hud-item .value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
    letter-spacing: 1px;
    line-height: 1;
}

/* ─── PAUSE BUTTON ─── */
.pause-btn {
    position: fixed;
    top: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    color: var(--dim);
    width: 38px;
    height: 38px;
    border-radius: 8px;
    cursor: pointer;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    text-decoration: none;
}

.pause-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

/* ─── GAME AREA ─── */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    padding: 20px 16px;
    position: relative;
}

/* ─── LIGHTS PANEL ─── */
.lights-panel {
    display: flex;
    gap: clamp(10px, 3vw, 24px);
    align-items: center;
    justify-content: center;
    padding: 20px 28px;
    background: var(--surface2);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
    position: relative;
}

/* Carbon fiber texture on panel */
.lights-panel::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 16px;
    background:
        repeating-linear-gradient(45deg,
            rgba(255, 255, 255, 0.015) 0px,
            rgba(255, 255, 255, 0.015) 1px,
            transparent 1px,
            transparent 6px),
        repeating-linear-gradient(-45deg,
            rgba(255, 255, 255, 0.015) 0px,
            rgba(255, 255, 255, 0.015) 1px,
            transparent 1px,
            transparent 6px);
    pointer-events: none;
}

/* ─── LIGHTS ─── */
.light {
    width: clamp(44px, 10vw, 64px);
    height: clamp(44px, 10vw, 64px);
    border-radius: 50%;
    background: #000;
    border: 3px solid #1a1a1a;
    position: relative;
    transition: all 0.1s;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: inset 0 0 15px rgba(0, 0, 0, 1);
}

/* Grille de LEDs */
.light::before {
    content: '';
    position: absolute;
    inset: 2px;
    border-radius: 50%;
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.1) 30%, transparent 40%);
    background-size: 2px 2px;
    background-repeat: repeat;
    z-index: 1;
}

/* Effet de verre / Reflet */
.light::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 25%, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
    pointer-events: none;
    z-index: 2;
}

/* État ON (Grille rouge/blanc perçante) */
.light.on {
    border-color: #222;
    box-shadow:
        inset 0 0 10px rgba(0, 0, 0, 1),
        0 0 20px rgba(255, 0, 0, 0.3);
}

.light.on::before {
    background-image:
        radial-gradient(circle, #fff 10%, transparent 20%),
        radial-gradient(circle, #ff2200 40%, transparent 50%);
    background-size: 2px 2px;
    filter: drop-shadow(0 0 2px #ff0000);
}

/* PENALTY (Grille orange) */
.light.penalty {
    animation: penaltyFlash 0.15s ease-in-out 4;
}

.light.penalty::before {
    background-image:
        radial-gradient(circle, #fff 10%, transparent 20%),
        radial-gradient(circle, #ff9000 40%, transparent 50%);
    background-size: 2px 2px;
    filter: drop-shadow(0 0 2px #ff6b00);
}

@keyframes penaltyFlash {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.3;
    }
}

/* ─── CHRONO ─── */
.chrono-wrap {
    text-align: center;
}

.chrono {
    font-family: var(--font-mono);
    font-size: clamp(40px, 10vw, 72px);
    font-weight: 400;
    color: var(--text);
    letter-spacing: 2px;
    line-height: 1;
    transition: color 0.2s;
}

.chrono.running {
    color: var(--success);
}

.chrono.penalty {
    color: var(--penalty);
}

.chrono.early {
    color: var(--penalty);
}

.chrono-sub {
    font-size: 12px;
    letter-spacing: 2px;
    color: var(--dim);
    text-transform: uppercase;
    margin-top: 8px;
    font-family: var(--font-mono);
    min-height: 18px;
}

/* ─── LAST RESULT ─── */
.last-result {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--dim);
    letter-spacing: 1px;
    min-height: 20px;
    text-align: center;
}

.last-result.good {
    color: var(--success);
}

.last-result.penalty {
    color: var(--penalty);
}

/* ─── HOLD ZONE (invisible — interaction sur toute la page) ─── */
.hold-zone {
    display: none;
}

/* ─── OVERLAYS ─── */
.game-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 5, 6, 0.92);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(8px);
}

.game-overlay[style*="flex"] {
    display: flex !important;
}

.overlay-content {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 36px 32px;
    text-align: center;
    max-width: 340px;
    width: 92%;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
    animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popIn {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.overlay-content h2 {
    font-size: 26px;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: 1px;
    color: var(--text);
}

/* ─── RECORD POPUP ─── */
.record-popup {
    border-color: rgba(255, 215, 0, 0.2);
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 40px rgba(255, 215, 0, 0.05);
}

.record-popup::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.record-badge {
    font-size: 40px;
    margin-bottom: 8px;
}

.record-details {
    margin: 16px 0 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.record-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
}

.record-row .label {
    color: var(--dim);
    font-size: 11px;
    letter-spacing: 1px;
}

.record-row .old {
    color: var(--dim);
    text-decoration: line-through;
}

.record-row .new {
    color: var(--gold);
    font-size: 16px;
    font-weight: 700;
}

.record-row .arrow {
    color: var(--accent);
    font-size: 16px;
    margin: 0 6px;
}

.record-msg-label {
    font-size: 12px;
    color: var(--dim);
    margin-bottom: 10px;
    text-align: left;
    font-family: var(--font-mono);
}

/* ─── BUTTONS ─── */
.btn-primary {
    width: 100%;
    padding: 14px;
    margin: 8px 0 0;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 700;
    font-family: var(--font-display);
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 6px 20px rgba(255, 30, 0, 0.3);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

/* ─── INPUTS ─── */
.message-input-wrapper {
    margin: 16px 0 0;
    position: relative;
}

#recordMsgInput {
    width: 100%;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 2px solid var(--accent);
    color: var(--text);
    padding: 12px 16px;
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 14px;
    outline: none;
    transition: all 0.2s;
}

#recordMsgInput:focus {
    background: rgba(255, 255, 255, 0.07);
    box-shadow: 0 4px 20px rgba(255, 30, 0, 0.15);
}

.char-counter {
    position: absolute;
    bottom: -20px;
    right: 4px;
    font-size: 10px;
    color: var(--dim);
    font-family: var(--font-mono);
}

/* ─── RECORDS MODAL ─── */
.records-modal {
    max-width: 380px !important;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--dim);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.2s;
}

.modal-close:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.08);
}

.records-title {
    font-size: 22px !important;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 20px !important;
    color: var(--text) !important;
}

.records-section {
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    text-align: left;
}

.records-section h3 {
    font-size: 10px !important;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--dim) !important;
    margin-bottom: 10px !important;
    font-family: var(--font-mono);
}

.record-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.record-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.record-card.global {
    border-color: rgba(255, 215, 0, 0.15);
    background: rgba(255, 215, 0, 0.03);
}

.rc-label {
    font-size: 9px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    font-family: var(--font-mono);
}

.rc-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    font-family: var(--font-mono);
}

.record-card.global .rc-value {
    color: var(--gold);
}

.rc-message {
    display: block;
    font-size: 11px;
    color: var(--dim);
    font-style: italic;
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px solid var(--border);
    font-family: var(--font-mono);
}

.connection-status {
    font-size: 10px;
    text-align: center;
    margin-top: 10px;
    color: var(--dim);
    font-family: var(--font-mono);
    opacity: 0.6;
}

/* ─── HISTORY MODAL ─── */
.history-modal {
    max-width: 380px !important;
    position: relative;
    max-height: 85dvh;
    display: flex;
    flex-direction: column;
}

.history-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 14px;
    flex-shrink: 0;
}

.hist-stat {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.hs-val {
    font-family: var(--font-mono);
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.hs-lbl {
    font-family: var(--font-mono);
    font-size: 8px;
    color: var(--dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.history-list {
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
    margin-bottom: 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
}

.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.history-empty {
    text-align: center;
    color: var(--dim);
    font-family: var(--font-mono);
    font-size: 12px;
    padding: 30px 0;
}

.hist-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    font-family: var(--font-mono);
    flex-shrink: 0;
}

.hist-row.penalty-row {
    border-color: rgba(255, 107, 0, 0.15);
    background: rgba(255, 107, 0, 0.04);
}

.hist-num {
    font-size: 10px;
    color: var(--dim);
    letter-spacing: 1px;
    min-width: 28px;
}

.hist-indicator {
    font-size: 10px;
}

.hist-time {
    font-size: 15px;
    font-weight: 700;
    margin-left: auto;
    letter-spacing: 1px;
}

.hist-label-penalty {
    font-size: 10px;
    color: var(--penalty);
    letter-spacing: 1px;
    text-transform: uppercase;
    flex: 1;
}

.good-time {
    color: var(--success);
}

.bad-time {
    color: #ff4444;
}

.penalty-time {
    color: var(--penalty);
    font-size: 14px;
}

/* ─── SECONDARY BUTTON ─── */
.btn-secondary {
    width: 100%;
    padding: 11px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 700;
    font-family: var(--font-display);
    letter-spacing: 2px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.15s;
    background: transparent;
    color: var(--dim);
    flex-shrink: 0;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.2);
}

/* ─── RESPONSIVE ─── */
@media (max-width: 500px) {
    .lights-panel {
        gap: 8px;
        padding: 16px 20px;
    }

    .record-grid {
        grid-template-columns: 1fr;
    }
}