/**
 * LLOT Modern Design 2025 - Clean and Functional
 */

/* CSS Variables */
:root {
  /* Light theme colors */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --border-focus: #3b82f6;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --error: #ef4444;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  --space-2xl: 3rem;
  
  /* Borders */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

/* Dark theme */
[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #334155;
  --border: #475569;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --accent: #60a5fa;
  --accent-hover: #3b82f6;
}

/* Reset and base styles */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
}

/* Layout - wider like DeepL */
.app-container {
  min-height: 100vh;
  /* iOS Safari vh fix */
  min-height: -webkit-fill-available;
  padding: var(--space-sm);
}

.main-container {
  max-width: 1600px; /* Wider like DeepL */
  margin: 0 auto;
  width: 100%;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* Options dropdown styles */

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  text-decoration: none;
  color: var(--text-primary);
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.brand-logo img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.brand-subtitle {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.header-info {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
}

.status-indicator:hover .status-details {
  opacity: 1;
  visibility: visible;
}

.status-details {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--space-sm);
  padding: var(--space-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  opacity: 0;
  visibility: hidden;
  z-index: 100;
  transition: opacity 0.2s, visibility 0.2s;
}

.status-details div {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.status-details div:last-child {
  margin-bottom: 0;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: all 0.2s ease;
}

.status-dot.connected { background: var(--success); }
.status-dot.warning { background: #f59e0b; }
.status-dot.error { background: var(--error); }
.status-dot.pulse { animation: pulse 1.5s infinite; }

.theme-toggle {
  width: 40px;
  height: 40px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* Workspace */
.workspace {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden; /* Clip content to workspace rounded corners */
}

/* Control bar - hidden */
.control-bar {
  display: none;
}

/* Language controls bar like DeepL - hidden on desktop, visible on mobile */
.language-controls-bar {
  display: none;
}


/* Panel headers container with swap button */
.panels-header {
  display: flex;
  position: relative;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

/* Panel headers - consolidated with reduced height */
.panel-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  padding: var(--space-md);
  background: var(--bg-secondary);
  height: 60px; /* Reduced height */
  box-sizing: border-box;
  flex: 1;
  position: relative;
}



/* Ensure consistent width for language dropdowns */
.panel-header .language-dropdown:first-child {
  width: 180px; /* Fixed width based on longest language name "Detect language" */
}

/* Source language dropdown - align to right (towards swap button) */
.panel-header:first-child .language-dropdown:first-child {
  margin-left: auto;
  margin-right: 20px; /* Fixed distance from swap button */
}

/* Source language dropdown text - align right */
.panel-header:first-child .language-dropdown-trigger {
  text-align: right;
  justify-content: flex-end;
  padding-right: var(--space-sm); /* Reduce right padding to align text to edge */
}

.panel-header:first-child .selected-language {
  text-align: right;
}

/* Source dropdown arrow - keep default position (right side) */
.panel-header:first-child .language-dropdown-trigger::after {
  /* Arrow pointing down (normal dropdown arrow) */
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  border-bottom: none;
  margin-left: var(--space-sm);
  margin-right: 0;
}

/* Target dropdown arrow - keep default position (right side) */
.panel-header:last-child .language-dropdown-trigger::after {
  /* Arrow pointing down (normal dropdown arrow) */
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  border-bottom: none;
  margin-left: var(--space-sm);
  margin-right: 0;
}

/* Target language dropdown - align to left (towards swap button) */  
.panel-header:last-child .language-dropdown:first-child {
  position: absolute;
  left: 36px; /* Adjusted distance to match source symmetry */
  transform: none;
  width: 180px; /* Same fixed width as source dropdown for symmetry */
}

.panel-header .language-dropdown-trigger {
  width: 100%;
  min-width: 180px; /* Ensure minimum width */
}

/* Swap button in header center */
.swap-button-header {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
  z-index: 10;
  transition: all 0.2s;
}

.swap-button-header:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.panel-header .options-menu {
  position: absolute;
  right: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  z-index: 100;
}

.options-menu .options-trigger {
  background: transparent;
  border: none;
  padding: var(--space-sm);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all 0.2s ease;
  min-width: 40px;
  min-height: 40px;
  justify-content: center;
  display: flex;
  align-items: center;
  cursor: pointer;
}

/* Remove arrow from options trigger */
.options-menu .options-trigger::after {
  display: none;
}

.options-menu .options-trigger:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}


.options-content {
  padding: 0;
  background: var(--bg-card);
}

.option-section {
  padding: var(--space-md);
}

.option-header {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}

.option-item {
  margin-bottom: var(--space-lg);
  position: relative;
}

.option-item:last-child {
  margin-bottom: 0;
}

/* Better layout for options with custom selects */
.option-section {
  padding: var(--space-lg) !important; /* Minimal padding - dropdowns escape completely */
}

.option-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  align-items: start;
}

@media (max-width: 768px) {
  .option-controls {
    grid-template-columns: 1fr;
    gap: var(--space-md);
  }
  
}

.option-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.option-select {
  width: 100%;
  height: 44px;
  padding: 0 var(--space-md);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 12px center;
  background-repeat: no-repeat;
  background-size: 16px;
  padding-right: 44px;
  box-sizing: border-box;
  position: relative;
  z-index: 2001;
}

.option-select:hover {
  border-color: var(--accent);
  background-color: var(--bg-secondary);
}

.option-select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
  background-color: var(--bg-primary);
}


.swap-button-top {
  width: 36px;
  height: 36px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  flex-shrink: 0;
}

.swap-button-top:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Translation interface */
.translation-interface {
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 500px;
  position: relative;
}

/* Continuous separator line through entire interface */
.translation-interface::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--border);
  transform: translateX(-50%);
  z-index: 1;
}

.input-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.output-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Swap button */
.swap-button-center {
  display: none;
}

.swap-button-center:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}


/* Language dropdowns */
.language-dropdown {
  position: relative;
  display: inline-block;
}

.language-dropdown-trigger {
  background: transparent;
  border: none;
  padding: var(--space-sm) var(--space-lg) var(--space-sm) var(--space-sm);
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  position: relative;
}

.language-dropdown-trigger::after {
  content: '';
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
  margin-left: var(--space-sm);
  transition: transform 0.2s;
}

.language-dropdown.open .language-dropdown-trigger::after {
  transform: rotate(180deg);
}

.language-dropdown-panel {
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  min-width: 450px;
  max-width: 600px;
  display: none;
  opacity: 0;
  visibility: hidden;
  transform: none;
  transition: opacity 0.15s ease, visibility 0.15s ease;
}

.language-dropdown.open .language-dropdown-panel {
  display: block;
  opacity: 1;
  visibility: visible;
}

.language-dropdown-search {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.language-dropdown-search input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.language-dropdown-search input:focus {
  outline: none;
  border-color: var(--border-focus);
}

.language-dropdown-content {
  display: grid;
  grid-template-columns: repeat(3, max-content);
  gap: var(--space-sm);
  padding: var(--space-md);
  max-height: 400px;
  overflow-y: auto;
  overflow-x: hidden;
  justify-content: start;
  /* Ensure scrollbar doesn't overlap rounded corners */
  padding-right: calc(var(--space-md) + 2px); /* Extra padding for scrollbar */
  scrollbar-gutter: stable; /* Reserve space for scrollbar */
}

/* Custom scrollbar for dropdown */
.language-dropdown-content::-webkit-scrollbar {
  width: 6px;
}

.language-dropdown-content::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 3px;
}

.language-dropdown-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.language-dropdown-content::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}


/* Clean translation states */
.text-output {
  cursor: text;
  position: relative;
  font-size: 1.125rem;
  line-height: 1.6;
  transition: opacity 0.2s ease;
}

.text-output.translating {
  opacity: 0.6;
}

.language-dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: background-color 0.2s;
  white-space: nowrap;
  min-width: 0;
}

.language-dropdown-item:hover {
  background: var(--bg-secondary);
}

.language-dropdown-item.selected {
  background: var(--bg-secondary);
  color: var(--accent);
  font-weight: 500;
}

.language-dropdown-item .flag {
  font-size: 1rem;
  width: 20px;
}

.language-dropdown-item .name {
  flex: 1;
}

/* Text areas */
.text-input, .text-output {
  flex: 1;
  padding: var(--space-lg);
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 2rem; /* Start with large font like DeepL */
  line-height: 1.4;
  transition: font-size 0.2s ease, line-height 0.2s ease;
  color: var(--text-primary);
  resize: none;
  outline: none;
  min-height: 400px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

/* Ensure text doesn't overlap with TTS button */
.text-output {
  word-wrap: break-word;
  overflow-wrap: anywhere;
  word-break: break-all;
  white-space: pre-wrap;
  hyphens: auto;
  word-spacing: -0.15em;
}

/* Create space only in the top-right area where action buttons are positioned */
.text-output::before {
  content: '';
  float: right;
  width: 5rem; /* Width for two buttons + gap */
  height: 2.5rem; /* Height to cover button area */
  shape-outside: rectangle();
}

/* Clickable words in output */

.clickable-word {
  cursor: pointer;
  padding: 2px 4px;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  display: inline;
  position: relative;
}

.clickable-word:hover {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
}

.clickable-word.selected {
  background: var(--accent);
  color: white;
}

.text-input {
  overflow: hidden;
  resize: none;
  height: auto;
}

.text-input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--border-focus);
  border-radius: var(--radius-sm);
}

.text-input::placeholder {
  color: var(--text-muted);
}

/* Dynamic font scaling like DeepL for both input and output */
.text-input.font-large, .text-output.font-large {
  font-size: 2rem;
  line-height: 1.4;
}

.text-input.font-medium, .text-output.font-medium {
  font-size: 1.5rem;
  line-height: 1.5;
}

.text-input.font-normal, .text-output.font-normal {
  font-size: 1.125rem;
  line-height: 1.6;
}

.text-input.font-small, .text-output.font-small {
  font-size: 1rem;
  line-height: 1.7;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.translation-status {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.char-count {
  font-size: 0.875rem;
  color: var(--text-muted);
}

/* History panel - improved contrast */
.history-panel {
  margin-top: var(--space-xl);
  background: var(--bg-card);
  border: 1px solid #d1d5db; /* Visible gray border */
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); /* Stronger shadow for better definition */
  padding: var(--space-lg); /* Add padding to panel instead of individual elements */
}

/* Dark theme history panel */
[data-theme="dark"] .history-panel {
  border: 1px solid #4b5563; /* Visible border in dark theme */
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.history-header {
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; /* Round top corners to match panel */
  margin: calc(-1 * var(--space-lg)) calc(-1 * var(--space-lg)) var(--space-md) calc(-1 * var(--space-lg)); /* Extend to panel edges */
  padding: var(--space-lg); /* Add padding back to header content */
}

.history-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.history-list {
  max-height: 200px;
  overflow-y: auto;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); /* Round bottom corners to match panel */
  margin: 0 calc(-1 * var(--space-lg)) calc(-1 * var(--space-lg)) calc(-1 * var(--space-lg)); /* Extend to panel edges */
  /* Ensure scrollbar doesn't overlap rounded corners */
  padding-right: 8px; /* More padding to prevent scrollbar from touching rounded corner */
  scrollbar-gutter: stable; /* Reserve space for scrollbar */
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background-color 0.2s;
  gap: var(--space-md);
}

.history-item:last-child {
  border-bottom: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg); /* Round bottom corners for last item */
}

.history-item:hover {
  background: var(--bg-secondary);
}

.history-text {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.4;
}

.history-source {
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.history-result {
  color: var(--text-primary);
  font-weight: 500;
}

.history-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--space-xs);
  flex-shrink: 0;
}

.history-lang {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-time {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Error message */
.error-message {
  background: var(--bg-card);
  border: 1px solid var(--error);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  margin-top: var(--space-lg);
  color: var(--error);
}

/* iOS Safari fixes - Enhanced for better compatibility */
@supports (-webkit-touch-callout: none) {
  .app-container {
    /* Fix for iOS Safari viewport height with address bar */
    min-height: -webkit-fill-available;
  }
  
  /* Prevent iOS Safari zoom on input focus - Enhanced */
  input, textarea, select {
    font-size: 16px !important;
    -webkit-text-size-adjust: 100%;
  }
  
  /* Fix dropdown positioning on iOS - Enhanced */
  .language-dropdown-panel {
    position: fixed !important;
    z-index: 9999 !important;
    /* Use transform for better positioning */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Ensure dropdown stays within viewport */
    max-width: 85vw !important;
    box-sizing: border-box;
  }
  
  /* iOS Safari specific dropdown positioning for top bar */
  .language-controls-bar .language-dropdown-panel {
    max-width: 75vw !important;
    left: 50% !important;
    transform: translateX(-50%) translateZ(0) !important;
    -webkit-transform: translateX(-50%) translateZ(0) !important;
  }
  
  /* Better touch handling on iOS - Enhanced */
  .language-dropdown-trigger,
  .action-button,
  .theme-toggle,
  .swap-button-center {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* Prevent scroll issues on iOS when dropdown opens */
  body.dropdown-open {
    position: fixed !important;
    width: 100%;
    overflow: hidden;
  }
}

/* General dropdown scroll lock (works on all devices) */
body.dropdown-open {
  position: fixed !important;
  top: 0;
  left: 0;
  width: 100%;
  overflow: hidden;
}

/* Responsive design */
@media (max-width: 768px) {
  .app-container {
    padding: var(--space-md);
    /* Additional iOS viewport fix */
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  .header {
    /* Keep header in one line on mobile like DeepL */
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-sm);
    /* Reduce padding on mobile for space efficiency */
    padding: var(--space-md);
  }
  
  .header-info {
    /* Keep connection status compact on mobile */
    flex-direction: row;
    gap: var(--space-sm);
    align-items: center;
  }
  
  /* Show language controls bar on mobile like DeepL */
  .language-controls-bar {
    display: flex !important;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    min-height: 56px; /* Increased to accommodate 48px button + padding */
    position: relative; /* Ensure proper stacking context */
    z-index: 10; /* Ensure it appears above other elements */
    overflow: visible; /* Ensure rounded corners of dropdown buttons are not clipped */
  }
  
  /* Language dropdowns in mobile bar */
  .language-controls-bar .language-dropdown {
    flex: 1;
    min-width: 0; /* Allow flex shrinking */
  }
  
  .language-controls-bar .language-dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    font-size: 0.875rem;
    font-weight: 500;
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    min-height: 40px;
    transition: all 0.15s ease;
  }
  
  .language-controls-bar .language-dropdown-trigger:hover {
    border-color: var(--border-focus);
    background: var(--bg-card);
  }
  
  .language-controls-bar .language-dropdown-trigger .selected-language {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: var(--space-sm);
  }
  
  .language-controls-bar .swap-button-top {
    flex-shrink: 0;
    width: 48px; /* Increased for Android touch target guidelines */
    height: 48px; /* Increased for Android touch target guidelines */
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    margin: 0;
  }
  
  .language-controls-bar .swap-button-top:hover {
    border-color: var(--border-focus);
    background: var(--bg-card);
    color: var(--accent);
  }
  
  /* Workspace adjustments for mobile */
  .workspace {
    border-radius: var(--radius-lg);
    overflow: hidden; /* Clip content to show rounded corners properly */
  }

  /* Hide panel headers on mobile to prevent overlap with language-controls-bar */
  .panels-header {
    display: none !important; /* Hide completely on mobile to prevent overlap */
  }

  .translation-interface {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
    position: relative;
    margin-top: 0; /* Ensure no gap between language-controls-bar and interface */
    border-radius: 0 0 var(--radius-lg) var(--radius-lg); /* Only round bottom corners */
  }
  
  /* Change separator line to horizontal on mobile */
  .translation-interface::before {
    left: 0;
    right: 0;
    top: 50%;
    bottom: auto;
    width: auto;
    height: 1px;
    transform: translateY(-50%);
  }
  
  .input-panel {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0; /* Round top corners - panel is at the top */
    border-top: none; /* Remove top border to connect seamlessly with language-controls-bar */
  }
  
  .output-panel {
    border-radius: 0 0 var(--radius-lg) var(--radius-lg); /* Only round bottom corners */
    border-top: 1px solid var(--border); /* Add separator between input and output */
  }
  
  /* Hide desktop swap button on mobile */
  .swap-button-center {
    display: none;
  }
  
  .text-input, .text-output {
    min-height: 200px;
  }
  
  /* iOS keyboard handling */
  .text-input:focus {
    /* Prevent iOS from zooming when keyboard appears */
    font-size: 16px !important;
    /* Ensure input stays visible when keyboard appears */
    transform: translateZ(0);
  }
  
  /* Fix for all inputs on iOS to prevent zoom */
  .language-dropdown-search input:focus {
    font-size: 16px !important;
    zoom: 1;
  }
  
  /* Adjust font scaling for mobile - slightly smaller base sizes for both input and output */
  .text-input.font-large, .text-output.font-large {
    font-size: 1.75rem;
  }
  
  .text-input.font-medium, .text-output.font-medium {
    font-size: 1.25rem;
  }
  
  .text-input.font-normal, .text-output.font-normal {
    font-size: 1rem;
  }
  
  .text-input.font-small, .text-output.font-small {
    font-size: 0.875rem;
  }
  
  /* Mobile adjustments for action buttons */
  .output-actions {
    gap: var(--space-sm);
  }
  
  .action-button {
    width: 36px;
    height: 36px;
    padding: var(--space-md);
  }
  
  .text-output::before {
    width: 6rem; /* Extra space for larger mobile buttons */
  }
  
  /* Mobile dropdown panel sizing - responsive to screen width */
  .language-dropdown-panel {
    min-width: min(280px, 80vw); /* Responsive minimum width */
    max-width: 85vw; /* Ensure it never exceeds 85% of viewport */
    width: auto; /* Allow content-based sizing */
  }
  
  /* Special handling for language controls bar dropdowns */
  .language-controls-bar .language-dropdown-panel {
    min-width: min(240px, 70vw); /* Even smaller for Android compatibility */
    max-width: 70vw; /* More constrained to prevent overflow */
    left: 50%; /* Center align */
    transform: translateX(-50%); /* Perfect centering */
    box-sizing: border-box; /* Include padding/border in width calculation */
  }
  
  .language-dropdown-content {
    grid-template-columns: 1fr; /* Single column on mobile */
  }
}

@media (max-width: 480px) {
  .brand-title {
    font-size: 1.25rem;
  }
  
  .brand-subtitle {
    font-size: 0.8125rem;
  }
  
  /* Extra small screens: make header even more compact */
  .header {
    padding: var(--space-sm);
    gap: var(--space-xs);
  }
  
  .header-info {
    gap: var(--space-xs);
  }
  
  /* Hide status details text on very small screens, keep only dot */
  .status-indicator .status-text {
    display: none;
  }
  
  /* Very small screen dropdown sizing */
  .language-dropdown-panel {
    min-width: min(240px, 70vw); /* Even more constrained on small screens */
    max-width: 90vw; /* Allow more space on very small screens */
    width: auto;
  }
  
  /* Top bar dropdowns on very small screens */
  .language-controls-bar .language-dropdown-panel {
    min-width: min(200px, 60vw); /* Ultra compact for small Android screens */
    max-width: 65vw; /* Very tight constraint */
    left: 50%;
    transform: translateX(-50%);
    box-sizing: border-box;
  }
  
  .language-dropdown-content {
    grid-template-columns: 1fr;
    max-height: 250px;
  }
  
  .text-input, .text-output {
    min-height: 150px;
  }
}

/* Focus styles */
button:focus-visible,
select:focus-visible,
textarea:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Scrollbar - Enhanced for rounded corners visibility */
::-webkit-scrollbar {
  width: 6px; /* Thinner scrollbar to avoid overlapping rounded corners */
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  margin: 2px; /* Add margin to prevent overlap with rounded corners */
  border-radius: var(--radius-sm);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-sm);
  margin: 1px; /* Small margin to respect rounded corner areas */
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* For Safari - ensure scrollbars don't overlap rounded corners */
::-webkit-scrollbar-corner {
  background: transparent;
}

/* History list specific scrollbar - extra small */
.history-list::-webkit-scrollbar {
  width: 4px; /* Very thin scrollbar for history */
}

.history-list::-webkit-scrollbar-track {
  background: transparent; /* Invisible track */
  margin: 4px; /* More margin from rounded corners */
}

.history-list::-webkit-scrollbar-thumb {
  background: var(--text-muted); /* Lighter color */
  border-radius: 2px;
  margin: 2px; /* Extra margin from edges */
}

.history-list::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Selection */
::selection {
  background: var(--accent);
  color: white;
}

/* Word alternatives popup */
.word-alternatives {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-md);
  z-index: 1000;
  min-width: 200px;
  max-width: 300px;
  display: none;
}

.word-alternatives.show {
  display: block;
}

.alternatives-header {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border);
}

.alternatives-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.alternative-item {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-primary);
  transition: background-color 0.2s ease;
  border: 1px solid transparent;
}

.alternative-item:hover {
  background: var(--bg-secondary);
  color: var(--accent);
  border-color: var(--border);
}

.alternative-item.current {
  background: rgba(59, 130, 246, 0.1);
  color: var(--accent);
  font-weight: 500;
}

.alternatives-loading {
  text-align: center;
  padding: var(--space-lg);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.alternatives-loading .spinner {
  margin: 0 auto var(--space-sm);
}

/* Validation popup */
.validation-popup {
  position: fixed;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-lg);
  z-index: 2000;
  min-width: 300px;
  max-width: 400px;
  display: none;
}

.validation-popup.show {
  display: block;
}

.validation-message {
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: var(--space-lg);
  text-align: center;
}

.validation-actions {
  display: flex;
  gap: var(--space-sm);
  justify-content: center;
}

.validation-btn {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.validation-btn:hover {
  background: var(--bg-card);
  transform: translateY(-1px);
}

.validation-btn.accept {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.validation-btn.accept:hover {
  background: var(--accent-hover);
}

.validation-btn.reject {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.validation-btn.reject:hover {
  background: #dc2626;
}

/* Validating word state */
.clickable-word.validating {
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

/* Output Actions Container */
.output-actions {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  display: flex;
  gap: var(--space-xs);
  z-index: 10;
}

/* Action Buttons (TTS and Copy) */
.action-button {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
  width: 32px;
  height: 32px;
}

.action-button:hover {
  background: rgba(255, 255, 255, 1);
  color: var(--accent);
  border-color: var(--accent);
  transform: scale(1.05);
  box-shadow: var(--shadow-md);
}

.action-button:active {
  transform: scale(0.95);
}

/* TTS Button specific styles */
.tts-button.playing {
  color: var(--success);
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
}

/* Copy Button specific styles */
.copy-button.copied {
  color: var(--success);
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--success);
}

/* Disabled state for both buttons */
.action-button:disabled,
.action-button.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  color: var(--text-muted);
  border-color: var(--border);
}

.action-button:disabled:hover,
.action-button.disabled:hover {
  transform: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-muted);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.action-button.loading {
  color: var(--text-muted);
  background: rgba(248, 250, 252, 0.9);
  border-color: var(--border);
  opacity: 0.6;
  cursor: not-allowed;
}


/* Dark theme action buttons */
[data-theme="dark"] .action-button {
  background: rgba(51, 65, 85, 0.9);
  border-color: var(--border);
}

[data-theme="dark"] .action-button:hover {
  background: rgba(51, 65, 85, 1);
}

[data-theme="dark"] .action-button.disabled:hover {
  background: rgba(51, 65, 85, 0.9);
}

/* Simple Options Menu */
.options-panel {
  position: absolute;
  right: 0;
  top: 100%;
  background: white;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 12px;
  min-width: 200px;
  z-index: 1000;
  display: none;
}

.options-menu.open .options-panel {
  display: block;
}

.option-item {
  margin-bottom: 12px;
}

.option-item:last-child {
  margin-bottom: 0;
}

.option-item label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
  font-weight: 500;
}

.simple-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
  font-size: 13px;
  color: #333;
}

.simple-select:focus {
  outline: none;
  border-color: #0066cc;
}

/* Dark theme */
[data-theme="dark"] .options-panel {
  background: #2d3748;
  border-color: #4a5568;
}

[data-theme="dark"] .option-item label {
  color: #a0aec0;
}

[data-theme="dark"] .simple-select {
  background: #2d3748;
  border-color: #4a5568;
  color: #e2e8f0;
}