/* Custom styles for typing practice app */

html,
body {
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.container-fluid {
    max-width: 100%;
    padding: 0;
    margin: 0;
}

/* Prevent focus-related page jumping */
button:focus,
select:focus,
input:focus {
    outline: 2px solid var(--pico-primary-color);
    outline-offset: 2px;
}

button {
    cursor: pointer;
    padding: 5px 10px !important;
}

.grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    height: 100vh;
    gap: 0;
    position: relative;
}

/* Sidebar collapsed state */
.grid.sidebar-collapsed {
    grid-template-columns: 0 1fr;
}

/* Sidebar Styles */
.sidebar {
    background: var(--pico-background-color);
    border-right: 1px solid var(--pico-border-color);
    padding: 1rem;
    overflow-y: auto;
    transition: transform 0.3s ease, opacity 0.3s ease;
    position: relative;
    z-index: 100;
}

/* Sidebar collapsed state */
.grid.sidebar-collapsed .sidebar {
    transform: translateX(-100%);
    opacity: 0;
    pointer-events: none;
}

.sidebar h3 {
    margin-bottom: 1rem;
    color: var(--pico-primary-color);
}

.sidebar .header {
    display: flex;
    justify-content: space-between;

}

.center {
    align-items: center;
    justify-content: space-between;
    display: flex;
}

.article-controls {
    margin-bottom: 1rem;
}

.article-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.article-item {
    position: relative;
    display: flex;
    align-items: flex-start;
    padding: 1rem;
    border: 1px solid var(--pico-border-color);
    border-radius: var(--pico-border-radius);
    cursor: pointer;
    transition: all 0.2s ease;
    background: var(--pico-card-background-color);
}

.article-item:hover {
    background: var(--pico-secondary-background);
    border-color: var(--pico-primary-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.article-item.active {
    background: var(--pico-primary-background);
    border-color: var(--pico-primary-color);
    box-shadow: 0 0 0 2px rgba(var(--pico-primary-color), 0.2);
}

.article-content {
    flex: 1;
    min-width: 0;
    /* Allow text truncation */
}

.article-item h4 {
    margin: 0 0 0.5rem 0;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--pico-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.article-item .meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--pico-muted-color);
    margin-bottom: 0.5rem;
}

.article-item .meta span {
    background: var(--pico-secondary-background);
    padding: 0.2rem 0.4rem;
    border-radius: 0.25rem;
    white-space: nowrap;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--pico-border-color);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--pico-primary-color);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.delete-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--pico-muted-color);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    opacity: 0;
}

.article-item:hover .delete-btn {
    opacity: 1;
}

.delete-btn:hover {
    background: var(--pico-del-color);
    color: white;
    transform: scale(1.1);
}

.delete-btn svg {
    width: 14px;
    height: 14px;
}

/* Main Content Styles */
.main-content {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Toolbar Styles */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--pico-border-color);
    background: var(--pico-background-color);
    min-height: 60px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.toolbar-left h2 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    padding: 0.5rem 0.75rem !important;
    font-size: 1.2rem;
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--pico-border-radius);
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--pico-secondary-background);
    transform: scale(1.05);
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: nowrap;
}

.toolbar-right button {
    margin: 0;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

.toolbar-right label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    font-size: 0.9rem;
    white-space: nowrap;
    cursor: pointer;
}

.toolbar-right input[type="checkbox"] {
    margin: 0;
    transform: scale(0.9);
}

/* Speech Controls */
.speech-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.speech-controls button {
    padding: 0.4rem 0.8rem;
    font-size: 1rem;
    min-width: 40px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.speech-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Typing Area Styles */
.typing-container {
    flex: 1;
    padding: 2rem;
    overflow: auto;
    background: var(--pico-card-background-color);
}

.typing-hint {
    text-align: center;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: rgba(255, 193, 7, 0.1);
    border: 1px solid rgba(255, 193, 7, 0.3);
    border-radius: var(--pico-border-radius);
    color: var(--pico-muted-color);
}

.typing-area {
    position: relative;
    font-family: 'Courier New', monospace;
    font-size: 1.1rem;
    line-height: 1.8;
    max-width: 800px;
    margin: 0 auto;
    min-height: 300px;
    padding: 1rem;
    border: 2px solid var(--pico-border-color);
    border-radius: var(--pico-border-radius);
    color: var(--pico-accordion-open-summary-color);
}

.text-layer {
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    pointer-events: none;
    white-space: pre-wrap;
    word-wrap: break-word;
    opacity: 0.1;
    transition: opacity 0.3s ease;
    letter-spacing: 6px;
    font-size: 22px;
}

/* Dictation mode - hide original text and typed text */
.typing-container.dictation-mode .text-layer {
    opacity: 0;
}

.typing-container.dictation-mode .typing-layer {
    color: transparent;
}

/* Keep cursor visible in dictation mode */
.typing-container.dictation-mode .cursor {
    opacity: 1;
}

/* Keep current character indicator visible in dictation mode */
.typing-container.dictation-mode .char-current {
    border-bottom: 3px solid;
    border-color: var(--pico-text-selection-color);
    animation: pulse 1s infinite;
}

.typing-layer {
    position: relative;
    z-index: 2;
    white-space: pre-wrap;
    word-wrap: break-word;
    min-height: 100%;
    font-weight: bold;
    font-size: 22px;
}

.typing-layer span {
    border-bottom: 1px solid var(--pico-contrast-border);
    margin-right: 5.7px;
}

.cursor {
    position: absolute;
    width: 2px;
    height: 1.8rem;
    background: var(--pico-primary-color);
    animation: blink 1s infinite;
    z-index: 3;
}

@keyframes blink {

    0%,
    50% {
        opacity: 1;
    }

    51%,
    100% {
        opacity: 0;
    }
}

.char-correct {
    color: #28a745;
    background: rgba(40, 167, 69, 0.1);
}

.char-wrong {
    color: #dc3545;
    background: rgba(220, 53, 69, 0.2);
}

.char-current {
    /* background: rgba(0, 123, 255, 0.3); */
    border-bottom: 3px solid;
    border-color: var(--pico-text-selection-color);
    animation: pulse 1s infinite;
}

.char-current.char-punctuation {
    border-color: #ffc107;
    animation: punctuation-pulse 1s infinite;
}

@keyframes pulse {

    0%,
    100% {
        border-color: var(--pico-text-selection-color);
    }

    50% {
        border-color: var(--pico-primary-border);
    }
}

@keyframes punctuation-pulse {

    0%,
    100% {
        border-color: #ffc107;
    }

    50% {
        border-color: #ffed4e;
    }
}

/* Punctuation styling - make punctuation less prominent */
.punctuation {
    opacity: 0.5;
    color: var(--pico-muted-color);
    font-weight: normal;
}

.punctuation.char-correct {
    opacity: 0.7;
    color: #28a745;
}

.punctuation.char-wrong {
    opacity: 1;
    color: #dc3545;
}

.punctuation.char-current {
    opacity: 1;
    color: #ffc107;
}

/* Speech highlighting */
.speech-highlight {
    background: rgba(255, 193, 7, 0.2);
    border-radius: 2px;
    animation: speech-glow 2s ease-in-out infinite;
}

@keyframes speech-glow {

    0%,
    100% {
        background: rgba(255, 193, 7, 0.2);
    }

    50% {
        background: rgba(255, 193, 7, 0.4);
    }
}

.speech-reading {
    background: rgba(0, 123, 255, 0.1);
    border-left: 3px solid var(--pico-primary-color);
    /* Remove margin/padding that causes position shift */
}

/* Feedback Area Styles */
.feedback-area {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--pico-border-color);
    background: var(--pico-background-color);
    min-height: 60px;
    gap: 1rem;
}

.feedback-left {
    flex: 1;
    min-width: 200px;
}

.progress-section {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.progress-section span {
    font-size: 0.85rem;
    white-space: nowrap;
    min-width: 120px;
}

.progress-section progress {
    flex: 1;
    height: 8px;
    margin: 0;
}

.feedback-center {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex: 0 0 auto;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.stat-item label {
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    margin: 0;
}

.stat-item span {
    font-weight: bold;
    font-size: 0.9rem;
    min-width: 50px;
}

.feedback-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 0 0 auto;
}

.feedback-right button {
    margin: 0;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    white-space: nowrap;
}

/* Modal Styles */
#add-article-modal {
    max-width: 600px;
}

#add-article-modal textarea {
    min-height: 200px;
    resize: vertical;
}

.file-upload {
    margin-top: 1rem;
}

/* Speech Settings Modal */
#speech-settings-modal {
    max-width: 400px;
}

.setting-group {
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.setting-group label {
    min-width: 60px;
    font-weight: 600;
}

.setting-group input[type="range"] {
    flex: 1;
    margin: 0;
}

.setting-group span {
    min-width: 50px;
    font-size: 0.9rem;
    color: var(--pico-muted-color);
}

.setting-group select {
    flex: 1;
    margin: 0;
}

.setting-group button {
    margin: 0;
}

/* Responsive Design */
@media (max-width: 768px) {
    .grid {
        grid-template-columns: 1fr;
        position: relative;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        z-index: 1000;
        border-right: 1px solid var(--pico-border-color);
        border-bottom: none;
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
        transform: translateX(-100%);
        opacity: 0;
        pointer-events: none;
    }

    .grid.sidebar-open .sidebar {
        transform: translateX(0);
        opacity: 1;
        pointer-events: all;
    }

    /* Mobile overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .grid.sidebar-open .sidebar-overlay {
        opacity: 1;
        pointer-events: all;
    }

    .main-content {
        width: 100%;
    }

    .toolbar {
        flex-direction: row;
        align-items: flex-start;
        gap: 0.5rem;
        padding: 1rem;
    }

    .toolbar-left {
        /* width: 100%; */
        justify-content: flex-start;
    }

    .toolbar-right {
        gap: 1rem;
        flex-wrap: wrap;
        width: 100%;
        justify-content: flex-end;
    }

    .feedback-area {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
        padding: 1rem;
    }

    .feedback-center {
        justify-content: space-around;
        gap: 1rem;
    }

    .feedback-right {
        justify-content: center;
        flex-wrap: wrap;
    }
}

/* Desktop responsive behavior */
@media (min-width: 769px) {
    .sidebar-overlay {
        display: none;
    }

    .grid.sidebar-collapsed {
        grid-template-columns: 0 1fr;
    }

    .grid.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
        opacity: 0;
        pointer-events: none;
    }
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--pico-muted-color);
}

.empty-state h3 {
    margin-bottom: 1rem;
}

/* Loading state */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Spe
ech Settings Modal */
.speech-settings-content {
    max-height: 60vh;
    overflow-y: auto;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: var(--color);
}

.range-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.range-control input[type="range"] {
    flex: 1;
    margin: 0;
}

.range-control span {
    min-width: 3rem;
    text-align: right;
    font-weight: 500;
    color: var(--primary);
}

.mode-options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.mode-option {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.mode-option:hover {
    border-color: var(--primary);
    background-color: var(--primary-hover);
}

.mode-option input[type="radio"] {
    margin: 0;
    margin-top: 0.125rem;
}

.mode-option span {
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.mode-option small {
    display: block;
    color: var(--muted-color);
    font-size: 0.875rem;
    line-height: 1.3;
}

.mode-option input[type="radio"]:checked+span {
    color: var(--primary);
}

#speech-settings-modal article {
    max-width: 500px;
    width: 90vw;
}

#speech-settings-modal footer {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}

#speech-settings-modal footer button {
    margin: 0;
}

/* S
peech Highlighting */
.speech-highlight {
    background-color: rgba(var(--primary-rgb), 0.2);
    border-radius: 2px;
    padding: 0 2px;
    animation: speech-pulse 1.5s ease-in-out infinite;
}

@keyframes speech-pulse {

    0%,
    100% {
        background-color: rgba(var(--primary-rgb), 0.2);
    }

    50% {
        background-color: rgba(var(--primary-rgb), 0.4);
    }
}

.speech-word-highlight {
    background-color: rgba(255, 193, 7, 0.3);
    border-radius: 2px;
    padding: 0 1px;
    transition: background-color 0.3s ease;
}

/* Speech mode indicator */
.speech-mode-indicator {
    position: fixed;
    top: 80px;
    right: 20px;
    background: var(--primary);
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 20px;
    font-size: 0.875rem;
    z-index: 999;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    pointer-events: none;
    /* 避免阻挡点击 */
}

.speech-mode-indicator.show {
    opacity: 1;
    transform: translateY(0);
}

.speech-mode-indicator.follow {
    background: #28a745;
}

.speech-mode-indicator.auto {
    background: #17a2b8;
}

/* Notification System */
.notification-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column-reverse;
    gap: 0.5rem;
    pointer-events: none;
}

.notification {
    background: var(--pico-background-color);
    border: 1px solid var(--pico-border-color);
    border-radius: var(--pico-border-radius);
    padding: 0.75rem 1rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 300px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.notification.show {
    transform: translateX(0);
    opacity: 1;
}

.notification-success {
    border-left: 4px solid #28a745;
    background: rgba(40, 167, 69, 0.05);
}

.notification-info {
    border-left: 4px solid #17a2b8;
    background: rgba(23, 162, 184, 0.05);
}

.notification-warning {
    border-left: 4px solid #ffc107;
    background: rgba(255, 193, 7, 0.05);
}

.notification-error {
    border-left: 4px solid #dc3545;
    background: rgba(220, 53, 69, 0.05);
}