/* Base styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header styles */
header {
    background-color: #fff;
    border-bottom: 1px solid #e0e0e0;
    padding: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

.controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 1;
}

.control-element {
    padding: 0.1rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 1rem;
    background-color: #fff;
    font-size: 0.8rem;
    min-height: 2rem;
    line-height: 1.2;
    cursor: pointer;
    box-sizing: border-box;
    transition: background-color 0.2s;
}

.control-element:hover {
    background-color: #f5f5f5;
}

#deck-selector.control-element {
    min-width: 40px;
    max-width: 150px;
}

#deck-selector.control-element:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}

#deck-selector.control-element option {
    padding: 0.25rem;
}

/* Controls styles */
.controls {
    display: flex;
    gap: 1rem;
    align-items: center;
}

#review-toggles {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Progress bar styles */
#review-progress-bar {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    height: 1.5rem;
    width: 150px;
    border-radius: 1rem;
    overflow: hidden;
    border: 0px solid #ccc;
}

.progress-segment {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    transition: opacity 0.2s;
}

.progress-segment:first-child {
    padding-left: 0.25rem;
}

.progress-segment:last-child {
    padding-right: 0.25rem;
}

.progress-segment:hover {
    opacity: 0.8;
}

.segment-number {
    color: white;
    font-size: 10px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    pointer-events: none;
}

#filter-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Filter dropdown styles */
.filter-dropdown {
    position: relative;
    display: inline-block;
}

.filter-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    width: auto;
    min-width: 200px;
    z-index: 1000;
    padding: 0;
}

.filter-menu-columns {
    display: block;
    gap: 0;
    min-height: auto;
    max-height: none;
    overflow-y: visible;
}

.filter-column {
    display: block;
    min-width: 0;
    padding: 0;
    margin-bottom: 0.5rem;
    border-right: none;
}

.filter-column:last-child {
    margin-bottom: 0;
}

.filter-column-header {
    font-weight: 600;
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 0.5rem;
    display: inline-block;
    vertical-align: middle;
}

.filter-column-content {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    max-height: none;
    overflow-y: visible;
    vertical-align: middle;
}

/* Mobile responsive: stack columns vertically on small screens */
@media (max-width: 600px) {
    .filter-menu {
        min-width: 250px;
    }

    .filter-menu-columns {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .filter-column {
        min-width: auto; /* Allow full width on mobile */
        border-right: none;
        border-bottom: 1px solid #eee;
    }

    .filter-column:last-child {
        border-bottom: none;
    }
}

.filter-option {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem;
    cursor: pointer;
    border-radius: 3px;
    transition: background-color 0.2s;
    white-space: nowrap;
}

.filter-option:hover {
    background-color: #f5f5f5;
}

/* Tag badge styling in filters */
.filter-option .tag-badge {
    opacity: 0.6;
    background-color: #e0e0e0 !important; /* Neutral gray for unselected */
    transition: opacity 0.2s;
}

.filter-option.selected .tag-badge {
    opacity: 1;
}

/* Apply specific colors for selected tags */
.filter-option.selected .tag-daily-life { background-color: #C5D8E8 !important; }
.filter-option.selected .tag-descriptions { background-color: #B8EBE5 !important; }
.filter-option.selected .tag-grammar { background-color: #E4CDEE !important; }
.filter-option.selected .tag-location { background-color: #FFD8C3 !important; }
.filter-option.selected .tag-objects { background-color: #EDE2D4 !important; }
.filter-option.selected .tag-people { background-color: #FFD6DE !important; }
.filter-option.selected .tag-numbers { background-color: #FBD6E3 !important; }
.filter-option.selected .tag-time { background-color: #C4DEF8 !important; }
.filter-option.selected .tag-nature { background-color: #C8E8C8 !important; }
.filter-option.selected .tag-expressions { background-color: #F7E98E !important; }

/* HSK badge styling */
.hsk-badge {
    display: inline-block;
    font-size: 0.5rem;
    font-weight: 500;
    padding: 0.1rem 0.4rem;
    border-radius: 1.0rem;
    color: #333;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    background-color: #e0e0e0; /* Neutral gray for unselected */
    transition: background-color 0.2s;
}

.filter-option.selected .hsk-badge {
    background-color: #007bff; /* Blue for selected HSK levels */
    color: white;
}

.deck-status {
    font-size: 0.9rem;
    color: #666;
    font-style: italic;
    min-height: 1.2rem;
}

.deck-status.loading::before {
    content: "Loading deck...";
}

.deck-status.error {
    color: #d32f2f;
}

.deck-status.success {
    color: #2e7d32;
}

/* Navigation styles */
nav {
    display: flex;
    gap: 0.15rem;
    flex-shrink: 1;
}

.tab {
    padding: 0 0.6rem;
    border: 2px solid #ccc;
    background-color: #f9f9f9;
    border-radius: 0.7rem;
    cursor: pointer;
    transition: background-color 0.2s;
    font-size: 0.7rem;
    font-weight: bold;
    height: 1.5rem;
    display: flex;
    align-items: center;
}

.tab:hover {
    background-color: #e9e9e9;
}

.tab.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

/* Main content styles */
main {
    padding: 0;
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.view {
    background-color: #fff;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

h2 {
    margin-bottom: 1rem;
    color: #666;
    flex-shrink: 0;
}

/* Error banner styles */
.error-banner {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    padding: 1rem;
    margin: 1rem;
    display: none;
}

.error-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.error-message {
    color: #721c24;
    flex: 1;
}

.retry-btn {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
}

.retry-btn:hover {
    background-color: #c82333;
}

/* Validation banner styles */
.validation-banner {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    padding: 1rem;
    margin: 1rem;
    display: none;
}

.validation-content {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.validation-message {
    color: #856404;
    flex: 1;
    line-height: 1.4;
}

/* Utility classes */
.is-hidden {
    display: none !important;
}

.is-visible {
    display: block !important;
}

/* Card review styles */
#card-table-wrapper {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

#card-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

#card-table {
    border-collapse: collapse;
    table-layout: auto;
    margin: 0;
    border-spacing: 0.5rem;
    --scale-factor: 1;
    max-width: 1200px;
}

#card-table td {
    padding: 0.25rem 0.75rem;
/*    border: 1px solid #ddd; */
    text-align: center;
    vertical-align: middle;
    font-size: calc(1.5rem * var(--scale-factor));
}

#card-table .row-hanzi td {
    font-size: calc(4rem * var(--scale-factor));
    white-space: nowrap;
/*    font-weight: bold; */
}

#card-table .row-pinyin td {
    font-size: calc(1.5rem * var(--scale-factor));
    color: #888;
}

#card-table .row-def-words td {
    font-size: calc(1rem * var(--scale-factor));
    color: #aaa;
}

/* Table cells are now interactive for hover detection on padding */

/* Make word text spans interactive */
.word-text {
  pointer-events: auto;
  cursor: pointer;
}

/* Make table rows interactive for whole expression */
#card-table tr {
  cursor: pointer;
}

/* Hover effect for whole expression (shows on row padding/space) */
#card-table tr.space-hover {
  background-color: #f0f000;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.8);
}

/* Hover effect for individual words */
.word-text.word-hover {
  background-color: #f0f000;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.8);
}

/* English section styles */
#card-def {
    text-align: center;
    margin: 0 auto 2rem auto;
    max-width: 1200px;
    padding: 1rem 0.75rem;
    font-size: calc(3rem * var(--def-scale-factor));
    --def-scale-factor: 1;
}

#card-def .pos-prefix {
    font-size: calc(1.3rem * var(--def-scale-factor));
    color: #888;
    font-style: italic;
    margin-right: 0.5em;
}

#card-def .def-text {
    color: #333;
}

/* Flip and mode visibility */
/* Hanzi First: front hanzi only */
#card-table:not(.flipped).mode-hanzi-first .row-pinyin,
#card-table:not(.flipped).mode-hanzi-first .row-def-words {
    visibility: hidden;
}
#card-def:not(.flipped).mode-hanzi-first {
    visibility: hidden;
}

/* Listening: front audio only */
#card-table:not(.flipped).mode-listening .row-hanzi,
#card-table:not(.flipped).mode-listening .row-pinyin,
#card-table:not(.flipped).mode-listening .row-def-words {
    visibility: hidden;
}
#card-def:not(.flipped).mode-listening {
    visibility: hidden;
}

/* Meaning to Chinese: front def only */
#card-table:not(.flipped).mode-meaning-to-chinese .row-hanzi,
#card-table:not(.flipped).mode-meaning-to-chinese .row-pinyin,
#card-table:not(.flipped).mode-meaning-to-chinese .row-def-words {
    visibility: hidden;
}

/* Pronunciation: front hanzi only */
#card-table:not(.flipped).mode-pronunciation .row-pinyin,
#card-table:not(.flipped).mode-pronunciation .row-def-words,
#card-table:not(.flipped).mode-pronunciation .row-audio {
    visibility: hidden;
}
#card-def:not(.flipped).mode-pronunciation {
    visibility: hidden;
}

/* Ensure audio row is visible when flipped in all modes */
#card-table.flipped .row-audio {
    visibility: visible;
    pointer-events: auto;
}

/* Tone color classes - unflipped: all black */
#card-table:not(.flipped) .tone-1,
#card-table:not(.flipped) .tone-2,
#card-table:not(.flipped) .tone-3,
#card-table:not(.flipped) .tone-4,
#card-table:not(.flipped) .tone-5 {
    color: rgb(0, 0, 0);
}

/* Tone color classes - flipped: apply tone colors */
#card-table.flipped .tone-1 {
    color: rgb(255, 0, 0);
}
#card-table.flipped .tone-2 {
    color: rgb(208, 144, 0);
}
#card-table.flipped .tone-3 {
    color: rgb(0, 160, 0);
}
#card-table.flipped .tone-4 {
    color: rgb(0, 68, 255);
}
#card-table.flipped .tone-5 {
    color: rgb(0, 0, 0);
}

/* Card buttons */
#card-buttons {
    display: none;
    justify-content: center;
    gap: clamp(1rem, 3vw, 2rem);
    flex-direction: row;
}

#btn-incorrect {
    background-color: #dc3545;
    color: white;
    border: none;
    padding: clamp(0.75rem, 2vw, 1.5rem) clamp(1.5rem, 4vw, 2.5rem);
    border-radius: 8px;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    cursor: pointer;
    transition: background-color 0.2s;
}

#btn-incorrect:hover {
    background-color: #c82333;
}

#btn-correct {
    background-color: #28a745;
    color: white;
    border: none;
    padding: clamp(0.75rem, 2vw, 1.5rem) clamp(1.5rem, 4vw, 2.5rem);
    border-radius: 8px;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    cursor: pointer;
    transition: background-color 0.2s;
}

#btn-correct:hover {
    background-color: #218838;
}

/* System message styles */
.system-message {
    text-align: center;
    padding: 2rem 1rem;
    font-size: 1.2rem;
    font-weight: bold;
    color: #666;
    background-color: #f9f9f9;
    border-radius: 8px;
    margin: 1rem auto;
    max-width: 600px;
    width: 100%;
}

@media (max-width: 350px) {
    header {
        flex-direction: column;
        align-items: stretch;
    }

    .controls {
        justify-content: space-between;
    }

    nav {
        justify-content: center;
    }
}
/* Start screen styles */
.start-screen {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
    max-width: 600px;
    margin: 0 auto;
}

.start-screen > .start-info {
    margin-bottom: 1.5rem;
    font-size: 1.1rem;
    line-height: 1.4;
}

.start-info {
    color: #666;
}

.start-info:first-child {
    font-size: 1.3rem;
    font-weight: 600;
    color: #333;
}

.start-button {
    background-color: #28a745;
    color: white;
    border: none;
    padding: 1rem 2rem;
    border-radius: 8px;
    font-size: 1.2rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
    margin-top: 1rem;
}

.start-button:hover {
    background-color: #218838;
}

.start-button:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}
/* Responsive design */
@media (max-width: 499px) {
    :root {
        --scale-factor: 0.65;
        --def-scale-factor: 0.5;
    }

    main {
        padding: 0;
    }

    .view {
        padding: 1rem;
    }

    #card-table td {
        padding: 0.5rem;
    }


    #card-def {
        padding: 0.75rem 0.5rem;
    }

    #card-buttons {
        gap: 1rem;
    }

    #btn-incorrect, #btn-correct {
        padding: 0.75rem 1.5rem;
        font-size: 1rem;
    }

    /* Progress bar responsive */
        #review-progress-bar {
            width: 120px; /* Reduce width further on mobile for better fit */
        }
    
        .segment-number {
            font-size: 8px; /* Reduce font size to keep numbers visible on narrow screens */
        }
    
    /* App-level loading (global, outside views) */
    .app-loading-section {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: rgba(255, 255, 255, 0.95);
        z-index: 1000;
    }
    
    /* Review sections */
    .deck-message-section {
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 150px;
        width: 100%;
    }
    
    .card-interaction-section {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        min-height: 300px;
    }
    
    /* Loading progress bar styles */
    .loading-progress-container {
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 2rem 1rem;
        width: 100%;
    }
    
    .loading-progress-bar {
        position: relative;
        width: 100%;
        max-width: 400px;
        height: 24px;
        background-color: #e0e0e0;
        border-radius: 12px;
        overflow: hidden;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    
    .loading-progress-fill {
        height: 100%;
        background: linear-gradient(90deg, #007bff, #28a745);
        border-radius: 12px;
        transition: width 0.3s ease;
        width: 0%;
    }
    
    .loading-progress-text {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        color: #333;
        font-size: 0.9rem;
        font-weight: 500;
        text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
        pointer-events: none;
        white-space: nowrap;
    }
    
    /* Responsive loading progress bar */
    @media (max-width: 499px) {
        .loading-progress-container {
            padding: 1.5rem 0.5rem;
        }
    
        .loading-progress-bar {
            max-width: 300px;
            height: 20px;
        }
    
        .loading-progress-text {
            font-size: 0.8rem;
        }
    }
    
    /* Mobile responsive for start screen */
    .start-screen {
        padding: 1rem;
    }

    .start-screen > .start-info {
        margin-bottom: 1rem;
        font-size: 1rem;
    }

    .start-info:first-child {
        font-size: 1.1rem;
    }

    .start-button {
        padding: 0.875rem 1.5rem;
        font-size: 1.1rem;
    }
}

/* Play audio button styles */
.play-audio-btn {
    background-color: transparent;
    color: #007bff;
    border: 1px solid #6c757da0; /* Grey outline instead of blue */
    padding: 0.6rem; /* Increased padding for larger size */
    border-radius: 50%;
    font-size: 1rem; /* 50% bigger than 1rem */
    cursor: pointer;
    transition: all 0.2s ease;
    width: 1.5rem; /* 50% bigger than 2rem */
    height: 1.5rem; /* 50% bigger than 2rem */
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.play-audio-btn:hover {
    background-color: #007bff;
    color: white;
    transform: scale(1.05);
}

.play-audio-btn:active {
    transform: scale(0.98);
}

#card-table .play-audio-btn.playing {
    background-color: #28a745 !important;
    color: white !important;
    border-color: #28a745 !important;
}

/* Card table audio row styles */
#card-table .row-audio {
    height: 2.5rem;
    display: none;
    pointer-events: none;
}

#card-table.flipped .row-audio {
    display: table-row;
    pointer-events: auto;
}

#card-table .audio-cell {
    text-align: center;
    padding: 0.5rem 0;
}

#card-table .play-audio-btn {
    font-size: 3rem;
    background-color: transparent;
    color: #007bff;
    border: 1px solid #6c757da0; /* Grey outline instead of blue */
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 9rem;
    height: auto;
}

#card-table .play-audio-btn:hover {
    background-color: #007bff;
    color: white;
    transform: scale(1.05);
}

#card-table .play-audio-btn:active {
    transform: scale(0.98);
}

/* Stats view styles */
.stats-controls {
    margin-bottom: 1rem;
    display: flex;
    gap: 1rem;
}

#stats-direction-toggle,
#reset-stats-btn {
    padding: 0.5rem 1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: 1rem;
    cursor: pointer;
    min-width: 50px;
}

#reset-stats-btn {
    background-color: #dc3545;
    color: white;
    border-color: #dc3545;
    margin-left: auto;
}

#reset-stats-btn:hover {
    background-color: #c82333;
}

.stats-metrics {
    margin-bottom: 2rem;
}

.stats-metrics p {
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.stats-histogram {
    margin-bottom: 2rem;
}

.stats-histogram h3 {
    margin-bottom: 1rem;
    color: #666;
}


.stats-top-lists {
    display: flex;
    gap: 2rem;
}

.top-best, .top-worst {
    flex: 1;
}

.top-best h3, .top-worst h3 {
    margin-bottom: 1rem;
    color: #666;
}

.top-best ul, .top-worst ul {
    list-style: none;
    padding: 0;
}

.top-best li, .top-worst li {
    padding: 0.5rem;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}

@media (max-width: 768px) {
    .stats-top-lists {
        flex-direction: column;
        gap: 1rem;
    }
}

.stats-due-timeline,
.stats-overall-accuracy,
.stats-streak-histogram,
.stats-streak-records {
    margin-bottom: 2rem;
}

.stats-due-timeline h3,
.stats-overall-accuracy h3,
.stats-streak-histogram h3,
.stats-streak-records h3 {
    margin-bottom: 1rem;
    color: #666;
}

.stats-streak-records p {
    margin-bottom: 0.5rem;
    font-size: 1rem;
}

/* New: modern stats layout */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.metric-card {
    background: linear-gradient(180deg, #ffffff, #fbfbff);
    border: 1px solid #eceff5;
    border-radius: 8px;
    padding: 0.9rem;
    box-shadow: 0 2px 6px rgba(20, 30, 60, 0.03);
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.metric-card.wide {
    grid-column: span 2;
}

.metric-title {
    font-size: 0.85rem;
    color: #6b7280;
}

.metric-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: #111827;
}

.metric-value.large {
    font-size: 1.6rem;
    color: #0b66ff;
}


/* Panels grid */
.panel-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: 2rem;
}

/* Panel card */
.panel {
    background: #fff;
    border: 1px solid #eef2f6;
    border-radius: 8px;
    padding: 0rem;
    box-shadow: 0 1px 3px rgba(20,30,60,0.04);
}

.panel h3 {
    margin-bottom: 0.2rem;
    color: #374151;
}

/* Small lists */
.small-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 220px;
    overflow: auto;
}

.small-item {
    display: flex;
    gap: 0.2rem;
    align-items: center;
    padding: 0.1rem 0;
    border-bottom: 1px dashed #f1f5f9;
    font-size: 0.92rem;
}

.mini-hanzi {
    font-size: 1.1rem;
    min-width: 4.2rem;
    color: #111827;
    font-weight: 600;
}

.mini-pinyin {
    font-size: 0.9rem;
    color: #888;
    min-width: 4rem;
}

.mini-def {
    color: #111827;
    font-size: 1rem;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mini-stats {
    font-weight: 700;
    color: #111827;
    min-width: 6rem;
    text-align: right;
}

/* Streak records styling */
.stats-records p {
    margin: 0.4rem 0;
}

/* Responsive tweaks */
@media (max-width: 640px) {
    .metric-card.wide { grid-column: span 1; }
    .panel-grid { grid-template-columns: 1fr; }
}

/* Search view styles */
.search-inputs {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-shrink: 0;
}

#search-label {
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    font-weight: 500;
    min-width: 70px;
}

.search-inputs input {
    flex: 1;
    padding: clamp(0.4rem, 1vw, 0.6rem);
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
}

#search-type-toggle {
    padding: clamp(0.4rem, 1vw, 0.6rem) clamp(0.8rem, 2vw, 1.2rem);
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: clamp(0.9rem, 2vw, 1.2rem);
    cursor: pointer;
    transition: background-color 0.2s;
}

#search-type-toggle:hover {
    background-color: #e9e9e9;
}

#search-results {
    flex: 1;
    overflow-y: auto;
}

.search-results-list {
    height: 100%;
    overflow-y: auto;
}

.search-result {
    padding: 0.25rem;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    transition: background-color 0.2s;
    display: grid;
    grid-template-columns: auto auto 1fr 2fr;
    align-items: center;
    gap: 0.5rem;
}

.search-result.no-tags {
    grid-template-columns: 300px 1fr auto;
}

.search-result:nth-child(even) {
    background-color: #f9f9f9;
}

.search-result:hover {
/*    background-color: #e9e9e9;
*/
}

.search-result-tags {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin-right: 1rem;
    align-items: center;
    width: fit-content;
}

.result-hanzi-pinyin {
    /* width: 300px; */
    display: flex;
    flex-direction: column;
    align-items: center;
}

.result-def-column {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-align: left;
}

.search-result-buttons {
    display: inline-flex;
    flex-direction: column;
    gap: 0.25rem;
    justify-content: center;
    align-items: center;
}

.dict-btn {
    background-color: #4dabf730;
    color: #0033ff;
    padding: 0.1rem 0.4rem;
    border-radius: 1.0rem;
    font-weight: 900;
    font-size: 0.5rem;
    border: none;
    cursor: pointer;
    width: fit-content;
    transition: background-color 0.2s;
}

.dict-btn:hover {
    background-color: #4dabf7;
    color: white;
}

.tag-badge {
    display: inline-block;
    font-size: 0.5rem;
    font-weight: 500;
    padding: 0.1rem 0.4rem;
    border-radius: 1.0rem;
    color: #333;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.tag-daily-life { background-color: #C5D8E8; }
.tag-descriptions { background-color: #B8EBE5; }
.tag-grammar { background-color: #E4CDEE; }
.tag-location { background-color: #FFD8C3; }
.tag-objects { background-color: #EDE2D4; }
.tag-people { background-color: #FFD6DE; }
.tag-numbers { background-color: #FBD6E3; }
.tag-time { background-color: #C4DEF8; }
.tag-nature { background-color: #C8E8C8; }
.tag-expressions { background-color: #F7E98E; }

.result-hanzi {
    font-size: clamp(1rem, 3vw, 2rem);
    margin-bottom: 0.1rem;
}

.hanzi-char {
    cursor: pointer;
}

.hanzi-char:hover {
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.8);
    background-color: #f0f000;
}

.result-pinyin {
    font-size: clamp(0.8rem, 2vw, 1.2rem);
    color: #888;
    margin-bottom: 0.1rem;
}

.result-def {
    font-size: clamp(0.9rem, 2.5vw, 1.5rem);
    color: #666;
    text-align: left;
}



.result-pos {
    font-size: clamp(0.7rem, 1.5vw, 0.9rem);
    color: #999;
    font-style: italic;
    min-width: 3rem;
    text-align: left;
}

@media (min-width: 1200px) {
    .view {
        padding: clamp(2rem, 4vw, 3rem);
    }
}

@media (max-width: 768px) {
    .search-inputs {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    #search-label {
        min-width: auto;
    }
}
/* Hide buttons when system message is active */
.system-message.active ~ #card-buttons {
    display: none !important;
}

/* Hamburger button styles */
.hamburger-btn {
    background: none    ;
    border: 0px solid #ccc;
    border-radius: 0.7rem;
    padding: 0 0;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s;
    min-width: 2rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hamburger-btn:hover {
    background-color: #f5f5f5;
}

.hamburger-btn:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-overlay.is-hidden {
    display: none;
}

.modal-content {
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: background-color 0.2s;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close-btn:hover {
    background-color: #f5f5f5;
}

.modal-body {
    padding: 0.75rem;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

@media (min-width: 601px) {
    .modal-body {
        grid-template-columns: 1fr 1fr;
    }
    .modal-section.full-width {
        grid-column: 1 / -1;
    }
}

.modal-section {
    margin-bottom: 0;
}

.modal-section h3 {
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.modal-section label {
    display: inline-block;
    margin-right: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #888;
    /* text-transform: uppercase; */
    /* letter-spacing: 0.5px; */
}

.modal-section.inline-control {
    display: flex;
    align-items: center;
}

.modal-section.inline-control .modal-control {
    flex: 1;
    width: auto;
}

.modal-control {
    padding: 0.1rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    font-size: 0.9rem;
    width: 100%;
    cursor: pointer;
    transition: border-color 0.2s;
}

.modal-control:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.modal-control:hover {
    border-color: #999;
}

/* Mode selector */
.mode-selector {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 100%;
}

.mode-option {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    background-color: #fafafa;
    flex-wrap: nowrap;
    min-width: fit-content;
    width: 100%;
    white-space: nowrap;
    line-height: 1.2;
}

.mode-option > * {
    display: inline-block !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
}

.mode-option .mode-details {
    display: inline-block !important;
    vertical-align: middle !important;
    white-space: nowrap !important;
    padding-left: 0.2rem;
}

.mode-option:hover {
    background-color: #f0f0f0;
    border-color: #ccc;
}

.mode-option input[type="radio"] {
    margin: 0;
    width: 1rem;
    height: 1rem;
    vertical-align: middle;
    flex-shrink: 0;
}

.mode-icon {
    font-size: 1.3rem;
    min-width: 1.3rem;
    text-align: center;
    width: 1.3rem;
    flex-shrink: 0;
    display: inline-block;
    line-height: 1;
    margin: 0;
    padding: 0;
    vertical-align: middle;
}

.mode-details {
    flex: 1;
    min-width: 0;
    white-space: normal;
    min-width: 200px;
}

.mode-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    min-width: fit-content;
}

.mode-description {
    font-size: 0.8rem;
    color: #666;
    line-height: 1.2;
}

/* Settings controls */
.settings-controls {
    display: flex;
    flex-direction: column;
}

.setting-item {
    display: flex;
    align-items: center;
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.setting-item:hover {
    background-color: #f8f9fa;
}

.setting-item input[type="checkbox"] {
    width: 0.7rem;
    height: 0.7rem;
    margin: 0;
}

.setting-item span {
    font-size: 0.8rem;
    user-select: none;
    vertical-align: top;
    font-weight: 500;
    letter-spacing: -0.02rem;
}

/* Modal filter styles */
#modal-filters-content {
    max-height: none;
    overflow-y: visible;
}

#modal-filters-content .filter-column-content {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    max-height: none;
    overflow-y: visible;
}

#modal-filters-content .filter-menu-columns {
    grid-template-columns: 1fr;
    gap: 0.5rem;
    min-height: auto;
    max-height: none;
}

#modal-filters-content .filter-column {
    min-width: 0;
    padding: 0.25rem;
    border-right: none;
    border-bottom: 1px solid #f0f0f0;
}

#modal-filters-content .filter-column:last-child {
    border-bottom: none;
}

#modal-filters-content .filter-column.inline-control {
    display: flex;
    align-items: flex-start;
    margin-bottom: 0.25rem;
}

#modal-filters-content .filter-column.inline-control .filter-column-header {
    flex-shrink: 0;
    margin-right: 0.5rem;
    margin-bottom: 0;
}

#modal-filters-content .filter-column.inline-control .filter-column-content {
    flex: 1;
}

/* Mobile responsive modal */
@media (max-width: 600px) {
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 0.5rem;
        border-radius: 8px 8px 0 0;
    }

    .modal-body {
        padding: 0.5rem;
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .modal-header {
        padding: 0.5rem 0.75rem;
    }

    .modal-section h3 {
        font-size: 0.75rem;
        margin-bottom: 0.25rem;
    }

    .mode-option {
        padding: 0.3rem;
        gap: 0.3rem;
    }

    .mode-icon {
        font-size: 1.2rem;
        min-width: 1.2rem;
    }

    .mode-name {
        font-size: 0.9rem;
        text-transform: uppercase;
    }

    .mode-description {
        font-size: 0.7rem;
        /* reduce kerning to save horizontal space: */
        letter-spacing: -0.02em;
    }

    .modal-overlay {
        align-items: flex-end;
    }

    .modal-content {
        animation: modalSlideUp 0.3s ease-out;
    }

    @keyframes modalSlideUp {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
}

/* Very narrow screens (400px and below) */
@media (max-width: 400px) {
    .modal-content {
        width: 100%;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
    }

    .modal-body {
        padding: 0.25rem;
        gap: 0.25rem;
    }

    .modal-header {
        padding: 0.25rem 0.5rem;
    }

    .mode-details {
        min-width: 0;
    }

    .mode-option {
        flex-wrap: wrap;
        white-space: normal;
        min-width: 0;
    }

    .mode-name {
        white-space: normal;
        min-width: 0;
    }

    .mode-description {
        white-space: normal;
    }

    .filter-column {
        width: auto !important;
    }
}

/* Listening Mode Popup Styles */
.listening-popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(3px);
}

.popup-content {
  background-color: #fff;
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  text-align: center;
  width: 300px;
  max-width: 90vw;
  animation: popupFadeIn 0.3s ease-out;
}

.popup-content.audio-playing {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

@keyframes popupFadeIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.listen-text {
    font-size: 2rem;
    font-weight: 700;
    color: #333;
    margin-bottom: 1.5rem;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.waveform-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 60px;
    margin-bottom: 1.5rem;
}

.waveform-bar {
    width: 8px;
    background: linear-gradient(180deg, #007bff, #0056b3);
    border-radius: 4px;
    animation: waveformPulse 1.5s ease-in-out infinite;
}

.waveform-bar:nth-child(1) { animation-delay: 0s; }
.waveform-bar:nth-child(2) { animation-delay: 0.1s; }
.waveform-bar:nth-child(3) { animation-delay: 0.2s; }
.waveform-bar:nth-child(4) { animation-delay: 0.3s; }
.waveform-bar:nth-child(5) { animation-delay: 0.4s; }
.waveform-bar:nth-child(6) { animation-delay: 0.5s; }
.waveform-bar:nth-child(7) { animation-delay: 0.4s; }
.waveform-bar:nth-child(8) { animation-delay: 0.3s; }

@keyframes waveformPulse {
    0%, 100% {
        height: 20px;
        opacity: 0.7;
    }
    50% {
        height: 50px;
        opacity: 1;
    }
}

.countdown-timer {
    font-size: 3rem;
    font-weight: 900;
    color: #007bff;
    margin: 0;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    text-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
}

.countdown-timer:hover {
    transform: scale(1.05);
    color: #0056b3;
}

/* Phase text */
.phase-text {
    font-size: 1.5rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 1rem;
    text-align: center;
}

/* Old Film Countdown Styles */
.old-film-countdown {
    position: relative;
    width: 120px;
    height: 120px;
    margin: 1.5rem auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.countdown-digit {
    font-size: 4rem;
    font-weight: 900;
    color: #007bff;
    z-index: 2;
    position: relative;
    text-shadow: 0 2px 4px rgba(0, 123, 255, 0.3);
    user-select: none;
}

.countdown-sector {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
background: conic-gradient(
        from 0deg,
        transparent 0deg,
        rgba(239, 239, 0, 0.2) 200deg, /* Длинный слабый хвост */
        rgba(239, 239, 0, 0.7) 315deg, /* Усиление цвета */
        rgb(239, 239, 0) 360deg    /* Самая яркая точка (сам луч) */
    );
    animation: rotate-sector 1s linear infinite;
    z-index: 1;
}

@keyframes rotate-sector {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}


/* Mobile responsive for popup */
@media (max-width: 600px) {
    .popup-content {
        width: 280px;
        padding: 1.5rem;
    }

    .phase-text {
        font-size: 1.3rem;
    }

    .old-film-countdown {
        width: 100px;
        height: 100px;
        margin: 1rem auto;
    }

    .countdown-digit {
        font-size: 3rem;
    }

    .waveform-container {
        height: 50px;
        gap: 3px;
    }

    .waveform-bar {
        width: 6px;
    }
}

@media (max-width: 400px) {
    .popup-content {
        width: 250px;
        padding: 1rem;
    }

    .phase-text {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
    }

    .old-film-countdown {
        width: 80px;
        height: 80px;
        margin: 0.75rem auto;
    }

    .countdown-digit {
        font-size: 2.5rem;
    }

    .waveform-container {
        height: 40px;
        margin-bottom: 1rem;
    }

    .waveform-bar {
        width: 5px;
    }
}

