/* ═══════════════════════════════════════════════════════════════════════
 * Custom Styles for Translator App
 * ═══════════════════════════════════════════════════════════════════════ */

/* Make sure the text display areas fill the available space */
.card-body {
    flex-grow: 1;
}

.text-display {
    height: 100%;
    overflow-y: auto;
    scroll-behavior: smooth;
}

/* Custom scrollbar for a cleaner look */
.text-display::-webkit-scrollbar {
    width: 8px;
}
.text-display::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
    border-radius: 4px;
}
.text-display::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    transition: background 0.2s;
}
.text-display::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.15);
}

/* Prevent Google Translate from translating the UI */
.notranslate {
    translate: no !important;
}

/* Active language panel border highlight */
#jaPanel.active-ja, .language-panel.active-ja {
    border-color: var(--bs-primary) !important;
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.15);
}
#zhPanel.active-zh, .language-panel.active-zh {
    border-color: var(--bs-purple) !important;
    box-shadow: 0 0 0 3px rgba(var(--bs-purple-rgb), 0.15);
}

.panel-title h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0;
    margin-left: 0.5rem;
}

.panel-title span {
    font-size: 1.5rem;
}


/* ═══════════════════════════════════════════════════════════════════════
 * Center Toolbar
 * ═══════════════════════════════════════════════════════════════════════ */

/* Mic button states */
#micButton.active {
    background-color: var(--bs-danger);
    border-color: var(--bs-danger);
    animation: pulse 1.5s infinite;
}
#micButton.paused {
    background-color: var(--bs-warning);
    border-color: var(--bs-warning);
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(var(--bs-danger-rgb), 0.4);
    }
    50% {
        box-shadow: 0 0 0 10px rgba(var(--bs-danger-rgb), 0);
    }
}

/* Flip button active state */
#flipButton.active {
    background-color: var(--bs-primary-subtle);
    border-color: var(--bs-primary);
    color: var(--bs-primary);
}


/* ═══════════════════════════════════════════════════════════════════════
 * Text Styles (Core App Functionality)
 * ═══════════════════════════════════════════════════════════════════════ */

/* Ruby characters for Romaji annotations */
ruby {
    display: inline-block;
    position: relative;
    line-height: 2.5em;
}
rt {
    font-size: 0.7em;
    position: absolute;
    top: -0.8em;
    left: 0;
    right: 0;
    text-align: center;
    white-space: nowrap;
    color: var(--bs-secondary-color);
}
.text-stable ruby rt { color: #4CAF50; }
.text-unstable ruby rt { color: #FFC107; }

/* Text segments */
.text-segment {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--bs-border-color);
}
.text-segment:last-child {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Text styling for different states */
.text-recognition, .text-translation, .text-stable, .text-unstable {
    white-space: pre-wrap;
    word-wrap: break-word;
    line-height: 1.6;
    padding: 0.5rem 0.75rem;
    border-radius: var(--bs-border-radius);
    margin-top: 0.5rem;
}
.text-recognition {
    background-color: var(--bs-gray-200);
}
.text-translation {
    background-color: rgba(var(--bs-primary-rgb), 0.05);
}
.text-stable {
    background-color: rgba(var(--bs-success-rgb), 0.05);
    border-left: 3px solid rgba(var(--bs-success-rgb), 0.3);
}
.text-stable.translation {
    background-color: rgba(var(--bs-primary-rgb), 0.05);
    border-left-color: rgba(var(--bs-primary-rgb), 0.3);
}
.text-unstable {
    color: var(--bs-danger-text-emphasis) !important;
    font-style: italic;
    font-weight: bold !important;
    background-color: var(--bs-warning-bg-subtle) !important;
    border-left: 3px dashed rgba(var(--bs-warning-rgb), 0.4);
    opacity: 1 !important;
    font-size: 1.2rem !important;
}
.text-placeholder {
    color: var(--bs-secondary-color);
}

/* Connection status dot */
.connection-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--bs-secondary-bg-subtle);
    transition: background-color 0.3s;
}
.connection-dot.connected {
    background-color: var(--bs-success);
}

/* Face-to-face flipped mode */
/* 旋转第一个面板（日语面板），让对面的人可以看到 */
/* Rotate the first panel (Japanese panel) so the person facing you can read it */

/* 添加过渡动画 / Add transition animation */
#jaPanel {
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center center;
}

.main-content.flipped #jaPanel,
#jaPanel.flipped {
    transform: rotate(180deg) !important;
}

/* 移动端也适用 / Also works on mobile */
.language-panel {
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform-origin: center center;
}

.main-content.flipped .col-12:first-of-type .language-panel,
.main-content.flipped .col-md-6:first-of-type .language-panel {
    transform: rotate(180deg) !important;
}

/* Fullscreen mode */
/* 全屏模式 - 隐藏导航栏，最大化内容区域 */
body.fullscreen-mode .navbar {
    display: none !important;
}

body.fullscreen-mode main {
    height: 100vh !important;
    padding-top: 0.5rem !important;
    padding-bottom: 0.5rem !important;
}

/* 全屏模式下隐藏中间工具栏的非必要按钮 */
body.fullscreen-mode .center-toolbar-new #clearButton,
body.fullscreen-mode .center-toolbar-new #flipButton {
    opacity: 0.3;
    transition: opacity 0.3s;
}

body.fullscreen-mode .center-toolbar-new #clearButton:hover,
body.fullscreen-mode .center-toolbar-new #flipButton:hover {
    opacity: 1;
}

/* 全屏过渡动画 */
.navbar {
    transition: all 0.3s ease;
}

main {
    transition: height 0.3s ease, padding 0.3s ease;
}

/* Play button for text segments */
.segment-play-btn {
    background: rgba(var(--bs-primary-rgb), 0.15);
    border: 1px solid rgba(var(--bs-primary-rgb), 0.5);
    color: var(--bs-primary-text-emphasis);
    transition: all 0.2s ease;
}
.segment-play-btn:hover:not(:disabled) {
    background: rgba(var(--bs-primary-rgb), 0.25);
    border-color: rgba(var(--bs-primary-rgb), 0.8);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(var(--bs-primary-rgb), 0.3);
}
.segment-play-btn.playing {
    background: rgba(var(--bs-success-rgb), 0.2);
    border-color: var(--bs-success);
    color: var(--bs-success-text-emphasis);
    animation: segmentPulse 1.5s ease-in-out infinite;
}
@keyframes segmentPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(var(--bs-success-rgb), 0.4); }
    50% { box-shadow: 0 0 0 4px rgba(var(--bs-success-rgb), 0); }
}

/* Hide original control buttons that are now replaced or unused */
.direction-button, .provider-display, .backend-selector {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════
 * Fixed Height Layout - 固定高度布局（所有模式）
 * ═══════════════════════════════════════════════════════════════════════ */

/* Main content fills available space between navbar and bottom */
.main-content {
    height: calc(100vh - 56px); /* 56px is navbar height */
    overflow: hidden;
}

.main-content > .row {
    height: 100%;
}

.main-content > .row > .col-md-6 {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.main-content > .row > .col-md-6 .language-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.main-content > .row > .col-md-6 .card-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.main-content > .row > .col-md-6 .text-display {
    height: 100%;
    overflow-y: auto;
}

/* ═══════════════════════════════════════════════════════════════════════
 * Mobile Layout Optimization - 移动端布局优化
 * ═══════════════════════════════════════════════════════════════════════ */

@media (max-width: 767.98px) {
    /* 减少主内容区的内边距 */
    .main-content {
        padding-top: 0.5rem !important;
        padding-bottom: 0.5rem !important;
    }

    /* 移动端翻转模式 - 确保变换生效 */
    #jaPanel {
        transform-origin: center center;
        will-change: transform;
    }
    .main-content.flipped #jaPanel,
    #jaPanel.flipped {
        transform: rotate(180deg) !important;
    }

    /* 让两个面板等高并紧密排列 */
    .main-content > .row {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    /* 上下面板等高 */
    .main-content > .row > .col-md-6 {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .main-content > .row > .col-md-6 .language-panel {
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .main-content > .row > .col-md-6 .card-body {
        flex: 1;
        min-height: 0;
        overflow: hidden;
    }

    .main-content > .row > .col-md-6 .text-display {
        height: 100%;
        overflow-y: auto;
    }

    /* 移动端工具栏紧凑布局 */
    .main-content > .row > .col-12.d-md-none {
        flex: 0 0 auto;
        padding-top: 0.25rem !important;
        padding-bottom: 0.25rem !important;
    }

    /* 减少卡片间距 */
    .language-panel {
        margin-bottom: 0 !important;
    }

    .language-panel .card-header {
        padding: 0.5rem 0.75rem;
    }

    .language-panel .card-body {
        padding: 0.5rem;
    }
}

/* ═══════════════════════════════════════════════════════════════════════
 * Audio Level Bar - 音频能量条
 * ═══════════════════════════════════════════════════════════════════════ */

/* Desktop: Horizontal bar below buttons */
.audio-level-bar-container {
    width: 50px;
    height: 8px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.audio-level-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4CAF50, #8BC34A, #FFEB3B, #FF9800, #f44336);
    border-radius: 4px;
    transition: width 0.05s ease-out;
}

/* Mobile: Vertical bar on left side */
.audio-level-bar-mobile {
    width: 8px;
    height: 50px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.audio-level-bar-fill-mobile {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    background: linear-gradient(0deg, #4CAF50, #8BC34A, #FFEB3B, #FF9800, #f44336);
    border-radius: 4px;
    transition: height 0.05s ease-out;
}

/* Recording animation for level bar */
.audio-level-bar-container.active,
.audio-level-bar-mobile.active {
    box-shadow: 0 0 8px rgba(244, 67, 54, 0.4);
}