/**
 * EarWay — Design System
 * Low Vision + Poster Aesthetic
 *
 * Guidelines followed:
 * - WCAG 2.1 AAA contrast (≥ 7:1 for normal text, ≥ 4.5:1 for large text)
 * - Minimum 20px body text
 * - Minimum 44px touch targets (Apple HIG)
 * - Bold weight (≥ 700) for all interactive text
 * - Color never as sole information carrier
 * - Thick, visible focus rings
 * - Poster aesthetic: large typography, stark black/yellow, geometric
 */

/* ─── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&display=swap');

/* ─── Design Tokens ────────────────────────────────────────────────────────── */
:root {
  --black:        #000000;
  --black-soft:   #0A0A0A;
  --gray-900:     #111111;
  --gray-800:     #1A1A1A;
  --gray-700:     #252525;
  --gray-500:     #555555;
  --gray-300:     #999999;

  --yellow:       #FFD700;
  --yellow-dim:   #C8A800;
  --yellow-glow:  rgba(255, 215, 0, 0.15);
  --yellow-glow-strong: rgba(255, 215, 0, 0.35);

  --white:        #FFFFFF;
  --off-white:    #E8E8E8;

  --red:          #FF3B30;
  --red-dim:      rgba(255, 59, 48, 0.2);

  --font:         'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;

  --focus-ring:   0 0 0 4px var(--yellow), 0 0 0 7px var(--black);
  --radius-sm:    4px;
  --radius-md:    8px;
  --radius-full:  9999px;

  /* App shell */
  --header-h:     88px;
  --status-h:     48px;
  --footer-h:     180px;
}

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

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

/* ─── Base ─────────────────────────────────────────────────────────────────── */
body {
  background: var(--black);
  color: var(--white);
  font-family: var(--font);
  font-size: 20px;
  font-weight: 400;
  line-height: 1.55;
  min-height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ─── Focus ─────────────────────────────────────────────────────────────────── */
/* Critical for VoiceOver visual users — must be thick and high-contrast */
*:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ─── Accessibility Utilities ───────────────────────────────────────────────── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ─── App Shell ─────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 680px;
  margin: 0 auto;
  position: relative;
}

/*
  VoiceOver DOM order vs visual order:
  - Mic footer is DOM-first (order 5 visually = bottom)
  - Header is DOM-second (order 1 visually = top)
  - This ensures VoiceOver lands on mic button immediately
*/
.mic-section          { order: 5; }
.app-header           { order: 1; }
.status-bar           { order: 2; }
.conversation-container { order: 3; }
.interim-bar          { order: 4; }

/* ─── Header ────────────────────────────────────────────────────────────────── */
.app-header {
  flex-shrink: 0;
  height: var(--header-h);
  background: var(--black);
  border-bottom: 3px solid var(--yellow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: relative;
  overflow: hidden;
}

/* Subtle poster grid lines in background */
.app-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 60px,
      rgba(255, 215, 0, 0.04) 60px,
      rgba(255, 215, 0, 0.04) 61px
    );
  pointer-events: none;
}

.header-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
}

.app-title {
  font-size: clamp(2rem, 6vw, 2.8rem);
  font-weight: 900;
  color: var(--yellow);
  letter-spacing: -0.03em;
  line-height: 1;
  /* Poster-style: large, commanding */
}

.app-tagline {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--white);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  opacity: 0.6;
}

/* AI badge — decorative, poster accent */
.header-badge {
  font-size: 0.65rem;
  font-weight: 900;
  color: var(--black);
  background: var(--yellow);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  letter-spacing: 0.12em;
  position: relative;
  z-index: 1;
}

/* ─── Status Bar ────────────────────────────────────────────────────────────── */
.status-bar {
  flex-shrink: 0;
  height: var(--status-h);
  background: var(--gray-900);
  border-bottom: 1px solid var(--gray-800);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--yellow);
  flex-shrink: 0;
  transition: background 0.3s;
}

.status-dot--recording {
  background: var(--red);
  animation: pulse-dot 1.2s ease-in-out infinite;
}

.status-dot--processing {
  background: var(--yellow);
  animation: spin-dot 1.5s linear infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

@keyframes spin-dot {
  0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.6); }
  70% { box-shadow: 0 0 0 8px rgba(255, 215, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
}

#status-text {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--yellow);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

/* ─── Conversation Container ────────────────────────────────────────────────── */
.conversation-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 20px;
  scroll-behavior: smooth;

  /* Custom scrollbar — low vision friendly */
  scrollbar-width: thin;
  scrollbar-color: var(--yellow-dim) var(--black);
}

.conversation-container::-webkit-scrollbar {
  width: 4px;
}
.conversation-container::-webkit-scrollbar-track {
  background: var(--black);
}
.conversation-container::-webkit-scrollbar-thumb {
  background: var(--yellow-dim);
  border-radius: 2px;
}

#conversation {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ─── Welcome Screen ────────────────────────────────────────────────────────── */
.welcome-block {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 0 12px;
}

.welcome-headline {
  font-size: clamp(1.8rem, 5vw, 2.5rem);
  font-weight: 900;
  color: var(--yellow);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.welcome-sub {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--off-white);
  line-height: 1.5;
  max-width: 480px;
}

.welcome-hint {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gray-300);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-top: 4px;
}

/* Yellow accent bar — poster element */
.welcome-bar {
  width: 48px;
  height: 4px;
  background: var(--yellow);
  border-radius: 2px;
  margin-bottom: 4px;
}

/* ─── Messages ──────────────────────────────────────────────────────────────── */
.msg {
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: msg-appear 0.2s ease-out;
}

@keyframes msg-appear {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-label {
  font-size: 0.7rem;
  font-weight: 900;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* User message */
.msg--user {
  align-self: flex-end;
  max-width: 88%;
}

.msg--user .msg-label {
  color: var(--gray-300);
  text-align: right;
}

.msg--user .msg-text {
  background: var(--gray-800);
  color: var(--white);
  padding: 14px 18px;
  border-radius: var(--radius-md) var(--radius-md) 0 var(--radius-md);
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.45;
  border: 1px solid var(--gray-700);
}

/* AI message */
.msg--ai {
  align-self: flex-start;
  max-width: 96%;
  width: 100%;
}

.msg--ai .msg-label {
  color: var(--yellow);
}

.msg-summary {
  background: var(--gray-900);
  color: var(--white);
  padding: 16px 20px;
  border-radius: 0 var(--radius-md) var(--radius-md) var(--radius-md);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.5;
  border-left: 4px solid var(--yellow);
  min-height: 56px;
}

/* Details section — revealed on tap */
.msg-details {
  display: none;
  background: var(--gray-900);
  color: var(--off-white);
  padding: 16px 20px;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.65;
  border-left: 4px solid var(--gray-700);
  margin-top: -4px;
}

.msg-details--visible {
  display: block;
  animation: msg-appear 0.2s ease-out;
}

/* Action buttons */
.msg-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-left: 4px;
}

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s, transform 0.1s, box-shadow 0.15s;
}

button:active {
  transform: scale(0.96);
}

/* Secondary: outlined yellow */
.btn-secondary {
  background: transparent;
  color: var(--yellow);
  border: 2px solid var(--yellow);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  min-height: 44px;
}

.btn-secondary:hover {
  background: var(--yellow);
  color: var(--black);
}

.btn-secondary:focus-visible {
  box-shadow: var(--focus-ring);
}

/* Ghost: white outline */
.btn-ghost {
  background: transparent;
  color: var(--gray-300);
  border: 2px solid var(--gray-700);
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 700;
  border-radius: var(--radius-sm);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  min-height: 44px;
}

.btn-ghost:hover {
  color: var(--white);
  border-color: var(--gray-500);
}

.btn-ghost:focus-visible {
  box-shadow: var(--focus-ring);
}

/* ─── Interim Text ──────────────────────────────────────────────────────────── */
.interim-bar {
  flex-shrink: 0;
  min-height: 36px;
  padding: 0 24px;
  display: flex;
  align-items: center;
}

#interim-text {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--gray-500);
  font-style: italic;
  transition: color 0.3s;
}

/* ─── Mic Footer ────────────────────────────────────────────────────────────── */
.mic-section {
  flex-shrink: 0;
  height: var(--footer-h);
  background: var(--black-soft);
  border-top: 3px solid var(--yellow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* Radial glow behind mic button — poster accent */
.mic-section::before {
  content: '';
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    var(--yellow-glow-strong) 0%,
    transparent 70%
  );
  pointer-events: none;
  transition: opacity 0.4s;
}

/* ─── Mic Button ────────────────────────────────────────────────────────────── */
.mic-btn {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: var(--yellow);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  transition:
    background 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  box-shadow: 0 0 0 0 var(--yellow-glow);
}

.mic-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 0 32px var(--yellow-glow);
}

.mic-btn:focus-visible {
  box-shadow:
    var(--focus-ring),
    0 0 40px var(--yellow-glow-strong);
}

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

/* Recording state */
.mic-btn--recording {
  background: var(--red);
  animation: mic-pulse 1.4s ease-in-out infinite;
}

.mic-section:has(.mic-btn--recording)::before {
  background: radial-gradient(
    circle,
    rgba(255, 59, 48, 0.25) 0%,
    transparent 70%
  );
}

@keyframes mic-pulse {
  0%   { box-shadow: 0 0 0 0  rgba(255, 59, 48, 0.7); }
  50%  { box-shadow: 0 0 0 24px rgba(255, 59, 48, 0); }
  100% { box-shadow: 0 0 0 0  rgba(255, 59, 48, 0); }
}

/* Processing state */
.mic-btn--processing {
  background: var(--gray-800);
  animation: mic-thinking 2s linear infinite;
}

.mic-btn--processing .mic-icon {
  fill: var(--gray-500);
}

@keyframes mic-thinking {
  0%   { box-shadow: 0 0 0 0  rgba(255, 215, 0, 0.5); }
  50%  { box-shadow: 0 0 0 20px rgba(255, 215, 0, 0); }
  100% { box-shadow: 0 0 0 0  rgba(255, 215, 0, 0); }
}

.mic-icon {
  width: 44px;
  height: 44px;
  fill: var(--black);
  flex-shrink: 0;
}

.mic-label {
  font-size: 0.8rem;
  font-weight: 900;
  color: var(--white);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  z-index: 1;
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .app-header {
    padding: 0 16px;
  }

  .conversation-container {
    padding: 16px;
  }

  .mic-btn {
    width: 88px;
    height: 88px;
  }

  .mic-icon {
    width: 38px;
    height: 38px;
  }

  .welcome-headline {
    font-size: 1.7rem;
  }

  .msg-summary {
    font-size: 1.05rem;
  }
}

/* ─── Reduced motion ────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ─── High contrast mode (Windows) ─────────────────────────────────────────── */
@media (forced-colors: active) {
  .mic-btn {
    border: 3px solid ButtonText;
  }
  .btn-secondary,
  .btn-ghost {
    border: 2px solid ButtonText;
  }
}
