:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-light: #334155;
  --accent-a: #2563eb;
  --accent-a-active: #1d4ed8;
  --accent-b: #16a34a;
  --accent-b-active: #15803d;
  --text: #f8fafc;
  --text-dim: #94a3b8;
  --error: #dc2626;
  --bubble-a: #2563eb;
  --bubble-b: #16a34a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

.screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* --- Login --- */

#login-screen {
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-box {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-box h1 { font-size: 2rem; margin-bottom: 4px; }
.login-sub { color: var(--text-dim); margin-bottom: 24px; }

#login-form { display: flex; flex-direction: column; gap: 12px; }

#login-password {
  font-size: 1.3rem;
  padding: 16px;
  border-radius: 12px;
  border: 2px solid var(--panel-light);
  background: var(--panel);
  color: var(--text);
  text-align: center;
}

#login-form button {
  font-size: 1.2rem;
  padding: 16px;
  border-radius: 12px;
  border: none;
  background: var(--accent-a);
  color: white;
  font-weight: 600;
}

.error-text { color: #fca5a5; margin-top: 12px; font-size: 1rem; }

/* --- App shell --- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  gap: 8px;
}

#context-select {
  flex: 1;
  background: var(--panel);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.95rem;
}

.icon-btn {
  background: var(--panel);
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  padding: 10px 14px;
  border-radius: 10px;
}

.error-banner {
  background: var(--error);
  color: white;
  padding: 12px 16px;
  margin: 0 12px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.info-banner {
  background: var(--accent-a);
  color: white;
  padding: 12px 16px;
  margin: 8px 12px 0;
  border-radius: 10px;
  font-size: 0.95rem;
  text-align: center;
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: text;
}

.bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  line-height: 1.35;
}

.bubble.side-a { align-self: flex-start; background: var(--bubble-a); border-bottom-left-radius: 4px; }
.bubble.side-b { align-self: flex-end; background: var(--bubble-b); border-bottom-right-radius: 4px; }

.bubble .original { font-size: 0.82rem; opacity: 0.8; margin-bottom: 2px; }
.bubble .translation { font-size: 1.08rem; font-weight: 600; }

.status-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px;
  color: var(--text-dim);
  font-size: 0.95rem;
}

.spinner {
  width: 16px; height: 16px;
  border: 3px solid var(--panel-light);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* --- Controls --- */

.controls {
  display: flex;
  align-items: stretch;
  gap: 8px;
  padding: 10px 10px calc(var(--safe-bottom) + 14px);
  background: var(--panel);
}

.speaker-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lang-select {
  background: var(--panel-light);
  color: var(--text);
  border: none;
  border-radius: 10px;
  padding: 8px;
  font-size: 0.95rem;
  text-align: center;
}

.talk-btn {
  flex: 1;
  min-height: 130px;
  border: none;
  border-radius: 20px;
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  touch-action: none;
  transition: transform 0.08s, filter 0.08s;
}

.speaker-panel[data-speaker="A"] .talk-btn { background: var(--accent-a); }
.speaker-panel[data-speaker="B"] .talk-btn { background: var(--accent-b); }

.talk-btn.recording {
  transform: scale(0.97);
  filter: brightness(1.25);
  box-shadow: 0 0 0 6px rgba(255,255,255,0.25);
}

.talk-btn .flag { font-size: 2.6rem; }
.talk-btn .name { font-size: 1.3rem; font-weight: 700; margin-top: 2px; }
.talk-btn .hint { font-size: 0.82rem; opacity: 0.85; }

.swap-btn {
  align-self: center;
  background: var(--panel-light);
  border: none;
  color: var(--text);
  font-size: 1.6rem;
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

@media (min-width: 640px) {
  .controls { padding-bottom: calc(var(--safe-bottom) + 24px); }
  .talk-btn { min-height: 180px; }
}
