*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --error: #dc2626;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Brand bar */
.brand-bar {
  background: #15803d;
  text-align: center;
  padding: 0.5rem 1rem;
}

.brand-name {
  color: white;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.daily-counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  border-radius: 10px;
  padding: 0.3rem 0.75rem;
  min-width: 56px;
}

.daily-counter-number {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.daily-counter-label {
  font-size: 0.65rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.streak-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #fff7ed;
  border: 1.5px solid #fed7aa;
  border-radius: 10px;
  padding: 0.3rem 0.75rem;
  min-width: 56px;
}

.streak-number {
  font-size: 1.3rem;
  font-weight: 700;
  color: #ea580c;
  line-height: 1;
}

.streak-label {
  font-size: 0.65rem;
  color: #9a3412;
  letter-spacing: 0.03em;
}

nav a {
  text-decoration: none;
  color: var(--text-light);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s;
  margin-left: 0.25rem;
}

nav a:hover, nav a.active {
  color: var(--primary);
  background: #eff6ff;
}

main {
  max-width: 680px;
  margin: 2rem auto;
  padding: 0 1rem;
}

/* Progress */
.progress-container {
  margin-bottom: 1.25rem;
}

.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* Stats */
.stats {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-badge {
  flex: 1;
  background: white;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-number {
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 0.25rem;
}

/* Card scene (3D container) */
.card-scene {
  perspective: 1200px;
  width: 100%;
  height: 340px;
  cursor: pointer;
  margin-bottom: 1.25rem;
  user-select: none;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.55s ease;
}

.card.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.card-back-face {
  transform: rotateY(180deg);
  background: #f0fdf4;
  border: 2px solid #bbf7d0;
}

.card-face p {
  font-size: 1.15rem;
  line-height: 1.65;
  color: var(--text);
  font-weight: 500;
}

.card-hint {
  margin-top: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-light);
}

/* Settings bar */
.settings-bar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 2rem;
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.setting-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.setting-group label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
}

.setting-group select,
.setting-group input[type="number"] {
  padding: 0.3rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  background: white;
  font-family: inherit;
}

.setting-group input[type="number"] {
  width: 70px;
}

.setting-group select:focus,
.setting-group input[type="number"]:focus {
  outline: none;
  border-color: var(--primary);
}

/* Answer buttons */
.answer-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-bottom: 1.5rem;
}

.btn-hard, .btn-medium, .btn-easy {
  flex: 1;
  max-width: 160px;
  padding: 0.8rem 0.5rem;
  border: 2px solid transparent;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-hard {
  background: #fee2e2;
  color: var(--error);
  border-color: #fca5a5;
}
.btn-hard:hover {
  background: var(--error);
  color: white;
  border-color: var(--error);
}

.btn-medium {
  background: #fef9c3;
  color: #92400e;
  border-color: #fde68a;
}
.btn-medium:hover {
  background: #f59e0b;
  color: white;
  border-color: #f59e0b;
}

.btn-easy {
  background: #dcfce7;
  color: var(--success);
  border-color: #86efac;
}
.btn-easy:hover {
  background: var(--success);
  color: white;
  border-color: var(--success);
}

/* Empty and completion states */
.empty-state, .session-complete {
  text-align: center;
  padding: 3rem 2rem;
  background: white;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.empty-state h2, .session-complete h2 {
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
}

.session-complete h2 {
  color: var(--success);
}

.empty-state p, .session-complete p {
  color: var(--text-light);
  margin-bottom: 0.4rem;
  font-size: 0.95rem;
}

.session-complete button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 1.75rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 1.25rem;
  transition: background 0.2s;
}

.session-complete button:hover {
  background: var(--primary-dark);
}

.session-complete .btn-secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
  margin-top: 0.5rem;
}

.session-complete .btn-secondary:hover {
  background: #eff6ff;
}

.empty-state button {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.75rem 1.75rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.empty-state button:hover {
  background: var(--primary-dark);
}

/* Admin styles */
.admin-section {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
}

.admin-section h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  color: var(--text);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.375rem;
}

.form-group input[type="number"] {
  width: 100px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  transition: border-color 0.2s;
  font-family: inherit;
  resize: vertical;
  background: white;
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.7rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.api-key-note {
  font-size: 0.72rem;
  color: var(--text-light);
  margin-top: 0.35rem;
}

/* Status messages */
.status-message {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-top: 0.75rem;
}

.status-success { background: #dcfce7; color: var(--success); }
.status-error   { background: #fee2e2; color: var(--error); }
.status-loading { background: #eff6ff; color: var(--primary); }

/* Card list */
.card-item {
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.card-item-content { flex: 1; min-width: 0; }

.card-item-front {
  font-weight: 500;
  font-size: 0.875rem;
  color: var(--text);
  margin-bottom: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-item-back {
  font-size: 0.8rem;
  color: var(--text-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-item-actions {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.btn-delete,
.btn-edit {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  flex-shrink: 0;
  transition: color 0.15s;
}

.btn-delete:hover { color: var(--error); }
.btn-edit:hover   { color: var(--primary); }

.card-edit-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.edit-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  margin-top: 0.5rem;
}

.edit-front,
.edit-back {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.2s;
}

.edit-front:focus,
.edit-back:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.edit-front,
.edit-back {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  resize: vertical;
  transition: border-color 0.2s;
}

.edit-front:focus,
.edit-back:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.edit-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-save-edit {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-save-edit:hover { background: var(--primary-dark); }

.btn-cancel-edit {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text-light);
  padding: 0.4rem 1rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel-edit:hover {
  border-color: var(--text-light);
  color: var(--text);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.btn-danger-small {
  background: none;
  border: 1.5px solid var(--error);
  color: var(--error);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-danger-small:hover {
  background: var(--error);
  color: white;
}

/* Admin filter bar */
.admin-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.admin-filter-bar label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  white-space: nowrap;
}

.admin-filter-bar select {
  padding: 0.3rem 0.5rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  color: var(--text);
  background: white;
  font-family: inherit;
}

.admin-filter-bar select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Area counts */
.area-counts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.area-count-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #f8fafc;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem 0.75rem;
  min-width: 70px;
}

.area-count-number {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  line-height: 1;
}

.area-count-name {
  font-size: 0.65rem;
  color: var(--text-light);
  text-align: center;
  margin-top: 0.2rem;
}

/* Stats section */
.stats-section {
  background: white;
  border-radius: 16px;
  box-shadow: var(--shadow);
  margin-top: 1.5rem;
  overflow: hidden;
}

.stats-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.25rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  user-select: none;
}

.stats-section-header:hover {
  background: #f8fafc;
}

.stats-panel {
  padding: 0 1.25rem 1.25rem;
}

.stats-empty {
  font-size: 0.85rem;
  color: var(--text-light);
  text-align: center;
  padding: 0.5rem 0;
}

.stats-alltime {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.5rem 0 0.75rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.stats-alltime-number {
  font-size: 2rem;
  font-weight: 700;
  color: #15803d;
}

.stats-alltime-label {
  font-size: 0.85rem;
  color: var(--text-light);
}

.stats-overall {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.stats-pct-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stats-pct-label {
  font-size: 0.85rem;
  color: var(--text-light);
}

.stats-specialty-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.stats-spec-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.stats-spec-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text);
  width: 130px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-bar-wrap {
  flex: 1;
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.stats-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.4s ease;
}

.stats-spec-pct {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  width: 35px;
  text-align: right;
  flex-shrink: 0;
}

/* Specialty badge in admin card list */
.card-specialty-badge {
  display: inline-block;
  background: #eff6ff;
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  margin-bottom: 0.3rem;
}

/* Edit specialty input */
.edit-specialty {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text);
  background: white;
  transition: border-color 0.2s;
}

.edit-specialty:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Area badge on card */
.card-area-badge {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: #eff6ff;
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 99px;
  border: 1.5px solid #bfdbfe;
  letter-spacing: 0.02em;
}

/* Session breakdown by area */
.session-breakdown {
  margin: 0.75rem 0;
  background: #f8fafc;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  text-align: left;
}

.session-breakdown-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--border);
}

.session-breakdown-row:last-child {
  border-bottom: none;
}

.session-breakdown-area {
  font-weight: 600;
  color: var(--text);
}

.session-breakdown-stats {
  color: var(--text-light);
  font-size: 0.8rem;
}

/* Card images (study mode) */
.card-image {
  max-width: 100%;
  max-height: 140px;
  object-fit: contain;
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

/* Image preview (admin upload) */
.img-preview {
  display: block;
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  border-radius: 6px;
  margin-top: 0.5rem;
  border: 1.5px solid var(--border);
}

/* Thumbnails in card list */
.card-item-thumbs {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.card-thumbnail {
  height: 40px;
  width: 60px;
  object-fit: cover;
  border-radius: 4px;
  border: 1.5px solid var(--border);
}

/* Edit image section */
.edit-image-row {
  display: flex;
  gap: 1rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
}

.edit-image-group {
  flex: 1;
  min-width: 140px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 500;
}

.edit-image-group input[type="file"] {
  font-size: 0.75rem;
  color: var(--text-light);
}

.edit-remove-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--error);
  cursor: pointer;
  font-weight: 400;
}

/* Daily history chart */
.stats-daily-section {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.stats-daily-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-light);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.stats-daily-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.stats-day-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-width: 0;
}

.stats-day-bar-wrap {
  width: 100%;
  height: 70px;
  background: var(--border);
  border-radius: 4px;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.stats-day-bar-fill {
  width: 100%;
  background: var(--primary);
  border-radius: 3px;
  min-height: 3px;
  transition: height 0.4s ease;
}

.stats-day-label {
  font-size: 0.58rem;
  color: var(--text-light);
  white-space: nowrap;
}

.stats-day-count {
  font-size: 0.6rem;
  font-weight: 600;
  color: var(--text-light);
}

/* Utility */
.hidden { display: none !important; }
