/* ClearFeed Beta - Mobile-first Styles */

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

:root {
  --bg: #0f0f1a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #222240;
  --text: #e8e8f0;
  --text-secondary: #9898b0;
  --accent: #4f7cff;
  --accent-hover: #3a66e8;
  --success: #34d399;
  --error: #f87171;
  --warning: #fbbf24;
  --border: #2a2a45;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

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

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

input[type="text"],
input[type="email"],
input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--accent);
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-card-hover);
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.875rem;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: color 0.2s, background 0.2s;
}

.btn-icon:hover {
  color: var(--text);
  background: var(--bg-card);
}

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

/* ---- Auth Pages ---- */
.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-tagline {
  color: var(--text-secondary);
  margin-top: 4px;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.auth-form h2 {
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.auth-switch {
  text-align: center;
  margin-top: 16px;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.auth-error {
  background: rgba(248, 113, 113, 0.1);
  color: var(--error);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  font-size: 0.875rem;
}

.auth-success {
  background: rgba(52, 211, 153, 0.1);
  color: var(--success);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-top: 16px;
  font-size: 0.875rem;
}

.auth-form .btn {
  width: 100%;
  margin-top: 8px;
}

/* ---- Onboarding ---- */
.onboarding-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.onboarding-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px 24px;
  box-shadow: var(--shadow);
}

.onboarding-progress {
  margin-bottom: 28px;
}

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 25%;
  transition: width 0.3s ease;
}

.progress-text {
  display: block;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 8px;
}

.onboarding-step {
  display: none;
}

.onboarding-step.active {
  display: block;
}

.onboarding-step h2 {
  margin-bottom: 4px;
}

.step-subtitle {
  color: var(--text-secondary);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.choice-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}

.choice-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.2s;
}

.choice-card:has(input:checked) {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.08);
}

.choice-card input {
  accent-color: var(--accent);
}

.choice-label {
  font-weight: 500;
}

.conditional-section {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.chip:has(input:checked) {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.12);
}

.chip input {
  display: none;
}

.btn-next {
  width: 100%;
  margin-top: 24px;
}

.btn-detect-location {
  width: 100%;
  margin-top: 8px;
}

/* Topic grid (onboarding) */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.topic-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.topic-card.selected,
.topic-card:has(input:checked) {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.1);
}

.topic-card input {
  display: none;
}

.topic-icon {
  font-size: 1.5rem;
}

.topic-name {
  font-size: 0.85rem;
  font-weight: 500;
}

/* Voice grid */
.voice-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.voice-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.voice-card.selected {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.1);
}

.voice-card input {
  display: none;
}

.voice-name {
  font-weight: 600;
  font-size: 1rem;
}

.voice-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* ---- App Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-title {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

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

/* ---- App Main ---- */
.app-main {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.greeting {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

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

.section-card h2 {
  font-size: 1.1rem;
  margin-bottom: 4px;
}

.section-card h3 {
  font-size: 0.95rem;
  margin-bottom: 8px;
  margin-top: 16px;
}

.section-subtitle {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-bottom: 16px;
}

/* Topic chips (main app) */
.topic-select-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.topic-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.topic-chip.selected {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.12);
}

.topic-chip input {
  display: none;
}

.chip-icon {
  font-size: 1rem;
}

.chip-name {
  font-weight: 500;
}

/* Length selector */
.length-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.length-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.2s, background 0.2s;
}

.length-option.selected {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.1);
}

.length-option input {
  display: none;
}

.length-label {
  font-weight: 600;
  font-size: 1rem;
}

.length-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.btn-generate {
  width: 100%;
  margin-top: 20px;
  padding: 14px 24px;
  font-size: 1.05rem;
}

/* ---- Audio Player ---- */
.audio-player-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.play-btn {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  transition: background 0.2s;
}

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

.player-progress {
  flex: 1;
  min-width: 0;
}

.player-progress input[type="range"] {
  width: 100%;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.player-progress input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.player-progress input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}

.player-times {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.speed-control {
  flex-shrink: 0;
}

.btn-speed {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-speed:hover {
  background: var(--bg-card-hover);
}

.player-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  color: var(--text-secondary);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ---- Script ---- */
.script-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.script-content {
  margin-top: 12px;
  font-size: 0.9rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

.script-content p {
  margin-bottom: 8px;
}

.script-section {
  margin: 16px 0 8px;
}

.script-marker {
  display: inline-block;
  padding: 2px 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 4px;
  letter-spacing: 0.05em;
}

/* ---- Articles ---- */
.article-card {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.article-card:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.article-topic-badge {
  display: inline-block;
  padding: 2px 8px;
  background: rgba(79, 124, 255, 0.15);
  color: var(--accent);
  font-size: 0.7rem;
  font-weight: 600;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.article-title {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 6px 0 4px;
}

.article-source {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.article-link {
  display: inline-block;
  font-size: 0.8rem;
  margin-top: 4px;
}

.article-feedback {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.feedback-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.feedback-btn:hover {
  background: var(--bg-card-hover);
}

.feedback-btn.active {
  border-color: var(--accent);
  background: rgba(79, 124, 255, 0.15);
}

/* ---- History ---- */
.history-card {
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.history-card:hover {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

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

.history-topics {
  font-weight: 500;
  margin: 4px 0 2px;
}

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

/* ---- Back button ---- */
.btn-back-home {
  margin-bottom: 16px;
}

/* ---- Status Messages ---- */
.status-message {
  padding: 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-top: 12px;
}

.status-info {
  background: rgba(79, 124, 255, 0.1);
  color: var(--accent);
}

.status-error {
  background: rgba(248, 113, 113, 0.1);
  color: var(--error);
}

.status-success {
  background: rgba(52, 211, 153, 0.1);
  color: var(--success);
}

.error-text {
  color: var(--error);
}

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

/* ---- Responsive ---- */
@media (min-width: 640px) {
  .app-main {
    padding: 28px 20px 60px;
  }

  .auth-card,
  .onboarding-card {
    padding: 40px 32px;
  }

  .topic-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 380px) {
  .length-options {
    grid-template-columns: 1fr;
  }

  .voice-grid {
    grid-template-columns: 1fr;
  }

  .player-controls {
    flex-wrap: wrap;
  }
}
