:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border-color: #ddd;
    --accent-color: #4a90e2;
    --accent-hover: #357abd;
    --grid-bg: #ffffff;
    --cell-bg: #ffffff;
    --cell-border: #333;
    --cell-filled: #e8f4f8;
    --cell-highlight: #ffd700;
    --cell-mirrored: #ff6b6b;
    --shadow: rgba(0, 0, 0, 0.1);
    --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-4: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    --gradient-5: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

[data-theme="dark"] {
    --bg-primary: #0a0a0a;
    --bg-secondary: #1a1a1a;
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --border-color: #333;
    --accent-color: #5aa3f0;
    --accent-hover: #4a90e2;
    --grid-bg: #0f0f0f;
    --cell-bg: #1a1a1a;
    --cell-border: #444;
    --cell-filled: #2a3a4a;
    --cell-highlight: #ffd700;
    --cell-mirrored: #ff6b6b;
    --shadow: rgba(0, 0, 0, 0.5);
    --gradient-1: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-2: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-3: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-4: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    --gradient-5: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

[data-theme="dark"] body {
    background: linear-gradient(135deg, #1a0a2e 0%, #16213e 25%, #0f3460 50%, #533483 75%, #1a0a2e 100%);
    background-size: 400% 400%;
}

[data-theme="dark"] body::before {
    background: 
        radial-gradient(circle at 20% 50%, rgba(102, 126, 234, 0.2) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(240, 147, 251, 0.2) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(79, 172, 254, 0.2) 0%, transparent 50%);
}

[data-theme="dark"] header,
[data-theme="dark"] .controls,
[data-theme="dark"] .clues-section,
[data-theme="dark"] .grid-container {
    background: rgba(26, 26, 26, 0.9);
    border-color: rgba(102, 126, 234, 0.3);
}

[data-theme="dark"] .cell.filled {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    border-color: rgba(102, 126, 234, 0.4);
}

[data-theme="dark"] #crosswordGrid {
    background: rgba(15, 15, 15, 0.98);
    border-image: linear-gradient(135deg, #667eea, #764ba2, #f093fb, #f5576c) 1;
}

[data-theme="dark"] .btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.5);
}

[data-theme="dark"] .btn-primary:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.7);
}

[data-theme="dark"] .btn-secondary {
    background: rgba(26, 26, 26, 0.9);
    color: var(--text-primary);
    border: 2px solid rgba(102, 126, 234, 0.5);
    backdrop-filter: blur(10px);
}

[data-theme="dark"] .btn-secondary:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
    border-color: #667eea;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

[data-theme="dark"] .legend {
    background: rgba(26, 26, 26, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(102, 126, 234, 0.3);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .legend h2 {
    color: #667eea;
}

[data-theme="dark"] .legend-section {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.15) 0%, rgba(118, 75, 162, 0.15) 100%);
    border-image: linear-gradient(135deg, rgba(102, 126, 234, 0.5), rgba(118, 75, 162, 0.5)) 1;
}

[data-theme="dark"] .legend-section:hover {
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.2) 0%, rgba(118, 75, 162, 0.2) 100%);
}

[data-theme="dark"] .legend-section h3 {
    color: #667eea;
    border-bottom-color: rgba(102, 126, 234, 0.4);
}

[data-theme="dark"] .legend-text {
    color: var(--text-primary);
}

[data-theme="dark"] .legend-list li {
    color: var(--text-primary);
}

[data-theme="dark"] .legend-list li::before {
    color: #667eea;
}

[data-theme="dark"] .legend-list kbd {
    background: rgba(26, 26, 26, 0.8);
    border-color: rgba(102, 126, 234, 0.4);
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .legend-section p {
    color: var(--text-secondary);
}

[data-theme="dark"] .color-indicator {
    border-color: rgba(102, 126, 234, 0.4);
}

[data-theme="dark"] .legend-cell {
    border-color: rgba(102, 126, 234, 0.4);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #f5576c 75%, #4facfe 100%);
    background-size: 400% 400%;
    animation: gradientShift 15s ease infinite;
    color: var(--text-primary);
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(circle at 20% 50%, rgba(120, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 119, 198, 0.3) 0%, transparent 50%),
        radial-gradient(circle at 40% 20%, rgba(79, 172, 254, 0.3) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

body > * {
    position: relative;
    z-index: 1;
}

@keyframes gradientShift {
    0% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
    100% {
        background-position: 0% 50%;
    }
}

.container {
    max-width: 1400px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 30px;
    padding: 30px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    position: relative;
    overflow: hidden;
}

header::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: linear-gradient(45deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    animation: shine 3s infinite;
}

@keyframes shine {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    background: linear-gradient(90deg, #667eea, #764ba2, #f093fb, #f5576c, #4facfe, #00f2fe);
    background-size: 300% 300%;
    animation: gradientText 5s ease infinite;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 800;
    text-shadow: 0 0 30px rgba(102, 126, 234, 0.3);
    position: relative;
}

@keyframes gradientText {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

.subtitle {
    color: var(--text-secondary);
    font-style: italic;
    font-size: 1.1em;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    margin-bottom: 30px;
    padding: 25px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    touch-action: manipulation;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-primary);
    border: 2px solid rgba(102, 126, 234, 0.3);
    backdrop-filter: blur(10px);
}

.btn-secondary:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-color: #667eea;
    transform: translateY(-3px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.dark-mode-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
}

.dark-mode-toggle input {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.puzzle-container {
    display: flex;
    gap: 30px;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
}

.clues-section {
    flex: 1;
    min-width: 300px;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 25px;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.clues-column h3 {
    margin-bottom: 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 1.3em;
    border-bottom: 3px solid;
    border-image: linear-gradient(90deg, #667eea, #764ba2, #f093fb) 1;
    padding-bottom: 10px;
    font-weight: 700;
}

.clue-item {
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
    border-left: 3px solid transparent;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    touch-action: manipulation;
}

.clue-item:hover {
    background: linear-gradient(90deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    border-left-color: #667eea;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.2);
}

.clue-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    transform: translateX(5px);
}

.clue-number {
    font-weight: bold;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-right: 8px;
    font-size: 1.1em;
}

.clue-item.active .clue-number {
    color: white;
}

.grid-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 300px;
    padding: 25px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    overflow-x: auto;
}

#crosswordGrid {
    display: inline-grid;
    gap: 0;
    border: 4px solid;
    border-image: linear-gradient(135deg, #667eea, #764ba2, #f093fb, #f5576c) 1;
    background: rgba(255, 255, 255, 0.98);
    padding: 3px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    border-radius: 5px;
}

.cell {
    width: 35px;
    height: 35px;
    border: 1px solid var(--cell-border);
    background: var(--cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    position: relative;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    touch-action: manipulation;
    cursor: pointer;
}

.cell.blocked {
    background: var(--text-primary);
    border-color: var(--text-primary);
}

.cell.filled {
    background: var(--cell-filled);
}

.cell.highlight {
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.6);
    animation: pulse 1s ease-in-out infinite;
    transform: scale(1.05);
    z-index: 5;
}

.cell.mirrored {
    background: var(--cell-mirrored);
    color: white;
    transform: scaleX(-1);
}

.cell input {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    color: var(--text-primary);
    font-family: inherit;
    z-index: 1;
    position: relative;
    -webkit-user-select: text;
    user-select: text;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.cell input:focus {
    outline: none;
    background: linear-gradient(135deg, #ffd700 0%, #ffed4e 100%);
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    transform: scale(1.1);
    z-index: 10;
}

.cell-number {
    position: absolute;
    top: 1px;
    left: 2px;
    font-size: 11px;
    font-weight: bold;
    color: var(--text-primary);
    z-index: 10;
    line-height: 1;
    pointer-events: none;
    user-select: none;
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.8);
}

[data-theme="dark"] .cell-number {
    color: var(--text-primary);
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.8);
}

.cell.mirrored .cell-number {
    transform: scaleX(-1);
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(0);
    }
}

@keyframes slideInReverse {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.solution-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeIn 0.3s ease;
}

.solution-overlay.hidden {
    display: none;
}

.solution-content {
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    padding: 40px;
    border-radius: 20px;
    max-width: 90%;
    max-height: 90%;
    overflow: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    border: 2px solid;
    border-image: linear-gradient(135deg, #667eea, #764ba2, #f093fb, #f5576c) 1;
}

.solution-content h2 {
    margin-bottom: 20px;
    text-align: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-size: 2em;
    font-weight: 800;
}

.solution-grid {
    display: inline-grid;
    gap: 0;
    border: 3px solid var(--cell-border);
    background: var(--grid-bg);
    padding: 2px;
    margin: 20px auto;
}

.solution-grid .cell {
    width: 35px;
    height: 35px;
    border: 1px solid var(--cell-border);
    background: var(--cell-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    text-transform: uppercase;
    position: relative;
}

.solution-grid .cell.blocked {
    background: var(--text-primary);
    border-color: var(--text-primary);
}

.solution-grid .cell.filled {
    background: var(--cell-filled);
}

.solution-grid .cell.mirrored {
    background: var(--cell-mirrored);
    color: white;
    transform: scaleX(-1);
}

.solution-grid .cell.mirrored .cell-number {
    transform: scaleX(-1);
}

@media (max-width: 768px) {
    .solution-grid .cell {
        width: 25px;
        height: 25px;
        font-size: 14px;
    }
    
    .solution-grid .cell-number {
        font-size: 8px;
    }
}

.message {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 18px 30px;
    border-radius: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: bold;
    z-index: 1001;
    animation: slideIn 0.3s ease;
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.message.hidden {
    display: none;
}

.message.error {
    background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
    box-shadow: 0 8px 25px rgba(245, 87, 108, 0.4);
}

.message.success {
    background: linear-gradient(135deg, #43e97b 0%, #38f9d7 100%);
    box-shadow: 0 8px 25px rgba(67, 233, 123, 0.4);
}

/* Tablet styles */
@media (max-width: 1024px) and (min-width: 769px) {
    .cell {
        width: 35px;
        height: 35px;
        font-size: 18px;
    }
    
    .cell input {
        font-size: 18px;
    }
    
    .cell-number {
        font-size: 10px;
        padding: 2px;
    }
    
    .btn {
        padding: 12px 20px;
        font-size: 15px;
        min-height: 48px;
    }
}

/* Mobile styles */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    h1 {
        font-size: 1.6em;
        margin-bottom: 8px;
    }
    
    .subtitle {
        font-size: 0.9em;
    }

    header {
        padding: 20px 15px;
        margin-bottom: 20px;
    }

    .controls {
        flex-direction: column;
        gap: 12px;
        padding: 15px;
    }
    
    .controls-row {
        flex-direction: column;
        gap: 12px;
        width: 100%;
    }

    .btn {
        width: 100%;
        padding: 14px 20px;
        font-size: 16px;
        min-height: 50px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.3);
    }
    
    .btn:active {
        transform: scale(0.98);
    }

    .puzzle-container {
        flex-direction: column;
        gap: 20px;
    }

    .clues-section {
        max-width: 100%;
        padding: 20px 15px;
    }
    
    .clues-column {
        margin-bottom: 20px;
    }
    
    .clue-item {
        padding: 15px;
        margin-bottom: 10px;
        font-size: 15px;
        min-height: 50px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2);
    }
    
    .clue-item:active {
        transform: scale(0.98);
    }

    .grid-container {
        width: 100%;
        padding: 15px;
        overflow-x: auto;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        touch-action: pan-x pan-y;
    }
    
    .grid-container::-webkit-scrollbar {
        height: 8px;
        width: 8px;
    }
    
    .grid-container::-webkit-scrollbar-thumb {
        background: rgba(102, 126, 234, 0.5);
        border-radius: 4px;
    }
    
    .grid-container::-webkit-scrollbar-track {
        background: rgba(102, 126, 234, 0.1);
        border-radius: 4px;
    }
    
    #crosswordGrid {
        margin: 0 auto;
    }

    .cell {
        width: 38px;
        height: 38px;
        font-size: 18px;
        min-width: 38px;
        min-height: 38px;
    }
    
    .cell input {
        font-size: 18px;
        text-align: center;
        -webkit-appearance: none;
        -moz-appearance: textfield;
        appearance: none;
    }
    
    .cell input:focus {
        font-size: 20px;
    }
    
    .cell-number {
        font-size: 10px;
        padding: 2px 3px;
        font-weight: 700;
    }
    
    .message {
        top: 10px;
        right: 10px;
        left: 10px;
        padding: 15px 20px;
        font-size: 14px;
        border-radius: 10px;
    }
    
    .dark-mode-toggle {
        padding: 10px 15px;
        font-size: 14px;
    }
    
    .legend {
        padding: 20px 15px;
        margin: 15px 10px;
        max-width: calc(100% - 20px);
    }
    
    .legend h2 {
        font-size: 1.4em;
        margin-bottom: 15px;
    }
    
    .legend-section {
        padding: 15px;
        margin-bottom: 15px;
    }
    
    .legend-item {
        flex-direction: column;
        gap: 10px;
    }
    
    .legend-sample {
        margin-bottom: 5px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    h1 {
        font-size: 1.4em;
    }
    
    .subtitle {
        font-size: 0.85em;
    }
    
    header {
        padding: 15px 10px;
    }
    
    .cell {
        width: 32px;
        height: 32px;
        font-size: 16px;
        min-width: 32px;
        min-height: 32px;
    }
    
    .cell input {
        font-size: 16px;
    }
    
    .cell input:focus {
        font-size: 18px;
    }
    
    .cell-number {
        font-size: 9px;
    }
    
    .clue-item {
        padding: 12px;
        font-size: 14px;
    }
    
    .btn {
        padding: 12px 18px;
        font-size: 15px;
        min-height: 48px;
    }
    
    .controls {
        padding: 12px;
    }
    
    .clues-section {
        padding: 15px 10px;
    }
    
    .grid-container {
        padding: 10px;
    }
}

.legend {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    padding: 35px;
    margin: 20px auto;
    max-width: 900px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    animation: fadeIn 0.3s ease;
}

.legend.hidden {
    display: none;
}

.legend h2 {
    color: var(--accent-color);
    margin-bottom: 20px;
    text-align: center;
    font-size: 1.8em;
}

.legend-content {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 30px;
    margin-bottom: 20px;
}

.legend-section {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    padding: 20px;
    border-radius: 12px;
    border: 2px solid;
    border-image: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3)) 1;
    transition: all 0.3s ease;
}

.legend-section:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.2);
}

.legend-section h3 {
    color: var(--accent-color);
    margin-bottom: 15px;
    font-size: 1.2em;
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.legend-sample {
    flex-shrink: 0;
}

.legend-cell {
    width: 30px;
    height: 30px;
    margin: 0;
}

.legend-text {
    flex: 1;
    font-size: 0.95em;
    line-height: 1.4;
}

.legend-list {
    list-style: none;
    padding: 0;
}

.legend-list li {
    margin-bottom: 10px;
    padding-left: 20px;
    position: relative;
    line-height: 1.5;
}

.legend-list li::before {
    content: "•";
    color: var(--accent-color);
    font-weight: bold;
    position: absolute;
    left: 0;
}

.legend-list kbd {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 0.9em;
    box-shadow: 0 2px 4px var(--shadow);
    margin: 0 2px;
}

.color-indicator {
    width: 20px;
    height: 20px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.color-indicator.correct {
    background: var(--accent-color);
}

.color-indicator.incorrect {
    background: #ff6b6b;
}

.legend-section p {
    line-height: 1.6;
    color: var(--text-secondary);
    margin-top: 10px;
}

@media (max-width: 768px) {
    .legend-content {
        grid-template-columns: 1fr;
    }
    
    .legend {
        padding: 20px;
    }
}

@media print {
    /* Hide interactive elements when printing from main page */
    .controls,
    .solution-overlay,
    .legend,
    .message {
        display: none !important;
    }

    /* Show puzzle container properly */
    .puzzle-container {
        page-break-inside: avoid;
        display: flex !important;
        gap: 30px;
        justify-content: center;
        align-items: flex-start;
    }

    .clues-section {
        display: flex !important;
        gap: 20px;
        min-width: 350px;
    }

    .grid-container {
        flex-shrink: 0;
    }

    .cell {
        width: 30px;
        height: 30px;
        page-break-inside: avoid;
    }

    .cell input {
        border: none;
        background: transparent;
    }

    /* Ensure proper spacing */
    body {
        padding: 20px;
    }

    header {
        margin-bottom: 20px;
    }
}

