:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-soft: #ccfbf1;
  --mint: #e6f7f4;
  --gray-bubble: #f1f5f9;
  --text: #0f172a;
  --muted: #94a3b8;
  --border: #e2e8f0;
  --bg: #ffffff;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

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

html, body {
  margin: 0;
  height: 100%;
  background: #e8eef5;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

.app {
  width: 100%;
  max-width: 430px;
  height: 100%;
  max-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: var(--shadow);
}

/* Header */
.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(12px + var(--safe-t)) 14px 10px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
  z-index: 5;
}

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

.brand-icon {
  color: var(--teal);
  display: flex;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.lang-pill {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.lang-pill:active { transform: scale(0.98); }

.lang-pill .swap {
  color: var(--teal);
  font-weight: 700;
  margin: 0 2px;
}

.lang-pill .flag { font-size: 0.95rem; line-height: 1; }

.icon-btn {
  border: none;
  background: transparent;
  color: #64748b;
  padding: 6px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
}

.icon-btn:active { background: var(--gray-bubble); }

/* Mode tabs */
.mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 8px 14px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mode-tab {
  border: none;
  background: var(--gray-bubble);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
  font-weight: 700;
  color: #64748b;
  cursor: pointer;
}

.mode-tab.active {
  background: var(--teal);
  color: #fff;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.3);
}

.mode-tab:active { transform: scale(0.98); }

.lang-menu {
  position: absolute;
  top: calc(108px + var(--safe-t));
  right: 14px;
  left: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 20;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.lang-menu[hidden] { display: none; }

.lang-menu button {
  border: none;
  background: transparent;
  text-align: left;
  padding: 14px 16px;
  font-size: 0.92rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.lang-menu button:last-child { border-bottom: none; }
.lang-menu button:active { background: var(--mint); }

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.view[hidden] { display: none; }

/* Chat */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: linear-gradient(180deg, #fafbfc 0%, #fff 40%);
  -webkit-overflow-scrolling: touch;
}

.empty-hint {
  margin: auto;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 260px;
  line-height: 1.45;
  padding: 24px 8px;
}

.empty-hint strong { color: var(--teal-dark); }

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: fadeIn 0.25s ease;
}

.bubble-wrap.anda { align-self: flex-start; }
.bubble-wrap.lawan { align-self: flex-end; }
.bubble-wrap.seminar { align-self: stretch; max-width: 100%; }

.bubble {
  padding: 12px 14px;
  border-radius: 18px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
}

.bubble-wrap.anda .bubble {
  background: var(--mint);
  border-bottom-left-radius: 6px;
  color: var(--text);
}

.bubble-wrap.lawan .bubble {
  background: var(--gray-bubble);
  border-bottom-right-radius: 6px;
  color: var(--text);
}

.bubble-wrap.seminar .bubble {
  background: var(--mint);
  border-radius: 14px;
}

.bubble .orig {
  display: block;
}

.bubble .trans {
  display: block;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(0,0,0,0.06);
  font-size: 0.82rem;
  color: #475569;
}

.bubble-wrap.seminar .bubble .trans {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  border-top-color: rgba(13, 148, 136, 0.2);
}

.bubble-wrap.seminar .bubble .orig {
  font-size: 0.82rem;
  color: #64748b;
}

.meta {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
  padding: 0 4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bubble-wrap.lawan .meta { justify-content: flex-end; }

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

/* Footer Ngobrol */
.footer {
  flex-shrink: 0;
  padding: 10px 14px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.voice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.voice-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 10px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: transform 0.1s, box-shadow 0.15s;
}

.voice-btn:active { transform: scale(0.97); }

.voice-btn.primary {
  background: linear-gradient(135deg, #14b8a6 0%, #0ea5e9 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.35);
}

.voice-btn.secondary {
  background: #fff;
  color: var(--teal);
  border: 2px solid var(--teal);
}

.voice-btn.listening {
  animation: pulseBtn 1.2s ease infinite;
}

.voice-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@keyframes pulseBtn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(13, 148, 136, 0.45); }
  50% { box-shadow: 0 0 0 10px rgba(13, 148, 136, 0); }
}

.compose {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.segment {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--gray-bubble);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg {
  border: none;
  background: transparent;
  padding: 8px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
}

.seg.active {
  background: #fff;
  color: var(--teal-dark);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.input-row {
  display: flex;
  align-items: center;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 4px 4px 16px;
  gap: 6px;
}

.input-row input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 0.95rem;
  background: transparent;
  min-width: 0;
  padding: 10px 0;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--teal);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:active { background: var(--teal-dark); }
.send-btn:disabled { opacity: 0.5; }

/* ===== Seminar ===== */
.seminar-main {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: linear-gradient(180deg, #f0fdfa 0%, #fff 50%);
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

.seminar-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #64748b;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  align-self: flex-start;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
  flex-shrink: 0;
}

.status-dot.live {
  background: #ef4444;
  animation: pulseBtn 1s ease infinite;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
}

.status-dot.paused {
  background: #f59e0b;
}

.seminar-live {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.seminar-label {
  margin: 0 0 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.seminar-label.teal { color: var(--teal-dark); margin-top: 14px; }

.seminar-source {
  margin: 0;
  font-size: 0.95rem;
  color: #64748b;
  line-height: 1.45;
  min-height: 1.4em;
  word-break: break-word;
}

.seminar-source.interim { font-style: italic; opacity: 0.85; }

.seminar-trans {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  letter-spacing: -0.02em;
  min-height: 1.4em;
  word-break: break-word;
}

.seminar-log {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 8px;
}

.seminar-footer {
  flex-shrink: 0;
  padding: 10px 14px calc(12px + var(--safe-b));
  border-top: 1px solid var(--border);
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.seminar-tts-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  font-weight: 600;
  color: #475569;
}

.seminar-tts-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.seminar-actions {
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 10px;
}

.seminar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px 12px;
  border-radius: 14px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  border: none;
}

.seminar-btn.start {
  background: linear-gradient(135deg, #14b8a6 0%, #0ea5e9 100%);
  color: #fff;
  box-shadow: 0 4px 14px rgba(13, 148, 136, 0.35);
}

.seminar-btn.start.listening {
  background: linear-gradient(135deg, #ef4444 0%, #f97316 100%);
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
  animation: pulseBtn 1.2s ease infinite;
}

.seminar-btn.pause {
  background: #fff;
  color: var(--teal-dark);
  border: 2px solid var(--teal);
}

.seminar-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  animation: none !important;
}

.seminar-btn:active:not(:disabled) { transform: scale(0.97); }

.seminar-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.35;
}

/* Shared language bar (both modes) */
.lang-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 14px 10px;
  border-bottom: 1px solid var(--border);
  background: #fff;
}

.lang-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.lang-field span {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.lang-field select {
  width: 100%;
  padding: 10px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
}

.lang-field select:focus { outline: 2px solid var(--teal-soft); border-color: var(--teal); }

.lang-swap-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid var(--teal);
  background: #fff;
  color: var(--teal-dark);
  font-size: 1.15rem;
  cursor: pointer;
}

.lang-swap-btn:active { background: var(--mint); transform: scale(0.95); }

/* Settings */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

.overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 430px;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(24px + var(--safe-b));
  box-shadow: 0 -8px 32px rgba(0,0,0,0.12);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: #cbd5e1;
  border-radius: 2px;
  margin: 0 auto 14px;
}

.sheet h2 {
  margin: 0 0 16px;
  font-size: 1.1rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
}

.setting-row input[type="range"] {
  width: 120px;
  accent-color: var(--teal);
}

.setting-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--teal);
}

.rate-label {
  margin: 4px 0 16px;
  text-align: right;
  color: var(--muted);
  font-size: 0.85rem;
}

.sheet-close {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(120px + var(--safe-b));
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  max-width: min(90vw, 360px);
  z-index: 60;
  text-align: center;
  box-shadow: var(--shadow);
  line-height: 1.35;
}

.toast[hidden] { display: none; }

/* Listening overlay */
.listen-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 24px;
}

.listen-overlay[hidden] { display: none; }

.listen-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  text-align: center;
  width: min(280px, 90vw);
  box-shadow: var(--shadow);
}

.pulse {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: linear-gradient(135deg, #14b8a6, #0ea5e9);
  animation: pulseRing 1.4s ease infinite;
}

@keyframes pulseRing {
  0% { box-shadow: 0 0 0 0 rgba(20, 184, 166, 0.5); transform: scale(1); }
  70% { box-shadow: 0 0 0 18px rgba(20, 184, 166, 0); transform: scale(1.05); }
  100% { box-shadow: 0 0 0 0 rgba(20, 184, 166, 0); transform: scale(1); }
}

.listen-card p {
  margin: 0 0 16px;
  font-weight: 600;
  color: var(--text);
}

.listen-cancel {
  border: 1px solid var(--border);
  background: #fff;
  padding: 10px 20px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  color: #64748b;
}

@media (min-width: 480px) {
  body { padding: 16px 0; }
  .app {
    height: min(860px, 100dvh);
    border-radius: 24px;
    overflow: hidden;
  }
}

.meta-label {
  line-height: 1;
}

.replay-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: #fff;
  color: var(--teal);
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.replay-btn:active {
  background: var(--mint);
  transform: scale(0.94);
}

.replay-btn.playing {
  background: var(--teal-soft);
  border-color: var(--teal);
  animation: pulseBtn 1s ease infinite;
}

.setting-hint {
  margin: -4px 0 8px;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}
