/* ===== DESIGN TOKENS ===== */
:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2333;
    --bg-card: #21262d;
    --border-color: #30363d;
    --border-glow: #58a6ff33;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;

    --accent-blue: #58a6ff;
    --accent-green: #3fb950;
    --accent-red: #f85149;
    --accent-orange: #d29922;
    --accent-purple: #bc8cff;

    --gradient-primary: linear-gradient(135deg, #58a6ff 0%, #bc8cff 100%);
    --gradient-repair: linear-gradient(135deg, #3fb950 0%, #58a6ff 100%);
    --gradient-danger: linear-gradient(135deg, #f85149 0%, #d29922 100%);

    --shadow-glow: 0 0 20px rgba(88, 166, 255, 0.15);
    --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ===== LAYOUT ===== */
#app {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    min-height: 100vh;
}

header {
    text-align: center;
    padding: 1rem 0;
}

header h1 {
    font-size: 2rem;
    font-weight: 800;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

header .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 400;
    margin-top: 0.35rem;
}

header .intro {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 400;
    line-height: 1.5;
    margin: 0.75rem auto 0;
    max-width: 720px;
    opacity: 0.88;
}

#lang-selector {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 0.75rem;
    background: var(--bg-card);
    padding: 6px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-card);
    display: inline-flex;
}

.lang-btn {
    background: transparent;
    border: none;
    border-radius: 8px;
    width: 56px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.75rem;
    transition: all var(--transition-fast);
    opacity: 0.5;
    filter: grayscale(80%);
}

.lang-btn .fi {
    font-size: 1.5rem;
    line-height: 1;
    width: 2em;
    height: 1.5em;
    border-radius: 3px;
}

.lang-btn:hover {
    background: var(--bg-tertiary);
    opacity: 0.8;
    filter: grayscale(40%);
}

.lang-btn.active {
    opacity: 1;
    filter: grayscale(0%);
    background: rgba(88, 166, 255, 0.15);
    box-shadow: inset 0 0 0 1px rgba(88, 166, 255, 0.4);
}

main {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 800px) {
    main {
        grid-template-columns: 1.6fr 1fr;
    }
}

/* ===== CUBE VIEWPORT ===== */
#cube-viewport {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    position: relative;
    overflow: hidden;
    aspect-ratio: 1 / 0.85;
    min-height: 400px;
    box-shadow: var(--shadow-card);
}

#cube-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    touch-action: none;
}

#cube-canvas:active {
    cursor: grabbing;
}

/* Rotation arrow buttons */
.cube-rotate-btn {
    position: absolute;
    z-index: 10;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: rgba(22, 27, 34, 0.85);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    backdrop-filter: blur(4px);
}

.cube-rotate-btn:hover {
    background: rgba(88, 166, 255, 0.2);
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    transform: scale(1.1);
}

.cube-rotate-btn:active {
    transform: scale(0.95);
    background: rgba(88, 166, 255, 0.35);
}

.rotate-up {
    top: 50px;
    left: 50%;
    transform: translateX(-50%);
}
.rotate-up:hover {
    transform: translateX(-50%) scale(1.1);
}

.rotate-down {
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%);
}
.rotate-down:hover {
    transform: translateX(-50%) scale(1.1);
}

.rotate-left {
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
}
.rotate-left:hover {
    transform: translateY(-50%) scale(1.1);
}

.rotate-right {
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
}
.rotate-right:hover {
    transform: translateY(-50%) scale(1.1);
}

#status-bar {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 5;
    pointer-events: none;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 100px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-input {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(88, 166, 255, 0.3);
}

.mode-repair {
    background: rgba(63, 185, 80, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(63, 185, 80, 0.3);
    animation: pulse-badge 2s ease-in-out infinite;
}

.mode-error {
    background: rgba(248, 81, 73, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248, 81, 73, 0.3);
}

@keyframes pulse-badge {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

#status-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#rotation-hint {
    position: absolute;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    opacity: 0.7;
    transition: opacity var(--transition-normal);
    pointer-events: none;
}

#cube-viewport:hover #rotation-hint {
    opacity: 1;
}

/* ===== CONTROLS PANEL ===== */
#controls-panel {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

#controls-panel section {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
}

#controls-panel h2 {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

/* ===== COLOR SWATCHES ===== */
#color-swatches {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.swatch {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    border: 3px solid transparent;
    background: var(--swatch-color);
    cursor: pointer;
    position: relative;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.swatch:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.swatch.active {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.3), 0 4px 16px rgba(0,0,0,0.4);
    transform: scale(1.1);
}

.swatch-check {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    opacity: 0;
    transition: opacity var(--transition-fast);
    color: #000;
    text-shadow: 0 1px 2px rgba(255,255,255,0.5);
}

.swatch.active .swatch-check {
    opacity: 1;
}

.swatch[data-color="blue"] .swatch-check,
.swatch[data-color="red"] .swatch-check,
.swatch[data-color="green"] .swatch-check {
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-align: center;
    margin-top: 0.85rem;
}

/* ===== BUTTONS ===== */
#actions-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: none !important;
    border: none !important;
    padding: 0 !important;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0.8rem 1.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--gradient-primary);
    color: #fff;
    box-shadow: 0 4px 16px rgba(88, 166, 255, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 24px rgba(88, 166, 255, 0.45);
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    border-color: var(--text-muted);
}

/* ===== RESULTS ===== */
#results-section {
    transition: all var(--transition-normal);
}

#results-content {
    margin-bottom: 1rem;
}

.result-ok {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 1rem;
    background: rgba(63, 185, 80, 0.08);
    border: 1px solid rgba(63, 185, 80, 0.25);
    border-radius: var(--radius-sm);
    color: var(--accent-green);
    font-weight: 500;
}

.result-ok svg {
    flex-shrink: 0;
}

.result-broken {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.corner-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.85rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: border-color var(--transition-normal);
}

.corner-card.highlight {
    border-color: var(--accent-orange);
    background: rgba(210, 153, 34, 0.06);
}

.corner-card .corner-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.corner-card .corner-icon.cw {
    background: rgba(210, 153, 34, 0.15);
    color: var(--accent-orange);
}

.corner-card .corner-icon.ccw {
    background: rgba(188, 140, 255, 0.15);
    color: var(--accent-purple);
}

.corner-card .corner-info {
    flex: 1;
}

.corner-card .corner-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.corner-card .corner-fix {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.corner-stickers {
    display: flex;
    gap: 3px;
}

.corner-sticker {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255,255,255,0.15);
}

/* ===== REPAIR OVERLAY ===== */
#repair-overlay {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    pointer-events: none;
}

#repair-banner {
    max-width: 600px;
    margin: 0 auto 1.5rem;
    background: var(--bg-card);
    border: 1px solid rgba(63, 185, 80, 0.3);
    border-radius: var(--radius-md);
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    animation: slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    pointer-events: auto;
}

@keyframes slide-up {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

#repair-corner-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--accent-green);
}

#repair-direction {
    font-size: 0.85rem;
    color: var(--text-secondary);
    flex: 1;
}

#repair-countdown {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid var(--accent-green);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--accent-green);
    position: relative;
}

#repair-countdown::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--accent-green);
    animation: countdown-spin 4s linear infinite;
}

@keyframes countdown-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ===== SOLVE BUTTON ===== */
.btn-solve {
    background: var(--gradient-repair);
    color: #fff;
    box-shadow: 0 4px 16px rgba(63, 185, 80, 0.3);
}

.btn-solve:hover {
    box-shadow: 0 6px 24px rgba(63, 185, 80, 0.45);
    filter: brightness(1.1);
}

/* ===== SOLVER SECTION ===== */
#solver-section {
    transition: all var(--transition-normal);
}

#solver-status {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    min-height: 1.2em;
}

#solver-step-display {
    text-align: center;
    padding: 1.25rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
}

#solver-move-label {
    font-size: 2rem;
    font-weight: 800;
    background: var(--gradient-repair);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: 0.05em;
}

#solver-step-counter {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

#solver-nav {
    display: flex;
    gap: 8px;
    justify-content: center;
}

.btn-nav {
    width: 56px;
    height: 48px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-nav:hover {
    border-color: var(--accent-blue);
    box-shadow: 0 0 12px rgba(88, 166, 255, 0.2);
}

/* ===== PLAYBACK SPEED SLIDER ===== */
#solver-speed-control {
    margin-top: 14px;
    padding: 10px 12px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
}

#solver-speed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

#solver-speed-header label {
    font-weight: 600;
    letter-spacing: 0.02em;
}

#solver-speed-value {
    font-variant-numeric: tabular-nums;
    color: var(--accent-blue);
    font-weight: 600;
}

#solver-speed {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 999px;
    background: var(--bg-card);
    outline: none;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

#solver-speed::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: 2px solid var(--bg-primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
    transition: transform var(--transition-fast);
}

#solver-speed::-webkit-slider-thumb:hover {
    transform: scale(1.15);
}

#solver-speed::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-blue);
    border: 2px solid var(--bg-primary);
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}

#solver-speed-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.mode-solving {
    background: rgba(63, 185, 80, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(63, 185, 80, 0.3);
    animation: pulse-badge 2s ease-in-out infinite;
}

/* ===== UTILITIES ===== */
.hidden {
    display: none !important;
}

/* ===== CORNER HIGHLIGHT ON CUBE (glow ring) ===== */
.corner-glow {
    animation: corner-glow-pulse 1.5s ease-in-out infinite;
}

@keyframes corner-glow-pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== RESPONSIVE ===== */
@media (max-width: 799px) {
    #app {
        padding: 0.75rem;
        gap: 1rem;
    }

    header {
        padding: 0.5rem 0;
    }

    header h1 {
        font-size: 1.35rem;
        line-height: 1.3;
    }

    header .subtitle {
        font-size: 0.8rem;
        margin-top: 0.2rem;
    }

    /* Language selector: larger on mobile for touch */
    .lang-btn {
        width: 52px;
        height: 44px;
        font-size: 1.5rem;
    }

    .lang-btn .fi {
        font-size: 1.35rem;
    }

    /* Stack vertically */
    main {
        grid-template-columns: 1fr !important;
    }

    /* Cube viewport: always take full available width.
       (Avoid combining aspect-ratio with max-height, which causes the box
       to shrink horizontally to preserve the ratio on short screens.) */
    #cube-viewport {
        width: 100%;
        aspect-ratio: 1 / 0.9;
        min-height: 260px;
        border-radius: var(--radius-md);
    }

    /* Make every control section span the full width and stay centered */
    #controls-panel {
        width: 100%;
    }
    #controls-panel section {
        width: 100%;
    }

    .cube-rotate-btn {
        width: 32px;
        height: 32px;
    }

    .rotate-up { top: 40px; }
    .rotate-down { bottom: 30px; }

    #rotation-hint {
        font-size: 0.65rem;
        bottom: 6px;
    }

    /* Controls: compact */
    #controls-panel {
        gap: 0.75rem;
    }

    #controls-panel section {
        padding: 1rem;
    }

    #controls-panel h2 {
        font-size: 0.78rem;
        margin-bottom: 0.75rem;
    }

    /* Color swatches: smaller on mobile */
    #color-swatches {
        gap: 8px;
    }

    .swatch {
        width: 42px;
        height: 42px;
    }

    .hint {
        font-size: 0.72rem;
        margin-top: 0.5rem;
    }

    /* Buttons: touch-friendly (44px min) */
    .btn {
        padding: 0.7rem 1rem;
        font-size: 0.85rem;
        min-height: 44px;
    }

    /* Solver step display */
    #solver-move-label {
        font-size: 1.6rem;
    }

    #solver-step-display {
        padding: 1rem;
    }

    #solver-nav {
        gap: 6px;
    }

    .btn-nav {
        width: 50px;
        height: 44px;
    }

    /* Status badge */
    .status-badge {
        font-size: 0.65rem;
        padding: 4px 10px;
    }
}

/* Extra small phones */
@media (max-width: 400px) {
    header h1 {
        font-size: 1.1rem;
    }

    /* Reduce horizontal padding so boxes reach edge-to-edge */
    #app {
        padding: 0.5rem;
    }

    .swatch {
        width: 36px;
        height: 36px;
    }

    #cube-viewport {
        width: 100%;
        min-height: 220px;
    }

    .btn {
        font-size: 0.8rem;
        padding: 0.65rem 0.8rem;
    }
}

/* Landscape phones: side-by-side but compact */
@media (max-height: 500px) and (orientation: landscape) {
    #cube-viewport {
        min-height: 200px;
        max-height: 70vh;
        aspect-ratio: 1 / 0.7;
    }

    header {
        padding: 0.25rem 0;
    }

    header h1 {
        font-size: 1.2rem;
    }

    header .subtitle {
        display: none;
    }
}

/* ===== CUSTOM ALERT MODAL ===== */
#custom-alert-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 17, 23, 0.7);
    backdrop-filter: blur(8px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#custom-alert-overlay:not(.hidden) {
    opacity: 1;
    pointer-events: auto;
}

#custom-alert-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    max-width: 450px;
    width: 90%;
    text-align: center;
    box-shadow: 0 24px 48px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.05);
    transform: translateY(20px) scale(0.95);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

#custom-alert-overlay:not(.hidden) #custom-alert-box {
    transform: translateY(0) scale(1);
}

#custom-alert-icon {
    margin-bottom: 1.25rem;
    display: flex;
    justify-content: center;
}

#custom-alert-message {
    font-size: 1.05rem;
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 1.75rem;
    white-space: pre-line;
}

#custom-alert-btn {
    width: 100%;
    font-size: 1.05rem;
    padding: 0.85rem;
}
