:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --grid-border: #334155;
    --cell-border: #94a3b8;
    --panel-size: clamp(260px, 40vw, 380px);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
    flex: 1;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

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

.upload-section {
    margin-bottom: 2rem;
}

.upload-area {
    background-color: var(--card-bg);
    border: 3px dashed var(--border-color);
    border-radius: 1rem;
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
}

.upload-area:hover {
    border-color: var(--primary-color);
    background-color: #eff6ff;
}

.upload-area.dragover {
    border-color: var(--primary-color);
    background-color: #dbeafe;
}

.upload-icon {
    width: 64px;
    height: 64px;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.upload-hint {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.preview-section {
    background-color: var(--card-bg);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.preview-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.preview-card {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-card h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.preview-card img {
    width: 100%;
    max-width: var(--panel-size);
    aspect-ratio: 1 / 1;
    object-fit: contain;
    background-color: #f8fafc;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
    display: block;
    margin: 0 auto;
    padding: 0.25rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 500;
    border: none;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    width: 100%;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

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

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-loader {
    display: inline-flex;
    align-items: center;
}

.btn-loader::after {
    content: '';
    width: 16px;
    height: 16px;
    margin-left: 0.5rem;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.results-section {
    background-color: var(--card-bg);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.grids-container {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 2rem;
}

.grid-card h3 {
    margin-bottom: 1rem;
    text-align: center;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.grid-card {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sudoku-grid {
    display: grid;
    grid-template-columns: repeat(9, minmax(0, 1fr));  /* inputs' default width would widen 1fr columns */
    gap: 1px;
    width: 100%;
    max-width: var(--panel-size);
    background-color: var(--grid-border);
    border: 3px solid var(--grid-border);
    border-radius: 0.25rem;
    overflow: clip;  /* not hidden: focusing a cell input would scroll a hidden-overflow grid */
}

.sudoku-cell {
    aspect-ratio: 1;
    background-color: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 500;
    line-height: 1;
    color: var(--text-primary);
}

.sudoku-cell.given {
    background-color: #f1f5f9;
    font-weight: 700;
}

.sudoku-cell.solved {
    color: var(--primary-color);
}

input.sudoku-cell {
    width: 100%;
    min-width: 0;
    min-height: 0;
    border: none;
    text-align: center;
    padding: 0;
    font: inherit;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

input.sudoku-cell:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: -2px;
}

input.sudoku-cell.edited {
    color: var(--warning-color);
}

.stats {
    margin-top: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

.notice {
    margin-top: 0.75rem;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.hint {
    margin: 0.75rem 0 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-align: center;
}

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

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Thicker borders for 3x3 boxes */
.sudoku-cell:nth-child(3n) {
    border-right: 2px solid var(--grid-border);
}

.sudoku-cell:nth-child(9n) {
    border-right: none;
}

.sudoku-grid .sudoku-cell:nth-child(n+19):nth-child(-n+27),
.sudoku-grid .sudoku-cell:nth-child(n+46):nth-child(-n+54) {
    border-bottom: 2px solid var(--grid-border);
}

.message-section {
    margin-top: 1rem;
}

.message {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.message-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.message-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.message-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

@media (max-width: 640px) {
    header h1 {
        font-size: 2rem;
    }

    .preview-grid,
    .grids-container {
        grid-template-columns: 1fr;
    }

    .sudoku-cell {
        font-size: 1rem;
    }
}

.lang-switch {
    text-align: right;
    font-size: 0.9rem;
}

.lang-switch a {
    color: var(--text-secondary);
    text-decoration: none;
}

.info {
    margin-top: 2rem;
    padding: 1.5rem;
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    line-height: 1.6;
}

.info h2 {
    font-size: 1.25rem;
    margin: 1rem 0 0.5rem;
}

.info h2:first-child {
    margin-top: 0;
}

.info h3 {
    font-size: 1rem;
    margin: 0.75rem 0 0.25rem;
}

.info p,
.info li {
    color: var(--text-secondary);
}

.info ol {
    padding-left: 1.5rem;
}

.manual {
    margin-top: 0.5rem;
    text-align: center;
}

.link-button {
    background: none;
    border: none;
    padding: 0.25rem;
    font: inherit;
    font-size: 0.95rem;
    color: var(--primary-color);
    text-decoration: underline;
    text-underline-offset: 3px;
    cursor: pointer;
}

.share-button {
    margin-top: 1rem;
}

footer a {
    color: var(--primary-color);
}

/* Articles */
.article {
    margin-top: 1rem;
    padding: 2rem;
    background-color: var(--card-bg);
    border-radius: 0.75rem;
    line-height: 1.75;
}

.article h1 {
    font-size: 2rem;
    line-height: 1.3;
    margin-bottom: 1rem;
}

.article h2 {
    font-size: 1.35rem;
    margin: 2rem 0 0.75rem;
}

.article p,
.article li {
    margin-bottom: 0.9rem;
}

.article ul,
.article ol {
    padding-left: 1.5rem;
}

.article figure {
    margin: 1.5rem 0;
}

.article figure img {
    width: 100%;
    height: auto;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}

.article figcaption {
    margin-top: 0.4rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    text-align: center;
}

.article code {
    font-size: 0.9em;
    background-color: #f1f5f9;
    padding: 0.1em 0.3em;
    border-radius: 0.25rem;
}

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

.article .cta {
    width: auto;
    margin-top: 1rem;
    text-decoration: none;
}

@media (max-width: 640px) {
    .article {
        padding: 1.25rem;
    }

    .article h1 {
        font-size: 1.6rem;
    }
}
