/* =================================================================
   Variables & Basic Setup
   ================================================================= */
   :root {
    --primary-color: #007bff; --primary-hover: #0056b3; --secondary-color: #6c757d;
    --danger-color: #dc3545; --light-color: #f8f9fa; --dark-color: #343a40;
    --text-primary: #212529; --text-secondary: #6c757d; --background-color: #f4f7f6;
    --container-bg: #ffffff; --border-color: #dee2e6;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --shadow: 0 4px 12px rgba(0,0,0,0.08);
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: var(--font-family); background-color: var(--background-color); color: var(--text-primary); font-size: 16px; line-height: 1.6; }

/* =================================================================
   Universal Styles
   ================================================================= */
#main-view { display: flex; flex-direction: column; height: 100vh; }
.loading-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(255, 255, 255, 0.8); display: flex; justify-content: center; align-items: center; z-index: 1000; }
.spinner { border: 5px solid #f3f3f3; border-top: 5px solid var(--primary-color); border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
.screen { width: 100%; }
#auth-screen { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.auth-container { width: 100%; max-width: 400px; padding: 2rem; background-color: var(--container-bg); border-radius: 8px; box-shadow: var(--shadow); }
.auth-error { background-color: #ffebee; color: #c62828; padding: 0.75rem 1rem; border-radius: 4px; margin-bottom: 1rem; font-size: 0.9rem; border: 1px solid #ffcdd2; }
/* Auth Form Styles */
.auth-container h1 {
    text-align: center;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}
.auth-container h2 {
    text-align: center;
    font-size: 1rem;
    font-weight: normal;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}
.form-group {
    margin-bottom: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text-primary);
}
.form-group input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}
.button-group {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}
.button-group .btn {
    flex: 1;
}

.btn { display: inline-flex; justify-content: center; align-items: center; padding: 0.75rem 1.5rem; font-size: 1rem; font-weight: 600; text-align: center; border: 2px solid transparent; border-radius: 8px; cursor: pointer; background-color: var(--primary-color); color: white; transition: all 0.2s ease; }
.btn:hover:not(:disabled) { opacity: 0.8; }
.btn.selected { border-color: var(--primary-color); background-color: #e7f3ff; color: var(--primary-color); }
.btn:disabled { background-color: #e9ecef; color: #adb5bd; cursor: not-allowed; }
.btn-secondary { background-color: var(--secondary-color); }
.btn-danger { background-color: var(--danger-color); }
.btn-icon { background: none; border: none; font-size: 1.5rem; padding: 0.5rem; color: var(--text-secondary); }

/* =================================================================
   Budget Warning Banner
   ================================================================= */
.budget-warning-banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, #fff3cd 0%, #ffe8a1 100%);
    border-bottom: 2px solid #ffc107;
    color: #856404;
    font-size: 0.95rem;
    font-weight: 500;
    flex-shrink: 0;
}
.budget-warning-banner .warning-icon { font-size: 1.2rem; }
.budget-warning-banner .warning-text { flex: 1; }
@media (max-width: 768px) {
    .budget-warning-banner { padding: 0.5rem 1rem; font-size: 0.85rem; }
}

/* =================================================================
   Main Layout & Header
   ================================================================= */
.app-header { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 2rem; background-color: var(--container-bg); border-bottom: 1px solid var(--border-color); height: 60px; flex-shrink: 0; }
.app-logo { font-size: 1.5rem; font-weight: bold; color: var(--primary-color); }
.main-nav-pc a { text-decoration: none; margin-left: 1.5rem; color: var(--text-secondary); font-weight: 500; }
.user-menu { position: relative; cursor: pointer; }
.user-menu-dropdown { display: none; position: absolute; right: 0; top: 100%; margin-top: 10px; background-color: var(--container-bg); border-radius: 8px; box-shadow: var(--shadow); padding: 0.5rem; z-index: 10; width: max-content; }
.user-menu-dropdown.visible { display: block; }
.header-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#main-content { flex-grow: 1; overflow-y: auto; }

/* =================================================================
   Dashboard & Setup Screens
   ================================================================= */
.dashboard-grid, .setup-main { max-width: 900px; margin: 0 auto; padding: 2rem 1rem; }
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; }
.dashboard-card { background: var(--container-bg); padding: 1.5rem; border-radius: 8px; box-shadow: var(--shadow); }
.dashboard-card a { text-decoration: none; color: inherit; display: block; }
.character-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.program-item { background: var(--container-bg); padding: 1.5rem; border-radius: 8px; border: 2px solid var(--border-color); cursor: pointer; }
.program-item.selected { border-color: var(--primary-color); }
.mode-selection { display: flex; gap: 1rem; flex-wrap: wrap; }
.mode-btn { flex: 1; min-width: 200px; padding: 1.5rem; font-size: 1.1rem; gap: 0.5rem; }
#start-session-button { margin-top: 1rem; }

/* =================================================================
   Conversation Screen (PC)
   ================================================================= */
#conversation-screen { align-items: center; justify-content: center; flex-grow: 1; }
.conversation-container { display: grid; grid-template-columns: minmax(0, 1fr) 420px; height: calc(100vh - 100px); max-width: 1280px; width: 100%; margin: 0 auto; background-color: var(--container-bg); box-shadow: var(--shadow); border-radius: 12px; }
.avatar-section { display: flex; flex-direction: column; position: relative; padding: 2rem; }
.avatar-container { height: 420px; display: flex; justify-content: center; align-items: flex-end; padding-bottom: 2rem; }
#avatar-image { width: 380px; height: 380px; border-radius: 50%; object-fit: cover; }
.speech-bubble-container { flex: 1; display: flex; justify-content: center; align-items: flex-start; padding-top: 2rem; position: relative; }
#speech-bubble { background: rgba(248, 249, 250, 0.95); padding: 1.5rem 2rem; border-radius: 16px; border: 1px solid var(--border-color); max-width: 480px; width: 100%; font-size: 1.25rem; opacity: 0; visibility: hidden; transition: all 0.3s ease; overflow-wrap: break-word; min-height: 5rem; max-height: 30vh; overflow-y: auto; }
#speech-bubble.visible { opacity: 1; visibility: visible; }
.controls-section { width: 420px; background: var(--container-bg); border-left: 1px solid var(--border-color); display: grid; grid-template-rows: 1fr auto; height: 100%; overflow: hidden; border-radius: 0 12px 12px 0; }
.history-log { padding: 1.5rem; overflow-y: auto; }
.control-input-area { padding: 1.5rem; border-top: 1px solid var(--border-color); background: var(--light-color); text-align: center; }
.status-display { min-height: 24px; text-align: center; color: var(--text-secondary); margin-bottom: 1rem; }
.history-message { padding: 0.5rem 1rem; border-radius: 12px; margin-bottom: 0.75rem; max-width: 90%; line-height: 1.5; }
.history-user { background: var(--primary-color); color: white; margin-left: auto; }
.history-ai { background: var(--light-color); color: var(--text-primary); margin-right: auto; }
#record-button {
    width: 70px; height: 70px;
    border-radius: 50%; background-color: var(--primary-color);
    color: white; border: none; box-shadow: var(--shadow); cursor: pointer;
    margin: 0 auto;
}
#record-button.recording { background-color: var(--danger-color); }
#record-button .icon { font-size: 2rem; }

/* =================================================================
   Mobile Specific Styles
   ================================================================= */
.main-nav-mobile, .mobile-conversation-footer { display: none; }
#user-email-display.is-mobile::before { content: '👤'; font-size: 1.8rem; }
#user-email-display.is-mobile .email-text { display: none; }

@media (max-width: 768px) {
    body { overflow-y: auto; }
    .main-nav-pc, .controls-section { display: none; }
    
    /* ▼ヘッダー内モバイルナビゲーションのスタイル▼ */
    .main-nav-mobile {
        display: flex;
        align-items: center;
        gap: 0.5rem; /* アイコン間の余白 */
        margin-left: 1rem;
    }
    .main-nav-mobile .mobile-nav-item {
        color: var(--text-secondary);
        text-decoration: none;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0 0.5rem;
    }
    .main-nav-mobile .mobile-nav-item span {
        font-size: 1.5rem; /* アイコンサイズ */
    }
    .main-nav-mobile .mobile-nav-item label {
        font-size: 0.6rem; /* ラベルサイズ */
        margin-top: -4px;
    }
    .main-nav-mobile .mobile-nav-item.active {
        color: var(--primary-color);
    }
    /* ▲ヘッダー内モバイルナビゲーションのスタイル▲ */

    #main-content { padding: 0 0 80px 0; margin: 0; }
    #conversation-screen.active { display: flex; flex-direction: column; height: calc(100vh - 60px); }
    .conversation-container { display: grid; grid-template-columns: 1fr; flex-direction: column; height: 100%; width: 100%; max-width: 100%; border-radius: 0; box-shadow: none; }
    .avatar-section { padding: 1rem; flex: 3; }
    .avatar-container { padding: 0; align-items: center; justify-content: center; }
    #avatar-image { width: 150px; height: 150px; }
    .speech-bubble-container { padding: 1rem; flex: 2; }
    #speech-bubble { font-size: 1rem; max-width: 100%; }

    /* ▼会話中フッターのスタイル (フッターナビとは別)▼ */
    .mobile-conversation-footer { 
      display: flex; 
      position: fixed; 
      bottom: 0; 
      left: 0; 
      width: 100%; 
      background: var(--container-bg); 
      border-top: 1px solid var(--border-color); 
      z-index: 100; 
      box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
      padding: 0.5rem; 
      justify-content: space-between; 
      align-items: center;
    }
    #conversation-screen:not(.active) ~ .mobile-conversation-footer { display: none; }
    #record-button-mobile { width: 65px; height: 65px; margin: 0 auto; }
    #record-button-mobile .icon { font-size: 1.8rem; }
}

#text-controls-main, #text-controls-mobile {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: stretch;
}

#text-input, #text-input-mobile {
    padding: 0.75rem;
    font-size: 1rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    resize: none;
    overflow-y: hidden;
    min-height: 40px;
    font-family: inherit;
    line-height: 1.5;
}

#send-text-button-mobile {
    padding: 0.5rem;
    flex-shrink: 0;
    width: 50px;
}

#text-controls-mobile {
    flex-grow: 1;
    flex-direction: row;
    align-items: flex-end;
}

/* =================================================================
   Learning History Screen
   ================================================================= */
   .history-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1rem;
  }
  .history-group {
    background-color: var(--container-bg);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow);
  }
  .history-group h3 {
    margin-top: 0;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.75rem;
    margin-bottom: 0.5rem;
  }
  .history-summary {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
  }
  .history-item {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1rem;
    margin-top: 1rem;
  }
  .history-item-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid #f0f0f0;
  }
  .history-score strong {
    font-size: 1.2em;
    color: var(--primary-color);
  }
  .history-item-feedback p {
    margin: 0;
    line-height: 1.6;
  }
  .history-item-actions {
    margin-top: 1rem;
    text-align: right;
  }
  .btn-sm {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
  }
  
  /* =================================================================
     Evaluation Detail Modal
     ================================================================= */
  .evaluation-detail h4 {
    margin-top: 1.5rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
  }
  .evaluation-summary {
    text-align: center;
    padding: 1rem;
    background: #f8f9fa;
    border-radius: 8px;
  }
  .evaluation-overall-score {
    font-size: 3rem;
    font-weight: bold;
    color: var(--primary-color);
    margin: 0.5rem 0;
  }
  .evaluation-overall-score span {
    font-size: 1rem;
    font-weight: normal;
    color: var(--text-secondary);
    margin-left: 0.25rem;
  }
  .evaluation-summary p {
    font-size: 1rem;
    line-height: 1.6;
    margin: 0;
  }
  .detailed-score-item {
    border-bottom: 1px solid #f0f0f0;
    padding: 1rem 0;
  }
  .detailed-score-item:last-child {
    border-bottom: none;
  }
  .detailed-score-item .item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
  }
  .detailed-score-item .item-name {
    font-weight: bold;
  }
  .detailed-score-item .item-score {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1rem;
    white-space: nowrap;
  }
  .detailed-score-item .item-score strong {
    font-size: 1.2em;
  }
  .detailed-score-item .item-feedback {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.7;
    white-space: pre-wrap; /* 改行を反映 */
    word-break: break-word; /* 長い単語を折り返す */
  }
  .score-label {
    font-size: 0.8rem;
    font-weight: bold;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    color: white;
  }
  .score-excellent { background-color: #28a745; }
  .score-good { background-color: #17a2b8; }
  .score-ok { background-color: #ffc107; color: var(--text-primary); }
  .score-poor { background-color: #fd7e14; }
  .score-bad { background-color: #dc3545; }


/* =================================================================
   Modal Styles (Generic)
   ================================================================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1500;
}

.modal-content {
  background-color: var(--container-bg);
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: var(--shadow);
  width: 90%;
  max-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.btn-close {
  background: none;
  border: none;
  font-size: 2rem;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
}

#evaluation-detail-container {
  overflow-y: auto;
  padding-right: 1rem;
}
/* ===== Login Page ===== */
.login-page {
  min-height: 100vh;
  display: flex;
  
}

.login-container {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2rem;
}

.login-form {
  width: 100%;
  max-width: 420px;
  background-color: #ffffff;
  border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.login-header {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  padding: 1.5rem 2rem;
}

.login-header h1 {
  margin: 0;
  color: white;
   font-size: 1.75rem;
  font-weight: 700;
}

.login-body {
  padding: 2.5rem 2rem;
}

.login-body h1 {
  text-align: center;
  margin: 0 0 2rem 0;
  color: #333;
    font-size: 1.75rem;
  font-weight: 600;
}

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.login-form .form-group input {
  width: 100%;
  padding: 1rem 1.25rem;
  font-size: 1rem;
  border: 2px solid #e8e8e8;
  border-radius: 10px;
  box-sizing: border-box;
  background-color: #fafafa;
  transition: all 0.3s ease;
}

.login-form .form-group input:focus {
  outline: none;
  border-color: #007bff;
  background-color: #fff;
  box-shadow: 0 0 0 4px rgba(0, 123, 255, 0.1);
}

.login-form .button-group {
  margin-top: 1.5rem;
  display: flex;
  gap: 1rem;
}

.login-form .button-group .btn {
  flex: 1;
  padding: 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-form .button-group .btn:first-child {
  background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
  color: white;
  box-shadow: 0 4px 15px rgba(0, 123, 255, 0.3);
}

.login-form .button-group .btn:first-child:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 123, 255, 0.4);
}

.login-form .button-group .btn-secondary {
  background-color: #6c757d;
  color: white;
}

.login-form .error-message {
  background-color: #fff2f2;
  color: #e74c3c;
  padding: 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  text-align: center;
  border-left: 4px solid #e74c3c;
}
/* =================================================================
   RESPONSIVE - User Frontend
   Tương tự như Admin responsive
   ================================================================= */

/* === Tablet (≤1024px) === */
@media (max-width: 1024px) {
  /* Header */
  .app-header {
    padding: 0.5rem 1rem;
    height: 56px;
  }
  
  .app-logo img {
    height: 24px;
  }
  
  .main-nav-pc a {
    margin-left: 1rem;
    font-size: 0.9rem;
  }
  
  #logout-button {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
  }
  
  /* Login Page */
  .login-form {
    max-width: 380px;
  }
  
  .login-header {
    padding: 1.25rem 1.5rem;
  }
  
  .login-header h1 {
    font-size: 1.5rem;
  }
  
  .login-body {
    padding: 2rem 1.5rem;
  }
  
  .login-body h1 {
    font-size: 1.5rem;
  }
  
  /* Setup Screen */
  .setup-main {
    padding: 1.5rem 1rem;
  }
  
  .setup-main h2 {
    font-size: 1.3rem;
  }
  
  .setup-main h3 {
    font-size: 1rem;
  }
  
  .character-cards {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
  }
  
  .program-item {
    padding: 1rem;
  }
  
  .mode-btn {
    min-width: 160px;
    padding: 1.25rem;
    font-size: 1rem;
  }
  
  /* History Screen */
  .history-container {
    padding: 1.5rem 1rem;
  }
  
  .history-group {
    padding: 1.25rem;
  }
  
  .history-group h3 {
    font-size: 1.1rem;
  }
  
  /* Conversation Screen */
  .conversation-container {
    grid-template-columns: minmax(0, 1fr) 360px;
    height: calc(100vh - 90px);
  }
  
  .controls-section {
    width: 360px;
  }
  
  .avatar-container {
    height: 360px;
  }
  
  #avatar-image {
    width: 320px;
    height: 320px;
  }
  
  #speech-bubble {
    max-width: 400px;
    font-size: 1.1rem;
    padding: 1.25rem 1.5rem;
  }
  
  /* Modal */
  .modal-content {
    max-width: 600px;
    padding: 1.25rem;
  }
  
  .modal-header h2 {
    font-size: 1.3rem;
  }
  
  /* Evaluation Detail */
  .evaluation-overall-score {
    font-size: 2.5rem;
  }
}

/* === Mobile (≤768px) - Bổ sung thêm cho breakpoint có sẵn === */
@media (max-width: 768px) {
  /* Header enhancements */
  .app-header {
    padding: 0.5rem 0.75rem;
    height: 52px;
  }
    .header-left {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    min-width: 0;
  }
  
  .app-logo {
    flex-shrink: 0;
  }
  .app-logo img {
    height: 22px;
  }
  
  .header-right {
    gap: 0.5rem !important;
  }
  
  #logout-button {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
  }
  
  /* Login Page Mobile */
  .login-container {
    padding: 1rem;
  }
  
  .login-form {
    max-width: 100%;
    border-radius: 12px;
  }
  
  .login-header {
    padding: 1rem 1.25rem;
  }
  
  .login-header h1 {
    font-size: 1.35rem;
  }
  
  .login-body {
    padding: 1.5rem 1.25rem;
  }
  
  .login-body h1 {
    font-size: 1.35rem;
    margin-bottom: 1.5rem;
  }
  
  .login-form .form-group input {
    padding: 0.85rem 1rem;
    font-size: 1rem;
  }
  
  .login-form .button-group {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .login-form .button-group .btn {
    width: 100%;
  }
  
  /* Setup Screen Mobile */
  .setup-main {
    padding: 1rem 0.75rem;
  }
  
  .setup-main h2 {
    font-size: 1.2rem;
    margin-bottom: 1rem;
  }
  
  .setup-main h3 {
    font-size: 0.95rem;
  }
  
  .setup-section {
    margin-bottom: 1.5rem;
  }
  
  .character-cards {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }
  
  .program-item {
    padding: 0.85rem;
  }
  
  .mode-selection {
    flex-direction: column;
    gap: 0.75rem;
  }
  
  .mode-btn {
    min-width: 100%;
    padding: 1rem;
    font-size: 1rem;
  }
  
  .text-mode-options {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  
  .demo-launcher {
    margin-top: 1rem;
  }
  
  .demo-launcher .btn {
    width: 100%;
    font-size: 0.9rem;
  }
  
  #start-session-button {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
  }
  
  /* History Screen Mobile */
  .history-container {
    padding: 1rem 0.5rem;
  }
  
  .history-group {
    padding: 1rem;
    margin-bottom: 1rem;
  }
  
  .history-group h3 {
    font-size: 1rem;
    padding-bottom: 0.5rem;
  }
  
  .history-summary {
    font-size: 0.85rem;
  }
  
  .history-item {
    padding: 0.75rem;
  }
  
  .history-item-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
    font-size: 0.85rem;
  }
  
  .history-score {
    margin-top: 0.25rem;
  }
  
  .history-item-feedback p {
    font-size: 0.9rem;
  }
  
  .history-item-actions {
    text-align: center;
  }
  
  .history-item-actions .btn {
    width: 100%;
  }
  
  /* Conversation Screen Mobile (enhancement) */
  .avatar-section {
    padding: 0.75rem;
    flex: 2;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
  }
  
  .avatar-container {
    height: auto;
    padding: 0;
    flex-shrink: 0;
  }
  
  #avatar-image {
    width: 140px;
    height: 140px;
  }
  
  .speech-bubble-container {
    padding: 0.75rem;
    flex: 1;
    min-height: 80px;
  }
  
  #speech-bubble {
    font-size: 0.95rem;
    padding: 1rem;
    max-height: 25vh;
    border-radius: 12px;
  }
  
  /* Modal Mobile */
  .modal-content {
    width: 95%;
    max-width: 100%;
    max-height: 85vh;
    padding: 1rem;
    border-radius: 12px;
  }
  
  .modal-header {
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
  }
  
  .modal-header h2 {
    font-size: 1.1rem;
  }
  
  .btn-close {
    font-size: 1.5rem;
  }
  
  /* Evaluation Detail Mobile */
  .evaluation-summary {
    padding: 0.75rem;
  }
  
  .evaluation-overall-score {
    font-size: 2rem;
  }
  
  .evaluation-summary p {
    font-size: 0.9rem;
  }
  
  .detailed-score-item {
    padding: 0.75rem 0;
  }
  
  .detailed-score-item .item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.25rem;
  }
  
  .detailed-score-item .item-name {
    font-size: 0.95rem;
  }
  
  .detailed-score-item .item-score {
    font-size: 0.9rem;
  }
  
  .detailed-score-item .item-feedback {
    font-size: 0.85rem;
  }
  
  /* Footer Mobile */
  .mobile-conversation-footer {
    padding: 0.5rem 0.75rem;
    gap: 0.5rem;
  }
  
  #record-button-mobile {
    width: 60px;
    height: 60px;
  }
  
  #record-button-mobile .icon {
    font-size: 1.6rem;
  }
  
  .btn-icon {
    font-size: 1.3rem;
    padding: 0.4rem;
  }
  
  /* Text Controls Mobile */
  #text-controls-mobile {
    flex-grow: 1;
    gap: 0.5rem;
  }
  
  #text-input-mobile {
    font-size: 0.95rem;
    padding: 0.6rem;
    min-height: 38px;
  }
  
  #send-text-button-mobile {
    width: 44px;
    min-height: 44px;
    padding: 0.4rem;
    font-size: 1.2rem;
  }
}

/* === Small Mobile (≤480px) === */
@media (max-width: 480px) {
  /* Header Small Mobile */
  .app-header {
    padding: 0.4rem 0.5rem;
    height: 48px;
  }
  
  .app-logo img {
    height: 20px;
  }
  
  .main-nav-mobile .mobile-nav-item {
    padding: 0 0.35rem;
  }
  
  .main-nav-mobile .mobile-nav-item span {
    font-size: 1.3rem;
  }
  
  .main-nav-mobile .mobile-nav-item label {
    font-size: 0.55rem;
  }
  
  #logout-button {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
  }
  
  /* Login Page Small Mobile */
  .login-container {
    padding: 0.75rem;
  }
  
  .login-header {
    padding: 0.85rem 1rem;
  }
  
  .login-header h1 {
    font-size: 1.2rem;
  }
  
  .login-body {
    padding: 1.25rem 1rem;
  }
  
  .login-body h1 {
    font-size: 1.2rem;
    margin-bottom: 1.25rem;
  }
  
  .login-form .form-group {
    margin-bottom: 1rem;
  }
  
  .login-form .form-group input {
    padding: 0.75rem 0.85rem;
    font-size: 0.95rem;
    border-radius: 8px;
  }
  
  .login-form .button-group .btn {
    padding: 0.85rem;
    font-size: 0.95rem;
  }
  
  /* Setup Screen Small Mobile */
  .setup-main {
    padding: 0.75rem 0.5rem;
  }
  
  .setup-main h2 {
    font-size: 1.1rem;
  }
  
  .setup-main h3 {
    font-size: 0.9rem;
  }
  
  .program-item {
    padding: 0.75rem;
    font-size: 0.9rem;
  }
  
  .mode-btn {
    padding: 0.85rem;
    font-size: 0.95rem;
  }
  
  .mode-btn .mode-icon {
    font-size: 1.2rem;
  }
  
  #start-session-button {
    padding: 0.85rem;
    font-size: 0.95rem;
  }
  
  /* History Screen Small Mobile */
  .history-container {
    padding: 0.75rem 0.35rem;
  }
  
  .history-group {
    padding: 0.75rem;
  }
  
  .history-group h3 {
    font-size: 0.95rem;
  }
  
  .history-item {
    padding: 0.6rem;
  }
  
  .history-item-meta {
    font-size: 0.8rem;
  }
  
  .history-score strong {
    font-size: 1rem;
  }
  
  .btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
  }
  
  /* Conversation Screen Small Mobile */
  #conversation-screen.active {
    height: calc(100vh - 48px);
  }
  
  .avatar-section {
    padding: 0.5rem;
  }
  
  #avatar-image {
    width: 120px;
    height: 120px;
  }
  
  .speech-bubble-container {
    padding: 0.5rem;
  }
  
  #speech-bubble {
    font-size: 0.9rem;
    padding: 0.85rem;
    max-height: 22vh;
  }
  
  /* Modal Small Mobile */
  .modal-content {
    width: 98%;
    padding: 0.75rem;
    max-height: 90vh;
  }
  
  .modal-header h2 {
    font-size: 1rem;
  }
  
  .btn-close {
    font-size: 1.3rem;
  }
  
  /* Evaluation Detail Small Mobile */
  .evaluation-overall-score {
    font-size: 1.75rem;
  }
  
  .evaluation-summary p {
    font-size: 0.85rem;
  }
  
  .detailed-score-item .item-name {
    font-size: 0.9rem;
  }
  
  .detailed-score-item .item-feedback {
    font-size: 0.8rem;
    line-height: 1.6;
  }
  
  .score-label {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
  }
  
  /* Footer Small Mobile */
  .mobile-conversation-footer {
    padding: 0.4rem 0.5rem;
  }
  
  #record-button-mobile {
    width: 55px;
    height: 55px;
  }
  
  #record-button-mobile .icon {
    font-size: 1.4rem;
  }
  
  .btn-icon {
    font-size: 1.2rem;
    padding: 0.35rem;
  }
  
  #text-input-mobile {
    font-size: 0.9rem;
    padding: 0.5rem;
  }
  
  #send-text-button-mobile {
    width: 40px;
    min-height: 40px;
    font-size: 1.1rem;
  }
  
  /* Main content padding */
  #main-content {
    padding-bottom: 70px;
  }
}

/* === Landscape Mobile (chiều ngang) === */
@media (max-width: 768px) and (orientation: landscape) {
  .avatar-section {
    flex-direction: row;
    padding: 0.5rem;
  }
  
  .avatar-container {
    flex: 0 0 auto;
  }
  
  #avatar-image {
    width: 100px;
    height: 100px;
  }
  
  .speech-bubble-container {
    flex: 1;
    padding: 0.5rem;
    align-items: center;
  }
  
  #speech-bubble {
    max-height: 40vh;
  }
  
  #conversation-screen.active {
    height: calc(100vh - 48px);
  }
  
  .mobile-conversation-footer {
    padding: 0.35rem 0.5rem;
  }
  
  #record-button-mobile {
    width: 50px;
    height: 50px;
  }
}
/* === iPhone Specific Fixes === */
@supports (-webkit-touch-callout: none) {
  /* Header fix for iPhone */
  .app-header {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }
  
  .header-left {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
    -webkit-box-align: center;
  }
  
  /* Fix flexbox on older iOS */
  .app-header {
    display: -webkit-flex;
    display: flex;
    -webkit-justify-content: space-between;
    justify-content: space-between;
    -webkit-align-items: center;
    align-items: center;
  }
  
  .header-right {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
  }
  
  /* Mobile nav fix */
  .main-nav-mobile {
    display: -webkit-flex;
    display: flex;
    -webkit-align-items: center;
    align-items: center;
  }
}

/* iPhone 10/X series notch handling */

/* === iOS Safari Flexbox Fix === */
@media (max-width: 768px) {
  .header-left {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: flex !important;
    -webkit-box-orient: horizontal !important;
    -webkit-box-direction: normal !important;
    -webkit-flex-direction: row !important;
    flex-direction: row !important;
    -webkit-flex-wrap: nowrap !important;
    flex-wrap: nowrap !important;
    -webkit-box-align: center !important;
    -webkit-align-items: center !important;
    align-items: center !important;
    gap: 0.25rem;
  }

  .app-logo {
    -webkit-flex-shrink: 0 !important;
    flex-shrink: 0 !important;
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: flex !important;
    -webkit-box-align: center !important;
    -webkit-align-items: center !important;
    align-items: center !important;
  }

  .main-nav-mobile {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: flex !important;
    -webkit-box-orient: horizontal !important;
    -webkit-box-direction: normal !important;
    -webkit-flex-direction: row !important;
    flex-direction: row !important;
    -webkit-flex-wrap: nowrap !important;
    flex-wrap: nowrap !important;
    -webkit-box-align: center !important;
    -webkit-align-items: center !important;
    align-items: center !important;
  }

  .main-nav-mobile .mobile-nav-item {
    display: -webkit-box !important;
    display: -webkit-flex !important;
    display: flex !important;
    -webkit-box-orient: vertical !important;
    -webkit-box-direction: normal !important;
    -webkit-flex-direction: column !important;
    flex-direction: column !important;
    -webkit-box-align: center !important;
    -webkit-align-items: center !important;
    align-items: center !important;
  }
}

/* === Extra Small Mobile (≤320px) - iPhone SE, iPhone 5s === */
@media (max-width: 320px) {
  /* Prevent horizontal overflow */
  html, body {
    max-width: 100vw;
    overflow-x: hidden;
  }

  /* Header */
  .app-header {
    padding: 0.3rem 0.4rem;
    height: 44px;
  }

  .app-logo img {
    height: 18px;
  }

  .main-nav-mobile {
    gap: 0.2rem;
    margin-left: 0.5rem;
  }

  .main-nav-mobile .mobile-nav-item {
    padding: 0 0.25rem;
  }

  .main-nav-mobile .mobile-nav-item span {
    font-size: 1.1rem;
  }

  .main-nav-mobile .mobile-nav-item label {
    font-size: 0.5rem;
  }

  #logout-button {
    padding: 0.25rem 0.4rem;
    font-size: 0.7rem;
  }

  /* Main content */
  #main-content {
    padding: 0;
    padding-bottom: 65px;
  }

  /* Setup Screen */
  .setup-main {
    padding: 0.5rem 0.4rem;
  }

  .setup-main h2 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
  }

  .setup-main h3 {
    font-size: 0.85rem;
  }

  .program-item {
    padding: 0.6rem;
    font-size: 0.85rem;
    border-radius: 6px;
  }

  .program-item h4 {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
  }

  .program-item p {
    font-size: 0.8rem;
    margin: 0;
  }

  .mode-btn {
    padding: 0.75rem;
    font-size: 0.9rem;
  }

  #start-session-button {
    padding: 0.75rem;
    font-size: 0.9rem;
  }

  /* Conversation Screen */
  #conversation-screen.active {
    height: calc(100vh - 44px);
  }

  .avatar-section {
    padding: 0.4rem;
  }

  #avatar-image {
    width: 100px;
    height: 100px;
  }

  .speech-bubble-container {
    padding: 0.4rem;
  }

  #speech-bubble {
    font-size: 0.85rem;
    padding: 0.75rem;
    max-height: 20vh;
  }

  /* Footer */
  .mobile-conversation-footer {
    padding: 0.35rem 0.4rem;
  }

  #record-button-mobile {
    width: 50px;
    height: 50px;
  }

  #record-button-mobile .icon {
    font-size: 1.2rem;
  }

  /* History Screen */
  .history-container {
    padding: 0.5rem 0.3rem;
  }

  .history-group {
    padding: 0.6rem;
  }

  .history-group h3 {
    font-size: 0.9rem;
  }

  .history-item {
    padding: 0.5rem;
  }

  /* Modal */
  .modal-content {
    width: 100%;
    padding: 0.5rem;
    border-radius: 8px;
    margin: 0.25rem;
  }

  .modal-header h2 {
    font-size: 0.95rem;
  }
}
