/* ── CSS Variables ── */
:root {
  --color-primary: #4F46E5;
  --color-things: #3B82F6;
  --color-opinions: #10B981;
  --color-scenarios: #F97316;
  --color-stories: #EF4444;
  --color-bg: #F8FAFC;
  --color-surface: #FFFFFF;
  --color-text: #1E293B;
  --color-text-secondary: #64748B;
  --color-border: #E2E8F0;
  --color-danger: #DC2626;
  --radius: 12px;
  --nav-height: 64px;
  --max-width: 480px;
  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font-stack);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ── App Container ── */
#app {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: var(--nav-height);
  position: relative;
  overflow: hidden;
}

/* ── Pages ── */
.page {
  display: none;
  min-height: calc(100vh - var(--nav-height));
  animation: slideIn 0.25s ease;
}
.page.active { display: block; }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

.page-content { padding: 20px 16px; }

/* ── App Title ── */
.app-title { font-size: 22px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.app-subtitle { font-size: 14px; color: var(--color-text-secondary); text-align: center; margin-bottom: 24px; }
.page-heading { font-size: 20px; font-weight: 700; margin-bottom: 16px; }

/* ── Category Cards ── */
.category-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.category-card {
  display: flex; align-items: center; gap: 12px;
  padding: 16px;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  width: 100%;
  font-family: inherit;
  text-align: left;
}
.category-card:active { transform: scale(0.98); }
.card-things { border-left: 4px solid var(--color-things); }
.card-opinions { border-left: 4px solid var(--color-opinions); }
.card-scenarios { border-left: 4px solid var(--color-scenarios); }
.card-stories { border-left: 4px solid var(--color-stories); }
.card-icon { font-size: 28px; }
.card-title { font-size: 16px; font-weight: 700; }
.card-desc { font-size: 12px; color: var(--color-text-secondary); margin-left: auto; }

/* ── Duration Selector ── */
.duration-selector {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px; background: var(--color-surface); border-radius: var(--radius);
  font-size: 14px;
}
.duration-selector select {
  padding: 6px 12px; border: 1px solid var(--color-border);
  border-radius: 8px; font-size: 14px; font-family: inherit;
}

/* ── Buttons ── */
.btn-primary {
  background: var(--color-primary); color: #fff;
  border: none; border-radius: var(--radius); padding: 14px 24px;
  font-size: 16px; font-weight: 700; cursor: pointer;
  font-family: inherit; transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }
.btn-secondary {
  background: var(--color-bg); color: var(--color-text);
  border: 1px solid var(--color-border); border-radius: var(--radius);
  padding: 12px 20px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn-danger {
  background: var(--color-danger); color: #fff;
  border: none; border-radius: var(--radius); padding: 12px 20px;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.btn-large { width: 100%; padding: 16px; font-size: 18px; }
.btn-small { padding: 8px 16px; font-size: 13px; }
.btn-text { background: none; border: none; color: var(--color-primary); cursor: pointer; font-size: 13px; }

/* ── Ready Page ── */
.ready-content { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding-top: 40px; }
.ready-category {
  font-size: 12px; padding: 4px 14px; border-radius: 20px; margin-bottom: 16px;
  font-weight: 600; display: inline-block;
}
.ready-topic { font-size: 20px; font-weight: 700; line-height: 1.5; margin-bottom: 12px; max-width: 320px; }
.ready-hint { font-size: 14px; color: var(--color-text-secondary); margin-bottom: 32px; }

/* ── Recording Page ── */
.recording-content { display: flex; flex-direction: column; align-items: center; text-align: center; }
.recording-topic { font-size: 14px; color: var(--color-text-secondary); margin-bottom: 12px; max-width: 300px; line-height: 1.4; }

.timer-display { margin: 8px 0 16px; }
.timer-elapsed { font-size: 36px; font-weight: 800; color: var(--color-primary); }
.timer-sep { font-size: 24px; color: var(--color-text-secondary); margin: 0 4px; }
.timer-remaining { font-size: 20px; color: var(--color-text-secondary); }

.recording-indicator { position: relative; width: 80px; height: 80px; margin-bottom: 8px; }
.pulse-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid var(--color-danger);
  animation: pulseRing 1.5s ease-out infinite;
}
.pulse-dot {
  position: absolute; inset: 20px; border-radius: 50%;
  background: var(--color-danger);
  animation: pulseDot 1.5s ease-in-out infinite;
}
@keyframes pulseRing {
  0% { transform: scale(0.8); opacity: 1; }
  100% { transform: scale(1.4); opacity: 0; }
}
@keyframes pulseDot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}
.recording-status { font-size: 14px; color: var(--color-danger); font-weight: 600; margin-bottom: 16px; }

.recording-controls { display: flex; gap: 12px; margin-bottom: 16px; }

.transcript-box {
  width: 100%; max-height: 140px; overflow-y: auto;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 12px; text-align: left;
}
.transcript-label { font-size: 11px; color: var(--color-text-secondary); margin-bottom: 4px; }
.transcript-text { font-size: 13px; line-height: 1.6; color: var(--color-text); white-space: pre-wrap; }

/* ── Loading Page ── */
.loading-content { display: flex; flex-direction: column; align-items: center; justify-content: center; padding-top: 120px; }
.loading-spinner {
  width: 48px; height: 48px; border: 4px solid var(--color-border);
  border-top-color: var(--color-primary); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 16px; font-weight: 600; }

/* ── Report Page ── */
.report-content { padding: 20px 16px; }
.report-title { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 16px; }
.report-card { padding: 14px; border-radius: var(--radius); margin-bottom: 12px; }
.report-card h3 { font-size: 15px; margin-bottom: 8px; }
.grammar-card { background: #F0FDF4; }
.fluency-card { background: #FFFBEB; }
.structure-card { background: #EFF6FF; }
.score { font-size: 13px; font-weight: 400; }

.corrections { font-size: 12px; line-height: 1.8; }
.correction-item { margin-bottom: 6px; }
.correction-original { color: var(--color-danger); text-decoration: line-through; }
.correction-suggestion { color: #059669; font-weight: 600; }
.correction-reason { color: var(--color-text-secondary); font-size: 11px; display: block; }

.vocab-suggestions { margin-top: 8px; }
.vocab-tag { display: inline-block; background: #DCFCE7; color: #166534; padding: 2px 8px; border-radius: 12px; font-size: 11px; margin: 2px 4px 2px 0; }

.fluency-stats { font-size: 13px; line-height: 1.8; }

.structure-info { font-size: 13px; line-height: 1.8; }

.report-actions { display: flex; gap: 10px; margin-top: 16px; }
.report-actions button { flex: 1; }

/* ── Report Topic/Transcript Toggle ── */
.topic-transcript-toggle {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.toggle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  user-select: none;
  -webkit-user-select: none;
}
.toggle-header:active { background: #F8FAFC; }
.toggle-arrow {
  font-size: 10px;
  transition: transform 0.2s ease;
}
.toggle-arrow.open { transform: rotate(90deg); }
.toggle-body {
  padding: 0 14px 14px;
  display: none;
}
.toggle-body.open { display: block; }
.toggle-topic {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.5;
}
.toggle-divider {
  height: 1px;
  background: var(--color-border);
  margin: 10px 0;
}
.toggle-transcript {
  font-size: 13px;
  color: var(--color-text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
  max-height: 180px;
  overflow-y: auto;
}

/* ── History Page ── */
.history-content { padding: 20px 16px; }
.empty-state { text-align: center; color: var(--color-text-secondary); font-size: 14px; padding: 40px 0; }
.history-item {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.history-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.history-item-category { font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.history-item-date { font-size: 11px; color: var(--color-text-secondary); }
.history-item-topic { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.history-item-preview { font-size: 12px; color: var(--color-text-secondary); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ── Settings Page ── */
.settings-content { padding: 20px 16px; }
.setting-group { margin-bottom: 20px; }
.setting-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.setting-input {
  width: 100%; padding: 12px; border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: 14px; font-family: monospace; margin-bottom: 8px;
}
.setting-hint { font-size: 11px; color: var(--color-text-secondary); margin-top: 4px; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal-box {
  background: var(--color-surface); border-radius: 16px;
  padding: 24px; width: 280px; text-align: center;
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.modal-body { font-size: 14px; color: var(--color-text-secondary); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ── Bottom Nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 900;
  display: flex; justify-content: center; background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
  height: var(--nav-height);
}
.nav-item {
  flex: 1; max-width: 160px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; border: none; background: none; cursor: pointer;
  font-family: inherit; color: var(--color-text-secondary);
  font-size: 10px; transition: color 0.15s;
}
.nav-item.active { color: var(--color-primary); }
.nav-icon { font-size: 22px; }
.nav-label { font-weight: 600; }

/* ── Paused state ── */
.paused .pulse-ring, .paused .pulse-dot { animation-play-state: paused; }
.paused .recording-indicator { opacity: 0.5; }
