/* タイムマシンわ号フォント定義 */
@font-face {
    font-family: 'TimeMachine-wa';
    src: url('./assets/fonts/timemachine-wa.ttf') format('truetype');
    font-display: swap;
}

:root {
    --primary-color: #4a90e2;
    --secondary-color: #f5a623;
    --background-color: #f8f9fa;
    --text-color: #333;
    --light-text-color: #fff;
    --border-color: #ddd;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    font-family: 'M PLUS Rounded 1c', 'Zen Maru Gothic', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    overflow: hidden;
    box-sizing: border-box;
}

#app-container {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    margin: 0;
    box-sizing: border-box;
    padding: 10px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-shrink: 0;
    height: 50px;
}

header h1 {
    font-family: 'TimeMachine-wa', 'M PLUS Rounded 1c', 'Zen Maru Gothic', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 1.2rem;
    font-weight: 400;
    color: #333;
    margin: 0;
    letter-spacing: 1px;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.1);
}

#progress-container {
    display: flex;
    align-items: center;
    width: 30%;
}

#progress-bar {
    width: 80%;
    height: 20px;
    background-color: #e9ecef;
    border-radius: 10px;
    margin-right: 10px;
    overflow: hidden;
}

#progress-bar::before {
    content: '';
    display: block;
    width: 10%; /* To be updated by JS */
    height: 100%;
    background-color: var(--secondary-color);
    transition: width 0.3s ease;
}

#progress-label {
    font-size: 0.9rem;
    font-weight: 600;
}

main {
    display: flex;
    flex-grow: 1;
    gap: 10px;
    height: calc(100vh - 68px);
    position: relative;
    overflow: hidden;
}

/* YouTube風ビデオコンテナ */
#video-container {
    flex-basis: 80%;
    background: linear-gradient(135deg, #1e1e1e 0%, #2d2d2d 100%);
    border-radius: 12px;
    padding: 0;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* キャラクターエリア */
#character-area {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: radial-gradient(circle at center, rgba(52, 152, 219, 0.1) 0%, transparent 70%);
    padding: 30px;
}

/* VRoid 3Dコンテナ */
#vroid-container {
    width: 100%;
    height: 100%;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

#vroid-canvas {
    width: 100%;
    height: 100%;
    max-width: 400px;
    max-height: 400px;
    border-radius: 50%;
    box-shadow: 0 0 30px rgba(52, 152, 219, 0.3);
}

#character-image {
    width: clamp(200px, 25vw, 320px);
    height: clamp(200px, 25vw, 320px);
    object-fit: cover;
    border-radius: 50%;
    border: 4px solid rgba(255,255,255,0.2);
    transition: transform 0.3s ease;
    animation: breathe 4s ease-in-out infinite;
    box-shadow: 0 0 30px rgba(52, 152, 219, 0.3);
}

#character-image.speaking {
    animation: speaking 0.8s ease-in-out infinite;
    border-color: rgba(52, 152, 219, 0.8);
    box-shadow: 0 0 40px rgba(52, 152, 219, 0.6);
}

@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes speaking {
    0%, 100% { transform: scale(1) rotate(0deg); }
    25% { transform: scale(1.08) rotate(-2deg); }
    75% { transform: scale(1.08) rotate(2deg); }
}

#character-info {
    position: absolute;
    top: 20px;
    left: 20px;
    background: rgba(0,0,0,0.7);
    padding: 12px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

#character-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.control-btn-mini {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 0.65rem;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 110px;
}

.control-btn-mini:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

#character-name {
    font-size: 0.8rem;
    font-weight: 500;
    color: white;
    margin: 0 0 8px 0;
}

.faq-btn-mini {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.faq-btn-mini:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(240, 147, 251, 0.4);
}

/* 字幕エリア */
#subtitle-area {
    background: rgba(0,0,0,0.8);
    padding: 15px 20px;
    min-height: 60px;
    max-height: 120px;
    display: flex;
    align-items: center;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

#subtitle-content {
    width: 100%;
    text-align: center;
}

#subtitle-title {
    font-size: clamp(0.9rem, 2.5vw, 1.1rem);
    font-weight: 600;
    color: #3498db;
    margin-bottom: 6px;
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

#subtitle-text {
    font-size: clamp(0.8rem, 2vw, 1rem);
    line-height: 1.5;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
    max-height: 3.5em;
    overflow-y: auto;
}

/* ビデオコントロール */
#video-controls {
    background: rgba(0,0,0,0.9);
    padding: 10px 15px;
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}

#progress-bar-video {
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    margin-bottom: 12px;
    position: relative;
    overflow: hidden;
}

#progress-bar-video::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: var(--progress-percent, 10%);
    background: linear-gradient(90deg, #3498db 0%, #e74c3c 100%);
    border-radius: 2px;
    transition: width 0.3s ease;
}

#control-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}

.video-btn {
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.video-btn:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 4px 12px rgba(255,255,255,0.2);
}

.play-btn {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    padding: 0;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

.play-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(52, 152, 219, 0.4);
}

.complete-btn {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    margin-left: auto;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
}

.complete-btn:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 6px 16px rgba(46, 204, 113, 0.4);
}

/* 全画面表示ボタンスタイル */
#fullscreen-btn {
    background: rgba(255,255,255,0.15);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

#fullscreen-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-1px) scale(1.05);
    box-shadow: 0 4px 12px rgba(255,255,255,0.2);
}

/* 全画面表示時のスタイル */
.fullscreen-mode {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: #000 !important;
}

.fullscreen-mode #app-container {
    width: 100vw;
    height: 100vh;
    padding: 0;
    background: #000;
}

.fullscreen-mode header {
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(10px);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10000;
    padding: 10px 20px;
    height: auto;
}

.fullscreen-mode main {
    height: 100vh;
    padding-top: 60px;
}

.fullscreen-mode #sidebar {
    display: none;
}

.fullscreen-mode #video-container {
    flex-basis: 100%;
    width: 100%;
}

.fullscreen-mode #character-area {
    padding: 40px;
}

.fullscreen-mode #character-image {
    width: clamp(300px, 30vw, 500px);
    height: clamp(300px, 30vw, 500px);
}

.fullscreen-mode #vroid-container {
    width: 100%;
    height: 100%;
}

.fullscreen-mode #vroid-canvas {
    max-width: 600px;
    max-height: 600px;
}

.fullscreen-mode #subtitle-area {
    padding: 20px 30px;
    min-height: 80px;
    max-height: 150px;
}

.fullscreen-mode #subtitle-title {
    font-size: clamp(1.2rem, 3vw, 1.5rem);
}

.fullscreen-mode #subtitle-text {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    line-height: 1.6;
}

.fullscreen-mode #video-controls {
    padding: 15px 20px;
}

.fullscreen-mode .video-btn {
    width: 50px;
    height: 50px;
    font-size: 1.1rem;
}

.fullscreen-mode .play-btn {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
}

.fullscreen-mode .complete-btn {
    width: 60px;
    height: 60px;
    font-size: 1.3rem;
}

.fullscreen-mode #fullscreen-btn {
    width: 50px;
    height: 50px;
    font-size: 1.2rem;
}

#speed-controls-video {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

#speed-controls-video input[type="range"] {
    width: 80px;
    height: 4px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    outline: none;
}

#speed-controls-video input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: #3498db;
    border-radius: 50%;
    cursor: pointer;
}

#speed-label {
    color: white;
    font-size: 0.8rem;
    min-width: 30px;
}

footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    flex-wrap: wrap;
    gap: 15px;
}

#controls {
    display: flex;
    gap: 15px;
}

#speed-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
}

#speed-controls label {
    font-weight: bold;
    color: var(--text-color);
}

#speed-range {
    width: 120px;
    height: 6px;
    background: #ddd;
    outline: none;
    border-radius: 3px;
}

#speed-range::-webkit-slider-thumb {
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary-color);
    cursor: pointer;
    border-radius: 50%;
}

#speed-label {
    font-weight: bold;
    color: var(--primary-color);
    min-width: 40px;
}

.control-btn, #faq-btn, #close-faq-btn {
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.control-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.control-btn:active {
    transform: translateY(0);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#faq-btn {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
}

#faq-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(240, 147, 251, 0.3);
}

/* Modal Styles */
#faq-modal, #completion-modal, #progress-warning-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#faq-modal.hidden, #completion-modal.hidden, #progress-warning-modal.hidden {
    display: none;
}

#faq-content, #completion-content, #progress-warning-content {
    background-color: #fff;
    padding: 30px;
    border-radius: 15px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

/* Progress Warning Modal Specific Styles */
#progress-warning-content {
    max-width: 500px;
    text-align: center;
}

#progress-warning-content h2 {
    color: #e74c3c;
    margin-bottom: 20px;
    font-size: 1.4rem;
}

#progress-warning-content p {
    font-size: 1.1rem;
    line-height: 1.6;
    margin-bottom: 30px;
    color: #333;
}

.warning-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.warning-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 160px;
}

.warning-btn.danger {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: white;
}

.warning-btn.danger:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(231, 76, 60, 0.3);
}

.warning-btn.safe {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: white;
}

.warning-btn.safe:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(46, 204, 113, 0.3);
}

#faq-content h2 {
    margin-top: 0;
    text-align: center;
}

#faq-list {
    overflow-y: auto;
    margin-bottom: 20px;
}

.faq-item {
    margin-bottom: 15px;
}

.faq-item .question {
    font-weight: bold;
    font-size: 1.2rem;
    padding: 15px;
    background-color: #e9ecef;
    border-radius: 8px;
    cursor: pointer;
}

.faq-item .answer {
    padding: 15px;
    margin-top: 5px;
    background-color: #f8f9fa;
    border-radius: 8px;
    display: none; /* Initially hidden */
}

#close-faq-btn, #close-completion-btn {
    background-color: #6c757d;
    color: white;
    align-self: center;
}

#completion-content {
    text-align: center;
}

#completion-content h2 {
    color: var(--primary-color);
    margin-bottom: 20px;
}

#completion-content p {
    font-size: 1.2rem;
    margin-bottom: 15px;
    line-height: 1.6;
}

#complete-btn {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    color: white;
}

#complete-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 172, 254, 0.3);
}

/* Sidebar Styles */
#sidebar {
    flex-basis: 20%;
    background-color: #fff;
    border-radius: 12px;
    padding: 18px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    border: 1px solid #e8e8e8;
    overflow-y: auto;
    max-height: 100%;
}

.sidebar-section {
    margin-bottom: 8px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 8px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    font-weight: 500;
    font-size: 0.9rem;
    color: #2c3e50;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s ease;
    user-select: none;
    background-color: #f8f9fa;
}

.sidebar-header:hover {
    background-color: #e9ecef;
}

.sidebar-header.active {
    background-color: #3498db;
    color: white;
}

.sidebar-header.active .tree-icon {
    transform: rotate(90deg);
}

.tree-icon {
    margin-right: 8px;
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    color: #7f8c8d;
}

.tree-title {
    flex-grow: 1;
}

.sidebar-content {
    display: none;
    margin-top: 6px;
    padding-left: 20px;
    border-left: 2px solid #ecf0f1;
}

.sidebar-content.active {
    display: block;
}

.sidebar-link {
    display: block;
    padding: 6px 12px;
    color: #34495e;
    text-decoration: none;
    border-radius: 4px;
    margin: 2px 0;
    transition: all 0.2s ease;
    font-size: 0.85rem;
    position: relative;
}

.sidebar-link:before {
    content: "•";
    margin-right: 8px;
    color: #bdc3c7;
}

.sidebar-link:hover {
    background-color: #f1f2f6;
    color: #2c3e50;
    padding-left: 16px;
}

.sidebar-link.active {
    background-color: #e74c3c;
    color: white;
    font-weight: 500;
}

.sidebar-link.active:before {
    color: white;
}

/* FAQ Sidebar Button */
.faq-sidebar-btn {
    width: 100%;
    padding: 10px 16px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 15px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.faq-sidebar-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(240, 147, 251, 0.3);
}

/* FAQ Chat Container in Sidebar */
#faq-chat-container {
    margin-top: 10px;
    padding: 12px;
    background-color: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
    max-height: 400px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#faq-chat-container.hidden {
    display: none;
}

#faq-messages-sidebar {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 10px;
    padding: 8px;
    background-color: white;
    border-radius: 6px;
    border: 1px solid #ddd;
    flex-shrink: 0;
}

.faq-message-sidebar {
    margin-bottom: 8px;
    padding: 6px 10px;
    border-radius: 12px;
    max-width: 95%;
    word-wrap: break-word;
    font-size: 0.75rem;
    line-height: 1.3;
    clear: both;
}

.faq-message-sidebar.bot {
    background-color: var(--primary-color);
    color: white;
    float: left;
    border-bottom-left-radius: 3px;
}

.faq-message-sidebar.user {
    background-color: #e9ecef;
    color: var(--text-color);
    float: right;
    border-bottom-right-radius: 3px;
}

#faq-buttons-sidebar {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-grow: 1;
    overflow-y: auto;
}

.faq-button-sidebar {
    background-color: #fff;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    padding: 6px 10px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 0.75rem;
    line-height: 1.2;
    flex-shrink: 0;
}

.faq-button-sidebar:hover {
    background-color: var(--primary-color);
    color: white;
}

/* FAQ Modal */
#faq-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#faq-content {
    background-color: #fff;
    border-radius: 15px;
    width: 80%;
    max-width: 600px;
    height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#faq-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    background-color: var(--primary-color);
    color: white;
    border-radius: 15px 15px 0 0;
}

#faq-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

#close-faq-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 50%;
    transition: background-color 0.2s;
}

#close-faq-btn:hover {
    background-color: rgba(255,255,255,0.2);
}

#faq-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f8f9fa;
}

.faq-message {
    margin-bottom: 15px;
    padding: 12px 16px;
    border-radius: 20px;
    max-width: 80%;
    word-wrap: break-word;
}

.faq-message.bot {
    background-color: var(--primary-color);
    color: white;
    margin-right: auto;
    border-bottom-left-radius: 5px;
}

.faq-message.user {
    background-color: #e9ecef;
    color: var(--text-color);
    margin-left: auto;
    border-bottom-right-radius: 5px;
}

#faq-input-area {
    padding: 20px;
    border-top: 1px solid #e9ecef;
}

#faq-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.faq-button {
    background-color: #fff;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
    padding: 12px 16px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
    font-size: 0.95rem;
}

.faq-button:hover {
    background-color: var(--primary-color);
    color: white;
}

/* iPad Pro 12.9" and larger tablets - Landscape */
@media screen and (min-width: 1024px) and (max-width: 1366px) and (orientation: landscape) {
    #app-container {
        padding: 12px;
    }
    
    header {
        height: 55px;
        margin-bottom: 10px;
    }
    
    header h1 {
        font-family: 'TimeMachine-wa', 'M PLUS Rounded 1c', sans-serif;
        font-size: 1.3rem;
    }
    
    main {
        height: calc(100vh - 77px);
        gap: 12px;
    }
    
    #video-container {
        flex-basis: 75%;
    }
    
    #sidebar {
        flex-basis: 25%;
        padding: 16px;
    }
    
    #character-image {
        width: clamp(240px, 22vw, 320px);
        height: clamp(240px, 22vw, 320px);
    }
    
    #subtitle-area {
        padding: 16px 20px;
        min-height: 70px;
        max-height: 120px;
    }
    
    #subtitle-title {
        font-size: clamp(1rem, 2.2vw, 1.2rem);
    }
    
    #subtitle-text {
        font-size: clamp(0.9rem, 1.8vw, 1rem);
    }
}

/* iPad Air and iPad Pro - General tablet optimization */
@media screen and (min-width: 768px) and (max-width: 1024px) {
    #app-container {
        padding: 10px;
        height: 100vh;
        overflow: hidden;
    }
    
    header {
        height: 50px;
        margin-bottom: 8px;
        flex-shrink: 0;
    }
    
    header h1 {
        font-family: 'TimeMachine-wa', 'M PLUS Rounded 1c', sans-serif;
        font-size: 1.1rem;
    }
    
    #progress-container {
        width: 35%;
    }
    
    main {
        height: calc(100vh - 66px);
        gap: 10px;
        overflow: hidden;
    }
    
    #video-container {
        flex-basis: 70%;
        min-height: 0;
    }
    
    #sidebar {
        flex-basis: 30%;
        min-height: 0;
        padding: 14px;
        overflow-y: auto;
    }
    
    #character-area {
        padding: 25px;
        flex-grow: 1;
        min-height: 0;
    }
    
    #character-image {
        width: clamp(200px, 18vw, 280px);
        height: clamp(200px, 18vw, 280px);
    }
    
    #character-info {
        top: 15px;
        left: 15px;
        padding: 10px 14px;
    }
    
    #character-name {
        font-size: 0.85rem;
        margin-bottom: 6px;
    }
    
    .faq-btn-mini {
        padding: 5px 10px;
        font-size: 0.7rem;
    }
    
    #subtitle-area {
        padding: 14px 18px;
        min-height: 60px;
        max-height: 110px;
        flex-shrink: 0;
    }
    
    #subtitle-title {
        font-size: clamp(0.9rem, 2.2vw, 1.1rem);
        margin-bottom: 5px;
    }
    
    #subtitle-text {
        font-size: clamp(0.8rem, 1.9vw, 0.95rem);
        line-height: 1.4;
        max-height: 3.2em;
    }
    
    #video-controls {
        padding: 10px 14px;
        flex-shrink: 0;
    }
    
    #control-buttons {
        gap: 10px;
    }
    
    .video-btn {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        font-size: 0.85rem;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
    
    .play-btn {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        font-size: 1.3rem;
    }
    
    .complete-btn {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        font-size: 1.2rem;
    }
    
    #fullscreen-btn {
        width: 42px;
        height: 42px;
        border-radius: 50%;
        font-size: 1rem;
    }
    
    #speed-controls-video {
        gap: 6px;
    }
    
    #speed-controls-video input[type="range"] {
        width: 70px;
    }
    
    #speed-label {
        font-size: 0.75rem;
        min-width: 32px;
    }
    
    .sidebar-header {
        font-size: 0.85rem;
        padding: 7px 12px;
        border-radius: 8px;
    }
    
    .sidebar-link {
        font-size: 0.8rem;
        padding: 6px 10px;
        border-radius: 6px;
    }
    
    .sidebar-link:hover {
        padding-left: 14px;
    }
    
    .faq-button-sidebar {
        padding: 8px 12px;
        font-size: 0.8rem;
        border-radius: 10px;
    }
    
    #faq-chat-container {
        max-height: 350px;
    }
    
    #faq-messages-sidebar {
        max-height: 120px;
    }
}

/* iPad Portrait Specific */
@media screen and (max-width: 768px) and (orientation: portrait) {
    #app-container {
        padding: 8px;
        height: 100vh;
        overflow: hidden;
    }
    
    header {
        height: 45px;
        margin-bottom: 6px;
        flex-shrink: 0;
    }
    
    header h1 {
        font-family: 'TimeMachine-wa', 'M PLUS Rounded 1c', sans-serif;
        font-size: 1.0rem;
    }
    
    #progress-container {
        width: 40%;
    }
    
    #progress-label {
        font-size: 0.9rem;
    }
    
    main {
        flex-direction: column;
        height: calc(100vh - 59px);
        gap: 8px;
        overflow: hidden;
    }
    
    #video-container {
        flex-basis: 65%;
        min-height: 300px;
        max-height: 65vh;
    }
    
    #sidebar {
        flex-basis: 35%;
        min-height: 150px;
        padding: 10px;
        overflow-y: auto;
    }
    
    #character-area {
        padding: 15px;
        flex-grow: 1;
        min-height: 0;
    }
    
    #character-image {
        width: clamp(140px, 20vw, 180px);
        height: clamp(140px, 20vw, 180px);
    }
    
    #character-info {
        top: 10px;
        left: 10px;
        padding: 8px 12px;
    }
    
    #character-name {
        font-size: 0.75rem;
        margin-bottom: 4px;
    }
    
    .faq-btn-mini {
        padding: 4px 8px;
        font-size: 0.6rem;
    }
    
    #subtitle-area {
        padding: 10px 15px;
        min-height: 45px;
        max-height: 85px;
        flex-shrink: 0;
    }
    
    #subtitle-title {
        font-size: clamp(0.8rem, 2.5vw, 1rem);
        margin-bottom: 3px;
    }
    
    #subtitle-text {
        font-size: clamp(0.7rem, 2vw, 0.85rem);
        line-height: 1.3;
        max-height: 2.6em;
    }
    
    #video-controls {
        padding: 8px 12px;
        flex-shrink: 0;
    }
    
    #control-buttons {
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .video-btn {
        width: 38px;
        height: 38px;
        border-radius: 50%;
        font-size: 0.75rem;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }
    
    .play-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        font-size: 1.1rem;
    }
    
    .complete-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        font-size: 1rem;
    }
    
    #fullscreen-btn {
        width: 38px;
        height: 38px;
        border-radius: 50%;
        font-size: 0.9rem;
    }
    
    #speed-controls-video {
        gap: 4px;
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 4px;
    }
    
    #speed-controls-video input[type="range"] {
        width: 80px;
    }
    
    #speed-label {
        font-size: 0.65rem;
        min-width: 28px;
    }
    
    .sidebar-section {
        margin-bottom: 6px;
        padding-bottom: 6px;
    }
    
    .sidebar-header {
        font-size: 0.75rem;
        padding: 5px 8px;
        border-radius: 6px;
    }
    
    .sidebar-link {
        font-size: 0.7rem;
        padding: 4px 8px;
        border-radius: 4px;
    }
    
    .sidebar-link:hover {
        padding-left: 12px;
    }
    
    .faq-button-sidebar {
        padding: 6px 8px;
        font-size: 0.7rem;
        border-radius: 8px;
    }
    
    #faq-chat-container {
        max-height: 200px;
        padding: 8px;
    }
    
    #faq-messages-sidebar {
        max-height: 80px;
        padding: 6px;
    }
    
    .faq-message-sidebar {
        font-size: 0.65rem;
        padding: 4px 8px;
        margin-bottom: 4px;
    }
}

/* Touch and iPad-specific Accessibility Improvements */
@media (hover: none) and (pointer: coarse) {
    /* Touch-optimized elements for iPad */
    .video-btn, .control-btn, .faq-btn-mini, .control-btn-mini, .sidebar-header, .sidebar-link {
        min-height: 44px; /* Apple recommended touch target size */
        min-width: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .sidebar-link {
        min-height: 36px;
    }
    
    .faq-btn-mini {
        min-height: 32px;
        min-width: 60px;
    }
    
    /* Increase tap zones for better usability */
    #speed-controls-video input[type="range"] {
        height: 24px;
        -webkit-appearance: none;
        background: transparent;
    }
    
    #speed-controls-video input[type="range"]::-webkit-slider-track {
        height: 6px;
        background: rgba(255,255,255,0.3);
        border-radius: 3px;
    }
    
    #speed-controls-video input[type="range"]::-webkit-slider-thumb {
        height: 20px;
        width: 20px;
        border-radius: 50%;
        background: #3498db;
        border: 2px solid white;
        -webkit-appearance: none;
        margin-top: -9px;
    }
    
    /* Better feedback for touch interactions */
    .video-btn:active, .control-btn:active, .sidebar-header:active, .sidebar-link:active {
        background-color: rgba(52, 152, 219, 0.2);
        transform: scale(0.95);
    }
}

/* iPad Mini specific adjustments */
@media screen and (min-width: 744px) and (max-width: 768px) {
    header h1 {
        font-family: 'TimeMachine-wa', 'M PLUS Rounded 1c', sans-serif;
        font-size: 1.05rem;
    }
    
    #character-image {
        width: clamp(160px, 18vw, 220px);
        height: clamp(160px, 18vw, 220px);
    }
    
    #subtitle-title {
        font-size: clamp(0.85rem, 2.3vw, 1.05rem);
    }
    
    #subtitle-text {
        font-size: clamp(0.75rem, 1.9vw, 0.9rem);
    }
}

/* Landscape orientation optimizations for all iPads */
@media screen and (min-width: 768px) and (orientation: landscape) {
    main {
        flex-direction: row;
        height: calc(100vh - 66px);
    }
    
    #video-container {
        flex-basis: 72%;
    }
    
    #sidebar {
        flex-basis: 28%;
    }
    
    /* Optimize character positioning in landscape */
    #character-area {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-direction: row;
        padding: 20px 30px;
    }
    
    #character-image {
        margin-right: 20px;
    }
}

/* General accessibility and touch improvements */
.control-btn:disabled {
    background-color: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

.control-btn:disabled:hover {
    background-color: #ccc;
}

/* Progress bar animation */
#progress-bar::before {
    width: var(--progress-percent, 10%);
}

/* Better focus states for keyboard navigation */
button:focus, input:focus {
    outline: 3px solid var(--secondary-color);
    outline-offset: 2px;
}
