/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #0A0A0B;
  --bg-elevated: #131315;
  --bg-stealth: #000000;
  --fg: #F5F5F4;
  --fg-dim: #9A9A98;
  --fg-faint: #5A5A58;
  --border: #1F1F1F;
  --border-strong: #2A2A2A;
  --accent: #FFFFFF;
  --rec: #FF3B30;
  --warn: #FFD60A;

  --font-sans: 'Geist', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'Geist Mono', 'SF Mono', Menlo, monospace;

  --safe-top: env(safe-area-inset-top, 0);
  --safe-bottom: env(safe-area-inset-bottom, 0);
  --safe-left: env(safe-area-inset-left, 0);
  --safe-right: env(safe-area-inset-right, 0);
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-sans);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  overflow: hidden;
}

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

/* === MAIN LAYOUT === */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  position: relative;
}

/* === TOP BAR === */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  flex-shrink: 0;
}

.brand {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
}

.topbar-actions {
  display: flex;
  gap: 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--fg-dim);
  border-radius: 8px;
  transition: color 0.15s ease, background 0.15s ease;
}

.icon-btn:active {
  color: var(--fg);
  background: var(--bg-elevated);
}

/* === STATUS BAR === */
.status-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 22px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--fg-faint);
  flex-shrink: 0;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--fg-faint);
  transition: background 0.2s ease;
}

.status-bar.recording .status-dot {
  background: var(--rec);
  box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.5);
  animation: dotPulse 1.4s ease-out infinite;
}

.status-bar.warn .status-dot {
  background: var(--warn);
}

.status-bar.recording .status-text {
  color: var(--fg-dim);
}

.status-bar.warn .status-text {
  color: var(--warn);
}

.status-meta {
  margin-left: auto;
  color: var(--fg-faint);
}

@keyframes dotPulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.5); }
  100% { box-shadow: 0 0 0 8px rgba(255, 59, 48, 0); }
}

/* === TRANSCRIPT === */
.transcript-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 22px 24px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.transcript-area::-webkit-scrollbar {
  width: 0;
}

.transcript-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--fg-faint);
}

.empty-mark {
  font-size: 64px;
  line-height: 0.5;
  font-weight: 200;
  color: var(--border-strong);
}

.empty-text {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.transcript-content {
  font-size: var(--transcript-font-size, 17px);
  line-height: 1.55;
  font-weight: 400;
  letter-spacing: -0.01em;
  word-wrap: break-word;
  color: var(--fg);
}

.transcript-content .seg {
  display: block;
  margin-bottom: 10px;
}

.transcript-content .lang-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 18px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: var(--fg-faint);
  text-transform: uppercase;
}

.transcript-content .lang-divider::before,
.transcript-content .lang-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.transcript-content .gap-marker {
  display: block;
  margin: 16px 0;
  padding: 10px 14px;
  border-left: 2px solid var(--warn);
  background: rgba(255, 214, 10, 0.05);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--warn);
  border-radius: 0 6px 6px 0;
}

.transcript-interim {
  font-size: calc(var(--transcript-font-size, 17px) - 2px);
  line-height: 1.55;
  font-weight: 400;
  color: var(--fg-dim);
  font-style: italic;
  letter-spacing: -0.01em;
  margin-top: 6px;
  min-height: 0;
}

/* === LANGUAGE CHIPS === */
.lang-bar {
  display: flex;
  gap: 8px;
  padding: 8px 22px 12px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.chip {
  flex: 1;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--fg-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  transition: all 0.18s cubic-bezier(0.2, 0.6, 0.2, 1);
}

.chip:active {
  transform: scale(0.96);
}

.chip.active {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.chip-empty {
  color: var(--fg-faint);
  border-style: dashed;
}

.chip-empty.set {
  border-style: solid;
  color: var(--fg-dim);
}

.chip-more {
  flex: 0 0 38px;
  padding: 0;
  width: 38px;
  border-radius: 50%;
}

/* === CONTROLS === */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px 24px;
  flex-shrink: 0;
  position: relative;
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  color: var(--fg-dim);
  border-radius: 50%;
  border: 1px solid var(--border);
  transition: all 0.15s ease;
}

.ctrl-btn:active {
  color: var(--fg);
  background: var(--bg-elevated);
  transform: scale(0.94);
}

.mic-btn {
  width: 84px;
  height: 84px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  position: relative;
  transition: all 0.2s cubic-bezier(0.2, 0.6, 0.2, 1);
  box-shadow: 0 4px 24px -4px rgba(245, 245, 244, 0.2);
}

.mic-btn:active {
  transform: scale(0.92);
}

.mic-icon {
  position: relative;
  z-index: 2;
}

.mic-pulse {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--fg);
  opacity: 0;
  pointer-events: none;
}

.mic-btn.recording {
  background: var(--rec);
  color: var(--fg);
  box-shadow: 0 4px 32px -4px rgba(255, 59, 48, 0.4);
}

.mic-btn.recording .mic-pulse {
  border-color: var(--rec);
  animation: micPulse 2s cubic-bezier(0.2, 0.6, 0.2, 1) infinite;
}

.mic-btn.recording .mic-pulse-2 {
  animation-delay: 1s;
}

.mic-btn.warn {
  background: var(--warn);
  color: var(--bg);
}

@keyframes micPulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* === STEALTH MODE — overlay approach (doesn't fade #app, won't disrupt mic) === */
#stealth-overlay {
  position: fixed;
  inset: 0;
  background: #000000;
  z-index: 1000;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: calc(28px + var(--safe-bottom)) calc(24px + var(--safe-right));
  -webkit-tap-highlight-color: transparent;
  animation: stealthFade 0.35s ease forwards;
}

#stealth-overlay.hidden {
  display: none;
}

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

.stealth-pulse {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #FF3B30;
  box-shadow: 0 0 16px 3px rgba(255, 59, 48, 0.55);
  animation: stealthPulse 1.5s ease-in-out infinite;
}

#stealth-overlay.pulse-subtle .stealth-pulse {
  width: 6px;
  height: 6px;
  background: rgba(255, 59, 48, 0.55);
  box-shadow: 0 0 6px 1px rgba(255, 59, 48, 0.25);
}

#stealth-overlay.pulse-invisible .stealth-pulse {
  width: 3px;
  height: 3px;
  background: rgba(255, 59, 48, 0.14);
  box-shadow: none;
  animation-duration: 3s;
}

@keyframes stealthPulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.45); opacity: 0.5; }
}

/* === SHEETS === */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet.hidden {
  pointer-events: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sheet:not(.hidden) .sheet-backdrop {
  opacity: 1;
}

.sheet-content {
  position: relative;
  width: 100%;
  max-width: 480px;
  background: var(--bg-elevated);
  border-radius: 24px 24px 0 0;
  padding: 12px 22px calc(28px + var(--safe-bottom));
  border-top: 1px solid var(--border);
  transform: translateY(100%);
  transition: transform 0.34s cubic-bezier(0.2, 0.7, 0.2, 1);
  max-height: 80dvh;
  overflow-y: auto;
}

.sheet:not(.hidden) .sheet-content {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.sheet-title {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: -0.01em;
  margin-bottom: 20px;
}

/* === LANGUAGE LIST === */
.lang-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.lang-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 4px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.lang-item:active {
  background: var(--bg);
}

.lang-name {
  font-size: 15px;
  color: var(--fg);
}

.lang-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-faint);
  letter-spacing: 0.05em;
}

/* === SETTINGS === */
.setting-group {
  margin-bottom: 24px;
}

.setting-label {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  margin-bottom: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
}

.setting-text {
  font-size: 14px;
  color: var(--fg);
}

.setting-text-muted {
  font-size: 13px;
  color: var(--fg-dim);
  line-height: 1.5;
}

.seg-control {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 2px;
}

.seg-btn {
  flex: 1;
  height: 34px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-dim);
  letter-spacing: 0.02em;
  transition: all 0.18s ease;
}

.seg-btn.active {
  background: var(--fg);
  color: var(--bg);
}

.toggle {
  width: 44px;
  height: 26px;
  background: var(--border-strong);
  border-radius: 13px;
  position: relative;
  transition: background 0.2s ease;
}

.toggle[data-on="true"] {
  background: var(--fg);
}

.toggle-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--fg);
  transition: transform 0.22s cubic-bezier(0.2, 0.7, 0.2, 1), background 0.2s ease;
}

.toggle[data-on="true"] .toggle-knob {
  background: var(--bg);
  transform: translateX(18px);
}

/* === OVERLAY (resume prompt) === */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(12px);
  opacity: 1;
  transition: opacity 0.25s ease;
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.overlay-card {
  width: 100%;
  max-width: 360px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 22px;
}

.overlay-title {
  font-size: 17px;
  font-weight: 500;
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.overlay-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-dim);
  margin-bottom: 20px;
  letter-spacing: 0.04em;
}

.overlay-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.btn-primary, .btn-secondary {
  height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: all 0.15s ease;
}

.btn-primary {
  background: var(--fg);
  color: var(--bg);
}

.btn-primary:active {
  transform: scale(0.96);
}

.btn-secondary {
  background: transparent;
  color: var(--fg-dim);
  border: 1px solid var(--border);
}

.btn-secondary:active {
  color: var(--fg);
  border-color: var(--border-strong);
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: calc(120px + var(--safe-bottom));
  left: 50%;
  transform: translate(-50%, 20px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--fg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: -0.01em;
  opacity: 0;
  pointer-events: none;
  z-index: 400;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* === UTILS === */
.hidden {
  display: none !important;
}

@media (max-width: 380px) {
  .mic-btn { width: 76px; height: 76px; }
}

/* === DESKTOP / TABLET-STYLE LAYOUT === */
/* On wider viewports, expand container to feel more like a tablet in landscape
   rather than a narrow phone column. Add subtle frame for visual distinction
   from the page background. */
@media (min-width: 768px) {
  body {
    /* Slight gradient bg so the framed app stands out from the surrounding space */
    background: radial-gradient(ellipse at top, #141416 0%, var(--bg) 60%);
  }
  #app {
    max-width: 900px;
    height: calc(100dvh - 48px);
    margin: 24px auto;
    border: 1px solid var(--border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6),
                0 0 0 1px rgba(255, 255, 255, 0.02);
  }
  /* Slightly more breathing room on the inside */
  .topbar { padding: 18px 28px 12px; }
  .status-bar { padding: 8px 28px 10px; }
  .transcript-area { padding: 12px 32px 28px; }
  .lang-chips { padding: 10px 28px 14px; }
  .controls { padding: 18px 36px 28px; }
  /* Stealth overlay still covers full viewport */
  #stealth-overlay { border-radius: 0; }
}

/* Larger desktop — slightly bigger but capped for readability */
@media (min-width: 1200px) {
  #app {
    max-width: 1040px;
    height: calc(100dvh - 64px);
    margin: 32px auto;
  }
}

/* === DEBUG PANEL === */
#debug-panel {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  background: rgba(15, 15, 17, 0.97);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #2a2a2a;
  font-family: var(--font-mono);
  color: #C8E6FF;
  max-height: 60dvh;
  display: flex;
  flex-direction: column;
}

#debug-panel.hidden {
  display: none;
}

.debug-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid #2a2a2a;
  background: #0a0a0c;
}

.debug-title {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.05em;
  color: #8AB4F8;
}

.debug-actions {
  display: flex;
  gap: 4px;
}

.debug-btn {
  padding: 4px 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  background: #1a1a1c;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  color: #C8E6FF;
  cursor: pointer;
}

.debug-btn:active {
  background: #2a2a2c;
}

.debug-info {
  padding: 6px 10px;
  font-size: 10px;
  color: #FFD60A;
  border-bottom: 1px solid #1a1a1c;
  background: rgba(255, 214, 10, 0.05);
}

.debug-log {
  flex: 1;
  overflow-y: auto;
  padding: 4px 10px 10px;
  font-size: 10px;
  line-height: 1.5;
  font-family: var(--font-mono);
}

.debug-line {
  padding: 3px 0;
  border-bottom: 1px dashed #1a1a1c;
  word-break: break-all;
}

.debug-line .dl-time {
  color: #5A5A58;
  margin-right: 6px;
}

.debug-line .dl-evt {
  color: #8AB4F8;
  font-weight: 500;
}

.debug-line .dl-final {
  color: #66BB6A;
}

.debug-line .dl-interim {
  color: #FFD60A;
  font-style: italic;
}

.debug-line .dl-meta {
  color: #FF8A80;
}

.debug-line .dl-text {
  color: #F5F5F4;
}

/* Push app down when debug visible */
body.debug-on #app {
  padding-top: 0;
}
