* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #1976D2 0%, #1565C0 100%);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  width: 100%;
  max-width: 800px;
  background: white;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.header {
  background: white;
  padding: 20px 30px;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.header h1 {
  color: #1976D2;
  font-size: 24px;
  margin-bottom: 5px;
}

.header p {
  color: #666;
  font-size: 14px;
}

.header-info {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  font-size: 14px;
  color: #666;
}

.header-info span {
  padding: 5px 12px;
  background: #f5f5f5;
  border-radius: 12px;
}

.loading {
  text-align: center;
  padding: 60px 30px;
}

.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #1976D2;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

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

.loading p {
  color: #666;
  font-size: 16px;
}

.error-message {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #f44336;
  color: white;
  padding: 15px 25px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  max-width: 90%;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.language-selection {
  padding: 30px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.language-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
  margin-top: 20px;
}

.language-card {
  background: white;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.language-card:hover {
  border-color: #1976D2;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(25, 118, 210, 0.2);
}

.language-flag {
  font-size: 40px;
  margin-bottom: 10px;
}

.language-name {
  font-size: 14px;
  color: #333;
  font-weight: 500;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 600px;
  min-height: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #f5f5f5;
  min-height: 0;
}

.message {
  margin-bottom: 15px;
  max-width: 70%;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.own-message {
  margin-left: auto;
  text-align: right;
}

.other-message {
  margin-right: auto;
  text-align: left;
}

.message-text {
  font-size: 13px;
  color: #999;
  font-style: italic;
  margin-top: 5px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  word-wrap: break-word;
}

/* Own message text - always blue and prominent */
.own-message .message-text {
  background: #1976D2;
  color: white;
  font-size: 15px;
  font-weight: 500;
  font-style: normal;
  padding: 12px 16px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  margin-top: 0;
}

/* When own message has translation, make original text smaller */
.own-message .message-text.has-translation {
  background: rgba(255, 255, 255, 0.25);
  color: rgba(255, 255, 255, 0.9);
  font-size: 12px;
  font-style: italic;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: none;
}

.message-translation {
  background: white;
  padding: 12px 16px;
  border-radius: 12px;
  word-wrap: break-word;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  font-size: 15px;
  color: #333;
  font-weight: 500;
}

.own-message .message-translation {
  background: #1976D2;
  color: white;
  font-weight: 500;
}

.translating {
  opacity: 0.6;
}

.message-meta {
  font-size: 11px;
  color: #999;
  margin-top: 5px;
  display: flex;
  gap: 10px;
  justify-content: flex-start;
}

.own-message .message-meta {
  justify-content: flex-end;
}

.input-area {
  display: flex;
  gap: 12px;
  padding: 20px;
  background: white;
  border-top: 1px solid #e0e0e0;
  align-items: center;
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

#message-input:focus {
  border-color: #1976D2;
}

#send-button {
  padding: 12px 30px;
  background: #1976D2;
  color: white;
  border: none;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease;
}

#send-button:hover {
  background: #1565C0;
}

#send-button:active {
  transform: scale(0.98);
}

.action-button {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 2px solid #1976D2;
  background: white;
  color: #1976D2;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
}

.action-button:hover {
  background: #E3F2FD;
  transform: scale(1.05);
}

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

.mic-button.recording {
  background: #f44336;
  border-color: #f44336;
  color: white;
  animation: pulse 1.5s infinite;
}

.speaker-button.active {
  background: #4CAF50;
  border-color: #4CAF50;
  color: white;
}

.speaker-button.active:hover {
  background: #45a049;
}

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

@media (max-width: 768px) {
  html, body {
    padding: 0;
    margin: 0;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    width: 100%;
    overflow: hidden;
  }

  body {
    display: flex;
    flex-direction: column;
  }

  .container {
    border-radius: 0;
    max-width: 100%;
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    box-shadow: none;
    overflow: hidden;
  }

  .header {
    padding: 15px 20px;
    flex-shrink: 0;
  }

  .header h1 {
    font-size: 20px;
    margin-bottom: 8px;
  }

  .header-info {
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
  }

  .header-info span {
    padding: 4px 10px;
    font-size: 12px;
  }

  .chat-container {
    flex: 1;
    min-height: 0;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
  }

  .messages {
    padding: 15px;
    flex: 1 1 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    min-height: 0;
    max-height: 100%;
  }

  .message {
    max-width: 85%;
    margin-bottom: 12px;
  }

  .message-text {
    font-size: 12px;
    padding: 6px 10px;
    margin-top: 4px;
  }

  /* Own message text - always blue and prominent on mobile */
  .own-message .message-text {
    background: #1976D2;
    color: white;
    font-size: 14px;
    font-weight: 500;
    font-style: normal;
    padding: 10px 14px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-top: 0;
  }

  /* When own message has translation, make original text smaller */
  .own-message .message-text.has-translation {
    background: rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.95);
    font-size: 12px;
    font-style: italic;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: none;
  }

  .message-translation {
    padding: 10px 14px;
    font-size: 14px;
  }

  .own-message .message-translation {
    padding: 12px 16px;
    font-size: 15px;
    font-weight: 600;
  }

  .message-meta {
    font-size: 10px;
    margin-top: 4px;
  }

  .input-area {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    gap: 8px;
    flex-shrink: 0;
    flex-grow: 0;
    border-top: 1px solid #e0e0e0;
    background: white;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    position: relative;
    z-index: 100;
  }

  .action-button {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    font-size: 20px;
  }

  #message-input {
    font-size: 16px;
    padding: 10px 14px;
    -webkit-appearance: none;
    border-radius: 22px;
  }

  #send-button {
    padding: 10px 20px;
    font-size: 14px;
    border-radius: 22px;
    white-space: nowrap;
  }

  .language-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    padding: 20px;
  }

  .language-selection {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
    padding: 20px 15px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  .language-card {
    padding: 15px 10px;
  }

  .language-flag {
    font-size: 32px;
  }

  .language-name {
    font-size: 13px;
  }

  .error-message {
    top: 10px;
    left: 10px;
    right: 10px;
    max-width: calc(100% - 20px);
    transform: none;
    padding: 12px 20px;
    font-size: 14px;
  }
}

@media (max-width: 480px) {
  .header {
    padding: 12px 15px;
  }

  .header h1 {
    font-size: 18px;
  }

  .messages {
    padding: 12px;
  }

  .message {
    max-width: 90%;
  }

  .input-area {
    padding: 10px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    gap: 6px;
    flex-shrink: 0;
    flex-grow: 0;
    background: white;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    border-top: 1px solid #e0e0e0;
    position: relative;
    z-index: 100;
  }

  .mic-button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: 18px;
  }
  
  .action-button {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: 18px;
  }

  #message-input {
    font-size: 16px;
    padding: 8px 12px;
  }

  #send-button {
    padding: 8px 16px;
    font-size: 13px;
  }

  .language-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    padding: 15px;
  }

  .language-selection {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    flex: 1;
    min-height: 0;
    padding: 15px;
    padding-bottom: max(15px, env(safe-area-inset-bottom));
  }
}
