/* ===== RESET & BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Noto Sans Tamil', 'Lohit Tamil', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    overflow: hidden;
    -webkit-user-select: none;
    user-select: none;
    touch-action: manipulation;
}

html,
body {
    min-width: 0;
    min-height: 100%;
}

/* ===== MAIN CONTAINER ===== */
#mainContainer {
    width: 100%;
    height: 450px;
    display: flex;
    flex-direction: column;
    background: white;
    position: relative;
}

/* If opened in new tab, use 90vh */
@media (min-height: 600px) {
    body:not(.iframe-mode) #mainContainer {
        height: 90vh;
    }
}

/* ===== TITLE BAR ===== */
.title-bar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.title-bar.collapsed {
    padding: 4px 12px;
}

.title-text {
    font-size: 18px;
    font-weight: bold;
    transition: all 0.3s ease;
}

.title-bar.collapsed .title-text {
    font-size: 0;
    opacity: 0;
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
}

.toggle-btn:active {
    background: rgba(255, 255, 255, 0.4);
    transform: scale(0.95);
}

/* ===== CONTENT AREA ===== */
.content-area {
    flex: 1;
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 12px;
    padding: 12px;
    overflow: hidden;
}

/* ===== PANELS ===== */
.left-panel, .center-panel, .right-panel {
    background: white;
    border-radius: 12px;
    padding: 12px;
    overflow-y: auto;
    min-width: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.center-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ===== MODE SELECTOR ===== */
.mode-selector {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.mode-btn {
    flex: 1;
    padding: 12px;
    background: #e0e7ff;
    border: 2px solid #c7d2fe;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
    color: #4338ca;
}

.mode-btn:active {
    transform: scale(0.97);
    box-shadow: 0 0 12px rgba(102, 126, 234, 0.5);
}

.mode-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

/* ===== CONTROLS ===== */
.control-group {
    margin-bottom: 12px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 8px;
}

.control-label {
    display: block;
    font-size: 14px;
    font-weight: bold;
    margin-bottom: 6px;
    color: #334155;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    min-height: 44px;
}

.toggle-label input[type="checkbox"] {
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-text {
    font-size: 14px;
    color: #334155;
}

input[type="range"] {
    width: 100%;
    height: 44px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-track {
    width: 100%;
    height: 8px;
    background: #cbd5e1;
    border-radius: 4px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: #667eea;
    border-radius: 50%;
    cursor: pointer;
    margin-top: -8px;
}

input[type="range"]::-moz-range-track {
    width: 100%;
    height: 8px;
    background: #cbd5e1;
    border-radius: 4px;
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    background: #667eea;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

#speedValue, #pitchValue {
    display: inline-block;
    margin-left: 8px;
    font-weight: bold;
    color: #667eea;
}

/* ===== ACTION BUTTONS ===== */
.action-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
    margin-bottom: 8px;
}

.action-btn:active {
    transform: scale(0.97);
    box-shadow: 0 0 12px rgba(102, 126, 234, 0.5);
}

/* ===== WORD LIST ===== */
.section-title {
    font-size: 16px;
    font-weight: bold;
    color: #334155;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 2px solid #e2e8f0;
}

.word-list-container {
    margin-top: 12px;
}

.word-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.word-item {
    padding: 12px;
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.word-item:active,
.word-item.touch-active {
    background: #dbeafe;
    border-color: #667eea;
    box-shadow: 0 0 12px rgba(102, 126, 234, 0.3);
    transform: scale(0.98);
}

.word-item.selected {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: #667eea;
}

.word-tamil {
    font-size: 18px;
    font-weight: bold;
}

.word-roman {
    font-size: 12px;
    opacity: 0.8;
    font-style: italic;
}

.word-item.selected .word-roman {
    opacity: 1;
}

/* ===== DISPLAY CARD ===== */
.display-card {
    background: linear-gradient(135deg, #f0f4ff 0%, #e9d5ff 100%);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.current-word {
    font-size: 48px;
    font-weight: bold;
    color: #4338ca;
    margin-bottom: 12px;
    line-height: 1.2;
}

.current-roman {
    font-size: 20px;
    color: #7c3aed;
    font-style: italic;
    margin-bottom: 8px;
}

.current-meaning {
    font-size: 18px;
    color: #334155;
    margin-bottom: 16px;
}

.stress-markers {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 16px;
    min-height: 20px;
}

/* ===== PLAYBACK CONTROLS ===== */
.playback-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-bottom: 16px;
}

.play-btn {
    padding: 12px 20px;
    background: #10b981;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
    min-width: 120px;
}

.play-btn:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
    opacity: 0.6;
}

.play-btn:not(:disabled):active {
    transform: scale(0.97);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.5);
}

/* ===== EXAMPLE SENTENCE ===== */
.example-sentence {
    background: white;
    padding: 12px;
    border-radius: 8px;
    font-size: 16px;
    color: #334155;
    text-align: left;
    margin-top: 12px;
    min-height: 40px;
}

/* ===== DISCRIMINATION SECTION ===== */
.discrimination-section {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.instruction {
    font-size: 14px;
    color: #64748b;
    margin-bottom: 12px;
    text-align: center;
}

.discrimination-pairs {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.pair-item {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px;
}

.pair-words {
    display: flex;
    justify-content: space-around;
    margin-bottom: 12px;
}

.pair-word {
    font-size: 24px;
    font-weight: bold;
    color: #4338ca;
    padding: 8px 16px;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    min-width: 80px;
    text-align: center;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pair-word:active {
    background: #dbeafe;
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.3);
}

.pair-options {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.pair-option {
    flex: 1;
    padding: 12px;
    background: #e0e7ff;
    border: 2px solid #c7d2fe;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 48px;
    color: #4338ca;
}

.pair-option:active {
    transform: scale(0.97);
    box-shadow: 0 0 8px rgba(102, 126, 234, 0.3);
}

.pair-option.correct {
    background: #86efac;
    border-color: #10b981;
    color: #065f46;
}

.pair-option.incorrect {
    background: #fca5a5;
    border-color: #ef4444;
    color: #7f1d1d;
}

.pair-feedback {
    margin-top: 8px;
    font-size: 14px;
    font-weight: bold;
    text-align: center;
    min-height: 20px;
}

/* ===== QUIZ MODE ===== */
.mode-display {
    display: none;
    flex: 1;
    overflow-y: auto;
    min-width: 0;
}

.mode-display.active {
    display: flex;
    flex-direction: column;
}

.quiz-container {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.quiz-progress {
    font-size: 14px;
    font-weight: bold;
    color: #64748b;
    margin-bottom: 16px;
    text-align: center;
}

.quiz-question {
    font-size: 20px;
    font-weight: bold;
    color: #334155;
    margin-bottom: 20px;
    text-align: center;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.quiz-options {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 16px;
}

.quiz-option {
    padding: 16px;
    background: #f1f5f9;
    border: 2px solid #cbd5e1;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 54px;
    text-align: left;
}

.quiz-option:active {
    transform: scale(0.98);
    box-shadow: 0 0 12px rgba(102, 126, 234, 0.3);
}

.quiz-option.selected {
    background: #dbeafe;
    border-color: #667eea;
}

.quiz-option.correct {
    background: #86efac;
    border-color: #10b981;
    color: #065f46;
}

.quiz-option.incorrect {
    background: #fca5a5;
    border-color: #ef4444;
    color: #7f1d1d;
}

.quiz-option:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.quiz-feedback {
    background: #f0f9ff;
    border-left: 4px solid #0284c7;
    padding: 12px;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 12px;
    min-height: 40px;
}

.quiz-feedback.correct {
    background: #f0fdf4;
    border-color: #10b981;
    color: #065f46;
}

.quiz-feedback.incorrect {
    background: #fef2f2;
    border-color: #ef4444;
    color: #7f1d1d;
}

/* ===== ANALYTICS PANEL ===== */
.analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.analytics-panel {
    max-height: 400px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.analytics-panel.collapsed {
    max-height: 0;
    overflow: hidden;
}

.analytics-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding: 8px;
    background: #f8fafc;
    border-radius: 6px;
}

#deviceType {
    font-size: 12px;
    color: #64748b;
}

.clear-btn {
    padding: 6px 12px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    min-height: 32px;
    min-width: 60px;
}

.clear-btn:active {
    transform: scale(0.95);
}

.action-log {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.log-entry {
    padding: 8px;
    background: #f8fafc;
    border-left: 3px solid #cbd5e1;
    border-radius: 4px;
    font-size: 12px;
    color: #334155;
}

.log-entry.interaction {
    border-color: #3b82f6;
}

.log-entry.quiz {
    border-color: #8b5cf6;
}

.log-entry.correct {
    border-color: #10b981;
    background: #f0fdf4;
}

.log-entry.incorrect {
    border-color: #ef4444;
    background: #fef2f2;
}

.log-time {
    font-weight: bold;
    color: #64748b;
    margin-right: 6px;
}

/* ===== MODAL ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    border-bottom: 2px solid #e2e8f0;
}

.modal-header h3 {
    font-size: 18px;
    color: #334155;
}

.close-btn {
    background: #ef4444;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:active {
    transform: scale(0.95);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
}

.modal-body {
    padding: 16px;
}

#voiceDiagInfo {
    font-size: 14px;
    line-height: 1.6;
}

.diag-item {
    padding: 8px;
    margin-bottom: 8px;
    background: #f8fafc;
    border-radius: 6px;
}

.diag-label {
    font-weight: bold;
    color: #334155;
}

.diag-value {
    color: #64748b;
}

/* ===== FEEDBACK TOOLTIP ===== */
.feedback-tooltip {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border: 3px solid #667eea;
    border-radius: 12px;
    padding: 20px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    z-index: 999;
}

.feedback-tooltip.active {
    display: block;
}

.tooltip-close {
    position: absolute;
    top: 8px;
    right: 8px;
}

.tooltip-content {
    font-size: 16px;
    color: #334155;
    line-height: 1.6;
    margin-top: 8px;
}

/* ===== TOUCH FEEDBACK ===== */
@media (hover: none) and (pointer: coarse) {
    /* Touch device detected - increase button sizes */
    .mode-btn, .action-btn, .play-btn, .quiz-option, .pair-option {
        min-height: 54px;
        padding: 14px;
    }
    
    .word-item {
        min-height: 54px;
        padding: 14px;
    }
    
    .toggle-btn {
        width: 48px;
        height: 48px;
        min-width: 48px;
        min-height: 48px;
    }
}

/* Active state for touch */
[data-touch-active="true"] {
    box-shadow: 0 0 16px rgba(102, 126, 234, 0.6) !important;
    transform: scale(0.97) !important;
}

/* ===== SCROLLBAR STYLING ===== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ===== RESPONSIVE ADJUSTMENTS ===== */
@media (max-width: 900px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
        min-height: 100vh;
        min-height: 100dvh;
        -webkit-overflow-scrolling: touch;
    }

    #mainContainer,
    body:not(.iframe-mode) #mainContainer {
        width: 100%;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        overflow: visible;
    }

    .title-bar {
        padding: 8px 10px;
        gap: 10px;
    }

    .title-text {
        flex: 1;
        min-width: 0;
        font-size: clamp(17px, 4.8vw, 21px);
        line-height: 1.25;
    }

    .content-area {
        flex: none;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 10px;
        overflow: visible;
    }

    .left-panel,
    .center-panel,
    .right-panel {
        width: 100%;
        max-height: none;
        padding: 10px;
        overflow: visible;
        border-radius: 10px;
    }

    .left-panel {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-areas:
            "mode mode"
            "words words"
            "roman roman"
            "speed pitch"
            "diagnostics diagnostics";
        gap: 10px;
    }

    .mode-selector {
        grid-area: mode;
        margin-bottom: 0;
    }

    .word-list-container {
        grid-area: words;
        margin-top: 0;
    }

    .roman-control {
        grid-area: roman;
    }

    .speed-control {
        grid-area: speed;
    }

    .pitch-control {
        grid-area: pitch;
    }

    .voice-diag-btn {
        grid-area: diagnostics;
    }

    .control-group,
    .action-btn {
        margin-bottom: 0;
    }

    .word-list {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .word-item {
        min-width: 0;
        min-height: 58px;
        padding: 10px;
        justify-content: center;
    }

    .word-tamil {
        font-size: clamp(18px, 5vw, 23px);
        line-height: 1.3;
        overflow-wrap: anywhere;
    }

    .center-panel {
        gap: 10px;
    }

    .mode-display,
    .mode-display.active {
        flex: none;
        overflow: visible;
    }

    .display-card {
        padding: 16px 12px;
    }

    .current-word {
        font-size: clamp(34px, 11vw, 48px);
        overflow-wrap: anywhere;
    }

    .current-word.is-placeholder {
        font-size: clamp(24px, 7.5vw, 32px);
        line-height: 1.35;
    }

    .current-roman {
        font-size: 18px;
    }

    .current-meaning {
        font-size: 17px;
        margin-bottom: 12px;
    }

    .stress-markers {
        margin-bottom: 12px;
    }

    .playback-controls {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
        margin-bottom: 12px;
    }

    .play-btn {
        width: 100%;
        min-width: 0;
        padding: 10px 6px;
        font-size: 14px;
    }

    .example-sentence {
        margin-top: 8px;
    }

    .discrimination-section,
    .quiz-container {
        padding: 12px;
    }

    .pair-item {
        padding: 10px;
    }

    .pair-words,
    .pair-options {
        gap: 8px;
    }

    .pair-word {
        min-width: 0;
        flex: 1;
        padding: 8px;
        font-size: clamp(20px, 6vw, 24px);
    }

    .pair-option {
        min-width: 0;
        padding: 10px 6px;
        font-size: 13px;
    }

    .analytics-header {
        margin-bottom: 0;
    }

    .analytics-panel {
        max-height: none;
        margin-top: 10px;
        overflow: visible;
    }

    .analytics-panel.collapsed {
        display: none;
        max-height: none;
    }

    .modal {
        padding: 12px;
        align-items: flex-start;
        overflow-y: auto;
    }

    .modal-content {
        width: 100%;
        max-height: calc(100dvh - 24px);
        margin: auto 0;
    }

    .feedback-tooltip {
        width: calc(100% - 24px);
        max-width: 480px;
    }
}

@media (max-width: 600px) {
    .mode-btn {
        min-width: 0;
        padding: 10px 6px;
        font-size: 13px;
    }

    .control-label,
    .toggle-text {
        font-size: 13px;
    }

    .control-group {
        padding: 8px;
    }

    input[type="range"] {
        height: 38px;
    }

    .section-title {
        font-size: 15px;
    }

    .analytics-info {
        gap: 8px;
    }

    #deviceType {
        min-width: 0;
        overflow-wrap: anywhere;
    }
}

@media (max-width: 360px) {
    .left-panel {
        grid-template-columns: 1fr;
        grid-template-areas:
            "mode"
            "words"
            "roman"
            "speed"
            "pitch"
            "diagnostics";
    }

    .playback-controls {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) and (orientation: landscape) {
    .word-list {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
