/* Theme variables */
:root {
  --bg: #f5f5f5;
  --text: #333;
  --text-secondary: #555;
  --text-muted: #777;
  --text-faint: #888;
  --text-faintest: #999;
  --surface: #fff;
  --surface-alt: #ecf0f1;
  --border: #ddd;
  --shadow: rgba(0, 0, 0, 0.1);
  --shadow-hover: rgba(0, 0, 0, 0.15);
  --header-bg: #2c3e50;
  --header-text: #fff;
  --accent: #3498db;
  --accent-hover: #2980b9;
  --accent-dark: #2c3e50;
  --accent-dark-hover: #34495e;
  --heading-color: #2c3e50;
  --stat-value: #2c3e50;
  --disabled-bg: #bdc3c7;
  --code-bg: #f0f0f0;
  --pre-bg: #2c3e50;
  --pre-text: #ecf0f1;
  --divider: #ddd;
  --tag-bg: #ecf0f1;
  --tag-text: #555;
  --progress-bg: #ecf0f1;
  --quality-btn-bg: #fff;
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --text: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-muted: #909090;
  --text-faint: #808080;
  --text-faintest: #707070;
  --surface: #16213e;
  --surface-alt: #0f3460;
  --border: #2a2a4a;
  --shadow: rgba(0, 0, 0, 0.3);
  --shadow-hover: rgba(0, 0, 0, 0.5);
  --header-bg: #0f3460;
  --header-text: #e0e0e0;
  --accent: #4a9eed;
  --accent-hover: #3a8edd;
  --accent-dark: #0f3460;
  --accent-dark-hover: #1a4570;
  --heading-color: #e0e0e0;
  --stat-value: #e0e0e0;
  --disabled-bg: #3a3a5a;
  --code-bg: #0f3460;
  --pre-bg: #0a1628;
  --pre-text: #e0e0e0;
  --divider: #2a2a4a;
  --tag-bg: #0f3460;
  --tag-text: #b0b0b0;
  --progress-bg: #2a2a4a;
  --quality-btn-bg: #16213e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1a2e;
    --text: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #909090;
    --text-faint: #808080;
    --text-faintest: #707070;
    --surface: #16213e;
    --surface-alt: #0f3460;
    --border: #2a2a4a;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.5);
    --header-bg: #0f3460;
    --header-text: #e0e0e0;
    --accent: #4a9eed;
    --accent-hover: #3a8edd;
    --accent-dark: #0f3460;
    --accent-dark-hover: #1a4570;
    --heading-color: #e0e0e0;
    --stat-value: #e0e0e0;
    --disabled-bg: #3a3a5a;
    --code-bg: #0f3460;
    --pre-bg: #0a1628;
    --pre-text: #e0e0e0;
    --divider: #2a2a4a;
    --tag-bg: #0f3460;
    --tag-text: #b0b0b0;
    --progress-bg: #2a2a4a;
    --quality-btn-bg: #16213e;
  }
}

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

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

header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 600;
}

nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-btn {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.4rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.nav-btn:hover {
  color: white;
  border-color: white;
}

.nav-btn.active {
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-color: white;
}

.theme-toggle {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.7);
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  transition: all 0.2s;
  margin-left: 0.5rem;
}

.theme-toggle:hover {
  color: white;
  border-color: white;
}

main {
  max-width: 800px;
  margin: 2rem auto;
  padding: 0 1rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--surface);
  border-radius: 8px;
  padding: 1.2rem;
  text-align: center;
  box-shadow: 0 1px 3px var(--shadow);
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--stat-value);
}

.stat-card .label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.btn {
  display: inline-block;
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  transition: all 0.2s;
}

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

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

.btn-primary:disabled {
  background: var(--disabled-bg);
  cursor: not-allowed;
}

.btn-start {
  display: block;
  width: 100%;
  padding: 1rem;
  font-size: 1.2rem;
  margin-bottom: 2rem;
}

/* Session */
.session-progress {
  background: var(--surface);
  border-radius: 8px;
  padding: 0.8rem 1.2rem;
  margin-bottom: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 3px var(--shadow);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

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

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

.card-display {
  background: var(--surface);
  border-radius: 12px;
  padding: 2rem;
  min-height: 250px;
  box-shadow: 0 2px 8px var(--shadow);
  margin-bottom: 1.5rem;
}

.card-display .card-content {
  font-size: 1.1rem;
}

.card-display .card-content h1,
.card-display .card-content h2,
.card-display .card-content h3 {
  margin-bottom: 0.5rem;
}

.card-display .card-content p {
  margin-bottom: 0.8rem;
}

.card-display .card-content ul,
.card-display .card-content ol {
  margin-bottom: 0.8rem;
}

.card-display .card-content code {
  background: var(--code-bg);
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  font-size: 0.95em;
}

.card-display .card-content pre {
  background: var(--pre-bg);
  color: var(--pre-text);
  padding: 1rem;
  border-radius: 6px;
  overflow-x: auto;
  margin-bottom: 0.8rem;
}

.card-display .card-content pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.answer-divider {
  border: none;
  border-top: 2px dashed var(--divider);
  margin: 1.5rem 0;
}

.btn-show-answer {
  display: block;
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
  background: var(--accent-dark);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-show-answer:hover {
  background: var(--accent-dark-hover);
}

.quality-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.quality-btn {
  padding: 0.8rem 0.5rem;
  border: 2px solid;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.2s;
  background: var(--quality-btn-bg);
}

.quality-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px var(--shadow-hover);
}

.quality-btn[data-quality="0"] { border-color: #e74c3c; color: #e74c3c; }
.quality-btn[data-quality="1"] { border-color: #e67e22; color: #e67e22; }
.quality-btn[data-quality="2"] { border-color: #f39c12; color: #f39c12; }
.quality-btn[data-quality="3"] { border-color: #f1c40f; color: #b7950b; }
.quality-btn[data-quality="4"] { border-color: #2ecc71; color: #27ae60; }
.quality-btn[data-quality="5"] { border-color: #3498db; color: #2980b9; }

.quality-btn[data-quality="0"]:hover { background: #e74c3c; color: white; }
.quality-btn[data-quality="1"]:hover { background: #e67e22; color: white; }
.quality-btn[data-quality="2"]:hover { background: #f39c12; color: white; }
.quality-btn[data-quality="3"]:hover { background: #f1c40f; color: white; }
.quality-btn[data-quality="4"]:hover { background: #2ecc71; color: white; }
.quality-btn[data-quality="5"]:hover { background: #3498db; color: white; }

/* Session Summary */
.summary {
  background: var(--surface);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 2px 8px var(--shadow);
  text-align: center;
}

.summary h2 {
  margin-bottom: 1.5rem;
  color: var(--heading-color);
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* Card Browser */
.browser-controls {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.browser-controls input {
  flex: 1;
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
  background: var(--surface);
  color: var(--text);
}

.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.card-list-item {
  background: var(--surface);
  border-radius: 8px;
  padding: 1rem 1.2rem;
  box-shadow: 0 1px 3px var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-list-item:hover {
  box-shadow: 0 2px 8px var(--shadow-hover);
}

.card-list-item .card-question {
  font-weight: 500;
  flex: 1;
}

.card-list-item .card-meta {
  display: flex;
  gap: 0.8rem;
  font-size: 0.8rem;
  color: var(--text-faint);
  flex-shrink: 0;
  margin-left: 1rem;
}

.tag {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  margin-right: 0.3rem;
}

.due-badge {
  background: #e74c3c;
  color: white;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
}

.due-badge.not-due {
  background: #2ecc71;
}

/* Review History */
.history-section {
  margin-top: 2rem;
}

.history-section h3 {
  margin-bottom: 0.8rem;
  color: var(--heading-color);
}

.history-bar {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 80px;
  padding: 0;
}

.history-bar .bar {
  flex: 1;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  position: relative;
}

.history-bar .bar .bar-label {
  position: absolute;
  bottom: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  color: var(--text-faintest);
  white-space: nowrap;
}

/* Archive styles */
.btn-archive-toggle {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  transition: all 0.2s;
}

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

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

.archived-badge {
  background: #95a5a6;
  color: white;
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
}

.btn-archive {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

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

.card-list-item.archived {
  opacity: 0.55;
}

.no-cards-message {
  text-align: center;
  padding: 3rem;
  color: var(--text-faint);
  font-size: 1.1rem;
}

/* Tag Picker */
.tag-picker {
  position: relative;
  margin-bottom: 1rem;
}

.tag-picker-toggle {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s;
}

.tag-picker-toggle:hover {
  border-color: var(--accent);
}

.tag-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px var(--shadow);
  z-index: 100;
  max-height: 240px;
  overflow: hidden;
}

.tag-dropdown.open {
  display: block;
}

.tag-search {
  display: block;
  width: 100%;
  padding: 0.6rem 1rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

.tag-options {
  max-height: 180px;
  overflow-y: auto;
}

.tag-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text);
  transition: background 0.15s;
}

.tag-option:hover {
  background: var(--surface-alt);
}

.tag-option input[type="checkbox"] {
  accent-color: var(--accent);
}

.tag-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--accent);
  color: white;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
}

.tag-pill-remove {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  opacity: 0.8;
}

.tag-pill-remove:hover {
  opacity: 1;
}

/* Auth */
.auth-card {
  max-width: 400px;
  margin: 4rem auto;
  background: var(--surface);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.auth-card h2 {
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--heading-color);
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.auth-card input[type="text"],
.auth-card input[type="password"] {
  padding: 0.7rem 1rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}

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

.auth-card .btn {
  width: 100%;
  padding: 0.8rem;
  font-size: 1rem;
}

.auth-error {
  color: #e74c3c;
  font-size: 0.85rem;
  min-height: 1.2em;
}

.auth-toggle {
  text-align: center;
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

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

.auth-toggle a:hover {
  text-decoration: underline;
}

/* User info in header */
.user-info {
  color: rgba(255, 255, 255, 0.7);
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.btn-logout {
  background: transparent;
  color: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.3);
  padding: 0.4rem 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.btn-logout:hover {
  color: white;
  border-color: white;
}

/* Tools */
.tools-heading {
  margin-bottom: 1.5rem;
  color: var(--heading-color);
}

.tools-sections {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.tools-section {
  background: var(--surface);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.tools-section h3 {
  margin-bottom: 0.5rem;
  color: var(--heading-color);
}

.tools-description {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.tools-hint {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-bottom: 0.5rem;
}

.tools-status {
  margin-top: 0.8rem;
  font-size: 0.9rem;
  color: var(--text-muted);
  white-space: pre-line;
}

.tools-status-success {
  color: #2ecc71;
}

.tools-status-error {
  color: #e74c3c;
}

.tools-status-warning {
  color: #e67e22;
}

.file-input-wrapper {
  margin-bottom: 1rem;
}

.file-input-wrapper input[type="file"] {
  font-size: 0.9rem;
  color: var(--text);
}

.import-preview {
  margin-bottom: 1rem;
}

.import-preview-content {
  background: var(--surface-alt);
  border-radius: 6px;
  padding: 0.8rem 1rem;
  font-size: 0.9rem;
  color: var(--text);
}
