:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent-color: #8b5cf6;
    --accent-hover: #7c3aed;
    --grid-cell-bg: rgba(255, 255, 255, 0.05);
    --grid-cell-focus: rgba(139, 92, 246, 0.2);

    --font-family: 'Outfit', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    position: relative;
}

/* Background Effects */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
}

.blob-1 {
    width: 400px;
    height: 400px;
    background: #4c1d95;
    top: -100px;
    left: -100px;
}

.blob-2 {
    width: 500px;
    height: 500px;
    background: #1e3a8a;
    bottom: -150px;
    right: -100px;
}

.blob-3 {
    width: 300px;
    height: 300px;
    background: #be185d;
    top: 40%;
    left: 40%;
    opacity: 0.2;
}

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.8s ease-out;
}

h1 {
    font-size: 3rem;
    font-weight: 600;
    letter-spacing: -0.05em;
    margin-bottom: 0.5rem;
}

.accent {
    color: var(--accent-color);
    background: linear-gradient(45deg, var(--accent-color), #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

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

.panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

/* Glassmorphism Panel */
.panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    animation: fadeInUp 0.8s ease-out;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

h2 {
    font-size: 1.5rem;
    font-weight: 500;
}

/* Controls */
.btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border-color: var(--text-secondary);
}

.btn svg {
    display: block;
}

/* 5x5 Grid */
.grid-container {
    display: flex;
    justify-content: center;
}

.polybius-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    grid-template-rows: repeat(6, 1fr);
    gap: 0.3rem;
    width: 100%;
    max-width: 300px;
    /* Slight increase for headers */
    aspect-ratio: 1;
}

.grid-cell {
    background: var(--grid-cell-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.35rem;
    color: var(--text-primary);
    font-size: 1rem;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    outline: none;
    text-transform: uppercase;
    font-weight: 600;
    width: 2.5rem;
    /* Adjusted for 6 cols */
    height: 2.5rem;
}

.grid-header {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-weight: bold;
    font-size: 0.9rem;
    user-select: none;
}

.grid-header.empty {
    /* Corner */
    visibility: hidden;
}

.grid-cell:focus,
.grid-cell:hover {
    background: var(--grid-cell-focus);
    border-color: var(--accent-color);
    transform: scale(1.05);
    z-index: 2;
}

.grid-cell::placeholder {
    color: rgba(255, 255, 255, 0.1);
}

/* Highlight Animation */
.grid-cell.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 0 15px var(--accent-color);
    border-color: transparent;
}

/* Inputs & Outputs */
.io-area {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.input-group,
.output-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

textarea,
.result-box {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    resize: vertical;
    min-height: 100px;
    transition: border-color 0.2s;
}

textarea:focus {
    outline: none;
    border-color: var(--accent-color);
}

.result-box {
    background: rgba(0, 0, 0, 0.4);
    cursor: default;
    min-height: 100px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Animations */
@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 900px) {
    .panels {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .container {
        padding: 1rem;
    }

    h1 {
        font-size: 2rem;
    }

    .panel {
        padding: 1.5rem;
    }
}

/* Footer */
.footer {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: auto;
}

.footer a {
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.2s;
}

.footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Validation */
.validation-panel {
    background: rgba(220, 38, 38, 0.1);
    /* Red tint */
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 1rem;
    animation: fadeInDown 0.3s ease-out;
}

.validation-message {
    color: #f87171;
    /* Light red */
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.validation-actions {
    display: flex;
    gap: 0.5rem;
}

.btn.small {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

/* Error State for Cells */
.grid-cell.error {
    border-color: #ef4444;
    /* Red */
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    animation: shake 0.4s ease-in-out;
}

/* Success/Valid State override if needed, or just normal */

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-2px);
    }

    75% {
        transform: translateX(2px);
    }
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.btn.icon-only {
    padding: 0.3rem;
    display: flex;
    justify-content: center;
    align-items: center;
}

.btn.ghost {
    border: none;
    color: var(--text-secondary);
    opacity: 0.7;
}

.btn.ghost:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

.header-content {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: #1e293b;
    border: 1px solid var(--border-color);
    border-radius: 1rem;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    /* Ensure it fits in viewport */
    overflow-y: auto;
    /* Enable scrolling */
    padding: 2rem;
    position: relative;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: scaleIn 0.3s ease-out;
    display: flex;
    flex-direction: column;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1.5rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
    z-index: 10;
    /* Ensure clear of content */
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    margin: 1.5rem 0;
    line-height: 1.6;
    color: #cbd5e1;
    overflow-y: auto;
    /* Scroll info independently if needed */
}


/* Mobile Polish */
@media (max-width: 600px) {
    .modal-content {
        padding: 1.5rem;
        width: 95%;
    }

    .modal-close {
        top: 0.5rem;
        right: 1rem;
    }
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0f172a;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb {
    background: #334155;
    border-radius: 4px;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

.modal-body h3 {
    color: var(--accent-color);
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
}

.modal-body ul,
.modal-body ol {
    margin-left: 1.5rem;
    margin-bottom: 1rem;
}

.modal-body li {
    margin-bottom: 0.5rem;
}

.example-box {
    background: rgba(139, 92, 246, 0.1);
    border-left: 4px solid var(--accent-color);
    padding: 1rem;
    border-radius: 0.5rem;
    margin: 1rem 0;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
}

.btn.primary {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
}

.btn.primary:hover {
    background: var(--accent-hover);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}