/* ===========================
   Memory Flash — Components
   =========================== */

/* ---- Buttons ---- */
.btn {
    flex: 1;
    padding: 0.8rem;
    border: none;
    border-radius: 0.75rem;
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
}

.btn-secondary {
    flex: 0.7;
    padding: 0.7rem;
    background: var(--bg-key);
    color: var(--text-muted);
    border: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.8rem;
}

.btn-secondary:hover {
    background: var(--bg-key-hover);
    color: var(--text-secondary);
}

/* ---- Actions Row ---- */
.actions {
    display: flex;
    gap: 0.5rem;
}

/* ---- Keypad ---- */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    transition: opacity 0.3s ease;
}

.keypad.dimmed {
    opacity: 0.5;
}

.keypad.active .key {
    background: var(--bg-key-ready);
    box-shadow: 0 2px 8px var(--shadow-color);
}

.key {
    aspect-ratio: 1.4;
    background: var(--bg-key);
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.key:hover:not(:disabled) {
    background: var(--bg-key-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--shadow-color);
}

.key:active:not(:disabled) {
    background: var(--bg-key-active);
    transform: translateY(0);
}

.key.backspace {
    font-size: 1.25rem;
}

.key:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

/* ---- Mode Cards ---- */
.mode-cards {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
    max-width: 320px;
}

.mode-card {
    background: var(--bg-card);
    border: 2px solid rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    padding: 1rem 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.mode-card:hover {
    border-color: var(--accent);
    transform: translateY(-2px);
}

.mode-card.chill {
    border-left: 4px solid var(--success);
}

.mode-card.normal {
    border-left: 4px solid var(--accent);
}

.mode-card.hardcore {
    border-left: 4px solid var(--error);
}

.mode-card.zen {
    border-left: 4px solid #f59e0b;
}

.mode-card h3 {
    font-size: 1.1rem;
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mode-card p {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* ---- Modal (Game Over / Victory) ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 100;
}

[data-theme="light"] .modal-overlay,
[data-theme="light"] .level-picker-overlay {
    background: rgba(255, 255, 255, 0.85);
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: 1.25rem;
    padding: 1.5rem;
    text-align: center;
    max-width: 300px;
    width: 90%;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.visible .modal {
    transform: scale(1);
}

.modal h2 {
    font-size: 1.3rem;
    margin-bottom: 0.25rem;
}

.modal h2.success {
    color: var(--success);
}

.modal h2.fail {
    color: var(--error);
}

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

.modal .final-level {
    font-family: 'JetBrains Mono', monospace;
    font-size: 3rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin: 0.5rem 0;
}

.modal .best-label {
    color: var(--warning);
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.modal .stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.modal .stat-box {
    background: var(--bg-key);
    border-radius: 0.6rem;
    padding: 0.6rem;
}

.modal .stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.modal .stat-value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

.modal .btn {
    width: 100%;
}

.modal .btn+.btn {
    margin-top: 0.4rem;
}

/* ---- Settings / Shortcuts / Leaderboard Modal ---- */
.settings-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 200;
}

[data-theme="light"] .settings-modal-overlay {
    background: rgba(255, 255, 255, 0.85);
}

.settings-modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.settings-modal {
    background: var(--bg-card);
    border-radius: 1.25rem;
    padding: 1.5rem;
    width: 90%;
    max-width: 340px;
    border: 1px solid var(--border-color);
    box-shadow: 0 10px 40px var(--shadow-color);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.settings-modal-overlay.visible .settings-modal {
    transform: scale(1);
}

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

.settings-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

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

.settings-section {
    margin-bottom: 1.5rem;
}

.settings-section h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Settings Button */
.settings-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.settings-btn:hover {
    opacity: 1;
}

/* ---- Theme Switcher ---- */
.theme-switcher {
    display: flex;
    background: var(--bg-key);
    padding: 0.25rem;
    border-radius: 0.75rem;
    gap: 0.25rem;
}

.theme-option {
    flex: 1;
    border: none;
    background: none;
    padding: 0.5rem;
    border-radius: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.theme-option:hover {
    color: var(--text-primary);
}

.theme-option.active {
    background: var(--bg-card);
    color: var(--accent);
    box-shadow: 0 2px 8px var(--shadow-color);
}

/* ---- Settings Rows & Toggle ---- */
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.settings-row:last-child {
    border-bottom: none;
}

.settings-row .label {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.settings-row .sublabel {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-key);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.toggle.active {
    background: var(--accent);
}

.toggle::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
}

.toggle.active::after {
    transform: translateX(20px);
}

/* ---- Level Picker ---- */
.level-picker-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 150;
}

.level-picker-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.level-picker {
    background: var(--bg-card);
    border-radius: 1.25rem;
    padding: 1.25rem;
    max-width: 320px;
    width: 90%;
    max-height: 70vh;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.level-picker-overlay.visible .level-picker {
    transform: scale(1);
}

.level-picker h3 {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.level-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.5rem;
    max-height: 50vh;
    overflow-y: auto;
}

.level-option {
    aspect-ratio: 1;
    background: var(--bg-key);
    border: 2px solid transparent;
    border-radius: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
}

.level-option:hover {
    background: var(--bg-key-hover);
    border-color: var(--accent);
}

.level-option.selected {
    background: var(--accent);
    border-color: var(--accent);
}

.level-option .level-meta {
    font-size: 0.55rem;
    color: var(--text-muted);
    font-weight: 400;
}

.level-option.selected .level-meta {
    color: rgba(255, 255, 255, 0.7);
}

/* ---- Tabs (Leaderboard) ---- */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 0.8rem;
    color: var(--text-secondary);
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s ease;
}

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

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.score-filters {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    justify-content: center;
}

.filter-btn {
    background: var(--bg-key);
    border: 1px solid var(--border-color);
    padding: 0.3rem 0.8rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.leaderboard-list {
    max-height: 300px;
    overflow-y: auto;
}

.score-row {
    display: flex;
    justify-content: space-between;
    padding: 0.6rem;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

.score-row:nth-child(1) {
    color: #fbbf24;
    font-weight: bold;
}

.score-row:nth-child(2) {
    color: #94a3b8;
    font-weight: bold;
}

.score-row:nth-child(3) {
    color: #b45309;
    font-weight: bold;
}

.score-rank {
    width: 1.5rem;
    color: var(--text-muted);
}

.score-user {
    flex: 1;
}

.score-val {
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

/* ---- Auth Forms ---- */
.form-group {
    margin-bottom: 1rem;
}

.form-input {
    width: 100%;
    padding: 0.8rem;
    background: var(--bg-key);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    color: var(--text-primary);
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.auth-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
}

.auth-intro {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    text-align: center;
}

.auth-message {
    margin-top: 1rem;
    font-size: 0.85rem;
    text-align: center;
    min-height: 1.2rem;
}

.auth-message.error {
    color: var(--error);
}

.auth-message.success {
    color: var(--success);
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.avatar {
    width: 3rem;
    height: 3rem;
    background: var(--bg-key);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.profile-info h3 {
    margin: 0;
    font-size: 1.1rem;
}

.profile-email {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.input-row {
    display: flex;
    gap: 0.5rem;
}

/* ---- Zen Mode Review ---- */
.review-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.4rem 0.6rem;
    background: var(--bg-key);
    border-radius: 0.5rem;
    margin-bottom: 0.3rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.review-item.correct {
    border-left: 3px solid var(--success);
}

.review-item.wrong {
    border-left: 3px solid var(--error);
}

.review-item .result-icon {
    font-size: 0.9rem;
}

.review-list {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 1rem;
}

/* ---- Tutorial ---- */
.tutorial-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s ease;
}

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

.tutorial-slide {
    display: none;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 320px;
    animation: slideIn 0.4s ease;
}

.tutorial-slide.active {
    display: flex;
}

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

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

.tutorial-icon {
    font-size: 4rem;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

.tutorial-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.tutorial-text {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 2rem;
}

.tutorial-dots {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 2rem;
}

.tutorial-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bg-key);
    transition: all 0.3s ease;
}

.tutorial-dot.active {
    background: var(--accent);
    transform: scale(1.3);
}

/* ---- Shortcuts List ---- */
.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.key-badge {
    background: var(--bg-key);
    border: 1px solid var(--border-color);
    padding: 0.2rem 0.6rem;
    border-radius: 0.4rem;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    color: var(--text-primary);
    min-width: 2.5rem;
    text-align: center;
    box-shadow: 0 2px 0 var(--border-color);
}