:root {
  --bg: #f7f7fa;
  --surface: #ffffff;
  --text: #1a1a1e;
  --text-muted: #6b6b74;
  --border: #e2e2e8;
  --primary: #4f5ef0;
  --primary-text: #ffffff;
  --danger: #e0455a;
  --again: #e0455a;
  --hard: #e08a2b;
  --good: #3aa15c;
  --easy: #4f5ef0;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16161a;
    --surface: #1f1f24;
    --text: #f0f0f2;
    --text-muted: #9a9aa4;
    --border: #2e2e35;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

header h1 {
  margin: 0;
  font-size: 1.3rem;
  cursor: pointer;
}

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 16px 0;
}

button {
  font: inherit;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button.primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

button.back-btn {
  margin-bottom: 8px;
  border: none;
  background: none;
  color: var(--text-muted);
  padding: 4px 0;
}

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

.edit-btn {
  border: none;
  background: none;
  color: var(--primary);
  padding: 4px 0;
}

#prev-card-btn {
  margin-top: 4px;
}

.deck-list, .card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.deck-item, .card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

.card-item { cursor: default; }

.deck-item:hover { border-color: var(--primary); }

.deck-item-name { font-weight: 600; }

.deck-item-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.deck-item-meta .due { color: var(--good); font-weight: 600; }

.card-item-text { flex: 1; min-width: 0; }
.card-front { font-weight: 600; }
.card-back { color: var(--text-muted); font-size: 0.9rem; white-space: pre-line; }

.card-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.card-item-actions button { padding: 6px 10px; font-size: 0.85rem; }

.hint {
  color: var(--text-muted);
  font-size: 0.9rem;
}

textarea, input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

textarea {
  min-height: 220px;
  resize: vertical;
  white-space: pre;
}

input[type="file"] {
  margin: 10px 0;
  color: var(--text-muted);
}

#import-result {
  margin-top: 12px;
  font-weight: 600;
}

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

.study-progress {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.flashcard-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.flashcard {
  width: 100%;
  min-height: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  text-align: center;
  cursor: pointer;
  font-size: 1.4rem;
  gap: 14px;
}

.flashcard-face { width: 100%; }
.flashcard-back {
  font-size: 1.1rem;
  color: var(--text-muted);
  white-space: pre-line;
  border-top: 1px solid var(--border);
  padding-top: 14px;
  margin-top: 10px;
}

.grade-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  width: 100%;
}

.grade {
  color: #fff;
  border: none;
  font-weight: 600;
}

.grade-again { background: var(--again); }
.grade-hard { background: var(--hard); }
.grade-good { background: var(--good); }
.grade-easy { background: var(--easy); }
