/* =============================================================
   Flashcard App Styles — Bold & Minimal
   Matches marioncarr.com design: DM Sans, same palette
   ============================================================= */

:root {
  --fc-bg: #ffffff;
  --fc-bg-alt: #f7f7f7;
  --fc-text: #1a1a1a;
  --fc-text-muted: #7a8288;
  --fc-link: #1a56db;
  --fc-link-hover: #0f3a8a;
  --fc-border: #e5e5e5;
  --fc-card-bg: #ffffff;
  --fc-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --fc-success: #62c462;
  --fc-danger: #ee5f5b;
  --fc-warning: #f89406;
  --fc-radius: 4px;
  --fc-font: 'DM Sans', -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fc-bg: #111111;
    --fc-bg-alt: #1a1a1a;
    --fc-text: #e8e8e8;
    --fc-text-muted: #999999;
    --fc-link: #5b9cf5;
    --fc-link-hover: #7db4ff;
    --fc-border: #2a2a2a;
    --fc-card-bg: #1e1e1e;
    --fc-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  }
}

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

body {
  margin: 0;
  padding: 0;
  font-family: var(--fc-font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--fc-text);
  background: var(--fc-bg);
  -webkit-font-smoothing: antialiased;
}

/* App container */
.app-container {
  max-width: 700px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  min-height: 100vh;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 32px;
  padding-bottom: 16px;
  border-bottom: 2px solid var(--fc-border);
}

.app-header h1 {
  font-size: 1.5em;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
}

.app-header h1 a {
  color: var(--fc-text);
  text-decoration: none;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.875em;
}

.header-right .user-name {
  color: var(--fc-text-muted);
  font-weight: 500;
}

.btn-logout {
  background: none;
  border: 1px solid var(--fc-border);
  color: var(--fc-text-muted);
  padding: 4px 12px;
  border-radius: var(--fc-radius);
  cursor: pointer;
  font-family: var(--fc-font);
  font-size: 0.85em;
  transition: all 0.2s ease-in-out;
}

.btn-logout:hover {
  border-color: var(--fc-danger);
  color: var(--fc-danger);
}

/* Navigation tabs */
.nav-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 32px;
  border-bottom: 2px solid var(--fc-border);
}

.nav-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 10px 20px;
  font-family: var(--fc-font);
  font-size: 0.95em;
  font-weight: 500;
  color: var(--fc-text-muted);
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}

.nav-tab:hover {
  color: var(--fc-text);
}

.nav-tab.active {
  color: var(--fc-text);
  border-bottom-color: var(--fc-link);
  font-weight: 600;
}

/* Views — hide/show */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* Auth view */
.auth-container {
  max-width: 380px;
  margin: 60px auto;
}

.auth-container h2 {
  font-size: 1.5em;
  font-weight: 700;
  margin: 0 0 8px;
}

.auth-container p {
  color: var(--fc-text-muted);
  margin: 0 0 24px;
}

.auth-toggle {
  text-align: center;
  margin-top: 20px;
  font-size: 0.9em;
  color: var(--fc-text-muted);
}

.auth-toggle button {
  background: none;
  border: none;
  color: var(--fc-link);
  cursor: pointer;
  font-family: var(--fc-font);
  font-size: 1em;
  font-weight: 500;
  padding: 0;
  text-decoration: underline;
}

.auth-toggle button:hover {
  color: var(--fc-link-hover);
}

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

.form-group label {
  display: block;
  font-weight: 500;
  font-size: 0.9em;
  margin-bottom: 6px;
  color: var(--fc-text);
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--fc-border);
  border-radius: var(--fc-radius);
  background: var(--fc-bg);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 0.95em;
  transition: border-color 0.2s ease-in-out;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--fc-link);
}

.form-group textarea {
  resize: vertical;
  min-height: 100px;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 10px 24px;
  border: none;
  border-radius: var(--fc-radius);
  font-family: var(--fc-font);
  font-size: 0.95em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
}

.btn-primary {
  background: var(--fc-link);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--fc-link-hover);
}

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

.btn-block {
  display: block;
  width: 100%;
}

/* Messages */
.message {
  padding: 12px 16px;
  border-radius: var(--fc-radius);
  margin-bottom: 16px;
  font-size: 0.9em;
  font-weight: 500;
}

.message-error {
  background: rgba(238, 95, 91, 0.1);
  color: var(--fc-danger);
  border: 1px solid rgba(238, 95, 91, 0.2);
}

.message-success {
  background: rgba(98, 196, 98, 0.1);
  color: var(--fc-success);
  border: 1px solid rgba(98, 196, 98, 0.2);
}

.message-info {
  background: rgba(26, 86, 219, 0.08);
  color: var(--fc-link);
  border: 1px solid rgba(26, 86, 219, 0.15);
}

/* Study view */
.study-stats {
  display: flex;
  gap: 24px;
  margin-bottom: 24px;
  padding: 16px 0;
  border-bottom: 1px solid var(--fc-border);
  font-size: 0.9em;
}

.stat {
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.5em;
  font-weight: 700;
  line-height: 1.2;
}

.stat-label {
  color: var(--fc-text-muted);
  font-size: 0.85em;
}

/* Flashcard */
.flashcard-wrapper {
  perspective: 1000px;
  margin-bottom: 24px;
}

.flashcard {
  position: relative;
  width: 100%;
  min-height: 220px;
  cursor: pointer;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.flashcard.flipped {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  min-height: 220px;
  backface-visibility: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  border: 1px solid var(--fc-border);
  border-radius: 8px;
  background: var(--fc-card-bg);
  box-shadow: var(--fc-card-shadow);
}

.flashcard-front {
  flex-direction: column;
  gap: 12px;
}

.flashcard-back {
  transform: rotateY(180deg);
  flex-direction: column;
  gap: 12px;
}

.flashcard-face .card-label {
  font-size: 0.7em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--fc-text-muted);
}

.flashcard-face .card-text {
  font-size: 1.15em;
  font-weight: 500;
  text-align: center;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: -16px;
  margin-bottom: 20px;
}

.flashcard-hint {
  text-align: center;
  font-size: 0.8em;
  color: var(--fc-text-muted);
  margin: 0;
}

.btn-delete {
  background: none;
  border: none;
  color: var(--fc-text-muted);
  font-family: var(--fc-font);
  font-size: 0.8em;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--fc-radius);
  transition: color 0.2s ease-in-out;
}

.btn-delete:hover {
  color: var(--fc-danger);
}

/* Rating buttons */
.rating-buttons {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.rating-buttons.active {
  display: grid;
}

.rating-btn {
  padding: 12px 8px;
  border: 1px solid var(--fc-border);
  border-radius: var(--fc-radius);
  background: var(--fc-card-bg);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 0.85em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  text-align: center;
}

.rating-btn .rating-label {
  display: block;
  font-size: 0.8em;
  font-weight: 400;
  color: var(--fc-text-muted);
  margin-top: 2px;
}

.rating-btn:hover {
  border-color: var(--fc-link);
  background: rgba(26, 86, 219, 0.05);
}

.rating-btn.again:hover { border-color: var(--fc-danger); }
.rating-btn.hard:hover { border-color: var(--fc-warning); }
.rating-btn.good:hover { border-color: var(--fc-success); }
.rating-btn.easy:hover { border-color: var(--fc-link); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--fc-text-muted);
}

.empty-state h3 {
  font-size: 1.25em;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--fc-text);
}

.empty-state p {
  margin: 0;
  font-size: 0.95em;
}

/* Deck filter */
.deck-filter {
  margin-bottom: 24px;
}

.deck-filter select {
  padding: 8px 12px;
  border: 1px solid var(--fc-border);
  border-radius: var(--fc-radius);
  background: var(--fc-bg);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 0.9em;
}

/* Leaderboard — bar chart */
.leaderboard-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8em;
  color: var(--fc-text-muted);
  font-weight: 500;
}

.legend-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

.leaderboard-user {
  margin-bottom: 20px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.user-details {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.user-name-label {
  font-weight: 600;
  font-size: 0.95em;
  line-height: 1.3;
}

.user-meta {
  font-size: 0.78em;
  color: var(--fc-text-muted);
  line-height: 1.3;
}

.bar-container {
  width: 100%;
  background: var(--fc-bg-alt);
  border-radius: 4px;
  height: 22px;
  overflow: hidden;
}

.bar-track {
  display: flex;
  height: 100%;
  border-radius: 4px;
  overflow: hidden;
  transition: width 0.3s ease;
}

.bar-segment {
  height: 100%;
  min-width: 2px;
  transition: width 0.3s ease;
}

.bar-segment:first-child {
  border-radius: 4px 0 0 4px;
}

.bar-segment:last-child {
  border-radius: 0 4px 4px 0;
}

.bar-segment:only-child {
  border-radius: 4px;
}

/* Avatar badge (leaderboard + header) */
.avatar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 14px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* Avatar picker (signup) */
.avatar-picker-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.avatar-preview {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
  background: var(--fc-link);
}

.avatar-picker-options {
  flex: 1;
  min-width: 0;
}

.avatar-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}

.avatar-option {
  width: 32px;
  height: 32px;
  border: 2px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: var(--fc-bg-alt);
  padding: 0;
  transition: border-color 0.15s ease;
}

.avatar-option:hover {
  border-color: var(--fc-text-muted);
}

.avatar-option.selected {
  border-color: var(--fc-link);
}

.color-option {
  border-radius: 50%;
}

/* Browse view */
.browse-card {
  border: 1px solid var(--fc-border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--fc-card-bg);
}

.browse-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.browse-card-deck {
  font-size: 0.75em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fc-text-muted);
}

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

.browse-card-actions button {
  background: none;
  border: none;
  color: var(--fc-text-muted);
  font-family: var(--fc-font);
  font-size: 0.8em;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: var(--fc-radius);
  transition: color 0.2s ease-in-out;
}

.browse-card-actions .btn-edit:hover {
  color: var(--fc-link);
}

.browse-card-actions .btn-delete:hover {
  color: var(--fc-danger);
}

.browse-card-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.browse-card-field {
  font-size: 0.9em;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.browse-card-field strong {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fc-text-muted);
  display: block;
  margin-bottom: 2px;
}

.browse-card-divider {
  border: none;
  border-top: 1px solid var(--fc-border);
  margin: 4px 0;
}

/* Browse edit mode */
.browse-edit-form textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--fc-border);
  border-radius: var(--fc-radius);
  background: var(--fc-bg);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 0.9em;
  resize: vertical;
  min-height: 60px;
}

.browse-edit-form textarea:focus {
  outline: none;
  border-color: var(--fc-link);
}

.browse-edit-form input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--fc-border);
  border-radius: var(--fc-radius);
  background: var(--fc-bg);
  color: var(--fc-text);
  font-family: var(--fc-font);
  font-size: 0.9em;
}

.browse-edit-form input[type="text"]:focus {
  outline: none;
  border-color: var(--fc-link);
}

.browse-edit-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.browse-edit-actions .btn {
  padding: 6px 16px;
  font-size: 0.85em;
}

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

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

/* Add card success animation */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message {
  animation: fadeIn 0.2s ease-out;
}

/* Responsive */
@media (max-width: 600px) {
  .app-container {
    padding: 16px 16px 80px;
  }

  .app-header h1 {
    font-size: 1.2em;
  }

  .nav-tab {
    padding: 8px 14px;
    font-size: 0.85em;
  }

  .study-stats {
    gap: 16px;
  }

  .rating-buttons {
    grid-template-columns: repeat(2, 1fr);
  }

  .flashcard-face {
    min-height: 180px;
    padding: 24px 16px;
  }

  .leaderboard-legend {
    gap: 8px;
  }

  .bar-container {
    height: 18px;
  }
}
