:root {
    --game-primary: #c90c0f;
    --game-secondary: #f4c430;
}

body.rh-page {
    margin: 0;
    min-height: 100vh;
    font-family: "Rockwell", "Rockwell Nova", "Roboto Slab", serif;
    color: #e5e7eb;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 14% 8%, rgba(244, 196, 48, 0.14), transparent 42%),
        radial-gradient(circle at 88% 10%, rgba(201, 12, 15, 0.2), transparent 46%),
        linear-gradient(180deg, #111827 0%, #1f2937 48%, #0b1220 100%);
}

body.rh-page.game-menu-active {
    overflow-y: auto;
    overflow-x: hidden;
}

body.rh-page.game-menu-active #game-header {
    display: none !important;
}

.rh-page .game-screen {
    display: none;
    min-height: 100vh;
}

.rh-page .game-screen.active {
    display: block;
}

body.rh-page.with-game-header .rh-shell {
    padding-top: 5.5rem;
}

.rh-shell {
    max-width: min(760px, 96vw);
    margin: 0 auto;
    padding: 1.1rem 0.75rem 2.5rem;
}

.rh-hud {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 560px;
    margin: 0 auto 0.85rem;
    padding: 0.55rem 0.7rem;
    background: linear-gradient(180deg, #374151, #111827);
    border: 3px solid #0b1220;
    border-radius: 12px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12), 0 10px 24px rgba(0, 0, 0, 0.35);
}

.rh-lcd {
    min-width: 4.6rem;
    padding: 0.2rem 0.45rem;
    background: #030712;
    color: #f5c518;
    font-family: "Courier New", ui-monospace, monospace;
    font-size: 1.15rem;
    font-weight: 700;
    text-align: center;
    border-radius: 6px;
    box-shadow: inset 0 0 0 2px #7f1d1d, inset 0 8px 16px rgba(0, 0, 0, 0.45);
}

.rh-lcd span {
    display: block;
    font-size: 0.62rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #f4c430;
}

.rh-chip {
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    color: #fde68a;
    font-weight: 700;
}

.rh-chip.is-daily {
    background: #f4c430;
    color: #1a1a1a;
}

.rh-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
    margin: 0 auto 0.85rem;
    max-width: 560px;
}

.rh-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(244, 196, 48, 0.28);
    background: rgba(3, 7, 18, 0.75);
    color: #e5e7eb;
    font-weight: 700;
    cursor: pointer;
}

.rh-tool-btn:hover {
    border-color: #f5c518;
    color: #f5c518;
}

.rh-tool-btn:disabled {
    opacity: 0.45;
    cursor: default;
}

.rh-tool-btn[hidden] {
    display: none !important;
}

.rh-status {
    text-align: center;
    min-height: 1.4rem;
    margin: 0 auto 0.75rem;
    color: #fde68a;
    font-weight: 700;
}

.rh-board-frame {
    margin: 0 auto 0.25rem;
    max-width: min(560px, 96vw);
}

.rh-board-frame[data-daily="1"] {
    padding: 0.85rem 0.7rem 0.95rem;
    background: rgba(15, 22, 36, 0.78);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-left: 4px solid #c90c0f;
    border-radius: 16px;
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}

.rh-daily-chrome {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0 auto 0.55rem;
    max-width: 100%;
}

.rh-daily-chrome[hidden] {
    display: none !important;
}

.rh-daily-kicker {
    flex: 0 0 auto;
    padding: 0.4rem 0.95rem;
    border-radius: 999px;
    background: rgba(201, 12, 15, 0.9);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.rh-daily-meta {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.rh-daily-title {
    font-weight: 700;
    font-size: 1.05rem;
    color: #fff;
}

.rh-daily-date {
    font-size: 0.9rem;
    color: #f4c430;
    letter-spacing: 0.02em;
}

.rh-board-wrap {
    display: flex;
    justify-content: center;
    padding: 0.35rem 0.25rem 0.5rem;
}

.rh-board-frame[data-daily="1"] .rh-board-wrap {
    padding-bottom: 0.15rem;
}

.rh-board-frame[data-daily="1"] .rh-board {
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.08),
        0 0 0 3px #f4c430,
        0 0 0 6px #7f1d1d,
        0 16px 32px rgba(0, 0, 0, 0.45);
}

.rh-board {
    --rh-cell: min(64px, calc((min(92vw, 460px) - 28px) / 6));
    position: relative;
    width: calc(var(--rh-cell) * 6 + 28px + 18px);
    height: calc(var(--rh-cell) * 6 + 28px);
    padding: 14px 32px 14px 14px;
    background: linear-gradient(180deg, #4b5563, #1f2937);
    border: 4px solid #030712;
    border-radius: 18px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 16px 32px rgba(0, 0, 0, 0.45);
    overflow: hidden;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.rh-grid {
    position: relative;
    width: calc(var(--rh-cell) * 6);
    height: calc(var(--rh-cell) * 6);
    display: grid;
    grid-template-columns: repeat(6, var(--rh-cell));
    grid-template-rows: repeat(6, var(--rh-cell));
    overflow: visible;
    background:
        repeating-linear-gradient(0deg, transparent, transparent calc(var(--rh-cell) - 1px), rgba(255,255,255,0.06) calc(var(--rh-cell) - 1px), rgba(255,255,255,0.06) var(--rh-cell)),
        repeating-linear-gradient(90deg, transparent, transparent calc(var(--rh-cell) - 1px), rgba(255,255,255,0.06) calc(var(--rh-cell) - 1px), rgba(255,255,255,0.06) var(--rh-cell)),
        #111827;
    border-radius: 8px;
}

.rh-cell {
    min-width: 0;
    min-height: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0;
    z-index: 2;
    touch-action: none;
}

.rh-cell:focus-visible {
    outline: 2px solid #f4c430;
    outline-offset: -2px;
}

.rh-car {
    position: absolute;
    z-index: 3;
    border-radius: 11px;
    border: 2px solid rgba(0, 0, 0, 0.38);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.24), 0 3px 0 rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: #fff;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    perspective: 140px;
    transform-style: preserve-3d;
    transition:
        left 0.22s cubic-bezier(0.22, 1, 0.36, 1),
        top 0.22s cubic-bezier(0.22, 1, 0.36, 1),
        transform 0.16s ease,
        box-shadow 0.16s ease;
}

.rh-car > * {
    pointer-events: none;
}

.rh-car-label {
    position: relative;
    z-index: 2;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4);
}

.rh-car-shine {
    position: absolute;
    inset: 1px;
    border-radius: inherit;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 48%);
}

.rh-car-window {
    position: absolute;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(15, 23, 42, 0.22));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
}

.rh-car.is-horiz .rh-car-window {
    top: 18%;
    right: 9%;
    width: 28%;
    height: 64%;
    border-radius: 4px 10px 10px 4px;
}

.rh-car.is-horiz.is-lorry .rh-car-window {
    left: 7%;
    right: auto;
    width: 18%;
    border-radius: 10px 4px 4px 10px;
}

.rh-car.is-red.is-horiz .rh-car-window {
    right: 8%;
    left: auto;
    width: 28%;
    border-radius: 4px 10px 10px 4px;
}

.rh-car.is-vert .rh-car-window {
    top: 8%;
    left: 18%;
    width: 64%;
    height: 28%;
    border-radius: 10px 10px 4px 4px;
}

.rh-car.is-vert.is-lorry .rh-car-window {
    height: 18%;
}

.rh-lamp {
    position: absolute;
    border-radius: 2px;
}

.rh-car.is-horiz .rh-lamp {
    width: 7%;
    height: 16%;
    top: 50%;
    transform: translateY(-50%);
}

.rh-car.is-horiz .rh-lamp-a {
    right: 4%;
    background: #fde68a;
    box-shadow: 0 0 6px rgba(253, 230, 138, 0.85);
}

.rh-car.is-horiz .rh-lamp-b {
    left: 4%;
    background: #fecaca;
}

.rh-car.is-vert .rh-lamp {
    height: 7%;
    width: 16%;
    left: 50%;
    transform: translateX(-50%);
}

.rh-car.is-vert .rh-lamp-a {
    top: 4%;
    background: #fde68a;
    box-shadow: 0 0 6px rgba(253, 230, 138, 0.85);
}

.rh-car.is-vert .rh-lamp-b {
    bottom: 4%;
    background: #fecaca;
}

.rh-wheel {
    position: absolute;
    display: block;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    line-height: 0;
    font-size: 0;
    font-style: normal;
    background: #111827;
    border-radius: 50%;
    box-shadow: inset 0 0 0 1.5px #4b5563;
    transform-origin: 50% 50%;
    transform-box: border-box;
    transform-style: preserve-3d;
    backface-visibility: visible;
}

.rh-car.is-horiz .rh-wheel {
    width: 16%;
    height: 12%;
    transform: rotateX(55deg);
    background: repeating-linear-gradient(
        90deg,
        #111827 0 26%,
        #4b5563 26% 38%
    );
}

.rh-car.is-horiz .rh-wheel-a { top: -6%; left: 12%; }
.rh-car.is-horiz .rh-wheel-b { top: -6%; right: 12%; }
.rh-car.is-horiz .rh-wheel-c { bottom: -6%; left: 12%; }
.rh-car.is-horiz .rh-wheel-d { bottom: -6%; right: 12%; }
.rh-car.is-horiz .rh-wheel-e { top: -6%; left: 42%; }
.rh-car.is-horiz .rh-wheel-f { bottom: -6%; left: 42%; }

.rh-car.is-vert .rh-wheel {
    width: 12%;
    height: 16%;
    background: repeating-linear-gradient(
        180deg,
        #111827 0 26%,
        #4b5563 26% 38%
    );
}

.rh-car.is-vert .rh-wheel-a { left: -6%; top: 12%; }
.rh-car.is-vert .rh-wheel-b { left: -6%; bottom: 12%; }
.rh-car.is-vert .rh-wheel-c { right: -6%; top: 12%; }
.rh-car.is-vert .rh-wheel-d { right: -6%; bottom: 12%; }
.rh-car.is-vert .rh-wheel-e { left: -6%; top: 42%; }
.rh-car.is-vert .rh-wheel-f { right: -6%; top: 42%; }

.rh-car.is-car .rh-wheel-e,
.rh-car.is-car .rh-wheel-f {
    display: none;
}

.rh-car.is-red {
    color: #fff;
}

.rh-car.is-selected {
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22), 0 0 0 3px #f4c430;
    z-index: 4;
}

.rh-car.is-dragging {
    z-index: 6;
    cursor: grabbing;
    transform: scale(1.05);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.22), 0 0 0 3px #f4c430, 0 12px 20px rgba(0, 0, 0, 0.4);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.rh-car.is-horiz.is-sliding .rh-wheel,
.rh-car.is-horiz.is-dragging .rh-wheel {
    animation: rh-roll-horiz 0.38s linear infinite;
}

.rh-car.is-vert.is-sliding .rh-wheel,
.rh-car.is-vert.is-dragging .rh-wheel {
    animation: rh-roll-vert 0.38s linear infinite;
}

.rh-car.is-reverse .rh-wheel {
    animation-direction: reverse;
}

.rh-car.is-exiting {
    z-index: 5;
    transform: translateX(calc(var(--rh-cell) * 0.72));
    transition: transform 0.48s cubic-bezier(0.22, 1, 0.36, 1);
}

.rh-board.is-solved .rh-exit {
    background: #bbf7d0;
    box-shadow: 0 0 12px rgba(134, 239, 172, 0.85);
}

@keyframes rh-roll-horiz {
    from { transform: rotateX(55deg) rotateZ(0deg); }
    to { transform: rotateX(55deg) rotateZ(360deg); }
}

@keyframes rh-roll-vert {
    from { transform: rotateX(0deg); }
    to { transform: rotateX(360deg); }
}

.rh-exit {
    position: absolute;
    right: 4px;
    top: calc(14px + var(--rh-cell) * 2);
    width: 22px;
    height: var(--rh-cell);
    border-radius: 0 8px 8px 0;
    background: #86efac;
    color: #14532d;
    font-size: 0.62rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    display: flex;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
}

.rh-hint {
    text-align: center;
    color: #cbd5e1;
    font-size: 0.92rem;
    margin: 0.85rem auto 0;
    max-width: 36rem;
}

.rh-settings-panel__label {
    margin: 0 0 0.45rem;
    color: #1a120c;
    font-weight: 600;
}

.rh-settings-panel__buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
}

#settingsModal .rh-settings-panel__note {
    margin: 0.75rem 0 0;
    color: #7f1d1d;
    font-size: 0.9rem;
}

.difficulty-pill {
    padding: 0.45rem 0.75rem;
    min-height: 44px;
    border-radius: 999px;
    border: 2px solid #c90c0f;
    background: #fff !important;
    color: #c90c0f !important;
    font-weight: 700;
    cursor: pointer;
}

.difficulty-pill.is-selected,
.difficulty-pill:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    z-index: 12000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.active { display: flex; }

.modal-content {
    background: #fff;
    color: #1a1a1a;
    border-radius: 1rem;
    max-width: 640px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-large { max-width: 760px; }

.modal-header,
.modal-footer {
    padding: 1.1rem 1.4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.modal-header { border-bottom: 2px solid #eee; }

.modal-header h2 {
    margin: 0;
    color: #c90c0f;
    font-size: 1.35rem;
}

.modal-close {
    background: #fff !important;
    border: 2px solid #c90c0f;
    color: #c90c0f !important;
    border-radius: 8px;
    cursor: pointer;
    padding: 0.35rem 0.55rem;
}

.modal-close:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

.modal-body { padding: 1.2rem 1.4rem; }

.modal-footer {
    border-top: 2px solid #eee;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.help-section { margin-bottom: 1.1rem; }
.help-section h3 { color: #c90c0f; margin: 0 0 0.4rem; }
.help-section ul { margin: 0.3rem 0 0; padding-left: 1.2rem; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    background: #f8fafc;
    border-radius: 12px;
    padding: 0.85rem;
    text-align: center;
}

.stat-value { font-size: 1.6rem; color: #c90c0f; font-weight: 700; }
.stat-label { color: #64748b; font-size: 0.85rem; }

.difficulty-stats { display: grid; gap: 0.45rem; }
.difficulty-stats div {
    display: flex;
    justify-content: space-between;
    padding: 0.45rem 0.55rem;
    background: #f8fafc;
    border-radius: 8px;
}

.result-message { font-size: 1.05rem; margin: 0 0 1rem; }

.win-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    text-align: center;
}

.win-stat strong { display: block; font-size: 1.35rem; color: #c90c0f; }
.win-stat span { color: #64748b; font-size: 0.82rem; }

.rh-page .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem 1.1rem;
    border-radius: 0.55rem;
    border: 2px solid transparent;
    font-weight: 700;
    cursor: pointer;
}

.rh-page .btn-primary {
    background: #c90c0f !important;
    color: #fff !important;
    border-color: #c90c0f;
}

.rh-page .btn-secondary {
    background: #fff !important;
    color: #c90c0f !important;
    border-color: #c90c0f;
}

.rh-page .btn-secondary:hover {
    background: #c90c0f !important;
    color: #fff !important;
}

@media (max-width: 640px) {
    body.rh-page.with-game-header .rh-shell {
        padding-top: 0.75rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .rh-hud { max-width: 100%; }
    .rh-lcd { min-width: 0; flex: 1 1 0; }

    .rh-board-frame {
        max-width: 100%;
    }

    .rh-board-frame[data-daily="1"] {
        padding: 0.7rem 0.45rem 0.8rem;
        border-radius: 14px;
    }

    .rh-daily-chrome {
        gap: 0.55rem;
        margin-bottom: 0.4rem;
    }

    .rh-daily-title {
        font-size: 0.95rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .rh-car {
        transition: none;
    }

    .rh-car.is-sliding .rh-wheel,
    .rh-car.is-dragging .rh-wheel {
        animation: none;
    }

    .rh-car.is-horiz .rh-wheel {
        transform: rotateX(55deg);
    }

    .rh-car.is-vert .rh-wheel {
        transform: none;
    }

    .rh-car.is-exiting {
        animation: none;
        transform: none;
    }
}
