/* ── Reset & Base ─────────────────────────── */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #fff;
  color: #111;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

input, select {
  font-family: inherit;
  font-size: 16px; /* prevents iOS zoom on focus */
}

a {
  -webkit-tap-highlight-color: transparent;
}

/* ── Page transitions ────────────────────── */

.page {
  display: none;
  height: 100dvh;
  flex-direction: column;
}

.page.active {
  display: flex;
  animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.hidden {
  display: none !important;
}

/* ── Avatars ─────────────────────────────── */

.avatar-sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.avatar-xs {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

/* ── Loading page ────────────────────────── */

#loading-page {
  justify-content: center;
  align-items: center;
}

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid #e5e5e5;
  border-top-color: #888;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Navbar ───────────────────────────────── */

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  height: calc(52px + env(safe-area-inset-top));
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}

.nav-logo {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #555;
  font-weight: 500;
}

.link-btn {
  border: none;
  background: none;
  font-size: 13px;
  color: #888;
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
}

.link-btn:hover {
  color: #555;
}

.btn-signin {
  padding: 8px 18px;
  border: 1px solid #ddd;
  border-radius: 7px;
  background: #fff;
  font-size: 14px;
  font-weight: 500;
  color: #333;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-signin:hover {
  background: #fafafa;
  border-color: #ccc;
}

/* ── Landing page ────────────────────────── */

#landing-page {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.hero {
  padding: 56px 24px 48px;
  text-align: center;
  max-width: 580px;
  margin: 0 auto;
}

.hero h1 {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1.15;
  margin-bottom: 14px;
  color: #111;
}

.hero p {
  font-size: 16px;
  color: #666;
  line-height: 1.6;
  margin-bottom: 32px;
  max-width: 440px;
  margin-left: auto;
  margin-right: auto;
}

.btn-lg {
  padding: 14px 32px;
  font-size: 16px;
  border-radius: 10px;
  min-height: 48px;
  width: 100%;
  max-width: 300px;
}

.landing-divider {
  width: 48px;
  height: 1px;
  background: #e5e5e5;
  margin: 0 auto;
}

.how-it-works {
  padding: 48px 24px 64px;
  max-width: 680px;
  margin: 0 auto;
}

.how-it-works h2 {
  text-align: center;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin-bottom: 36px;
  color: #111;
}

.steps {
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  max-width: 260px;
  margin: 0 auto;
}

.step {
  text-align: center;
}

.step-num {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #f5f5f5;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: #555;
}

.step h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.step p {
  font-size: 14px;
  color: #888;
  line-height: 1.5;
}

.landing-footer {
  padding: 28px 24px;
  padding-bottom: max(28px, env(safe-area-inset-bottom));
  text-align: center;
  font-size: 13px;
  color: #ccc;
  border-top: 1px solid #f0f0f0;
  margin-top: auto;
  font-weight: 600;
  letter-spacing: -0.3px;
}

/* ── Buttons ─────────────────────────────── */

.btn-primary {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  background: #111;
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  min-height: 46px;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: #333;
}

.btn-primary:active {
  background: #444;
}

.btn-secondary {
  padding: 12px 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
  font-weight: 500;
  color: #333;
  min-height: 46px;
  transition: background 0.15s, border-color 0.15s;
}

.btn-secondary:hover {
  background: #fafafa;
  border-color: #ccc;
}

.btn-secondary:active {
  background: #f0f0f0;
}

/* ── Home page ───────────────────────────── */

.home-main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px 20px;
}

.home-card {
  max-width: 380px;
  width: 100%;
}

.home-section {
  padding: 4px 0;
}

.home-section h2 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 6px;
  letter-spacing: -0.2px;
}

.home-section p {
  font-size: 14px;
  color: #888;
  line-height: 1.5;
  margin-bottom: 16px;
}

.home-section .btn-primary {
  width: 100%;
}

.home-divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 24px 0;
  color: #ccc;
  font-size: 13px;
}

.home-divider::before,
.home-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #eee;
}

.input-row {
  display: flex;
  gap: 8px;
}

.input-row input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  min-height: 46px;
  transition: border-color 0.15s;
}

.input-row input:focus {
  border-color: #aaa;
}

/* ── Room header ─────────────────────────── */

.room-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid #f0f0f0;
  min-height: 48px;
  flex-shrink: 0;
  gap: 8px;
}

.room-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.room-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  min-width: 40px;
  min-height: 40px;
  transition: color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.icon-btn:hover {
  color: #333;
  background: #f5f5f5;
}

.room-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.room-code {
  font-size: 13px;
  color: #999;
  font-family: 'SF Mono', 'Fira Code', 'Fira Mono', monospace;
  font-weight: 500;
  white-space: nowrap;
}

.link-btn-sm {
  border: none;
  background: none;
  font-size: 12px;
  color: #999;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
  display: flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.link-btn-sm:hover {
  color: #555;
}

/* ── Language picker (header, compact) ────── */

.lang-picker {
  position: relative;
}

.lang-picker-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: #333;
  cursor: pointer;
  min-height: 40px;
  transition: border-color 0.15s, background 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.lang-picker-btn:hover {
  border-color: #ccc;
  background: #fafafa;
}

.lang-picker-btn .flag {
  width: 18px;
  height: 13px;
  border-radius: 2px;
  object-fit: cover;
}

.lang-picker-label {
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  width: 220px;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  z-index: 50;
  padding: 4px;
  -webkit-overflow-scrolling: touch;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.lang-option:hover {
  background: #f5f5f5;
}

.lang-option:active {
  background: #eeeeee;
}

.lang-option.selected {
  background: #f0f0f0;
  font-weight: 500;
}

.lang-option .flag {
  width: 22px;
  height: 16px;
  border-radius: 2px;
  object-fit: cover;
  flex-shrink: 0;
}

/* ── Language overlay (full screen on mobile) ── */

.lang-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  z-index: 60;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.18s ease;
}

.lang-overlay-card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 0 16px;
  padding-top: max(16px, env(safe-area-inset-top));
  padding-bottom: env(safe-area-inset-bottom);
}

.lang-overlay-card h2 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.4px;
  text-align: center;
  margin-bottom: 4px;
  padding-top: 24px;
  flex-shrink: 0;
}

.lang-overlay-card > p {
  font-size: 14px;
  color: #888;
  text-align: center;
  margin-bottom: 20px;
  flex-shrink: 0;
}

.lang-search-wrap {
  position: relative;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.lang-search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #bbb;
  pointer-events: none;
}

.lang-search-wrap input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  min-height: 48px;
  transition: border-color 0.15s;
  background: #fafafa;
}

.lang-search-wrap input:focus {
  border-color: #aaa;
  background: #fff;
}

.lang-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 16px;
}

.lang-list-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 14px;
  border-radius: 12px;
  font-size: 16px;
  color: #333;
  cursor: pointer;
  transition: background 0.1s;
  flex-shrink: 0;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
}

.lang-list-item:hover {
  background: #f5f5f5;
}

.lang-list-item:active {
  background: #eeeeee;
}

.lang-list-item.selected {
  background: #f0f0f0;
  font-weight: 500;
}

.lang-list-item .flag {
  width: 28px;
  height: 21px;
  border-radius: 3px;
  object-fit: cover;
  flex-shrink: 0;
}

.lang-list-empty {
  text-align: center;
  color: #ccc;
  font-size: 14px;
  padding: 32px 0;
}

/* ── Partner bar ─────────────────────────── */

.partner-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fafafa;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
  color: #555;
  font-weight: 500;
  flex-shrink: 0;
}

.partner-dot {
  color: #ccc;
}

.partner-lang {
  color: #999;
  font-weight: 400;
}

/* ── Status banner ───────────────────────── */

.status-banner {
  padding: 10px 16px;
  text-align: center;
  font-size: 13px;
  color: #999;
  background: #fcfcfc;
  border-bottom: 1px solid #f0f0f0;
  flex-shrink: 0;
}

/* ── Messages ────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.message {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.message.sent {
  align-self: flex-end;
  align-items: flex-end;
}

.message.received {
  align-self: flex-start;
  align-items: flex-start;
}

.voice-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 8px;
  border-radius: 22px;
  background: #f4f4f4;
  transition: background 0.1s;
}

.message.sent .voice-bubble {
  background: #ebebeb;
}

.play-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  border: none;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  transition: background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.play-btn:hover {
  background: #f0f0f0;
  color: #333;
}

.play-btn:active {
  background: #e8e8e8;
}

.play-btn svg {
  display: block;
}

.waveform {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 28px;
}

.waveform .bar {
  width: 3px;
  background: #c0c0c0;
  border-radius: 1.5px;
  min-height: 3px;
  transition: background 0.2s;
}

.message.sent .waveform .bar {
  background: #aaa;
}

.waveform.playing .bar {
  background: #666;
}

.message.sent .waveform.playing .bar {
  background: #555;
}

.msg-time {
  font-size: 11px;
  color: #bbb;
  padding: 0 4px;
}

/* ── Empty state ─────────────────────────── */

.empty-state {
  margin: auto;
  text-align: center;
  color: #ccc;
  font-size: 14px;
  line-height: 1.6;
  padding: 0 20px;
}

/* ── Processing dots ─────────────────────── */

.processing-indicator {
  align-self: flex-start;
  padding: 14px 18px;
  border-radius: 22px;
  background: #f4f4f4;
  display: flex;
  align-items: center;
  gap: 4px;
}

.processing-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #bbb;
  animation: dotPulse 1.2s ease-in-out infinite;
}

.processing-indicator .dot:nth-child(2) { animation-delay: 0.15s; }
.processing-indicator .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Controls ────────────────────────────── */

.controls {
  padding: 14px 16px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  border-top: 1px solid #f0f0f0;
  flex-shrink: 0;
}

.record-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid #111;
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #111;
  transition: border-color 0.15s, background 0.15s, color 0.15s, box-shadow 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.record-btn:hover:not(:disabled) {
  background: #f5f5f5;
}

.record-btn:active:not(:disabled) {
  background: #eee;
}

.record-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.record-btn.recording {
  border-color: #e54;
  background: #fff5f4;
  color: #e54;
  animation: recordPulse 1.8s ease-in-out infinite;
}

.record-btn.recording .mic-icon {
  display: none;
}

.record-btn.recording .stop-icon {
  display: block !important;
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(238, 85, 68, 0.15); }
  50% { box-shadow: 0 0 0 12px rgba(238, 85, 68, 0); }
}

.record-label {
  font-size: 13px;
  color: #bbb;
  min-height: 18px;
  font-weight: 500;
}

/* ── Toast ────────────────────────────────── */

.toast {
  position: fixed;
  bottom: max(110px, calc(100px + env(safe-area-inset-bottom)));
  left: 50%;
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 22px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  z-index: 100;
  transition: opacity 0.25s;
  max-width: calc(100vw - 48px);
  text-align: center;
}

.toast.fade-out {
  opacity: 0;
}

/* ── Desktop / wider screens ─────────────── */

@media (min-width: 601px) {
  .navbar {
    padding: 0 24px;
    padding-top: env(safe-area-inset-top);
    height: calc(56px + env(safe-area-inset-top));
  }

  .hero {
    padding: 100px 24px 80px;
  }

  .hero h1 {
    font-size: 46px;
    letter-spacing: -1.5px;
  }

  .hero p {
    font-size: 17px;
  }

  .btn-lg {
    width: auto;
  }

  .how-it-works {
    padding: 64px 24px 80px;
  }

  .how-it-works h2 {
    font-size: 20px;
    margin-bottom: 44px;
  }

  .steps {
    grid-template-columns: repeat(3, 1fr);
    gap: 36px;
    max-width: none;
  }

  .home-section .btn-primary {
    width: auto;
  }

  .room-header {
    padding: 10px 16px;
    padding-top: max(10px, env(safe-area-inset-top));
    min-height: 52px;
  }

  .message {
    max-width: 320px;
  }

  .lang-overlay {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
    justify-content: center;
    align-items: center;
  }

  .lang-overlay-card {
    max-width: 400px;
    height: auto;
    max-height: 80dvh;
    padding: 0;
    border-radius: 16px;
    border: 1px solid #e5e5e5;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    background: #fff;
    padding: 0 20px 20px;
    padding-top: 0;
  }

  .lang-overlay-card h2 {
    padding-top: 28px;
  }

  .lang-list-item {
    font-size: 14px;
    padding: 11px 14px;
    min-height: 44px;
  }

  .lang-list-item .flag {
    width: 24px;
    height: 18px;
  }
}
