/* --- General & Background --- */
body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-image: url('https://petyabouianov.com/images/fish.jpg');
    background-size: cover;
    background-position: center;
    margin: 0;
    min-height: 100vh;
    /* Safe area for notched phones */
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Optional macOS wallpaper class */
.mac-wallpaper {
    background: url('https://4kwallpapers.com/images/wallpapers/macos-big-sur-apple-layers-fluidic-colorful-wwdc-2020-5120x2880-1455.jpg');
    background-size: cover;
    background-position: center;
}

/* --- Glass Window Effect --- */
.mac-window {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
}

/* --- Playlist/Finder Table Styles --- */
.finder-table tr {
    transition: all 0.15s ease;
}

.finder-table tr:nth-child(even) {
    background-color: #f8fafc;
}

/* The Blue Highlight Hover Effect */
.finder-table tr:hover {
    background-color: #3b99fc;
    color: white !important;
}

.finder-table tr:hover td {
    color: white !important;
}

/* Force text colors to white on hover */
.finder-table tr:hover .text-gray-500,
.finder-table tr:hover .text-gray-400,
.finder-table tr:hover .text-blue-600,
.finder-table tr:hover .text-red-500,
.finder-table tr:hover .text-gray-800,
.finder-table tr:hover .text-blue-700,
.finder-table tr:hover .text-purple-700 {
    color: white !important;
}

/* Adjust badge background on hover */
.finder-table tr:hover .badge {
    background-color: rgba(255, 255, 255, 0.25) !important;
    color: white !important;
}

/* Search Input Focus Ring */
.search-input:focus {
    ring: 2px solid #3b99fc;
}

/* Utility Colors */
.japan-red-text {
    color: #bc002d;
}

/* --- Custom Animations --- */
@keyframes fadeIn {
    from {
        opacity: 0;

    }

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

.animate-fade-in {
    animation: fadeIn 0.4s ease forwards;
}

.studio-save-row {
    display: flex;
    justify-content: center;
}

.studio-save-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
    max-width: 100%;
    padding: 0.75rem 1.75rem;
    border: 0;
    border-radius: 9999px;
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    color: #fff;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1;
    box-shadow: 0 18px 32px -20px rgba(37, 99, 235, 0.85);
    cursor: pointer;
    transition: background 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease, transform 0.18s ease;
}

.studio-save-btn:hover {
    background: linear-gradient(180deg, #256fd9 0%, #1d4fb8 100%);
    box-shadow: 0 20px 36px -22px rgba(29, 79, 184, 0.9);
    filter: brightness(0.96);
}

.studio-save-btn:active {
    transform: scale(0.985);
}

.studio-save-btn:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.28);
    outline-offset: 3px;
}

/* =========================================================
   IMPROVEMENT 4: MOBILE-FIRST RESPONSIVE STYLES
   ========================================================= */

/* Mobile: Remove window chrome, go full-screen */
@media (max-width: 767px) {
    body {
        padding: 0 !important;
        /* Keep safe-area on sides/bottom */
        padding-left: env(safe-area-inset-left) !important;
        padding-right: env(safe-area-inset-right) !important;
    }

    .mac-window {
        max-width: 100% !important;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important;
        /* Dynamic viewport height for mobile browsers */
        border-radius: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }

    /* Toolbar: Stack vertically */
    #system-bar {
        padding: 0.75rem !important;
    }

    /* Hide table columns on mobile for cleaner look */
    .finder-table th:nth-child(3),
    .finder-table td:nth-child(3),
    .finder-table th:nth-child(4),
    .finder-table td:nth-child(4) {
        display: none;
    }

    /* Larger touch targets for buttons */
    .finder-table button {
        padding: 0.5rem 0.75rem;
        font-size: 0.875rem;
    }

    /* Quiz section: Larger question text */
    #question-word {
        font-size: 2.25rem !important;
        line-height: 1.3 !important;
        word-break: break-word;
    }

    /* Answer input: Slightly smaller on mobile */
    #answer-input {
        font-size: 1.5rem !important;
        padding: 0.75rem !important;
    }

    /* Mic button: Ensure good size */
    #mic-btn {
        width: 5rem;
        height: 5rem;
    }

    /* Progress bar margins */
    #quiz-section .w-full.h-1\.5 {
        margin-bottom: 1.5rem;
    }

    /* Quit button */
    #quiz-section button:last-child {
        margin-top: 1.5rem;
    }
}

/* Extra small screens (< 375px) */
@media (max-width: 374px) {
    #question-word {
        font-size: 1.75rem !important;
    }

    #answer-input {
        font-size: 1.25rem !important;
    }

    #system-bar button,
    #system-bar select {
        font-size: 0.75rem;
        padding: 0.375rem 0.75rem;
    }

    .studio-save-btn {
        min-width: 180px;
        padding: 0.7rem 1.35rem;
        font-size: 0.9rem;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #quiz-section {
        padding: 1rem !important;
    }

    #question-word {
        font-size: 2rem !important;
        margin-bottom: 0.5rem !important;
    }

    #hearts-container {
        margin-bottom: 0.5rem !important;
    }

    .w-full.h-1\.5 {
        margin-bottom: 0.5rem !important;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 1024px) {
    .mac-window {
        max-width: 95% !important;
        height: 90vh !important;
    }
}

/* =========================================================
   DARK MODE
   ========================================================= */

body.dark {
    background-color: #0f0f0f;
    background-image: none;
}

body.dark .mac-window {
    background: rgba(30, 30, 30, 0.97);
    border-color: rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
}

/* Header bar */
body.dark .mac-window>div:first-child {
    background: linear-gradient(to bottom, #2a2a2a, #222) !important;
    border-bottom-color: #333 !important;
}

body.dark .mac-window>div:first-child .text-gray-600 {
    color: #aaa !important;
}

/* Toolbar / System bar */
body.dark #system-bar {
    background: rgba(25, 25, 25, 0.9) !important;
    border-bottom-color: #333 !important;
}

body.dark #system-bar button {
    background: #2a2a2a !important;
    border-color: #444 !important;
    color: #ccc !important;
}

body.dark #system-bar button:hover {
    background: #333 !important;
}

body.dark #system-bar select {
    background: #2a2a2a !important;
    border-color: #444 !important;
    color: #ccc !important;
}

body.dark #list-search {
    background: #2a2a2a !important;
    border-color: #444 !important;
    color: #ddd !important;
}

body.dark #list-search::placeholder {
    color: #666 !important;
}

/* Content area */
body.dark .bg-white,
body.dark #select-section .flex-1 {
    background-color: #1a1a1a !important;
}

/* Table */
body.dark .finder-table thead {
    background: #1e1e1e !important;
    border-bottom-color: #333 !important;
}

body.dark .finder-table th {
    color: #888 !important;
}

body.dark .finder-table tr {
    border-bottom-color: #2a2a2a !important;
}

body.dark .finder-table tr:nth-child(even) {
    background-color: #1e1e1e !important;
}

body.dark .finder-table tr:hover {
    background-color: #2563eb !important;
}

body.dark .finder-table td {
    color: #ccc !important;
}

body.dark .finder-table .text-gray-800 {
    color: #ddd !important;
}

body.dark .finder-table .text-gray-500,
body.dark .finder-table .text-gray-400 {
    color: #888 !important;
}

/* Footer */
body.dark .bg-gray-50 {
    background-color: #1a1a1a !important;
}

body.dark .border-gray-200,
body.dark .border-gray-300 {
    border-color: #333 !important;
}

body.dark .text-gray-400 {
    color: #666 !important;
}

body.dark .text-gray-500 {
    color: #888 !important;
}

body.dark .text-gray-600 {
    color: #999 !important;
}

body.dark .text-gray-700 {
    color: #bbb !important;
}

body.dark .text-gray-800 {
    color: #ddd !important;
}

/* Setup section */
body.dark #setup-section {
    background: #1a1a1a !important;
}

body.dark #setup-section .bg-gray-50 {
    background: #222 !important;
}

body.dark #setup-section input,
body.dark #setup-section textarea {
    background: #2a2a2a !important;
    border-color: #444 !important;
    color: #ddd !important;
}

/* Quiz section */
body.dark #quiz-section {
    background: #1a1a1a !important;
}

body.dark #question-word {
    color: #eee !important;
}

body.dark #answer-input {
    background: transparent !important;
    border-bottom-color: #555 !important;
    color: #eee !important;
}

body.dark #answer-input:focus {
    border-bottom-color: #3b82f6 !important;
}

body.dark .progress-bar-bg,
body.dark .bg-gray-100 {
    background-color: #2a2a2a !important;
}

/* Mic button dark */
body.dark #mic-btn {
    background: #2a2a2a !important;
    border-color: #444 !important;
}

/* Toast dark */
body.dark #toast-container div {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

/* =========================================================
   NEW FEATURE STYLES: Results, Stats, Multiple Choice
   ========================================================= */

/* --- Results Overlay --- */
.studio-results-overlay {
    position: absolute;
    inset: 0;
    background: white;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    overflow-y: auto;
    padding: 2rem;
    animation: fadeIn 0.4s ease forwards;
}

body.dark .studio-results-overlay {
    background: #1a1a1a !important;
    color: #ddd;
}

.results-score {
    font-size: 3.5rem;
    font-weight: 200;
    line-height: 1;
    letter-spacing: -0.02em;
}

.results-wrong-list {
    width: 100%;
    max-width: 500px;
    margin-top: 1.5rem;
}

.results-wrong-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e5e7eb;
    font-size: 0.95rem;
}

body.dark .results-wrong-item {
    border-bottom-color: #333;
}

.results-wrong-item .wrong-answer {
    color: #ef4444;
    font-weight: 600;
}

.results-wrong-item .correct-answer {
    color: #22c55e;
    font-weight: 600;
}

/* --- Stats Overlay --- */
.studio-stats-overlay {
    position: absolute;
    inset: 0;
    background: white;
    z-index: 30;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    animation: fadeIn 0.3s ease forwards;
}

body.dark .studio-stats-overlay {
    background: #1a1a1a !important;
    color: #ddd;
}

.stats-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

body.dark .stats-header {
    border-bottom-color: #333;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    padding: 1.5rem;
}

.stat-card {
    padding: 1rem 0.5rem;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 200;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.stat-card .stat-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #8e8e93;
    font-weight: 500;
    margin-top: 0.15rem;
}

.stats-section {
    padding: 0 1.5rem 1.5rem;
}

.stats-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #8e8e93;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.stats-table {
    width: 100%;
    font-size: 0.85rem;
    border-collapse: collapse;
}

.stats-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #9ca3af;
    font-weight: 600;
    border-bottom: 1px solid #e5e7eb;
}

body.dark .stats-table th {
    border-bottom-color: #333;
}

.stats-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
}

body.dark .stats-table td {
    border-bottom-color: #2a2a2a;
}

.mastery-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    background: #e5e7eb;
    margin-top: 0.5rem;
}

body.dark .mastery-bar {
    background: #333;
}

.mastery-bar .bar-mastered {
    background: #22c55e;
}

.mastery-bar .bar-learning {
    background: #eab308;
}

.mastery-bar .bar-new {
    background: #d1d5db;
}

body.dark .mastery-bar .bar-new {
    background: #555;
}

/* Session history items */
.session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.85rem;
}

body.dark .session-item {
    border-bottom-color: #2a2a2a;
}

/* Sparkline */
.sparkline-container {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    height: 30px;
    margin-top: 0.5rem;
}

.sparkline-bar {
    flex: 1;
    min-width: 4px;
    max-width: 16px;
    border-radius: 2px 2px 0 0;
    transition: height 0.3s ease;
}

/* --- Multiple Choice Buttons --- */
.choice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

.choice-btn {
    padding: 1rem 0.75rem;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    background: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
    word-break: break-word;
}

body.dark .choice-btn {
    background: #2a2a2a;
    border-color: #444;
    color: #ddd;
}

.choice-btn:hover {
    border-color: #3b82f6;
    background: #eff6ff;
}

body.dark .choice-btn:hover {
    background: #1e3a5f;
    border-color: #3b82f6;
}

.choice-btn.correct {
    border-color: #22c55e !important;
    background: #dcfce7 !important;
    color: #166534 !important;
}

body.dark .choice-btn.correct {
    background: #14532d !important;
    color: #86efac !important;
}

.choice-btn.wrong {
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
    color: #991b1b !important;
}

body.dark .choice-btn.wrong {
    background: #450a0a !important;
    color: #fca5a5 !important;
}

.choice-btn:disabled {
    cursor: default;
    opacity: 0.7;
}

/* Dark mode toggle switch */
.dark-mode-switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    cursor: pointer;
}

.dark-mode-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.dark-mode-switch .slider {
    position: absolute;
    inset: 0;
    background: #d1d5db;
    border-radius: 18px;
    transition: background 0.25s ease;
}

.dark-mode-switch .slider::before {
    content: '';
    position: absolute;
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background: white;
    border-radius: 50%;
    transition: transform 0.25s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.dark-mode-switch input:checked+.slider {
    background: #3b82f6;
}

.dark-mode-switch input:checked+.slider::before {
    transform: translateX(14px);
}

/* Header icon button */
.header-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #9ca3af;
    font-size: 0.85rem;
    padding: 2px;
    transition: color 0.2s ease;
    line-height: 1;
}

.header-icon-btn:hover {
    color: #3b82f6;
}

body.dark .header-icon-btn {
    color: #666;
}

body.dark .header-icon-btn:hover {
    color: #60a5fa;
}

@media (max-width: 767px) {
    .choice-grid {
        grid-template-columns: 1fr;
    }

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