/* ============================================================
   Realtime Translator — modern-minimal theme (light + dark)
   App shell: sticky app bar / scrolling workspace / docked bar
   ============================================================ */

:root {
  color-scheme: light dark;

  --font:
    "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", Roboto, sans-serif;

  /* Light palette */
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f3f5f8;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e6e9ef;
  --border-strong: #d4dae3;

  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --accent-2: #0d9488;
  --accent-2-soft: rgba(13, 148, 136, 0.1);
  --live: #16a34a;
  --danger: #dc2626;

  --on-accent: #ffffff;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.06);
  --shadow-bar: 0 -8px 24px rgba(15, 23, 42, 0.06);

  --radius: 16px;
  --radius-sm: 12px;
  --radius-lg: 20px;

  --maxw: 1040px;
  --pad-x: clamp(16px, 4vw, 28px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --surface: #121826;
    --surface-2: #0e131e;
    --text: #e7ecf4;
    --text-muted: #93a1b5;
    --border: #232c3b;
    --border-strong: #313c4e;

    --accent: #818cf8;
    --accent-soft: rgba(129, 140, 248, 0.16);
    --accent-2: #2dd4bf;
    --accent-2-soft: rgba(45, 212, 191, 0.16);
    --live: #22c55e;
    --danger: #f87171;

    --on-accent: #0b0f17;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
    --shadow-bar: 0 -10px 30px rgba(0, 0, 0, 0.5);
  }
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  /* App shell: fixed top + bottom, the middle scrolls. */
  height: 100vh;
  height: 100svh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
select {
  font: inherit;
  color: inherit;
}

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

:where(button, select, a):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg {
  display: block;
}

/* ----------------------------- App bar ----------------------------- */

.appbar {
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.appbar-inner {
  width: min(var(--maxw), 100%);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px
    max(var(--pad-x), env(safe-area-inset-right))
    12px
    max(var(--pad-x), env(safe-area-inset-left));
}

.appbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.appbar-user {
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.logout-form {
  margin: 0;
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.btn-logout svg {
  width: 16px;
  height: 16px;
}

.btn-logout:hover {
  border-color: var(--accent);
  color: var(--accent);
}

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

.brand-mark {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: var(--on-accent);
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, var(--accent-2)));
  box-shadow: var(--shadow-sm);
}

.brand-mark svg {
  width: 21px;
  height: 21px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}

.brand-name {
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
}

/* --------------------------- Workspace ---------------------------- */

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.workspace-inner {
  width: min(var(--maxw), 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 28px)
    max(var(--pad-x), env(safe-area-inset-right))
    clamp(20px, 4vw, 36px)
    max(var(--pad-x), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2.5vw, 20px);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.setup-card {
  padding: clamp(16px, 3vw, 22px);
}

/* ------------------------- Language panel ------------------------- */

.language-panel {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: clamp(10px, 2vw, 16px);
}

.field {
  min-width: 0;
}

.field-label {
  display: block;
  margin: 0 0 7px;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.select-wrap {
  position: relative;
}

.select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 48px;
  padding: 0 42px 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem; /* >=16px stops iOS focus zoom */
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.select:hover:not(:disabled) {
  border-color: var(--accent);
}

.select:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

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

.select-caret {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.swap-button {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: transform 0.18s ease, color 0.15s ease, border-color 0.15s ease;
}

.swap-button svg {
  width: 20px;
  height: 20px;
}

.swap-button:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

.swap-button:active:not(:disabled) {
  transform: rotate(180deg);
}

.swap-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ------------------------------ Hint ------------------------------ */

.hint {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: clamp(14px, 2.5vw, 18px) 0 0;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.hint-icon {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin-top: 1px;
}

/* --------------------------- Transcripts -------------------------- */

.transcripts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(14px, 2.5vw, 20px);
}

.transcript-card {
  padding: clamp(16px, 3vw, 22px);
}

.transcript-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: clamp(14px, 2.5vw, 18px);
}

.transcript-title {
  margin: 0;
  font-size: clamp(1.02rem, 2.6vw, 1.18rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.pill {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  border-radius: 999px;
  padding: 5px 11px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.transcript-block + .transcript-block {
  margin-top: clamp(12px, 2.5vw, 16px);
}

.label {
  display: block;
  margin: 0 0 7px;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.transcript {
  min-height: 84px;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.transcript.empty {
  color: var(--text-muted);
  opacity: 0.75;
}

/* --------------------------- Action bar --------------------------- */

.actionbar {
  flex: 0 0 auto;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-bar);
}

.actionbar-inner {
  width: min(var(--maxw), 100%);
  margin: 0 auto;
  padding: 12px
    max(var(--pad-x), env(safe-area-inset-right))
    calc(12px + env(safe-area-inset-bottom))
    max(var(--pad-x), env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.statusline {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background 0.2s ease, box-shadow 0.2s ease;
}

/* Live state driven purely by the recording button — no JS needed. */
.actionbar:has(.talk-button.active) .status-dot {
  background: var(--live);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 60%, transparent);
  animation: dot-pulse 1.6s ease-out infinite;
}

@keyframes dot-pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--live) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

.status {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.btn-stop {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.btn-stop svg {
  width: 15px;
  height: 15px;
}

.btn-stop:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-stop:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.talk-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 2vw, 14px);
}

.talk-button {
  --tb: var(--accent);
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 76px;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition:
    transform 0.12s ease,
    border-color 0.15s ease,
    background 0.15s ease,
    box-shadow 0.15s ease,
    color 0.15s ease;
}

.talk-button.language-a { --tb: var(--accent); }
.talk-button.language-b { --tb: var(--accent-2); }

.talk-icon {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: color-mix(in srgb, var(--tb) 12%, transparent);
  color: var(--tb);
  transition: background 0.15s ease, color 0.15s ease;
}

.talk-icon svg {
  width: 22px;
  height: 22px;
}

.talk-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 3px;
}

.button-title {
  font-size: clamp(1rem, 2.6vw, 1.12rem);
  font-weight: 800;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.button-subtitle {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.talk-button:hover:not(:disabled) {
  border-color: var(--tb);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.talk-button:active:not(:disabled) {
  transform: scale(0.99);
}

/* Live recording state */
.talk-button.active {
  background: var(--tb);
  border-color: var(--tb);
  color: var(--on-accent);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--tb) 35%, transparent);
  animation: talk-pulse 1.7s ease-out infinite;
}

.talk-button.active .talk-icon {
  background: color-mix(in srgb, var(--on-accent) 22%, transparent);
  color: var(--on-accent);
}

.talk-button.active .button-subtitle {
  color: color-mix(in srgb, var(--on-accent) 80%, transparent);
}

@keyframes talk-pulse {
  0% { box-shadow: 0 8px 22px color-mix(in srgb, var(--tb) 35%, transparent), 0 0 0 0 color-mix(in srgb, var(--tb) 45%, transparent); }
  70% { box-shadow: 0 8px 22px color-mix(in srgb, var(--tb) 35%, transparent), 0 0 0 12px transparent; }
  100% { box-shadow: 0 8px 22px color-mix(in srgb, var(--tb) 35%, transparent), 0 0 0 0 transparent; }
}

.talk-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ---------------------------- Responsive -------------------------- */

/* Stack transcripts on tablets and below. */
@media (max-width: 880px) {
  .transcripts {
    grid-template-columns: 1fr;
  }
}

/* Phones */
@media (max-width: 600px) {
  .language-panel {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .swap-button {
    justify-self: center;
    transform: rotate(90deg);
  }

  .swap-button:active:not(:disabled) {
    transform: rotate(270deg);
  }

  /* Keep the docked bar compact: title-only until recording. */
  .talk-button {
    gap: 11px;
    min-height: 64px;
    padding: 11px 12px;
  }

  .talk-icon {
    width: 36px;
    height: 36px;
  }

  .talk-button .button-subtitle {
    display: none;
  }

  .talk-button.active .button-subtitle {
    display: block;
  }

  .brand-sub {
    display: none;
  }
}

@media (max-width: 360px) {
  .talk-button {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .button-title {
    font-size: 0.95rem;
  }
}

/* ---------------------------- Login page -------------------------- */

/* Override the app-shell body for the centered auth screen. */
.auth-body {
  height: auto;
  min-height: 100vh;
  min-height: 100svh;
  overflow: auto;
}

.auth {
  flex: 1 1 auto;
  display: grid;
  place-items: center;
  padding: clamp(20px, 5vw, 48px)
    max(var(--pad-x), env(safe-area-inset-right))
    calc(clamp(20px, 5vw, 48px) + env(safe-area-inset-bottom))
    max(var(--pad-x), env(safe-area-inset-left));
}

.auth-card {
  width: min(420px, 100%);
  padding: clamp(22px, 5vw, 34px);
  display: flex;
  flex-direction: column;
}

.auth-brand {
  margin-bottom: 22px;
}

.auth-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.auth-sub {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.auth-error {
  margin: 18px 0 0;
  padding: 11px 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
  font-size: 0.88rem;
  font-weight: 600;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 18px;
}

.auth-input {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem; /* >=16px stops iOS focus zoom */
  font-weight: 600;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.auth-submit {
  margin-top: 24px;
  min-height: 48px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1rem;
  font-weight: 800;
  cursor: pointer;
  transition: filter 0.15s ease, transform 0.12s ease;
}

.auth-submit:hover {
  filter: brightness(1.05);
}

.auth-submit:active {
  transform: scale(0.99);
}

/* Reclaim app-bar space on phones. */
@media (max-width: 600px) {
  .appbar-user {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
