/* ═══════════════════════════════════════
   Design tokens
═══════════════════════════════════════ */
:root {
  --bg:             #ffffff;
  --bg-fade:        #f5f5f7;
  --text-primary:   #000000;
  --text-secondary: #6e6e73;
  --accent-red:     #ff3b30;
  --accent-black:   #1d1d1f;
  --border:         #d2d2d7;
  --dot-idle:       #d2d2d7;
  --dot-active:     #1d1d1f;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;

  /* iOS safe area */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top:    env(safe-area-inset-top, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden; /* prevent scroll bounce on iOS */
}

body {
  font-family: var(--font);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg);
  /* Subtle bottom fade for depth */
  background: linear-gradient(to bottom, #ffffff 70%, var(--bg-fade) 100%);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
}

button { cursor: pointer; border: none; background: none; font-family: var(--font); }
button:focus-visible { outline: 2px solid var(--accent-black); outline-offset: 2px; }

/* ═══════════════════════════════════════
   Header
═══════════════════════════════════════ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 12px;
  flex-shrink: 0;
}

.header-brand {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-name {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
  color: var(--text-primary);
}

.header-sub {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* ═══════════════════════════════════════
   Icon button (gear, copy, close)
═══════════════════════════════════════ */
.btn-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-primary);
  transition: background 0.15s;
  flex-shrink: 0;
}
.btn-icon:active { background: rgba(0,0,0,0.06); }

/* ═══════════════════════════════════════
   Main content
═══════════════════════════════════════ */
.main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 24px;
  padding-bottom: 8px;
  position: relative;
}

/* ═══════════════════════════════════════
   Dot matrix
═══════════════════════════════════════ */
.dot-matrix-wrap {
  width: 100%;
  flex: 1;
  /* display set exclusively by state class rules in index.html <style> */
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.dot-matrix {
  display: grid;
  /* 30 columns; dot size + gap = 10px each → 300px total.
     On small screens we scale via container query / clamp. */
  grid-template-columns: repeat(30, 6px);
  grid-template-rows: repeat(30, 6px);
  gap: 4px;
  /* Caps at 100% of the wrapper so it never overflows */
  max-width: 100%;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dot-idle);
  transition: background 0.05s, opacity 0.05s;
}

/* ─── Idle dots: all dim ─── */
.state-idle .dot {
  background: var(--dot-idle);
  opacity: 1;
}

/* ─── Recording dots: inactive ones fade, active ones darken (driven by JS) ─── */
.state-recording .dot {
  opacity: 0.3;
}
.state-recording .dot.active {
  background: var(--dot-active);
  opacity: 1;
}

/* ═══════════════════════════════════════
   Idle controls
═══════════════════════════════════════ */
.idle-controls {
  /* display set exclusively by state class rules in index.html <style> */
  justify-content: center;
  padding: 20px 0 8px;
  flex-shrink: 0;
}

.btn-record {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent-black);
  transition: transform 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
}
.btn-record:active {
  transform: scale(0.95);
  box-shadow: 0 0 0 6px rgba(0,0,0,0.04);
}

/* ═══════════════════════════════════════
   Recording controls
═══════════════════════════════════════ */
.recording-controls {
  /* display set exclusively by state class rules in index.html <style> */
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 12px 0 8px;
  flex-shrink: 0;
}

/* REC pill */
.rec-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-black);
  color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.5px;
  padding: 6px 14px;
  border-radius: 999px;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-red);
  animation: blink 1s step-start infinite;
  flex-shrink: 0;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

.rec-timer {
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

/* Stop button */
.btn-stop {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--accent-red);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s;
  flex-shrink: 0;
}
.btn-stop:active { transform: scale(0.95); }

/* ═══════════════════════════════════════
   Screens — non-display layout props only.
   All display/visibility is controlled by
   the inline <style> block in index.html.
═══════════════════════════════════════ */
.screen {
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ═══════════════════════════════════════
   Section header (title + Clear link)
═══════════════════════════════════════ */
.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.section-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.btn-clear {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  padding: 0;
  background: none;
  border: none;
}
.btn-clear:not([disabled]):hover { color: var(--accent-red); }
.btn-clear[disabled] { opacity: 0.4; cursor: default; }

/* ═══════════════════════════════════════
   Transcription box (shared shell)
═══════════════════════════════════════ */
.transcription-box {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px;
  flex-shrink: 0;
}

/* ─── Loading variant ─── */
.transcription-box--loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 140px;
}

.loading-label {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Spinner */
.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--accent-black);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ─── Textarea variant ─── */
.transcription-textarea {
  width: 100%;
  min-height: 120px;
  max-height: 300px;
  resize: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: transparent;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Copy button row */
.copy-row {
  display: flex;
  align-items: center;
  margin-top: 10px;
  flex-shrink: 0;
}

.btn-copy {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}
.btn-copy:active { background: rgba(0,0,0,0.05); }

/* ═══════════════════════════════════════
   Category section
═══════════════════════════════════════ */
.category-section {
  margin-top: 16px;
  flex-shrink: 0;
}

.category-label {
  display: block;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.category-select {
  width: 100%;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-family: var(--font);
  font-size: 16px;
  color: var(--text-primary);
  background: var(--bg);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='14' height='9' viewBox='0 0 14 9' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L7 7L13 1' stroke='%236e6e73' stroke-width='1.8' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.category-select:focus { outline: 2px solid var(--accent-black); outline-offset: 2px; }

/* ═══════════════════════════════════════
   Action buttons
═══════════════════════════════════════ */
.action-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  flex-shrink: 0;
  padding-bottom: 4px;
}

.btn-primary,
.btn-secondary,
.btn-danger {
  width: 100%;
  height: 48px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-primary {
  background: var(--accent-black);
  color: #ffffff;
  border: none;
}
.btn-primary:active  { opacity: 0.8; transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:active { background: rgba(0,0,0,0.04); transform: scale(0.99); }

.btn-danger {
  background: var(--accent-red);
  color: #ffffff;
  border: none;
}
.btn-danger:active { opacity: 0.85; }

/* Sending state: disable send button */
.state-sending .btn-primary {
  opacity: 0.6;
  pointer-events: none;
}

/* ═══════════════════════════════════════
   Success / Sent screen
═══════════════════════════════════════ */
.success-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  margin-bottom: 32px;
}

.success-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.success-sub {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ═══════════════════════════════════════
   Tab bar
═══════════════════════════════════════ */
.tab-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 20px;
  padding-bottom: calc(8px + var(--safe-bottom));
  flex-shrink: 0;

  /* Frosted pill background */
  background: rgba(0,0,0,0.04);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.tab {
  flex: 1;
  height: 36px;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  background: none;
  border: none;
  transition: background 0.15s, color 0.15s;
}

.tab--active {
  background: var(--bg);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.tab--disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

/* ═══════════════════════════════════════
   Toast
═══════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: calc(80px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 100;
}

.toast {
  background: var(--accent-black);
  color: #ffffff;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 999px;
  white-space: nowrap;
  max-width: calc(100vw - 48px);
  opacity: 0;
  transform: translateY(8px);
  animation: toast-in 0.25s ease forwards, toast-out 0.25s ease 2.5s forwards;
}

@keyframes toast-in {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(4px); }
}

/* ═══════════════════════════════════════
   Modals
═══════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  padding: 0 0 var(--safe-bottom);
}

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

.modal {
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  width: 100%;
  max-width: 480px;
  padding: 24px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 700;
}

.modal-body {
  font-size: 16px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-actions .btn-secondary,
.modal-actions .btn-danger {
  flex: 1;
}

/* ═══════════════════════════════════════
   Mic denied inline message
═══════════════════════════════════════ */
.mic-denied-msg {
  text-align: center;
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.6;
  padding: 0 16px;
  max-width: 280px;
}

/* ═══════════════════════════════════════
   Fade transition between states
═══════════════════════════════════════ */
.screen,
.idle-controls,
.recording-controls,
.dot-matrix-wrap {
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
