:root {
    --bg-color: #f8f9fa;
    --text-color: #495057;
    --accent-color: #ff8787;
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Quicksand', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

#settings-btn {
    position: fixed;
    top: 20px;
    left: 20px;
    background: none;
    border: 2px solid #dee2e6;
    padding: 6px 12px;
    color: #868e96;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.7rem;
    cursor: pointer;
    z-index: 100;
    letter-spacing: 0.05rem;
}

#settings-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}
#main-header {
    font-family: 'Quicksand', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    text-align: center;

    padding: 20px 0;
    margin-bottom: 30px;

    background: white;
    position: sticky;
    top: 0;
    z-index: 10;
}
#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    width: 95%;
    max-width: 800px;
    margin-top: 10px;
}

#stats-bar {
    font-weight: 700;
    font-size: 0.8rem;
    color: #adb5bd;
    letter-spacing: 0.1rem;
}

#solve-count {
    color: var(--text-color);
}

#controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 320px;
    gap: 0.5rem;
}

#action-btns {
    display: flex;
    gap: 8px;
    width: 100%;
}

#tutorial-btn {
    flex: 1;
    background: none;
    border: 2px solid #e9ecef;
    padding: 8px 10px;
    color: #adb5bd;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.65rem;
    letter-spacing: 0.05rem;
    transition: all 0.2s;
    white-space: nowrap;
}

#tutorial-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.custom-slider-container {
    position: relative;
    width: 100%;
    height: 44px;
    background: #e9ecef;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#slider-label {
    position: absolute;
    pointer-events: none;
    color: #868e96;
    font-weight: 700;
    font-size: 0.9rem;
    z-index: 1;
    letter-spacing: 0.05rem;
}

#length-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 100%;
    background: transparent;
    cursor: pointer;
    margin: 0;
    z-index: 2;
}

#length-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 44px;
    height: 44px;
    background: var(--accent-color);
    border-radius: 0;
    border: 4px solid #fff;
}

#length-slider::-moz-range-thumb {
    width: 44px;
    height: 44px;
    background: var(--accent-color);
    border-radius: 0;
    border: 4px solid #fff;
}

#puzzle-row {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 4px;
    height: 280px;
    width: 100%;
    padding: 20px 0;
}

.key {
    flex: 1;
    height: 220px;
    min-width: 0;
    position: relative;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    border: none;
    outline: none;
    background: #e9ecef;
    border-radius: 0;
    transition: transform 0.1s;
}

.key-window {
    width: 100%;
    aspect-ratio: 1 / 1;
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    border-radius: 0;
    background-color: var(--accent-color);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border: 4px solid #fff;
    box-sizing: border-box;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.4s cubic-bezier(0.23, 1, 0.32, 1), top 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-style: preserve-3d;
    will-change: transform, top;
}

.puzzle-row-3d .key {
    perspective: 1000px;
}

.puzzle-row-3d .key-window {
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible;
}

.prism-face {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: clamp(0.8rem, 3.5vw, 1.8rem);
    color: rgba(0, 0, 0, 0.7);
    border: 4px solid #fff;
    box-sizing: border-box;
    transition: filter 0.3s ease, opacity 0.3s ease;
    will-change: filter, opacity;
}

.prism-face.active {
    filter: brightness(1.15) saturate(1.1);
    opacity: 1;
    z-index: 2;
}

.prism-face.inactive {
    background-color: #000 !important;
    filter: brightness(0.5);
    opacity: 0.8;
    z-index: 1;
    color: transparent !important;
}

.prism-face.is-a {
    box-shadow: inset 0 0 20px rgba(255, 255, 255, 0.4);
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.8);
}

.key-window.solved-prism .prism-face {
    background-color: #212529 !important;
    box-shadow: 0 0 30px rgba(250, 82, 82, 0.6), inset 0 0 20px rgba(255, 255, 255, 0.1) !important;
    text-shadow: 0 0 10px #ff0000, 0 0 20px #ff0000, 0 0 30px #ff0000;
    color: #ff5c5c !important;
    border-color: #fa5252 !important;
}

@keyframes solved-spin {
    0% { transform: rotateX(0deg); }
    100% { transform: rotateX(360deg); }
}

.solved-spinning {
    animation: solved-spin 2s ease-in-out infinite !important;
}

.key-label {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(0.8rem, 3.5vw, 1.8rem);
    font-weight: 700;
    color: rgba(0, 0, 0, 0.7);
    transition: transform 0.2s;
}

#status {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.9rem;
    letter-spacing: 0.2rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--accent-color);
    height: 1.5rem;
    transition: color 0.3s ease;
    background: rgba(255,255,255,0.8);
    padding: 5px 15px;
    border-radius: 0;
}

.key.affected {
    filter: brightness(1.1);
    transform: scale(1.02);
    z-index: 5;
}

.arrow-indicator {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.8rem;
    font-weight: 900;
    color: #adb5bd;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, color 0.2s;
    z-index: 10;
    white-space: nowrap;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
}

.hint-dot {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    background-color: rgba(0,0,0,0.3);
    border-radius: 0;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 20;
}

.key.has-hint .hint-dot {
    opacity: 1;
}

.hint-value {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 900;
    color: rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 20;
}

.key.has-hint .hint-value {
    opacity: 1;
}

.key.affected .arrow-indicator {
    opacity: 1;
    color: var(--text-color);
}

.key:hover .arrow-indicator {
    font-size: 1.1rem;
}

.animate-up {
    animation: bump-up 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.animate-down {
    animation: bump-down 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes bump-up {
    0% { transform: translateY(0); }
    50% { transform: translateY(-15px); }
    100% { transform: translateY(0); }
}

@keyframes bump-down {
    0% { transform: translateY(0); }
    50% { transform: translateY(15px); }
    100% { transform: translateY(0); }
}

.solved-animation {
    animation: happy-bounce 0.6s ease infinite alternate;
}

@keyframes happy-bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-20px); }
}

#tutorial-overlay, #settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(248, 249, 250, 0.95);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
}

#tutorial-overlay.hidden, #settings-overlay.hidden {
    display: none;
}

#tutorial-modal, #settings-modal {
    background: white;
    width: 90%;
    max-width: 400px;
    padding: 2rem;
    border: 4px solid #495057;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    position: relative;
}

#settings-modal h2 {
    margin: 0 0 1rem 0;
    font-size: 1.2rem;
    color: var(--accent-color);
    letter-spacing: 0.2rem;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-top: 1px solid #eee;
    font-weight: 700;
    font-size: 0.9rem;
}

#settings-close {
    background: #495057;
    color: white;
    border: none;
    padding: 10px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

#tutorial-content {
    min-height: 150px;
}

#tutorial-content h2 {
    margin: 0 0 1rem 0;
    font-size: 1.2rem;
    color: var(--accent-color);
}

#tutorial-content p {
    line-height: 1.6;
    margin: 0;
}

#tutorial-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#tutorial-nav button {
    background: #495057;
    color: white;
    border: none;
    padding: 8px 16px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
}

#tutorial-nav button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#tutorial-dots {
    display: flex;
    gap: 8px;
}

.dot {
    width: 8px;
    height: 8px;
    background: #dee2e6;
}

.dot.active {
    background: var(--accent-color);
}

#tutorial-close {
    position: absolute;
    top: -45px;
    right: 0;
    background: none;
    border: none;
    font-weight: 700;
    cursor: pointer;
    color: #495057;
    font-family: inherit;
}

@media (max-width: 600px) {
    #puzzle-row {
        height: 260px;
        gap: 2px;
    }
    .key {
        height: 180px;
    }
    .key-window {
        border-width: 2px;
    }
}