/* --- ROOT & THEMES --- */
:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --accent: #facc15;
    --text: #f8fafc;
    --text-dim: #94a3b8;
    --border: #334155;
    --error: #ef4444;
    --success: #10b981;
    --glass-bg: rgba(255, 255, 255, 0.05);
    --glass-border: rgba(255, 255, 255, 0.1);
}

/* THEME: NEON (15 Stars) */
body.theme-neon {
    --bg: #000;
    --bg-card: #0a0a0a;
    --accent: #0ff;
    --border: #00f;
}

body.theme-neon .cell {
    border-color: #00f;
    box-shadow: 0 0 5px #00f;
}

/* THEME: PASTEL (40 Stars) */
body.theme-pastel {
    --bg: #fdf2f8;
    --bg-card: #fff;
    --accent: #f472b6;
    --text: #4b5563;
    --text-dim: #9ca3af;
    --border: #fbcfe8;
    --glass-bg: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(0, 0, 0, 0.1);
}

body.theme-pastel .btn {
    background: transparent;
    color: #4b5563;
}

/* THEME: GOLD (100 Stars) */
body.theme-gold {
    --bg: #1a1a1a;
    --bg-card: #262626;
    --accent: #fbbf24;
    --border: #78350f;
}

/* THEME: MINT (150 Stars) */
body.theme-mint {
    --bg: #f0fdf4;
    --bg-card: #ffffff;
    --accent: #10b981;
    --text: #334155;
    --text-dim: #94a3b8;
    --border: #bbf7d0;
    --glass-bg: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(0, 0, 0, 0.1);
}

body.theme-mint .btn {
    background: transparent;
    color: #334155;
}

/* THEME: OCEAN (200 Stars) */
body.theme-ocean {
    --bg: #eff6ff;
    --bg-card: #ffffff;
    --accent: #3b82f6;
    --text: #334155;
    --text-dim: #94a3b8;
    --border: #bfdbfe;
    --glass-bg: rgba(0, 0, 0, 0.05);
    --glass-border: rgba(0, 0, 0, 0.1);
}

body.theme-ocean .btn {
    background: transparent;
    color: #334155;
}

/* THEME: DIAMOND (300 Stars) */
body.theme-diamond {
    --bg: #f8fafc;
    --bg-card: #ffffff;
    --accent: #6366f1;
    --text: #1e293b;
    --text-dim: #64748b;
    --border: #e2e8f0;
    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-border: rgba(0, 0, 0, 0.08);
}

body.theme-diamond .btn {
    background: transparent;
    color: #1e293b;
}

/* Diamond Premium Moving Light Effect */
body.theme-diamond .board-container {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: relative;
    z-index: 1;
}

body.theme-diamond .board-container::before {
    content: '';
    position: absolute;
    inset: -4px;
    z-index: -1;
    border-radius: 16px;
    background: linear-gradient(45deg, rgba(203, 213, 225, 0.4), rgba(255, 255, 255, 1), rgba(99, 102, 241, 0.3), rgba(255, 255, 255, 1));
    background-size: 300% 300%;
    animation: diamond-shine 6s ease-in-out infinite alternate;
}

@keyframes diamond-shine {
    0% {
        background-position: 0% 50%;
    }

    100% {
        background-position: 100% 50%;
    }
}

/* --- LUXURY DAILY MODE --- */
body.daily-mode .board-container {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
    position: relative;
    z-index: 1;
}

body.daily-mode .board-container::before {
    content: '';
    position: absolute;
    inset: -4px;
    z-index: -1;
    border-radius: 16px;
    background: linear-gradient(45deg, #ff007f, #7f00ff, #00d4ff, #ff007f);
    background-size: 300% 300%;
    filter: blur(20px);
    opacity: 0.6;
    animation: aurora-shift 8s ease infinite;
}

@keyframes aurora-shift {
    0% {
        background-position: 0% 50%;
    }

    50% {
        background-position: 100% 50%;
    }

    100% {
        background-position: 0% 50%;
    }
}

/* Label for the header */
.daily-label {
    display: none;
    font-size: 10px;
    font-weight: 900;
    background: #fbbf24;
    color: #000;
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    text-transform: uppercase;
}

body.daily-mode .daily-label {
    display: inline-block;
}

/* Make the flame dance when the Daily Puzzle is open */
body.daily-mode .flame-icon svg {
    animation: pulse-glow 1.5s infinite ease-in-out;
}

@keyframes pulse-glow {

    0%,
    100% {
        filter: drop-shadow(0 0 2px #fbbf24);
        transform: scale(1);
    }

    50% {
        filter: drop-shadow(0 0 10px #fbbf24);
        transform: scale(1.1);
    }
}

/* --- BASE STYLES --- */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100svh;
    width: 100%;
    position: fixed;
    overflow: hidden;
    overscroll-behavior: none;
}

.wrap {
    width: 100%;
    max-width: 400px;
    padding: 15px;
    padding-top: calc(15px + env(safe-area-inset-top));
    height: 100svh;
    max-height: 850px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    z-index: 10;
    touch-action: none;
    margin: auto;
    /* Re-center the wrap itself if the screen is taller than max-height */
}

/* --- APP HEADER (iOS STYLE) --- */
.app-header {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 5px;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.app-title {
    margin: 0;
    font-size: 1.15rem;
    font-weight: 900;
    letter-spacing: 1px;
    color: var(--text);
    flex: 1;
    text-align: center;
}

.top-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.stat-pill {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 6px 12px;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.9rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-dim);
    cursor: pointer;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.2s;
    position: relative;
}

.icon-btn:active {
    transform: scale(0.9);
    background: var(--accent);
    color: #000;
}

.audio-btn.muted svg {
    opacity: 0.4;
}

.audio-btn.muted::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 2px;
    background: #ef4444;
    transform: rotate(45deg);
    border-radius: 2px;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

.level-badge {
    background: var(--bg-card);
    color: var(--text-dim);
    border: 1px solid var(--border);
    font-weight: 900;
    font-size: 0.75rem;
    padding: 6px 12px;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

body.daily-mode .level-badge {
    background: linear-gradient(45deg, #ff007f, #7f00ff, #00d4ff);
    background-size: 200% 200%;
    color: #fff;
    border: none;
    animation: aurora-shift 8s ease infinite;
}

.moves-pill {
    font-size: 0.8rem;
    padding: 4px 12px;
    color: var(--text);
}

.moves-label {
    color: var(--text-dim);
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 700;
    margin-right: 4px;
}

.moves-count {
    color: var(--accent);
    font-size: 1rem;
}

/* STREAK FLAME */
.flame-icon {
    transition: 0.3s;
}

.flame-icon svg {
    width: 18px;
    height: 18px;
}

.flame-icon.grey {
    color: var(--text-dim);
    opacity: 0.6;
}

.flame-icon.blue {
    color: #60a5fa;
    border-color: rgba(96, 165, 250, 0.3);
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.1);
}

.flame-icon.orange {
    color: #fb923c;
    border-color: rgba(251, 146, 60, 0.3);
    box-shadow: 0 0 10px rgba(251, 146, 60, 0.2);
    animation: flicker 0.5s infinite alternate;
}

@keyframes flicker {
    from {
        filter: brightness(1);
    }

    to {
        filter: brightness(1.2);
    }
}

/* SETTINGS GEAR & NOTIF DOT */
.settings-btn {
    position: relative;
}

.notif-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 10px;
    height: 10px;
    background: var(--error);
    border-radius: 50%;
    border: 2px solid var(--bg-card);
    display: none;
}

.notif-dot.show {
    display: block;
}

.help-list {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 10px;
}

.help-item {
    display: flex;
    align-items: center;
    gap: 15px;
    background: rgba(255, 255, 255, 0.03);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    font-size: 14px;
    color: var(--text);
    line-height: 1.4;
}

.badge-mini {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.badge-mini svg {
    width: 18px;
    height: 18px;
}

/* --- GAME BOARD --- */
#confetti {
    position: fixed;
    inset: 0;
    z-index: 5;
    pointer-events: none;
}

.board-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: var(--bg-card);
    border-radius: 12px;
    padding: var(--board-pad, 8px);
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.5), inset 0 0 20px rgba(0, 0, 0, 0.2);
    margin: auto 0;
}

.board-actions {
    display: flex;
    justify-content: center;
    margin: 5px 0 15px;
    z-index: 11;
}

.reset-pill {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    color: var(--text-dim);
    padding: 8px 18px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.reset-pill:active {
    transform: scale(0.92);
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
    box-shadow: 0 0 20px rgba(239, 68, 68, 0.2);
}

.reset-pill svg {
    transition: transform 0.5s ease;
}

.reset-pill:active svg {
    transform: rotate(-180deg);
}

.board {
    position: relative;
    width: 100%;
    height: 100%;
    display: grid;
    grid-template-columns: repeat(var(--grid-size, 6), 1fr);
    grid-template-rows: repeat(var(--grid-size, 6), 1fr);
    gap: var(--board-gap, 4px);
}

.cell {
    background: #33415533;
    border: 1px solid var(--border);
    border-radius: 4px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    container-type: size;
}

/* --- GEOMETRIC BADGES --- */
.badge {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    pointer-events: none;
    transition: transform 0.2s ease;
}

.badge.standard,
.badge.flexible {
    width: 85%;
    height: 85%;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.4);
}

.badge.square {
    width: 85%;
    height: 85%;
    border-radius: 6px;
}

.badge.horizontal {
    width: 95%;
    height: 65%;
    border-radius: 6px;
}

.badge.vertical {
    width: 65%;
    height: 95%;
    border-radius: 6px;
}

.clue-number {
    font-size: 38cqi;
    font-weight: 900;
    line-height: 1;
    pointer-events: none;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* --- OVERLAYS & SETTINGS --- */
.win-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.98);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s;
}

.win-overlay.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.win-content {
    width: 100%;
    height: 100%;
    padding: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-evenly;
    text-align: center;
    box-sizing: border-box;
    gap: 8px;
}

.settings-group {
    width: 100%;
    text-align: left;
    margin-bottom: 5px;
}

.settings-group label {
    display: block;
    font-size: 10px;
    font-weight: 800;
    color: var(--text-dim);
    margin-bottom: 5px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

.settings-select {
    width: 100%;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 8px;
    font-size: 14px;
}

#win-image {
    max-width: 95%;
    max-height: 45%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.4);
    flex-shrink: 1;
}

.final-img {
    width: 140px;
    height: 140px;
    aspect-ratio: 1/1;
    object-fit: cover;
    border-radius: 50%;
    border: 4px solid var(--accent);
    box-shadow: 0 0 25px var(--accent);
    margin: 5px 0;
}

.collection-tabs {
    display: flex;
    width: 100%;
    gap: 6px;
    margin-bottom: 8px;
}

.col-btn {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 10px 0;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 800;
    cursor: pointer;
    text-transform: uppercase;
}

.col-btn.active {
    background: var(--success);
    color: white;
    border-color: #059669;
}

.difficulty-filter {
    display: flex;
    width: 100%;
    gap: 5px;
    margin-bottom: 8px;
}

.diff-btn {
    flex: 1;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-dim);
    padding: 7px 0;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    transition: all 0.2s;
}

.diff-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.difficulty-filter.hidden {
    display: none;
}

.tab-nav-container {
    display: flex;
    align-items: center;
    width: 100%;
    gap: 6px;
    margin-bottom: 8px;
    position: relative;
    z-index: 10;
}

.nav-arrow {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--accent);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: bold;
    user-select: none;
}

.lvl-tabs {
    display: flex;
    gap: 4px;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-behavior: smooth;
}

.lvl-tabs::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 0 0 75px;
    background: #0f172a;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 8px 0;
    border-radius: 6px;
    font-size: 10px;
    font-weight: bold;
    cursor: pointer;
}

.tab-btn.active {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    width: 100%;
    padding: 5px;
    overflow-y: auto;
}

.lvl-card {
    aspect-ratio: 1;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0f172a;
    border: 2px solid var(--border);
    border-radius: 50%;
    cursor: pointer;
    font-weight: bold;
    font-size: 0.85rem;
    color: var(--text);
    position: relative;
    flex-direction: column;
    padding-bottom: 5px;
}

.lvl-card.solved {
    background: var(--success);
    border-color: #059669;
}

.lvl-card.current {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.toolbar {
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    padding: 10px 15px;
    border-radius: 24px;
    margin-bottom: 20px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    padding: 5px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 600;
    transition: 0.2s;
}

.btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.btn:active,
.btn.active {
    background: transparent;
    color: var(--accent);
}

.win-btn {
    background: var(--accent);
    color: var(--bg);
    border: none;
    padding: 12px 15px;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

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

.win-btn.danger {
    background: var(--error);
    color: white;
    font-size: 10px;
}

.overlay-button-row {
    display: flex;
    gap: 10px;
    width: 100%;
    justify-content: center;
}

.star-rating {
    font-size: 2rem;
    display: flex;
    gap: 8px;
    margin: 0;
}

.star {
    color: var(--border);
}

.star.active {
    color: var(--accent);
    text-shadow: 0 0 15px var(--accent);
}

.card-stars {
    font-size: 8px;
    margin-top: 2px;
    color: var(--accent);
    letter-spacing: 1px;
}

.help-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    width: 100%;
    text-align: left;
}

.help-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-dim);
    padding: 5px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.badge-mini {
    width: 32px;
    height: 32px;
    background: #334155;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.badge-mini svg {
    width: 18px;
    height: 18px;
}

@keyframes lock-pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
        filter: brightness(1.2);
    }

    100% {
        transform: scale(1);
    }
}

.cell.locked-in {
    animation: lock-pulse 0.3s ease-out;
}

@keyframes forbidden-shake {

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

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

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

.board.error {
    animation: forbidden-shake 0.15s ease-in-out 2;
    border-color: var(--error);
}