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

:root {
  --bg: #faf8f5;
  --card: #ffffff;
  --text: #2d3436;
  --text-secondary: #636e72;
  --text-light: #b2bec3;
  --accent: #e17055;
  --accent-hover: #d35400;
  --success: #00b894;
  --success-bg: #e8f8f5;
  --border: #e8e4e0;
  --recording: #d63031;
  --recording-bg: #ffeaa7;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
  --radius: 16px;
  --radius-sm: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Layout ─────────────────────────────────────────── */

.container {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 20px 100px;
}

/* ── Header ─────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  margin-bottom: 8px;
}

.header-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-btn {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}

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

.header-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ── Progress ───────────────────────────────────────── */

.progress-section {
  margin-bottom: 24px;
}

.progress-bar-track {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.progress-text {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.progress-text strong {
  color: var(--text);
}

/* ── Domain Badge ───────────────────────────────────── */

.domain-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.domain-badge span {
  font-size: 1rem;
}

/* ── Question Card ──────────────────────────────────── */

.question-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  position: relative;
}

.question-number {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.question-group {
  font-size: 0.8125rem;
  color: var(--text-light);
  margin-bottom: 16px;
}

.question-text {
  font-size: 1.375rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
  letter-spacing: -0.01em;
}

.read-aloud-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity 0.15s;
  padding: 4px;
}

.read-aloud-btn:hover,
.read-aloud-btn.speaking {
  opacity: 1;
}

/* ── Answer Area ────────────────────────────────────── */

.answer-area {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.answer-textarea {
  width: 100%;
  min-height: 160px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  font-family: inherit;
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.15s;
  background: var(--bg);
}

.answer-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.answer-textarea::placeholder {
  color: var(--text-light);
}

.answer-textarea.recording {
  border-color: var(--recording);
  background: #fff5f5;
}

.recording-indicator {
  display: none;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.8125rem;
  color: var(--recording);
  font-weight: 600;
}

.recording-indicator.active {
  display: flex;
}

.recording-dot {
  width: 8px;
  height: 8px;
  background: var(--recording);
  border-radius: 50%;
  animation: pulse 1.2s ease-in-out infinite;
}

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

/* ── Buttons ────────────────────────────────────────── */

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-record {
  flex: 1;
  background: var(--bg);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-record:hover {
  border-color: var(--text-secondary);
}

.btn-record.recording {
  background: #fff5f5;
  border-color: var(--recording);
  color: var(--recording);
  animation: recordPulse 1.5s ease-in-out infinite;
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(214, 48, 49, 0.2); }
  50% { box-shadow: 0 0 0 8px rgba(214, 48, 49, 0); }
}

.btn-save {
  flex: 1;
  background: var(--accent);
  color: white;
}

.btn-save:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-continue {
  width: 100%;
  background: var(--card);
  color: var(--accent);
  border: 1.5px solid var(--accent);
  padding: 16px;
}

.btn-continue:hover {
  background: var(--accent);
  color: white;
}

.btn-export {
  width: 100%;
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn-export:hover {
  border-color: var(--text-secondary);
}

.btn-icon {
  font-size: 1.125rem;
}

.no-speech-support {
  display: none;
  font-size: 0.8125rem;
  color: var(--text-light);
  text-align: center;
  margin-top: 8px;
}

/* ── Saved View ─────────────────────────────────────── */

.saved-view {
  text-align: center;
  padding: 40px 20px;
}

.saved-check {
  width: 72px;
  height: 72px;
  background: var(--success-bg);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  margin: 0 auto 20px;
  animation: scaleIn 0.3s ease;
}

@keyframes scaleIn {
  from { transform: scale(0.5); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.saved-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.saved-subtitle {
  font-size: 1rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.saved-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── History View ───────────────────────────────────── */

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

.history-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.history-count {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.history-domain {
  margin-bottom: 24px;
}

.history-domain-title {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1.5px solid var(--border);
}

.history-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.history-question {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.history-answer {
  font-size: 0.875rem;
  color: var(--text-secondary);
  line-height: 1.5;
  white-space: pre-wrap;
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-light);
  margin-top: 8px;
}

.history-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.history-empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.3;
}

/* ── Complete View ──────────────────────────────────── */

.complete-view {
  text-align: center;
  padding: 60px 20px;
}

.complete-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.complete-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.complete-text {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

/* ── Reminder Banner ────────────────────────────────── */

.reminder-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.reminder-banner.hidden {
  display: none;
}

.reminder-content {
  flex: 1;
}

.reminder-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

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

.reminder-time-input {
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  width: 110px;
}

.reminder-time-input:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-reminder {
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 700;
  color: white;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-reminder:hover {
  background: var(--accent-hover);
}

.reminder-dismiss {
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--text-light);
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  align-self: flex-start;
}

.reminder-dismiss:hover {
  color: var(--text-secondary);
}

/* ── Views ──────────────────────────────────────────── */

.view {
  display: none;
}

.view.active {
  display: block;
  animation: fadeIn 0.2s ease;
}

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

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 380px) {
  .question-text {
    font-size: 1.2rem;
  }

  .btn {
    padding: 12px 16px;
    font-size: 0.9375rem;
  }
}

@media (min-width: 768px) {
  .container {
    padding-top: 32px;
  }

  .question-card {
    padding: 36px 32px;
  }
}

/* ── Safe areas (notch) ─────────────────────────────── */

@supports (padding: env(safe-area-inset-top)) {
  .container {
    padding-left: calc(20px + env(safe-area-inset-left));
    padding-right: calc(20px + env(safe-area-inset-right));
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
  }
}
