* {
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --accent: #ec4899;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --bg-dark: #1e293b;
    --text: #0f172a;
    --text-light: #64748b;
    --border: #e2e8f0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
    background: linear-gradient(135deg, var(--bg) 0%, #f1f5f9 100%);
    color: var(--text);
    overflow-x: hidden;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    background: white;
    padding: 30px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.12);
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    animation: slideUp 0.4s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

header {
    width: 100%;
    margin-bottom: 16px;
}

header h1 {
    font-size: 2.5em;
    margin: 0 0 12px 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    letter-spacing: -1px;
}

#game-info {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-direction: column;
    flex-wrap: nowrap;
    margin-bottom: 12px;
    gap: 6px;
    width: 100%;
}

#score-timer-row {
    display: flex;
    width: 100%;
    gap: 10px;
}

#score,
#timer {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
    color: white;
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    flex: 1 1 50%;
    min-width: 0;
    width: 50%;
}

#challenge-progress {
    width: 100%;
    text-align: center;
    margin-top: 0;
    font-weight: 600;
    color: var(--text-light);
    font-size: 0.95em;
}

.header-actions {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

#pause-button,
#quick-restart-button,
#leaderboard-button,
#sound-toggle-button {
    background: linear-gradient(135deg, var(--accent) 0%, #d946a6 100%);
    color: white;
    border: none;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(236, 72, 153, 0.3);
}

#quick-restart-button {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

#leaderboard-button {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3);
}

#sound-toggle-button {
    background: linear-gradient(135deg, #0f172a 0%, #334155 100%);
    box-shadow: 0 4px 15px rgba(15, 23, 42, 0.22);
}

#sound-toggle-button.muted {
    background: linear-gradient(135deg, #94a3b8 0%, #64748b 100%);
    box-shadow: 0 4px 15px rgba(100, 116, 139, 0.22);
}

#pause-button:hover,
#quick-restart-button:hover,
#leaderboard-button:hover,
#sound-toggle-button:hover {
    transform: translateY(-2px);
}

#pause-button:hover {
    box-shadow: 0 6px 20px rgba(236, 72, 153, 0.4);
}

#quick-restart-button:hover {
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

#leaderboard-button:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

#sound-toggle-button:hover {
    box-shadow: 0 6px 20px rgba(15, 23, 42, 0.28);
}

#pause-button:active,
#quick-restart-button:active,
#leaderboard-button:active,
#sound-toggle-button:active {
    transform: translateY(0);
}

/* Game Board */
#game-board {
    display: inline-grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    margin: 14px 0 10px;
    gap: 0;
    background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
}

.cell {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    box-sizing: border-box;
    background: white;
    position: relative;
    transition: all 0.15s ease;
    cursor: grab;
}

.cell:hover {
    background: #f5f7fa;
}

.cell.occupied {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-color: var(--primary-dark);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: cellFill 0.4s ease-out;
}

@keyframes cellFill {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.cell.marked {
    background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
    border-color: #991b1b;
    animation: pulseMarked 2s infinite;
}

@keyframes pulseMarked {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.8;
    }
}

.cell.marked::after {
    content: '★';
    color: white;
    font-size: 18px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.cell.ghost {
    background: linear-gradient(135deg, #e0e7ff 0%, #dbeafe 100%);
    border-color: var(--primary-light);
    opacity: 0.7;
}

.cell.highlight {
    background: linear-gradient(135deg, var(--warning) 0%, #dd7a1a 100%);
    opacity: 0.8;
    border-color: #b45309;
    animation: highlightPulse 0.6s ease-out;
}

@keyframes highlightPulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

/* Block Container */
#block-container {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 14px;
    margin-top: 10px;
    flex-wrap: wrap;
    min-height: 92px;
    width: 100%;
}

#app-footer {
    width: 100%;
    margin-top: 8px;
    text-align: center;
    pointer-events: none;
    user-select: none;
    -webkit-user-select: none;
}

#app-version {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    color: rgba(100, 116, 139, 0.82);
    user-select: none;
}

#app-version a {
    pointer-events: auto;
    color: rgba(79, 70, 229, 0.75);
    text-decoration: none;
    border-bottom: 1px dotted rgba(79, 70, 229, 0.35);
    transition: color 0.2s ease, border-color 0.2s ease;
}

body.dragging-block #app-footer {
    opacity: 0.28;
}

#app-version a:hover {
    color: rgba(79, 70, 229, 0.95);
    border-bottom-color: rgba(79, 70, 229, 0.75);
}

.block-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    perspective: 1000px;
    min-height: 74px;
}

.block {
    display: grid;
    border: none;
    cursor: grab;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.2s ease;
    padding: 4px;
    background: white;
}

.block:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    transform: translateY(-4px);
}

.block-cell {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    margin: 2px;
    border-radius: 6px;
    box-shadow: inset 0 1px 2px rgba(255, 255, 255, 0.3);
}

.block-wrapper.dragging {
    position: fixed;
    z-index: 1000;
    pointer-events: none;
    opacity: 0.9;
    transform: scale(1.12);
    filter: drop-shadow(0 8px 24px rgba(99, 102, 241, 0.4));
}

.block-wrapper.dragging .block {
    transform-origin: 50% -10px;
    animation: draggingSwing 1.1s ease-in-out infinite;
}

.block-wrapper.dragging .block:hover {
    transform: none;
}

@keyframes draggingSwing {
    0% {
        transform: rotate(-4deg);
    }

    50% {
        transform: rotate(4deg);
    }

    100% {
        transform: rotate(-4deg);
    }
}

.rotate-btn {
    background: linear-gradient(135deg, var(--text) 0%, var(--text-light) 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    margin-top: 8px;
    font-size: 1.2em;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
}

.rotate-btn:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transform: scale(1.1) rotate(90deg);
}

.rotate-btn:active {
    transform: scale(0.95) rotate(180deg);
}

/* Mode Selector */
#mode-selector {
    position: fixed !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: white !important;
    padding: 40px !important;
    z-index: 3000 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 20px !important;
    border-radius: 20px !important;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2) !important;
    min-width: 300px !important;
}

#mode-selector h2 {
    margin: 0 0 20px 0;
    color: var(--text);
    font-size: 1.8em;
}

#mode-selector button {
    padding: 14px 28px !important;
    border: none !important;
    border-radius: 10px !important;
    font-size: 1.1em !important;
    font-weight: 600 !important;
    cursor: pointer !important;
    transition: all 0.3s ease !important;
    color: white !important;
}

#mode-selector button:first-of-type {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%) !important;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3) !important;
}

#mode-selector button:first-of-type:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4) !important;
}

#mode-selector button:last-of-type {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%) !important;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3) !important;
}

#mode-selector button:last-of-type:hover {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4) !important;
}

/* Game Over Screen */
#game-over-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2500;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

#game-over-screen.hidden {
    display: none !important;
}

#game-over-screen .game-over-card {
    background: white;
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: popUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: min(92%, 420px);
    max-height: 90vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-align: center;
}

@keyframes popUp {
    0% {
        opacity: 0;
        transform: scale(0.9);
    }

    100% {
        opacity: 1;
        transform: scale(1);
    }
}

#game-over-screen h2 {
    color: var(--primary);
    font-size: 2em;
    margin: 0 0 20px 0;
}

#game-over-screen p {
    color: var(--text);
    font-size: 1.1em;
    margin: 10px 0;
}

#game-over-screen span {
    font-weight: 700;
    color: var(--primary);
}

#game-over-screen input {
    width: 100%;
    padding: 12px;
    margin: 15px 0;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1em;
    transition: border-color 0.2s ease;
}

#game-over-screen input:focus {
    outline: none;
    border-color: var(--primary);
}

#game-over-screen button {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    margin: 10px 0;
    border-radius: 10px;
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

#game-over-screen button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.lb-btn-secondary {
    background: linear-gradient(135deg, var(--success) 0%, #059669 100%) !important;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.3) !important;
}

.lb-btn-secondary:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4) !important;
}

/* Leaderboard Screen */
#leaderboard-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.82);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3000;
    animation: fadeIn 0.25s ease;
    padding: 16px;
}

#leaderboard-screen.hidden {
    display: none !important;
}

.leaderboard-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
    animation: popUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
    width: min(100%, 520px);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.leaderboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 28px 16px;
    border-bottom: 2px solid var(--border);
    flex-shrink: 0;
}

.leaderboard-header h2 {
    margin: 0;
    color: var(--primary);
    font-size: 1.6em;
}

#leaderboard-close {
    background: none;
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-light);
    width: 36px;
    height: 36px;
    font-size: 1.1em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    padding: 0;
    box-shadow: none;
    width: auto;
    min-width: 36px;
}

#leaderboard-close:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
    transform: none;
    box-shadow: none;
}

.leaderboard-tabs {
    display: flex;
    gap: 8px;
    padding: 14px 28px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.lb-tab {
    background: none;
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text-light);
    padding: 6px 16px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: auto;
    box-shadow: none;
}

.lb-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: none;
    box-shadow: none;
}

.lb-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

#leaderboard-table-wrapper {
    overflow-y: auto;
    flex: 1;
    padding: 0 10px 16px;
}

#leaderboard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

#leaderboard-table th {
    position: sticky;
    top: 0;
    background: white;
    color: var(--text-light);
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 10px 8px;
    border-bottom: 2px solid var(--border);
    text-align: left;
}

#leaderboard-table td {
    padding: 10px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}

#leaderboard-table th:first-child,
#leaderboard-table td:first-child {
    color: var(--text-light);
    font-weight: 700;
    width: 36px;
}

#leaderboard-table tr:last-child td {
    border-bottom: none;
}

#leaderboard-table tr:nth-child(even) td {
    background: #f8fafc;
}

#leaderboard-table tr.highlight-row td {
    background: rgba(99, 102, 241, 0.08);
    font-weight: 600;
}

.lb-mode-badge {
    font-size: 0.75em;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 700;
}

.lb-mode-badge.classic {
    background: rgba(99, 102, 241, 0.12);
    color: var(--primary);
}

.lb-mode-badge.challenge {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success);
}

#leaderboard-table .lb-empty {
    text-align: center;
    color: var(--text-light);
    padding: 32px;
    font-style: italic;
}

/* Pause Screen */
#pause-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.58);
    color: white;
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 24px;
    z-index: 2000;
    backdrop-filter: blur(6px);
}

#pause-screen h2 {
    margin: 0;
    font-size: clamp(1.8rem, 4.2vw, 2.8rem);
    font-weight: 800;
    letter-spacing: -0.02em;
    padding: 14px 26px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.95), rgba(79, 70, 229, 0.95));
    box-shadow: 0 16px 40px rgba(79, 70, 229, 0.45);
}

#pause-screen p {
    margin: 2px 0 0;
    font-size: clamp(0.95rem, 2.1vw, 1.15rem);
    font-weight: 500;
    color: rgba(255, 255, 255, 0.92);
    background: rgba(15, 23, 42, 0.55);
    padding: 8px 14px;
    border-radius: 10px;
}

/* Debug Window */
#debug-window {
    position: fixed;
    bottom: 10px;
    right: 10px;
    width: 300px;
    max-height: 400px;
    overflow-y: auto;
    background-color: rgba(15, 23, 42, 0.95);
    color: #10b981;
    border: 2px solid #334155;
    border-radius: 10px;
    padding: 12px;
    z-index: 1999;
    font-family: 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    display: none;
}

#debug-window.visible {
    display: block;
}

#debug-window h4 {
    margin: 0 0 10px 0;
    color: #22d3ee;
    font-size: 12px;
}

#debug-window pre {
    margin: 0;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Responsive Design */
@media (max-width: 768px) {
    body {
        align-items: flex-start;
        padding: 10px;
    }

    #game-container {
        padding: 18px;
        border-radius: 16px;
        margin-top: 6px;
        width: min(100%, 640px);
    }

    header h1 {
        font-size: 2em;
        margin-bottom: 10px;
    }

    #game-info {
        flex-direction: column;
        justify-content: flex-start;
        gap: 4px;
        margin-bottom: 8px;
    }

    #score-timer-row {
        gap: 8px;
    }

    #score,
    #timer {
        padding: 8px 12px;
        font-size: 0.9em;
        flex: 1 1 50%;
    }

    .cell {
        width: 37px;
        height: 37px;
        font-size: 14px;
    }

    #block-container {
        gap: 12px;
        margin-top: 8px;
        min-height: 82px;
    }

    .block-cell {
        width: 16px;
        height: 16px;
        margin: 1px;
    }

    #game-over-screen .game-over-card {
        width: 92%;
        padding: 28px 18px;
    }
}

@media (max-width: 480px) {
    #game-container {
        padding: 13px;
        width: min(100%, 460px);
    }

    header h1 {
        font-size: 1.6em;
    }

    #game-info {
        gap: 4px;
        margin-bottom: 6px;
    }

    #score-timer-row {
        gap: 6px;
    }

    #score,
    #timer {
        padding: 7px 10px;
        font-size: 0.82em;
        flex: 1 1 50%;
    }

    .cell {
        width: 34px;
        height: 34px;
    }

    #block-container {
        gap: 8px;
        margin-top: 6px;
        min-height: 72px;
    }

    .header-actions {
        gap: 6px;
    }

    #pause-button,
    #quick-restart-button,
    #leaderboard-button,
    #sound-toggle-button {
        padding: 9px 12px;
        font-size: 0.84em;
        border-radius: 9px;
    }

    .block-wrapper {
        gap: 5px;
    }

    .block-cell {
        width: 14px;
        height: 14px;
        margin: 1px;
    }

    .rotate-btn {
        width: 32px;
        height: 32px;
        font-size: 1em;
    }
}

.hidden {
    display: none !important;
}

#debug-window h4 {
    margin-top: 0;
    border-bottom: 1px solid #555;
    padding-bottom: 5px;
}

#debug-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}