:root {
    --bg-body: #f3f4f6;
    --board-bg: #ffffff;
    --grid-line: #e5e7eb;
    --frame-color: #1f2937;

    --cell-size: 65px;
    --grid-size: 4;

    --path-color: #4f46e5;
    --path-head: #312e81;
    --win-color: #10b981;
    --dot-color: #000000;
    --text-color: #111827;
}

body {
    font-family: 'Rubik', sans-serif;
    background-color: var(--bg-body);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    user-select: none;
}

.main-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    max-width: calc((var(--cell-size) * var(--grid-size)) + 20px);
    padding: 0 5px;
    box-sizing: border-box;
}

h1 {
    margin: 0;
    font-size: 2.5rem;
    font-weight: 900;
    color: #374151;
    letter-spacing: -1px;
    text-transform: uppercase;
}

.stats-box {
    display: flex;
    align-items: center;
    gap: 10px;
}

.best-badge {
    font-size: 0.9rem;
    font-weight: bold;
    color: #6b7280;
    background: #e5e7eb;
    padding: 4px 8px;
    border-radius: 6px;
}

.timer-badge {
    font-size: 1.6rem;
    font-weight: bold;
    color: var(--frame-color);
    font-variant-numeric: tabular-nums;
    min-width: 45px;
    text-align: right;
}

.game-board-frame {
    background: transparent;
    padding: 0;
    border: 5px solid var(--frame-color);
    border-radius: 15px;
    width: calc((var(--cell-size) * var(--grid-size)) + (var(--grid-size) * 1px));
    height: calc((var(--cell-size) * var(--grid-size)) + (var(--grid-size) * 1px));
    perspective: 1000px;
    transition: width 0.3s, height 0.3s;
}

.flip-inner {
    position: relative;
    width: 100%;
    height: 100%;
    text-align: center;
    transition: transform 0.8s ease-in-out;
    transform-style: preserve-3d;
}

.flip-inner.flipped {
    transform: rotateY(180deg);
}

.flip-front,
.flip-back {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    border-radius: 8px;
    overflow: hidden;
}

.flip-front {
    background-color: var(--grid-line);
}

.flip-back {
    background-color: white;
    color: var(--text-color);
    transform: rotateY(180deg);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
}

.grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-size), var(--cell-size));
    grid-template-rows: repeat(var(--grid-size), var(--cell-size));
    background-color: var(--grid-line);
    gap: 1px;
    width: 100%;
    height: 100%;
}

.cell {
    background-color: var(--board-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    transition: all 0.20s ease-out;
}

.cell.visited {
    background-color: var(--path-color);
    border: 3px solid #818cf8;
    border-radius: 6px;
}

.cell.current-head {
    background-color: var(--path-head);
    border: 3px solid #818cf8;
    transform: scale(0.92);
    border-radius: 6px;
}

.dot {
    width: 55%;
    height: 55%;
    background-color: var(--dot-color);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 700;
    pointer-events: none;
}

.result-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.trophy {
    font-size: 3.5rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }

    40% { transform: translateY(-12px); }

    60% { transform: translateY(-8px); }
}

.result-content h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--frame-color);
}

.result-content p {
    margin: 0;
    color: #6b7280;
    font-weight: bold;
    font-size: 1rem;
}

.final-time-display {
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--path-color);
    line-height: 1;
}

.replay-btn {
    margin-top: 5px;
}

.replay-btn:hover {
    transform: scale(1.05);
}

.footer-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.controls-row {
    display: flex;
    gap: 20px;
    align-items: flex-end;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.input-group label {
    font-size: 0.8rem;
    font-weight: bold;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 2px solid var(--frame-color);
    background: white;
    font-family: 'Rubik', sans-serif;
    font-weight: bold;
    color: var(--frame-color);
    cursor: pointer;
    outline: none;
    font-size: 1rem;
}

button {
    background: var(--frame-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 50px;
    font-family: 'Rubik', sans-serif;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: transform 0.1s;
    height: 42px;
}

button:hover {
    transform: translateY(-2px);
}