/* #1649: Queens Game styles — grid layout, region colors, responsive design
   #1659: Responsive design for small screens — dynamic cell sizing, stacked layouts, touch targets */

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

:root {
    --color-bg: #f8f9fa;
    --color-surface: #ffffff;
    --color-text: #1a1a2e;
    --color-text-muted: #6c757d;
    --color-border: #dee2e6;
    --color-primary: #5c6bc0;
    --color-primary-hover: #3f51b5;
    --color-success: #4caf50;
    --color-error: #f44336;
    --color-warning: #ff9800;
    --nav-bg: #1a1a2e;
    --nav-text: #ffffff;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --radius: 8px;
    --radius-lg: 12px;
    --cell-size: 48px;
    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #0d1117;
        --color-surface: #161b22;
        --color-text: #e6edf3;
        --color-text-muted: #8b949e;
        --color-border: #30363d;
        --color-primary: #7c8ad9;
        --color-primary-hover: #9fa8e0;
        --nav-bg: #010409;
        --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
        --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    }
}

body {
    font-family: var(--font-sans);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    /* #1659: Prevent horizontal scrolling on mobile */
    overflow-x: hidden;
}

/* ========== Navbar ========== */
.navbar {
    background: var(--nav-bg);
    color: var(--nav-text);
    padding: 0 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.nav-content {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    height: 56px;
}

.nav-brand {
    color: var(--nav-text);
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.nav-brand:hover {
    opacity: 0.9;
}

/* #1699: Navbar links section — admin-only links between brand and user section */
.nav-links {
    margin-left: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-link {
    color: var(--nav-text);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.nav-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* #1694: Navbar user section — display name/email + logout link */
.nav-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.nav-username {
    color: var(--nav-text);
    opacity: 0.9;
}

/* #1725: Clickable username button that opens the name-change modal.
   Resets browser button styles to look like the plain .nav-username span,
   with hover/focus states to indicate interactivity. */
.nav-username-btn {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: var(--nav-text);
    opacity: 0.9;
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: opacity 0.15s, border-color 0.15s;
}

.nav-username-btn:hover {
    opacity: 1;
    border-bottom-color: var(--nav-text);
}

.nav-username-btn:focus-visible {
    outline: 2px solid var(--nav-text);
    outline-offset: 2px;
    border-radius: 2px;
}

.nav-logout {
    color: var(--nav-text);
    opacity: 0.7;
    text-decoration: none;
    font-size: 0.8rem;
}

.nav-logout:hover {
    opacity: 1;
    text-decoration: underline;
}

/* ========== Container ========== */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 2rem 1rem;
    /* #1659: Prevent text overflow on small screens */
    overflow-wrap: break-word;
}

h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    letter-spacing: -0.02em;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1.25rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s, opacity 0.15s;
}

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

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

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

.btn-secondary {
    background: var(--color-border);
    color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-text-muted);
    color: #fff;
}

/* ========== Filter Controls ========== */
/* #1675: HTMX-driven filter bar for size and difficulty on the board list page */
.filter-bar {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1.5rem;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.filter-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    letter-spacing: 0.03em;
}

.filter-select {
    appearance: none;
    -webkit-appearance: none;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    /* #1675: Custom dropdown arrow using encoded SVG for cross-browser consistency */
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236c757d' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    min-width: 140px;
}

.filter-select:hover {
    border-color: var(--color-primary);
}

.filter-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.25);
}

@media (prefers-color-scheme: dark) {
    .filter-select {
        /* #1675: Lighter arrow for dark backgrounds */
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238b949e' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    }
}

/* #1675: HTMX loading indicator — dim the board list while fetching */
#board-list.htmx-request {
    opacity: 0.5;
    transition: opacity 0.15s;
    pointer-events: none;
}

/* ========== Board List Grid ========== */
.board-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.board-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1.5rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s;
}

.board-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.board-card-difficulty {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
}

.board-card-difficulty.easy {
    background: #e8f5e9;
    color: #2e7d32;
}

.board-card-difficulty.medium {
    background: #fff3e0;
    color: #e65100;
}

.board-card-difficulty.hard {
    background: #fce4ec;
    color: #c62828;
}

/* #1729: Purple/violet tones for expert, distinct from hard (red) */
.board-card-difficulty.expert {
    background: #f3e5f5;
    color: #6a1b9a;
}

@media (prefers-color-scheme: dark) {
    .board-card-difficulty.easy {
        background: #1b3a1e;
        color: #66bb6a;
    }
    .board-card-difficulty.medium {
        background: #3e2a10;
        color: #ffb74d;
    }
    .board-card-difficulty.hard {
        background: #3e1519;
        color: #ef5350;
    }
    .board-card-difficulty.expert {
        background: #2e1338;
        color: #ce93d8;
    }
}

.board-card-size {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
}

.board-card-date {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.board-card-action {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-primary);
}

.pagination {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.empty-state {
    text-align: center;
    color: var(--color-text-muted);
    padding: 3rem 1rem;
    font-size: 1.1rem;
}

/* ========== Play Page ========== */
.play-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.play-header h1 {
    margin-bottom: 0;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.difficulty-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    vertical-align: middle;
}

.difficulty-badge.easy {
    background: #e8f5e9;
    color: #2e7d32;
}

.difficulty-badge.medium {
    background: #fff3e0;
    color: #e65100;
}

.difficulty-badge.hard {
    background: #fce4ec;
    color: #c62828;
}

/* #1729: Purple/violet tones for expert, distinct from hard (red) */
.difficulty-badge.expert {
    background: #f3e5f5;
    color: #6a1b9a;
}

@media (prefers-color-scheme: dark) {
    .difficulty-badge.easy {
        background: #1b3a1e;
        color: #66bb6a;
    }
    .difficulty-badge.medium {
        background: #3e2a10;
        color: #ffb74d;
    }
    .difficulty-badge.hard {
        background: #3e1519;
        color: #ef5350;
    }
    .difficulty-badge.expert {
        background: #2e1338;
        color: #ce93d8;
    }
}

.play-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
}

.board-info {
    text-align: center;
}

/* #1672: Row layout for queen count and timer side by side */
.board-status-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.queen-count {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

/* #1672: Timer display — monospace for stable digit width */
.timer-display {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text-muted);
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.timer-display #timer {
    font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.04em;
}

.timer-icon {
    font-size: 0.9em;
}

/* ========== Board Grid ========== */
.board {
    display: grid;
    gap: 0;
    /* #1724: Board border removed for cleaner look */
    border: none;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    /* #1659: Constrain board width so it never causes horizontal scroll */
    max-width: 100%;
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    /* #1659: Use em-based font sizes so glyphs scale with cell size */
    font-size: calc(var(--cell-size) * 0.5);
    /* #1703: Dark semi-transparent border for contrast against light pastel region backgrounds */
    border: 1px solid rgba(0, 0, 0, 0.10);
    transition: filter 0.1s, box-shadow 0.1s;
    user-select: none;
    position: relative;
    /* #1659: Minimum tap target — 24px allows large boards to fit on narrow
       screens without clipping. Preferred WCAG minimum is 44px but cell sizing
       dynamically balances fit vs. usability (see computeCellSize in app.js). */
    min-width: 24px;
    min-height: 24px;
}

.cell:hover {
    filter: brightness(0.92);
}

.cell.marked::after {
    content: "\00D7";
    /* #1659: Scale glyph proportionally to cell size */
    font-size: calc(var(--cell-size) * 0.55);
    line-height: 1;
    /* #1703: Dark glyph for light-mode pastel backgrounds */
    color: rgba(0, 0, 0, 0.45);
}

.cell.queen::after {
    content: "\265B";
    /* #1659: Scale glyph proportionally to cell size */
    font-size: calc(var(--cell-size) * 0.6);
    line-height: 1;
    /* #1703: Dark glyph for light-mode pastel backgrounds */
    color: #1a1a2e;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.cell.conflict {
    box-shadow: inset 0 0 0 3px var(--color-error);
}

.cell.queen.conflict::after {
    color: var(--color-error);
}

/* ========== Region Colors ========== */
/* #1706: Light-mode mid-tone palette — Material Design 300 tones for visual presence.
   Darkened from 100-level pastels per owner feedback ("Pastel is too light").
   Dark-mode retains the original saturated palette below via media query. */
.region-0  { background-color: #64b5f6; }
.region-1  { background-color: #dce775; }
.region-2  { background-color: #ba68c8; }
.region-3  { background-color: #81c784; }
.region-4  { background-color: #f06292; }
.region-5  { background-color: #ff8a65; }
.region-6  { background-color: #ffb74d; }
.region-7  { background-color: #9575cd; }
.region-8  { background-color: #aed581; }
.region-9  { background-color: #e57373; }
.region-10 { background-color: #7986cb; }
.region-11 { background-color: #fff176; }
.region-12 { background-color: #a1887f; }
.region-13 { background-color: #4db6ac; }
.region-14 { background-color: #90a4ae; }
.region-15 { background-color: #78909c; }

/* #1703: Dark-mode region colors — original saturated palette for dark backgrounds */
@media (prefers-color-scheme: dark) {
    .region-0  { background-color: #0d47a1; }
    .region-1  { background-color: #827717; }
    .region-2  { background-color: #6a1b9a; }
    .region-3  { background-color: #1b5e20; }
    .region-4  { background-color: #880e4f; }
    /* #1702: Deep orange — teal was too similar to region 0 dark blue */
    .region-5  { background-color: #e65100; }
    .region-6  { background-color: #bf360c; }
    .region-7  { background-color: #4527a0; }
    .region-8  { background-color: #33691e; }
    .region-9  { background-color: #b71c1c; }
    .region-10 { background-color: #1a237e; }
    .region-11 { background-color: #9e9d24; }
    .region-12 { background-color: #3e2723; }
    .region-13 { background-color: #004d40; }
    .region-14 { background-color: #37474f; }
    .region-15 { background-color: #263238; }

    /* #1703: Dark-mode cell styling — light borders and glyphs for dark region backgrounds */
    .cell {
        border-color: rgba(255, 255, 255, 0.15);
    }

    .cell.marked::after {
        color: #e6edf3;
    }

    .cell.queen::after {
        color: #e6edf3;
        text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
    }
}

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

/* ========== Edit Mode ========== */
/* #1661: Visual indicator when board is in edit mode */
/* #1724: Use outline instead of border-color since board border was removed */
.board.edit-mode {
    outline: 2px solid var(--color-warning);
    outline-offset: -2px;
    box-shadow: 0 0 0 2px var(--color-warning), var(--shadow-md);
}

.board.edit-mode .cell:hover {
    filter: brightness(0.85);
    cursor: crosshair;
}

/* ========== Swap Mode ========== */
/* #1676: Highlight for cells whose color is selected as the first swap operand.
   #1703: Dark inset border for light-mode pastels; white inset border for dark mode. */
.cell.swap-selected {
    box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.5);
    filter: brightness(0.9);
}

@media (prefers-color-scheme: dark) {
    .cell.swap-selected {
        box-shadow: inset 0 0 0 3px #ffffff;
        filter: brightness(1.25);
    }
}

/* #1676: Active state for the Swap Colors toggle button */
.btn-swap-active {
    background: var(--color-warning) !important;
    color: #1a1a2e !important;
}

.btn-swap-active:hover:not(:disabled) {
    background: #ffa726 !important;
    color: #1a1a2e !important;
}

/* ========== Messages ========== */
.message {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 0.95rem;
    text-align: center;
    min-width: 200px;
}

.message.hidden {
    display: none;
}

.message.success {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.message.error {
    background: #fce4ec;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

/* #1661: Info message style for edit mode instructions */
.message.info {
    background: #fff3e0;
    color: #e65100;
    border: 1px solid #ffcc80;
}

@media (prefers-color-scheme: dark) {
    .message.success {
        background: #1b3a1e;
        color: #66bb6a;
        border-color: #2e7d32;
    }
    .message.error {
        background: #3e1519;
        color: #ef5350;
        border-color: #c62828;
    }
    .message.info {
        background: #3e2a10;
        color: #ffb74d;
        border-color: #e65100;
    }
}

/* ========== Play Controls ========== */
.play-controls {
    display: flex;
    gap: 0.75rem;
}

/* ========== Victory Modal ========== */
/* #1681: Full-screen overlay with blurred dark backdrop and centered modal card.
   Hidden by default; JS removes the .hidden class on successful solve. */

.victory-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    /* #1681: Fade-in animation for polish */
    animation: victory-fade-in 0.35s ease-out;
}

.victory-overlay.hidden {
    display: none !important;
}

@keyframes victory-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* #1681: Slide-up entrance for the modal card itself */
@keyframes victory-slide-up {
    from {
        opacity: 0;
        transform: translateY(24px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.victory-modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    max-width: 400px;
    width: calc(100% - 2rem);
    text-align: center;
    animation: victory-slide-up 0.4s ease-out;
}

.victory-title {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 0.25rem;
    color: var(--color-text);
    letter-spacing: -0.02em;
}

.victory-subtitle {
    font-size: 1rem;
    color: var(--color-text-muted);
    margin-bottom: 1.5rem;
}

.victory-time-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 2rem;
}

.victory-time-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.victory-time {
    font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
    font-variant-numeric: tabular-nums;
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-primary);
    letter-spacing: 0.04em;
    line-height: 1;
}

.victory-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.victory-btn {
    width: 100%;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
}

/* ========== Home Page ========== */
/* #1734: Guest landing page and authenticated user homepage styles.
   The landing page uses a hero section with feature cards below.
   The user homepage is a centered greeting with a prominent play button. */

.home-hero {
    max-width: 560px;
    margin: 3rem auto 2.5rem;
    text-align: center;
}

.home-hero-icon {
    color: var(--color-primary);
    margin-bottom: 1.25rem;
}

.home-hero-title {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 0.75rem;
}

.home-hero-subtitle {
    color: var(--color-text-muted);
    font-size: 1.05rem;
    line-height: 1.6;
    margin-bottom: 2rem;
}

.home-hero-cta {
    padding: 0.75rem 2rem;
    font-size: 1.05rem;
}

.home-features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    max-width: 720px;
    margin: 0 auto 3rem;
}

.home-feature {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
}

.home-feature-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.home-feature-desc {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

/* #1734: Authenticated user homepage — centered greeting with play button */
.home-user {
    max-width: 480px;
    margin: 4rem auto;
    text-align: center;
}

.home-user-greeting {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.home-user-subtitle {
    color: var(--color-text-muted);
    font-size: 1.05rem;
    margin-bottom: 2rem;
}

.home-user-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.home-user-play {
    padding: 0.875rem 3rem;
    font-size: 1.1rem;
}

/* ========== Welcome / Onboarding ========== */
/* #1693: Centered card layout for the first-time user onboarding page.
   Keeps the form focused and quick to complete. */

.welcome-card {
    max-width: 440px;
    margin: 3rem auto;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow-md);
    text-align: center;
}

.welcome-heading {
    font-size: 1.75rem;
    font-weight: 800;
    margin-bottom: 0.5rem;
    letter-spacing: -0.02em;
}

.welcome-subtext {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 1.75rem;
}

.welcome-error {
    background: #fce4ec;
    color: #c62828;
    border: 1px solid #ef9a9a;
    border-radius: var(--radius);
    padding: 0.625rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 1.25rem;
}

@media (prefers-color-scheme: dark) {
    .welcome-error {
        background: #3e1519;
        color: #ef5350;
        border-color: #c62828;
    }
}

.welcome-form {
    text-align: left;
}

.welcome-field {
    margin-bottom: 1.5rem;
}

.welcome-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--color-text);
}

.welcome-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.welcome-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.25);
}

.welcome-input::placeholder {
    color: var(--color-text-muted);
    opacity: 0.7;
}

.welcome-hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.3rem;
}

.welcome-submit {
    width: 100%;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
}

/* ========== Settings Page ========== */
/* #1699: Admin settings index page — card grid for settings categories.
   Follows the same design language as the board-card grid. */

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.settings-card {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, transform 0.15s;
}

.settings-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.settings-card:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

.settings-card-icon {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.settings-card-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.settings-card-title {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.settings-card-description {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* ========== Settings / Admin Users ========== */
/* #1710: Card-based user listing with edit modal dialog.
   Replaces the previous table layout (#1700). */

.settings-page {
    max-width: 800px;
}

/* --- User Card List --- */
.user-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-card {
    display: flex;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s;
}

.user-card:hover {
    box-shadow: var(--shadow-md);
}

.user-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.user-card-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
}

/* #1710: Email styled as a clickable link-button that opens the edit dialog */
.user-card-email {
    background: none;
    border: none;
    padding: 0;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--color-primary);
    cursor: pointer;
    text-align: left;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s;
}

.user-card-email:hover {
    color: var(--color-primary-hover);
}

.user-card-email:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

.users-count {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.text-muted {
    color: var(--color-text-muted);
    font-style: italic;
}

/* --- Edit User Dialog --- */
/* #1710: Native <dialog> element styled as a centered modal card.
   ::backdrop provides the dark overlay; the dialog itself slides up.
   #1712: margin: auto centers the dialog both horizontally and vertically
   when opened with showModal(). */

.edit-dialog {
    border: none;
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    box-shadow: var(--shadow-lg);
    padding: 0;
    max-width: 440px;
    width: calc(100% - 2rem);
    margin: auto;
    animation: dialog-slide-up 0.25s ease-out;
}

.edit-dialog::backdrop {
    background: rgba(0, 0, 0, 0.5);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

@keyframes dialog-slide-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.edit-dialog-form {
    padding: 2rem;
}

/* #1712: Distinct header section for the dialog — uses negative margins
   to span the full width of the form padding, with its own background
   and bottom border for visual separation from the form fields. */
.edit-dialog-heading {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: -2rem -2rem 1.5rem -2rem;
    padding: 1.25rem 2rem;
    background: #f0f1f3;
    border-bottom: 1px solid var(--color-border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    color: var(--color-text);
}

/* #1712: Dark mode override for dialog header — darker tint that
   contrasts with the dialog surface without being too stark. */
@media (prefers-color-scheme: dark) {
    .edit-dialog-heading {
        background: #1c2129;
    }
}

.edit-dialog-field {
    margin-bottom: 1.25rem;
}

.edit-dialog-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--color-text);
}

.edit-dialog-input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-family: var(--font-sans);
    font-size: 1rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.edit-dialog-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.25);
}

.edit-dialog-input[readonly] {
    opacity: 0.6;
    cursor: not-allowed;
}

.edit-dialog-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.3rem;
}

.edit-dialog-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.75rem;
}

.edit-dialog-actions .btn {
    flex: 1;
}

/* ========== API Client Management ========== */
/* #1721: Styles for the API client admin page — listing,
   scope badges, delete confirmation, and one-time key display.
   #1726: Replaced inline create form with modal; added header layout
   and clickable card styles. */

/* #1726: Header row with page title and "New" button side by side */
.api-clients-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.api-clients-header h1 {
    margin-bottom: 0;
}

.api-client-section-heading {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    letter-spacing: -0.01em;
}

/* #1721: Fieldset reset for the scopes checkbox group */
.api-client-scopes-fieldset {
    border: none;
    padding: 0;
    margin: 0;
}

.api-client-scopes {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.api-client-scope-checkbox {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    cursor: pointer;
    user-select: none;
}

.api-client-scope-checkbox input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.api-client-scope-name {
    font-weight: 500;
    color: var(--color-text);
}

/* --- Client Listing --- */
.api-client-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.api-client-card {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s, border-color 0.15s;
    gap: 1rem;
    width: 100%;
    text-align: left;
}

/* #1726: Clickable card styles — button reset + interactive states.
   Cards are now <button> elements for keyboard accessibility. */
.api-client-card-clickable {
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.api-client-card-clickable:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-primary);
}

.api-client-card-clickable:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: var(--shadow-md);
}

.api-client-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}

.api-client-card-name {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-text);
}

.api-client-card-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.api-client-card-scopes {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.api-client-card-date {
    font-size: 0.8rem;
}

.api-client-count {
    margin-top: 0.75rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* --- Access Scope Badges --- */
/* #1721: Pill-shaped badges following the difficulty badge pattern */
.scope-badge {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #e3f2fd;
    color: #1565c0;
}

@media (prefers-color-scheme: dark) {
    .scope-badge {
        background: #0d2b4d;
        color: #64b5f6;
    }
}

/* --- Danger / Delete Button --- */
.btn-danger {
    background: var(--color-error);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #d32f2f;
}

.btn-danger-outline {
    background: transparent;
    color: var(--color-error);
    border: 1px solid var(--color-error);
}

.btn-danger-outline:hover:not(:disabled) {
    background: var(--color-error);
    color: #fff;
}

.btn-sm {
    padding: 0.3rem 0.75rem;
    font-size: 0.8rem;
}

/* #1726: Danger zone at the bottom of the edit dialog — separated from
   the primary actions with a top border and muted styling. */
.edit-dialog-danger-zone {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-border);
    text-align: center;
}

/* --- Delete Dialog --- */
.delete-dialog-message {
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 1rem;
    color: var(--color-text);
}

/* --- One-Time Key Display --- */
/* #1721: Prominent card for showing the API key once after creation */
.api-key-display-card {
    max-width: 600px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.api-key-warning {
    margin-bottom: 1.5rem;
}

.api-key-details {
    margin-bottom: 1.25rem;
}

.api-key-client-name {
    font-size: 0.95rem;
    margin-bottom: 0.5rem;
}

.api-key-scopes {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    color: var(--color-text);
    flex-wrap: wrap;
}

.api-key-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--color-text);
}

.api-key-copy-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.api-key-value {
    flex: 1;
    padding: 0.625rem 0.75rem;
    font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
    font-size: 0.85rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    user-select: all;
}

.api-key-value:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.25);
}

.api-key-back-link {
    display: inline-block;
}

/* ========== Import Form ========== */
/* #1746: Board import page — file upload form styled consistently
   with other settings sub-pages. */

.import-description {
    font-size: 0.95rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    margin-bottom: 1.5rem;
}

.import-description code {
    font-family: "SF Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
    font-size: 0.85em;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.1rem 0.35rem;
}

.import-form {
    max-width: 500px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.import-form-field {
    margin-bottom: 1.25rem;
}

.import-form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.375rem;
    color: var(--color-text);
}

.import-form-file-input {
    display: block;
    width: 100%;
    padding: 0.625rem 0.75rem;
    font-size: 0.9rem;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
}

.import-form-file-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(92, 107, 192, 0.25);
}

.import-form-hint {
    display: block;
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.import-form-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

/* ========== Responsive ========== */
/* #1659: Comprehensive responsive design for small screens.
   Cell size is now computed dynamically in app.js based on viewport width and board size.
   These breakpoints handle layout, typography, and spacing adjustments. */

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

    h1 {
        font-size: 1.3rem;
    }

    /* #1659: Stack play header vertically — title above, back button below */
    .play-header {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .play-header h1 {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* #1659: Full-width board info and controls on small screens */
    .board-info {
        width: 100%;
    }

    .play-controls {
        width: 100%;
        justify-content: center;
    }

    .play-controls .btn {
        flex: 1;
        min-width: 0;
    }

    .message {
        width: 100%;
        min-width: 0;
    }

    .board-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }

    /* #1681: Tighter modal padding on small screens */
    .victory-modal {
        padding: 2rem 1.5rem;
    }

    .victory-title {
        font-size: 1.5rem;
    }

    .victory-time {
        font-size: 2rem;
    }

    /* #1659: Larger touch targets for board cards on mobile */
    .board-card {
        padding: 1.25rem 1rem;
    }

    /* #1675: Full-width filter selects on small screens */
    .filter-bar {
        flex-direction: column;
        gap: 0.75rem;
    }

    .filter-select {
        width: 100%;
        min-width: 0;
    }

    /* #1710: Tighter card padding on small screens */
    .user-card {
        padding: 0.75rem 1rem;
    }

    /* #1710: Tighter dialog padding on small screens */
    .edit-dialog-form {
        padding: 1.5rem;
    }

    /* #1712: Match heading negative margins to reduced form padding */
    .edit-dialog-heading {
        margin: -1.5rem -1.5rem 1.25rem -1.5rem;
        padding: 1rem 1.5rem;
    }

    /* #1734: Stack feature cards vertically on small screens */
    .home-features {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .home-hero {
        margin: 2rem auto 2rem;
    }

    .home-hero-title {
        font-size: 1.75rem;
    }

    .home-user {
        margin: 2.5rem auto;
    }

    /* #1693: Tighter welcome card on small screens */
    .welcome-card {
        margin: 1.5rem auto;
        padding: 2rem 1.5rem;
    }

    /* #1699: Full-width settings cards on small screens */
    .settings-grid {
        grid-template-columns: 1fr;
    }

    /* #1726: Tighter card padding on small screens */
    .api-client-card {
        padding: 0.75rem 1rem;
    }

    /* #1721: Tighter key display card on small screens */
    .api-key-display-card {
        padding: 1.5rem;
    }
}

@media (max-width: 400px) {
    .container {
        padding: 0.75rem 0.5rem;
    }

    h1 {
        font-size: 1.1rem;
    }

    /* #1659: Single column card layout on very small screens */
    .board-grid {
        grid-template-columns: 1fr;
    }

    /* #1659: Touch-friendly card sizes with larger tap area */
    .board-card {
        flex-direction: row;
        justify-content: space-between;
        padding: 1rem;
        gap: 0.75rem;
    }

    .board-card-size {
        font-size: 1.5rem;
    }

    .nav-brand {
        font-size: 1.1rem;
    }

    /* #1694: Compact navbar user section on small screens */
    .nav-user {
        gap: 0.5rem;
        font-size: 0.8rem;
    }

    .nav-username,
    .nav-username-btn {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .queen-count,
    .timer-display {
        font-size: 0.9rem;
    }

    .board-status-row {
        gap: 1rem;
    }

    .difficulty-badge,
    .board-card-difficulty {
        font-size: 0.65rem;
    }

    /* #1693: Minimal welcome card padding on very small screens */
    .welcome-card {
        margin: 1rem auto;
        padding: 1.5rem 1rem;
    }

    .welcome-heading {
        font-size: 1.4rem;
    }

    /* #1681: Minimal padding on very small screens */
    .victory-modal {
        padding: 1.5rem 1rem;
    }

    .victory-time {
        font-size: 1.75rem;
    }
}
