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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #09090b;
    min-height: 100vh;
    color: #fafafa;
}

/* App Layout */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    position: relative;
}

/* Mobile Menu Button */
.menu-btn {
    display: none;
    position: fixed;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid #27272a;
    background: #18181b;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: #a1a1aa;
    z-index: 100;
    transition: all 0.15s ease;
}

.menu-btn:hover {
    background: #27272a;
    color: #fafafa;
}

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

/* Mobile Menu Overlay */
.menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 150;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 70px 16px 16px;
}

.menu-overlay.visible {
    display: flex;
}

.menu-panel {
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 12px;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: #a1a1aa;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.menu-item:hover {
    background: #27272a;
    color: #fafafa;
}

.menu-item svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Practice Wrapper with widgets on left */
.practice-wrapper {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 520px;
    justify-content: center;
}

/* Widget Buttons - aligned to flashcard bottom, stacking upward */
.widget-buttons {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    align-self: center;
    margin-top: -140px; /* Shift up to align with flashcard */
}

.widget-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 10px 10px 8px;
    border-radius: 10px;
    border: 1px solid #27272a;
    background: #18181b;
    color: #52525b;
    cursor: pointer;
    transition: all 0.15s ease;
    min-width: 56px;
}

.widget-btn:hover {
    background: #27272a;
    border-color: #3f3f46;
    color: #fafafa;
}

.widget-btn svg {
    width: 18px;
    height: 18px;
}

.widget-label {
    font-size: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Back Button */
.back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid #27272a;
    background: #18181b;
    color: #a1a1aa;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.back-btn:hover {
    background: #27272a;
    color: #fafafa;
}

.back-btn svg {
    width: 16px;
    height: 16px;
}

/* Pages */
.page {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.page.hidden {
    display: none;
}

.container {
    width: 100%;
    max-width: 380px;
}

/* Mode Banner */
.mode-banner {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    background: rgba(251, 191, 36, 0.1);
    border: 1px solid rgba(251, 191, 36, 0.2);
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    font-weight: 500;
    color: #fbbf24;
}

.mode-banner.visible {
    display: flex;
}

.mode-count {
    color: #a1a1aa;
    font-weight: 400;
}

.mode-exit {
    margin-left: auto;
}

.mode-exit {
    background: none;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.6;
    line-height: 1;
}

.mode-exit:hover {
    opacity: 1;
}

/* Header Stats */
.stats {
    display: flex;
    justify-content: space-between;
    margin-bottom: 24px;
    padding: 20px 24px;
    background: #18181b;
    border-radius: 12px;
    border: 1px solid #27272a;
}

.stat {
    text-align: center;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    color: #fafafa;
    font-variant-numeric: tabular-nums;
}

.stat-value.correct-val {
    color: #22c55e;
}

.stat-value.incorrect {
    color: #ef4444;
}

.stat-label {
    font-size: 11px;
    color: #71717a;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 4px;
    font-weight: 500;
}

/* Flashcard */
.flashcard {
    background: #18181b;
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    margin-bottom: 16px;
    border: 1px solid #27272a;
}

.pinyin-display {
    font-size: 15px;
    color: #71717a;
    margin-bottom: 24px;
    min-height: 32px;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.pinyin-display.revealed {
    color: #fafafa;
    font-size: 32px;
    font-weight: 600;
}

.pinyin-display.empty-message {
    font-size: 18px;
    color: #52525b;
    line-height: 1.4;
}

/* Speaker Button */
.speaker-btn {
    width: 88px;
    height: 88px;
    border-radius: 50%;
    border: none;
    background: #27272a;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    transition: background 0.15s ease;
}

.speaker-btn:hover {
    background: #3f3f46;
}

.speaker-btn:active {
    background: #27272a;
}

.speaker-btn svg {
    width: 32px;
    height: 32px;
    fill: #a1a1aa;
}

.hint-text {
    font-size: 13px;
    color: #52525b;
}

/* Tone Buttons */
.tone-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.tone-btn {
    padding: 20px 16px;
    border-radius: 12px;
    border: 1px solid #27272a;
    background: #18181b;
    color: #fafafa;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.tone-btn:hover:not(:disabled) {
    background: #27272a;
    border-color: #3f3f46;
}

.tone-btn:active:not(:disabled) {
    background: #18181b;
}

.tone-btn:disabled {
    cursor: default;
}

.tone-btn.correct {
    background: rgba(34, 197, 94, 0.1);
    border-color: #22c55e;
}

.tone-btn.correct .tone-number,
.tone-btn.correct .tone-mark,
.tone-btn.correct .tone-name {
    color: #22c55e;
}

.tone-btn.incorrect {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

.tone-btn.incorrect .tone-number,
.tone-btn.incorrect .tone-mark,
.tone-btn.incorrect .tone-name {
    color: #ef4444;
}

.tone-number {
    font-size: 20px;
    font-weight: 600;
    color: #fafafa;
}

.tone-mark {
    font-size: 22px;
    color: #a1a1aa;
    font-weight: 500;
}

.tone-name {
    font-size: 10px;
    color: #52525b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 500;
}

/* Next Button */
.next-btn {
    width: 100%;
    padding: 16px;
    margin-top: 12px;
    border-radius: 12px;
    border: none;
    background: #fafafa;
    color: #09090b;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease;
    display: none;
}

.next-btn.visible {
    display: block;
}

.next-btn:hover {
    opacity: 0.9;
}

/* Struggling count */
.struggling-indicator {
    text-align: center;
    margin-top: 16px;
    padding: 10px;
    background: transparent;
    border-radius: 8px;
    color: #71717a;
    font-size: 13px;
    display: none;
}

.struggling-indicator.visible {
    display: block;
}

/* Streak Toast */
.streak-toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 12px;
    padding: 16px 24px;
    text-align: center;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 100;
    pointer-events: none;
}

.streak-toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.streak-toast .streak-count {
    font-size: 32px;
    font-weight: 700;
    color: #fafafa;
    line-height: 1;
}

.streak-toast .streak-fire {
    font-size: 24px;
    margin-left: 4px;
}

.streak-toast .streak-message {
    font-size: 14px;
    color: #a1a1aa;
    margin-top: 6px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 16px;
    width: 100%;
    max-width: 360px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-large {
    max-width: 600px;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: #71717a;
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
}

.modal-close:hover {
    color: #fafafa;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* Settings Modal */
.danger-btn {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.danger-btn:hover {
    background: rgba(239, 68, 68, 0.2);
}

.danger-hint {
    font-size: 12px;
    color: #52525b;
    text-align: center;
    margin-top: 10px;
}

/* Explore Page */
#explore-page {
    align-items: stretch;
    justify-content: flex-start;
}

.explore-container {
    width: 100%;
    max-width: 1200px;
    height: 100%;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
}

.explore-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
    flex-shrink: 0;
}

.explore-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: #fafafa;
    flex: 1;
}

.search-input {
    padding: 10px 14px;
    border-radius: 8px;
    border: 1px solid #27272a;
    background: #0f0f11;
    color: #fafafa;
    font-size: 14px;
    outline: none;
    width: 200px;
}

.search-input:focus {
    border-color: #3f3f46;
}

.search-input::placeholder {
    color: #52525b;
}

.pinyin-chart-wrapper {
    flex: 1;
    overflow: auto;
    border: 1px solid #1c1c1f;
    border-radius: 12px;
    background: #0a0a0c;
}

/* Pinyin Chart Grid */
.pinyin-chart {
    display: grid;
    gap: 1px;
    background: #1c1c1f;
    min-width: fit-content;
}

.chart-row {
    display: contents;
}

.chart-cell {
    background: #0f0f11;
    padding: 8px 4px;
    text-align: center;
    font-size: 12px;
    color: #71717a;
    min-width: 44px;
    position: relative;
}

.chart-cell.header {
    background: #18181b;
    color: #a1a1aa;
    font-weight: 500;
    position: sticky;
    top: 0;
    z-index: 2;
}

.chart-cell.row-header {
    background: #18181b;
    color: #a1a1aa;
    font-weight: 500;
    position: sticky;
    left: 0;
    z-index: 1;
}

.chart-cell.corner {
    background: #18181b;
    position: sticky;
    top: 0;
    left: 0;
    z-index: 3;
}

.chart-cell.clickable {
    cursor: pointer;
    color: #a1a1aa;
    transition: all 0.1s ease;
}

.chart-cell.clickable:hover {
    background: #1c1c1f;
    color: #fafafa;
}

.chart-cell.clickable.active {
    background: #27272a;
    color: #fafafa;
}

.chart-cell.empty {
    color: #27272a;
}

.chart-cell.highlight {
    background: #1c1c1f;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #52525b;
    font-size: 14px;
    grid-column: 1 / -1;
}

/* Tone Picker Popover */
.tone-picker-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 250;
    display: none;
}

.tone-picker-overlay.visible {
    display: block;
}

.tone-picker {
    position: absolute;
    background: #1c1c1f;
    border: 1px solid #3f3f46;
    border-radius: 10px;
    padding: 6px;
    display: flex;
    gap: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 251;
}

.tone-picker::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid #3f3f46;
}

.tone-picker::after {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #1c1c1f;
}

/* Arrow pointing down when picker is above */
.tone-picker.above::before {
    top: auto;
    bottom: -6px;
    border-bottom: none;
    border-top: 6px solid #3f3f46;
}

.tone-picker.above::after {
    top: auto;
    bottom: -5px;
    border-bottom: none;
    border-top: 5px solid #1c1c1f;
}

.tone-picker-title,
.tone-picker-subtitle {
    display: none;
}

.tone-picker-buttons {
    display: flex;
    gap: 4px;
}

.tone-picker-btn {
    padding: 8px 12px;
    background: #27272a;
    border: 1px solid transparent;
    border-radius: 6px;
    color: #fafafa;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.1s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 44px;
}

.tone-picker-btn:hover {
    background: #3f3f46;
}

.tone-picker-btn.playing {
    background: #3f3f46;
    border-color: #52525b;
}

.tone-picker-mark {
    font-size: 16px;
    font-weight: 500;
}

.tone-picker-num {
    font-size: 9px;
    color: #71717a;
    text-transform: uppercase;
}

.tone-picker-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.tone-picker-btn:disabled:hover {
    background: #27272a;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .menu-btn {
        display: flex;
    }

    .widget-buttons {
        display: none;
    }

    .practice-wrapper {
        max-width: 100%;
        justify-content: center;
    }

    .page {
        padding: 20px;
        padding-top: 70px;
    }

    .container {
        max-width: 100%;
    }

    .flashcard {
        padding: 24px 20px;
    }

    .speaker-btn {
        width: 80px;
        height: 80px;
    }

    .speaker-btn svg {
        width: 28px;
        height: 28px;
    }

    .tone-btn {
        padding: 16px 12px;
    }

    .tone-number {
        font-size: 18px;
    }

    .tone-mark {
        font-size: 20px;
    }

    .explore-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .explore-header h2 {
        order: -1;
    }

    .back-btn {
        align-self: flex-start;
    }

    .search-input {
        width: 100%;
    }

    .chart-cell {
        font-size: 10px;
        padding: 6px 2px;
        min-width: 32px;
    }

    .chart-cell.row-header,
    .chart-cell.corner {
        min-width: 36px;
    }
}

/* Footer */
.site-footer {
    text-align: center;
    padding: 24px 0 4px;
    margin-top: 16px;
    color: #52525b;
    font-size: 13px;
}

.site-footer a {
    color: #a1a1aa;
    text-decoration: none;
    transition: color 0.15s ease;
}

.site-footer a:hover {
    color: #fafafa;
}
