/* ============================================
   HearthDoku — Clay Design System (Dark Mode)
   Dark canvas, warm oat accents, refined hovers
   ============================================ */

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

:root {
    /* Clay Dark Primary */
    --bg-canvas: #1c1917;
    --bg-surface: #292524;
    --bg-cell: #292524;
    --bg-cell-hover: #3a3532;
    --bg-elevated: #44403c;
    --border-oat: #57534e;
    --border-oat-light: #44403c;
    --text-primary: #fafaf9;
    --text-secondary: #a8a29e;
    --text-tertiary: #78716c;

    /* Swatch Palette (kept vibrant on dark) */
    --matcha-300: #84e7a5;
    --matcha-600: #22c55e;
    --matcha-800: #02492a;
    --slushie-500: #3bd3fd;
    --slushie-800: #22d3ee;
    --lemon-400: #f8cc65;
    --lemon-500: #fbbd41;
    --lemon-700: #f59e0b;
    --lemon-800: #d97706;
    --ube-300: #c1b0ff;
    --ube-800: #a78bfa;
    --ube-900: #7c3aed;
    --pomegranate-400: #fc7981;
    --blueberry-800: #60a5fa;
    --dragonfruit: #e040a0;

    /* Semantic Aliases */
    --accent-green: var(--matcha-600);
    --accent-blue: var(--slushie-500);
    --accent-red: var(--pomegranate-400);
    --accent-gold: var(--lemon-500);
    --accent-purple: var(--ube-800);

    /* Clay Shadows (adapted for dark) */
    --shadow-clay: 0px 1px 2px rgba(0,0,0,0.4), 0px -1px 1px rgba(255,255,255,0.03) inset, 0px 1px 0px rgba(255,255,255,0.05) inset;
    --shadow-hard: rgba(0,0,0,0.6) -5px 5px 0px;

    /* Fonts */
    --font-heading: 'DM Sans', Arial, sans-serif;
    --font-body: 'DM Sans', Arial, sans-serif;
    --font-mono: 'Space Mono', monospace;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    background: var(--bg-canvas);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ---------- Title Bar ---------- */
.title-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-oat-light);
    background: var(--bg-surface);
}

.title-bar__left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.title-bar__logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.hs-logo {
    filter: drop-shadow(0 0 8px rgba(251, 189, 65, 0.5));
}

.title-bar__title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.64px;
    color: var(--lemon-500);
}

/* ---------- Title Bar Right group ---------- */
.title-bar__right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

/* ---------- Twitter / X link ---------- */
.btn-twitter {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.78rem;
    font-weight: 500;
    text-decoration: none;
    transition: color 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    opacity: 0.75;
}

.btn-twitter:hover {
    color: var(--text-primary);
    opacity: 1;
}

.btn-twitter__icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

.btn-twitter__label {
    letter-spacing: -0.1px;
}

/* ---------- Buy Me a Coffee button ---------- */
.btn-coffee {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.9rem;
    background: var(--bg-cell);
    border: 1px solid var(--border-oat);
    border-radius: 12px;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    box-shadow: var(--shadow-clay);
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-coffee:hover {
    background: var(--bg-cell-hover);
    border-color: var(--lemon-700);
    color: var(--lemon-500);
    transform: translateY(-1px);
    box-shadow: var(--shadow-hard);
}

.btn-coffee__icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-coffee__label {
    letter-spacing: -0.16px;
}

/* ---------- Language Switcher ---------- */
.lang-switcher {
    position: relative;
}

.lang-select {
    font-family: var(--font-body);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.4rem 0.6rem;
    background: var(--bg-cell);
    color: var(--text-primary);
    border: 1px solid var(--border-oat);
    border-radius: 12px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    padding-right: 1.5rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a8a29e' d='M2 4l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.4rem center;
    box-shadow: var(--shadow-clay);
    transition: all 0.2s;
}

.lang-select:hover {
    border-color: var(--lemon-500);
    background-color: var(--bg-cell-hover);
}

.lang-select:focus {
    outline: rgb(20, 110, 245) solid 2px;
    border-color: var(--lemon-500);
}

.lang-select option {
    background: var(--bg-surface);
    color: var(--text-primary);
}

/* ---------- Main Layout ---------- */
.main-layout {
    display: flex;
    min-height: calc(100vh - 70px);
}

/* ---------- Controls Panel ---------- */
.controls-panel {
    width: 280px;
    background: var(--bg-surface);
    border-right: 1px solid var(--border-oat-light);
    padding: 1rem;
    overflow-y: auto;
    flex-shrink: 0;
}

.controls-toggle {
    display: none;
    background: var(--bg-cell);
    border: 1px solid var(--border-oat);
    color: var(--text-primary);
    font-size: 1.25rem;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    cursor: pointer;
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-clay);
    transition: all 0.2s;
}

.controls-toggle:hover {
    border-color: var(--lemon-500);
    background: var(--bg-cell-hover);
}

.controls-title {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--lemon-500);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 1.08px;
}

/* ---------- Buttons ---------- */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.btn {
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.85rem;
    padding: 0.6rem 1rem;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: -0.16px;
}

.btn--primary {
    background: var(--lemon-500);
    color: #1c1917;
    box-shadow: var(--shadow-clay);
}

.btn--primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hard);
    background: var(--lemon-400);
}

.btn--secondary {
    background: var(--bg-cell);
    color: var(--text-primary);
    border: 1px solid var(--border-oat);
    box-shadow: var(--shadow-clay);
}

.btn--secondary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hard);
    background: var(--bg-cell-hover);
    border-color: var(--lemon-500);
}

.btn--small {
    font-size: 0.75rem;
    padding: 0.4rem 0.6rem;
}

.btn--tiny {
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
    background: var(--bg-cell);
    color: var(--text-secondary);
    border: 1px dashed var(--border-oat);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn--tiny:hover {
    color: var(--text-primary);
    border-style: solid;
    border-color: var(--lemon-500);
}

.btn--preset {
    background: var(--ube-900);
    color: #fafaf9;
    border: none;
    box-shadow: var(--shadow-clay);
}

.btn--preset:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hard);
    background: var(--ube-800);
}

.btn--daily {
    background: rgba(251, 189, 65, 0.12);
    color: var(--lemon-500);
    border: 1px solid rgba(251, 189, 65, 0.3);
    box-shadow: var(--shadow-clay);
}

.btn--daily:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hard);
    background: rgba(251, 189, 65, 0.22);
    border-color: var(--lemon-500);
}

/* ---------- Filter Section ---------- */
.filter-section {
    border-top: 1px dashed var(--border-oat-light);
    padding-top: 1rem;
}

.filter-title {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--slushie-800);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.08px;
}

.filter-presets {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}

.filter-actions {
    display: flex;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
}

.filter-search {
    width: 100%;
    padding: 0.4rem 0.6rem;
    background: var(--bg-canvas);
    border: 1px solid var(--border-oat);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: var(--font-body);
    margin-bottom: 0.5rem;
    box-shadow: var(--shadow-clay);
}

.filter-search::placeholder {
    color: var(--text-tertiary);
}

.filter-search:focus {
    outline: rgb(20, 110, 245) solid 2px;
    border-color: var(--lemon-500);
}

.filter-list {
    max-height: 300px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.filter-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    padding: 0.25rem 0.4rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
}

.filter-item:hover {
    background: var(--bg-cell-hover);
    color: var(--text-primary);
}

.filter-item input[type="checkbox"] {
    accent-color: var(--lemon-500);
    flex-shrink: 0;
}

.filter-item__icon {
    width: 18px;
    height: 18px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

.filter-item__label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filter-list--compact {
    max-height: none;
    overflow-y: visible;
}

.filter-item--rarity-legendary .filter-item__label {
    color: var(--lemon-500);
    font-weight: 600;
}
.filter-item--rarity-epic .filter-item__label {
    color: var(--ube-800);
    font-weight: 600;
}
.filter-item--rarity-rare .filter-item__label {
    color: var(--blueberry-800);
    font-weight: 600;
}

/* ---------- Game Area ---------- */
.game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    position: relative;
    background: var(--bg-canvas);
}

/* ---------- Puzzle Mode Bar ---------- */
.puzzle-mode-bar {
    display: flex;
    justify-content: center;
    margin-bottom: 0.75rem;
    min-height: 28px;
}

.puzzle-mode-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.75rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    box-shadow: var(--shadow-clay);
}

.puzzle-mode-badge--daily {
    background: rgba(251, 189, 65, 0.1);
    border: 1px solid rgba(251, 189, 65, 0.25);
    color: var(--lemon-500);
}

.puzzle-mode-badge--free {
    background: rgba(59, 211, 253, 0.08);
    border: 1px solid rgba(59, 211, 253, 0.2);
    color: var(--slushie-500);
}

.puzzle-mode-badge--done {
    background: rgba(46, 204, 113, 0.1);
    border: 1px solid rgba(46, 204, 113, 0.3);
    color: #2ecc71;
    margin-left: 0.5rem;
}

/* Locked puzzle (daily already played) */
.puzzle-container--locked {
    opacity: 0.55;
    pointer-events: none;
    position: relative;
}

/* ---------- Stats Panel ---------- */
.stats-panel {
    display: flex;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-oat-light);
    border-radius: 12px;
    padding: 0.5rem 1rem;
    min-width: 80px;
    box-shadow: var(--shadow-clay);
}

.stat-label {
    font-family: var(--font-heading);
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 1.08px;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--lemon-500);
    font-weight: 700;
}

.stat-value--danger {
    color: var(--pomegranate-400) !important;
    animation: pulse 1s infinite;
}

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

/* ---------- Puzzle Grid ---------- */
.puzzle-container {
    position: relative;
}

.puzzle-grid {
    display: grid;
    grid-template-columns: 160px repeat(3, 200px);
    grid-template-rows: 120px repeat(3, 200px);
    gap: 6px;
}

.grid-corner {
    /* Empty corner cell */
}

.grid-col-header,
.grid-row-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
}

.grid-cell {
    background: var(--bg-surface);
    border: 2px solid var(--border-oat-light);
    border-radius: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-clay);
}

.grid-cell:hover {
    background: var(--bg-cell-hover);
    border-color: var(--lemon-500);
    box-shadow: 0 0 0 1px var(--lemon-500), var(--shadow-clay);
}

.grid-cell--correct {
    border-color: var(--matcha-600) !important;
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.2), 0 0 0 1px var(--matcha-600);
}

.grid-cell--correct:hover {
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.2), 0 0 0 1px var(--matcha-600);
}

.grid-cell--wrong {
    border-color: var(--pomegranate-400) !important;
    background: rgba(252, 121, 129, 0.06) !important;
    cursor: default;
}

.grid-cell--wrong:hover {
    box-shadow: var(--shadow-clay);
}

.grid-cell--solution {
    border-color: var(--slushie-500) !important;
    box-shadow: 0 0 12px rgba(59, 211, 253, 0.15), 0 0 0 1px var(--slushie-500);
    cursor: default;
}

.grid-cell--solution:hover {
    box-shadow: 0 0 12px rgba(59, 211, 253, 0.15), 0 0 0 1px var(--slushie-500);
}

/* ---------- Cell Card Content ---------- */
.cell-card {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    position: relative;
}

.cell-card img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.cell-card__name {
    font-size: 0.6rem;
    text-align: center;
    padding: 0.25rem;
    word-break: break-word;
}

.cell-card__name-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    font-size: 0.65rem;
    font-weight: 600;
    text-align: center;
    background: rgba(0, 0, 0, 0.8);
    color: var(--text-primary);
    padding: 3px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cell-card__score {
    position: absolute;
    top: 4px;
    right: 6px;
    font-family: var(--font-mono);
    font-size: 0.5rem;
    color: var(--matcha-600);
    background: rgba(0,0,0,0.7);
    padding: 2px 5px;
    border-radius: 6px;
    border: 1px solid var(--border-oat-light);
    font-weight: 700;
}

.cell-card__x {
    font-size: 2rem;
    color: var(--pomegranate-400);
    font-weight: bold;
}

.cell-card__solution-tag {
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-mono);
    font-size: 0.45rem;
    color: var(--slushie-500);
    background: rgba(0,0,0,0.7);
    padding: 2px 6px;
    border-radius: 6px;
    border: 1px solid var(--border-oat-light);
    font-weight: 700;
}

/* ---------- Badges ---------- */
.badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    min-width: 100px;
    max-width: 160px;
    word-break: break-word;
    line-height: 1.3;
    box-shadow: var(--shadow-clay);
}

.badge__icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge-icon-img {
    width: 30px;
    height: 30px;
    object-fit: contain;
    vertical-align: middle;
    filter: drop-shadow(0 1px 3px rgba(0,0,0,0.4));
}

.badge__label {
    font-size: 0.8rem;
}

/* Badge variants — dark Clay palette */
.badge--mana {
    background: rgba(96, 165, 250, 0.12);
    color: var(--blueberry-800);
    border: 1px solid rgba(96, 165, 250, 0.25);
}

.badge--health {
    background: rgba(252, 121, 129, 0.12);
    color: var(--pomegranate-400);
    border: 1px solid rgba(252, 121, 129, 0.25);
}

.badge--attack {
    background: rgba(251, 189, 65, 0.12);
    color: var(--lemon-500);
    border: 1px solid rgba(251, 189, 65, 0.25);
}

.badge--keyword {
    background: rgba(167, 139, 250, 0.12);
    color: var(--ube-800);
    border: 1px solid rgba(167, 139, 250, 0.25);
}

.badge--type {
    background: rgba(34, 197, 94, 0.12);
    color: var(--matcha-600);
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.badge--race {
    background: rgba(34, 211, 238, 0.12);
    color: var(--slushie-800);
    border: 1px solid rgba(34, 211, 238, 0.25);
}

.badge--class {
    border: 1px solid var(--border-oat-light);
}

.badge--class-mage { background: rgba(167, 139, 250, 0.12); color: var(--ube-800); }
.badge--class-warrior { background: rgba(252, 121, 129, 0.12); color: var(--pomegranate-400); }
.badge--class-paladin { background: rgba(251, 189, 65, 0.12); color: var(--lemon-500); }
.badge--class-hunter { background: rgba(34, 197, 94, 0.12); color: var(--matcha-300); }
.badge--class-rogue { background: rgba(168, 162, 158, 0.12); color: var(--text-secondary); }
.badge--class-priest { background: rgba(250, 250, 249, 0.08); color: var(--text-primary); }
.badge--class-shaman { background: rgba(96, 165, 250, 0.12); color: var(--blueberry-800); }
.badge--class-warlock { background: rgba(124, 58, 237, 0.15); color: var(--ube-300); }
.badge--class-druid { background: rgba(245, 158, 11, 0.12); color: var(--lemon-700); }
.badge--class-deathknight { background: rgba(59, 211, 253, 0.12); color: var(--slushie-500); }
.badge--class-demonhunter { background: rgba(34, 197, 94, 0.12); color: var(--matcha-600); }
.badge--class-neutral { background: rgba(168, 162, 158, 0.08); color: var(--text-secondary); }

.badge--set {
    background: rgba(217, 119, 6, 0.12);
    color: var(--lemon-700);
    border: 1px solid rgba(217, 119, 6, 0.25);
}

.badge--rarity {
    border: 1px solid var(--border-oat-light);
}

.badge--rarity-free { background: rgba(168, 162, 158, 0.08); color: var(--text-secondary); }
.badge--rarity-common { background: rgba(250, 250, 249, 0.06); color: var(--text-primary); }
.badge--rarity-rare { background: rgba(96, 165, 250, 0.12); color: var(--blueberry-800); }
.badge--rarity-epic { background: rgba(167, 139, 250, 0.12); color: var(--ube-800); }
.badge--rarity-legendary {
    background: linear-gradient(135deg, rgba(251, 189, 65, 0.15), rgba(245, 158, 11, 0.1));
    color: var(--lemon-500);
    border: 1px solid rgba(251, 189, 65, 0.3);
    box-shadow: 0 0 12px rgba(251, 189, 65, 0.1);
}

/* ---------- Cell Animations ---------- */
.anim-correct {
    animation: popIn 0.4s ease-out;
}

@keyframes popIn {
    0% { transform: scale(0.9); opacity: 0.5; }
    60% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.anim-wrong {
    animation: shake 0.35s ease-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-6px); }
    40% { transform: translateX(6px); }
    60% { transform: translateX(-3px); }
    80% { transform: translateX(3px); }
}

/* ---------- Loading ---------- */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(28, 25, 23, 0.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 16px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-oat-light);
    border-top-color: var(--lemon-500);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

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

.loading-text {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 1.08px;
    text-transform: uppercase;
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(8px);
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    /* Fade out: opacity first, then hide visibility after transition */
    transition: opacity 0.2s ease, visibility 0s linear 0.2s;
}

.modal-overlay--visible {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    /* Fade in: show visibility instantly, then transition opacity */
    transition: opacity 0.2s ease, visibility 0s linear 0s;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-oat-light);
    border-radius: 24px;
    padding: 1.5rem;
    max-width: 480px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-tertiary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

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

/* ---------- Search Modal ---------- */
.search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.search-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--lemon-500);
    letter-spacing: -0.4px;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-canvas);
    border: 2px solid var(--border-oat);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: var(--font-body);
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-clay);
}

.search-input:focus {
    outline: none;
    border-color: var(--lemon-500);
    box-shadow: 0 0 0 2px rgba(251, 189, 65, 0.25);
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.search-empty {
    text-align: center;
    color: var(--text-tertiary);
    padding: 1rem;
    font-size: 0.85rem;
}

.search-result {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: var(--bg-cell);
    border: 1px solid var(--border-oat-light);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.search-result:hover {
    border-color: var(--lemon-500);
    background: var(--bg-cell-hover);
}

.search-result--used {
    opacity: 0.35;
    cursor: not-allowed;
}

.search-result__info {
    flex: 1;
    min-width: 0;
}

.search-result__name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result__set {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result__set-icon {
    width: 14px;
    height: 14px;
    object-fit: contain;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

.search-result__used-tag {
    font-size: 0.6rem;
    color: var(--pomegranate-400);
    font-weight: 600;
    white-space: nowrap;
}

/* ---------- Victory Modal ---------- */
.victory-modal {
    text-align: center;
    overflow: visible;
    border: 1px solid rgba(251, 189, 65, 0.3);
    box-shadow: 0 24px 48px rgba(0,0,0,0.4), 0 0 40px rgba(251, 189, 65, 0.08);
}

.victory-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    color: var(--lemon-500);
    margin-bottom: 1.5rem;
    letter-spacing: -0.64px;
}

.victory-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.victory-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.victory-stat__label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 1.08px;
    margin-bottom: 0.25rem;
}

.victory-stat__value {
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--lemon-500);
    font-weight: 700;
}

.victory-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- Defeat Modal ---------- */
.defeat-modal {
    text-align: center;
    border: 1px solid rgba(252, 121, 129, 0.3);
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4), 0 0 40px rgba(252, 121, 129, 0.08);
}

.defeat-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 600;
    color: var(--pomegranate-400);
    margin-bottom: 0.5rem;
    letter-spacing: -0.64px;
}

.defeat-message {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 1.5rem;
}

.defeat-stats {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.defeat-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- Export Modal ---------- */
.export-modal {
    text-align: center;
}

.export-title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--lemon-500);
    margin-bottom: 1.5rem;
    letter-spacing: -0.4px;
}

.export-options {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------- Confetti Canvas ---------- */
#confettiCanvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    display: none;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--matcha-600);
    color: #1c1917;
    padding: 0.75rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.85rem;
    z-index: 200;
    opacity: 0;
    transition: all 0.3s;
    pointer-events: none;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--bg-canvas);
}

::-webkit-scrollbar-thumb {
    background: var(--border-oat);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ---------- Solution Popup Modal ---------- */
.solution-modal {
    max-width: 1200px;
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 24px;
}

.solution-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.solution-modal__title {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--lemon-500);
    letter-spacing: -0.4px;
}

.solution-modal__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.25rem;
}

.solution-cell {
    background: var(--bg-cell);
    border: 1px solid var(--border-oat-light);
    border-radius: 16px;
    padding: 1rem;
    overflow: hidden;
    box-shadow: var(--shadow-clay);
}

.solution-cell__header {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px dashed var(--border-oat-light);
}

.solution-cell__criteria {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--lemon-500);
    line-height: 1.5;
}

.solution-cell__count {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.solution-cell__cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    max-height: 320px;
    overflow-y: auto;
    padding-right: 4px;
}

.solution-card {
    text-align: center;
    cursor: default;
}

.solution-card img {
    width: 100%;
    height: auto;
    border-radius: 8px;
    transition: transform 0.2s;
}

.solution-card:hover img {
    transform: scale(1.06);
    z-index: 1;
    position: relative;
}

.solution-card__label {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.solution-card__name {
    font-size: 0.65rem;
    text-align: center;
    padding: 0.25rem;
    word-break: break-word;
    color: var(--text-secondary);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .controls-panel {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .controls-panel:has(.controls-content--open) {
        transform: translateX(0);
    }

    .controls-toggle {
        display: block;
        position: fixed;
        top: 80px;
        left: 0.5rem;
        z-index: 51;
    }

    .puzzle-grid {
        grid-template-columns: 120px repeat(3, 150px);
        grid-template-rows: 100px repeat(3, 150px);
    }

    .badge {
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
        min-width: 80px;
        max-width: 120px;
    }

    .badge__icon {
        font-size: 0.9rem;
    }

    .badge-icon-img {
        width: 24px;
        height: 24px;
    }

    .badge__label {
        font-size: 0.65rem;
    }

    .solution-modal__grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 520px) {
    .title-bar {
        padding: 0.75rem 1rem;
    }

    .title-bar__left {
        gap: 0.6rem;
    }

    .title-bar__title {
        font-size: 1.1rem;
    }

    .btn-coffee__label,
    .btn-twitter__label {
        display: none;
    }

    .btn-coffee,
    .btn-twitter {
        padding: 0.45rem 0.6rem;
    }

    .game-area {
        padding: 0.75rem;
    }

    .stats-panel {
        gap: 0.5rem;
        margin-bottom: 1rem;
    }

    .stat-item {
        padding: 0.3rem 0.5rem;
        min-width: 60px;
    }

    .stat-label {
        font-size: 0.45rem;
    }

    .stat-value {
        font-size: 0.7rem;
    }

    .puzzle-grid {
        grid-template-columns: 90px repeat(3, 100px);
        grid-template-rows: 75px repeat(3, 100px);
        gap: 3px;
    }

    .badge {
        font-size: 0.6rem;
        padding: 0.25rem 0.35rem;
        min-width: 60px;
        max-width: 90px;
    }

    .badge__icon {
        font-size: 0.75rem;
    }

    .badge-icon-img {
        width: 18px;
        height: 18px;
    }

    .badge__label {
        font-size: 0.5rem;
    }

    .modal-content {
        padding: 1rem;
        width: 95%;
        border-radius: 16px;
    }

    .solution-modal {
        border-radius: 16px;
    }

    .solution-modal__grid {
        grid-template-columns: 1fr;
    }

    .solution-cell__cards {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
}

/* ============================================
   Accessibility utilities
   ============================================ */
.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--accent-gold);
    color: var(--bg-canvas);
    padding: 0.5rem 0.75rem;
    z-index: 10000;
    text-decoration: none;
    font-weight: 700;
    border-radius: 0 0 8px 0;
}

.skip-link:focus {
    top: 0;
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

/* Respect user motion preferences */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ============================================
   Extension icons → rendered white
   Only extension/set icons; rarity & class kept intact
   ============================================ */
.filter-item__icon--set,
.search-result__set-icon {
    filter: brightness(0) invert(1) drop-shadow(0 1px 2px rgba(0, 0, 0, 0.4));
}

/* ============================================
   Site footer
   ============================================ */
.site-footer {
    margin-top: 2rem;
    padding: 1.25rem 1.5rem 1.5rem;
    border-top: 1px solid var(--border-oat-light);
    background: var(--bg-surface);
    color: var(--text-tertiary);
    font-size: 0.8rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.site-footer__text {
    max-width: 60ch;
    line-height: 1.5;
}

.site-footer__links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

.site-footer__links a,
.site-footer__link-btn {
    color: var(--text-secondary);
    text-decoration: none;
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

.site-footer__links a:hover,
.site-footer__link-btn:hover,
.site-footer__links a:focus-visible,
.site-footer__link-btn:focus-visible {
    color: var(--accent-gold);
    text-decoration: underline;
    outline: none;
}

/* ============================================
   Consent banner (RGPD)
   ============================================ */
.consent-banner {
    position: fixed;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    max-width: 640px;
    margin-inline: auto;
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-oat);
    border-radius: 14px;
    box-shadow: var(--shadow-clay), 0 8px 24px rgba(0, 0, 0, 0.5);
    padding: 1rem 1.25rem;
    z-index: 9999;
}

.consent-banner[hidden] {
    display: none;
}

.consent-banner__title {
    font-size: 1rem;
    margin-bottom: 0.4rem;
    color: var(--accent-gold);
}

.consent-banner__text {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
    margin-bottom: 0.85rem;
}

.consent-banner__text a {
    color: var(--accent-gold);
}

.consent-banner__actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    flex-wrap: wrap;
}

/* ============================================
   Legal page (privacy.html)
   ============================================ */
.legal-page {
    background: var(--bg-canvas);
}

.legal-content {
    max-width: 780px;
    margin: 2rem auto;
    padding: 0 1.25rem 3rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.legal-content h1 {
    font-size: 1.75rem;
    margin-bottom: 1.25rem;
    color: var(--accent-gold);
}

.legal-content h2 {
    font-size: 1.2rem;
    margin-top: 2rem;
    margin-bottom: 0.6rem;
    color: var(--text-primary);
}

.legal-content h3 {
    font-size: 1rem;
    margin-top: 1.25rem;
    margin-bottom: 0.4rem;
    color: var(--text-secondary);
}

.legal-content p,
.legal-content ul {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.legal-content ul {
    padding-left: 1.25rem;
}

.legal-content a {
    color: var(--accent-gold);
}

.legal-content code {
    font-family: var(--font-mono);
    background: var(--bg-surface);
    padding: 0.05rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}

.legal-footer {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-oat-light);
}
