django-flashdeck 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. django_flashdeck-0.1.0.dist-info/METADATA +215 -0
  2. django_flashdeck-0.1.0.dist-info/RECORD +53 -0
  3. django_flashdeck-0.1.0.dist-info/WHEEL +4 -0
  4. django_flashdeck-0.1.0.dist-info/licenses/LICENSE +28 -0
  5. flashdeck/__init__.py +1 -0
  6. flashdeck/admin.py +68 -0
  7. flashdeck/apps.py +8 -0
  8. flashdeck/bundles.py +346 -0
  9. flashdeck/conf.py +19 -0
  10. flashdeck/images.py +85 -0
  11. flashdeck/management/__init__.py +0 -0
  12. flashdeck/management/commands/__init__.py +0 -0
  13. flashdeck/management/commands/flashdeck_export.py +23 -0
  14. flashdeck/management/commands/flashdeck_import.py +29 -0
  15. flashdeck/manifest.py +33 -0
  16. flashdeck/marking.py +107 -0
  17. flashdeck/migrations/0001_initial.py +146 -0
  18. flashdeck/migrations/0002_card_options.py +44 -0
  19. flashdeck/migrations/0003_reference.py +28 -0
  20. flashdeck/migrations/__init__.py +0 -0
  21. flashdeck/models.py +325 -0
  22. flashdeck/practice.py +232 -0
  23. flashdeck/reference.py +108 -0
  24. flashdeck/scheduling.py +75 -0
  25. flashdeck/static/flashdeck/flashdeck.css +241 -0
  26. flashdeck/static/flashdeck/flashdeck.js +137 -0
  27. flashdeck/stats.py +248 -0
  28. flashdeck/templates/flashdeck/_account.html +1 -0
  29. flashdeck/templates/flashdeck/_assets.html +2 -0
  30. flashdeck/templates/flashdeck/_crumbs.html +1 -0
  31. flashdeck/templates/flashdeck/_crumbs_root.html +1 -0
  32. flashdeck/templates/flashdeck/_forms.html +3 -0
  33. flashdeck/templates/flashdeck/_prompt.html +5 -0
  34. flashdeck/templates/flashdeck/_reference_dialog.html +8 -0
  35. flashdeck/templates/flashdeck/_search.html +5 -0
  36. flashdeck/templates/flashdeck/admin/bundles.html +24 -0
  37. flashdeck/templates/flashdeck/fragment.html +1 -0
  38. flashdeck/templates/flashdeck/index.html +29 -0
  39. flashdeck/templates/flashdeck/nothing_due.html +21 -0
  40. flashdeck/templates/flashdeck/page.html +23 -0
  41. flashdeck/templates/flashdeck/progress.html +80 -0
  42. flashdeck/templates/flashdeck/question.html +46 -0
  43. flashdeck/templates/flashdeck/reference_deck.html +28 -0
  44. flashdeck/templates/flashdeck/reference_item.html +18 -0
  45. flashdeck/templates/flashdeck/reference_subject.html +19 -0
  46. flashdeck/templates/flashdeck/result.html +56 -0
  47. flashdeck/templates/flashdeck/settings.html +44 -0
  48. flashdeck/templatetags/__init__.py +0 -0
  49. flashdeck/templatetags/flashdeck_tags.py +52 -0
  50. flashdeck/urls.py +31 -0
  51. flashdeck/views.py +392 -0
  52. flashdeck/wagtail_hooks.py +109 -0
  53. flashdeck/wagtail_views.py +106 -0
flashdeck/practice.py ADDED
@@ -0,0 +1,232 @@
1
+ """Choosing the next card, marking and recording answers, claims, and each user's
2
+ choices of which cards to hide and how often the others come back."""
3
+
4
+ from collections import defaultdict
5
+ from datetime import datetime, time
6
+
7
+ from django.db import transaction
8
+ from django.utils import timezone
9
+
10
+ from .conf import setting
11
+ from .marking import Verdict, combine, mark
12
+ from .models import Answer, CardState, ClaimedAnswer, Deck, Review
13
+ from .scheduling import Frequency, due_of, effective_verdict, schedule
14
+
15
+ NEW_CARD_ORDER = [
16
+ "deck__subject__position",
17
+ "deck__position",
18
+ "deck_id",
19
+ "position",
20
+ "id",
21
+ ]
22
+
23
+
24
+ def visible_decks(user):
25
+ """The decks that a user may practise."""
26
+ decks = Deck.objects.select_related("subject")
27
+ if not user.has_perm("flashdeck.practise_private"):
28
+ decks = decks.filter(is_public=True)
29
+ return decks
30
+
31
+
32
+ def new_cards_left(user):
33
+ """How many more new cards the user may start today."""
34
+ midnight = timezone.make_aware(datetime.combine(timezone.localdate(), time.min))
35
+ # A card hidden before it was ever answered has no FSRS state, and was not
36
+ # started.
37
+ started = CardState.objects.filter(
38
+ user=user, created__gte=midnight, fsrs__isnull=False
39
+ ).count()
40
+ return setting("NEW_CARDS_PER_DAY") - started
41
+
42
+
43
+ def next_card(user, cards, *, after=None, ahead=False, more=False):
44
+ """The card to show next from `cards`, or None if nothing is due.
45
+
46
+ A visitor who is not logged in gets a random card. A user gets the card most
47
+ overdue; failing that, a new card (up to NEW_CARDS_PER_DAY, or beyond it with
48
+ `more`); failing that, with `ahead`, the card due soonest. Cards the user has
49
+ hidden are never shown. The card just shown (`after`) is not shown again
50
+ straight away unless it is the only choice.
51
+ """
52
+ if not user.is_authenticated:
53
+ pool = cards.exclude(pk=after) if after else cards
54
+ return pool.order_by("?").first() or cards.first()
55
+ states = CardState.objects.filter(
56
+ user=user, card__in=cards, suspended=False
57
+ ).select_related("card__deck__subject")
58
+ due = states.filter(due__lte=timezone.now()).order_by("due")
59
+ state = _first(due, card_id=after)
60
+ if state:
61
+ return state.card
62
+ if more or new_cards_left(user) > 0:
63
+ new = cards.exclude(states__user=user).order_by(*NEW_CARD_ORDER)
64
+ card = _first(new.select_related("deck__subject"), pk=after)
65
+ if card:
66
+ return card
67
+ if ahead:
68
+ state = _first(states.exclude(due=None).order_by("due"), card_id=after)
69
+ if state:
70
+ return state.card
71
+ return None
72
+
73
+
74
+ def _first(queryset, **exclude):
75
+ """The first in the queryset other than the excluded one, if there is one."""
76
+ if any(value is not None for value in exclude.values()):
77
+ found = queryset.exclude(**exclude).first()
78
+ if found:
79
+ return found
80
+ return queryset.first()
81
+
82
+
83
+ def mark_card(card, answers, given, user):
84
+ """Marks the answers given (a dictionary from Answer id to text).
85
+
86
+ Returns the results, one for each answer, and the verdict on the card. A user's
87
+ claimed answers that have not been rejected are marked right for that user.
88
+ """
89
+ claimed = defaultdict(list)
90
+ if user.is_authenticated:
91
+ for answer_id, text in ClaimedAnswer.objects.filter(
92
+ user=user, answer__in=answers, status=ClaimedAnswer.Status.PENDING
93
+ ).values_list("answer_id", "text"):
94
+ claimed[answer_id].append(text)
95
+ case_sensitive = card.deck.subject.case_sensitive
96
+ results = []
97
+ for answer in answers:
98
+ text = given.get(answer.pk, "").strip()
99
+ result = mark(
100
+ text, answer.accepted() + claimed[answer.pk], case_sensitive=case_sensitive
101
+ )
102
+ results.append(
103
+ {
104
+ "answer": answer.pk,
105
+ "given": text,
106
+ "verdict": result.verdict.value,
107
+ "expected": result.expected,
108
+ }
109
+ )
110
+ return results, combine(r["verdict"] for r in results)
111
+
112
+
113
+ @transaction.atomic
114
+ def record_review(user, card, results, verdict, looked_up=False):
115
+ """Saves a marked answer and reschedules the card (as if nearly right if the
116
+ user looked at the reference first and was right)."""
117
+ now = timezone.now()
118
+ state = CardState.objects.select_for_update().filter(user=user, card=card).first()
119
+ if state is None:
120
+ state = CardState(user=user, card=card)
121
+ before = state.fsrs
122
+ after = schedule(
123
+ before, effective_verdict(verdict, looked_up), now, card.pk, state.frequency
124
+ )
125
+ state.fsrs = after
126
+ state.due = due_of(after)
127
+ state.save()
128
+ return Review.objects.create(
129
+ user=user,
130
+ card=card,
131
+ created=now,
132
+ verdict=verdict,
133
+ results=results,
134
+ state_before=before,
135
+ looked_up=looked_up,
136
+ )
137
+
138
+
139
+ class ClaimError(Exception):
140
+ pass
141
+
142
+
143
+ @transaction.atomic
144
+ def claim(review, answer_id):
145
+ """Records the user's claim that their answer was right after all.
146
+
147
+ The answer is saved as a ClaimedAnswer, the review is marked again, and, if it
148
+ is the user's latest review of the card, the card is rescheduled as if the
149
+ review had been marked that way to begin with.
150
+ """
151
+ review = Review.objects.select_for_update().get(pk=review.pk)
152
+ entry = next((r for r in review.results if r["answer"] == answer_id), None)
153
+ if (
154
+ entry is None
155
+ or entry["verdict"] not in (Verdict.NEARLY, Verdict.WRONG)
156
+ or not entry["given"]
157
+ ):
158
+ raise ClaimError("Only an answer marked wrong or nearly right can be claimed.")
159
+ try:
160
+ answer = Answer.objects.get(pk=answer_id, card_id=review.card_id)
161
+ except Answer.DoesNotExist as error:
162
+ raise ClaimError("The answer no longer exists.") from error
163
+ claimed, created = ClaimedAnswer.objects.get_or_create(
164
+ answer=answer, user=review.user, text=entry["given"]
165
+ )
166
+ if not created and claimed.status == ClaimedAnswer.Status.REJECTED:
167
+ claimed.status = ClaimedAnswer.Status.PENDING
168
+ claimed.save(update_fields=["status"])
169
+ entry["verdict"] = Verdict.CLAIMED.value
170
+ review.verdict = combine(r["verdict"] for r in review.results)
171
+ review.save(update_fields=["results", "verdict"])
172
+ latest = (
173
+ Review.objects.filter(user=review.user, card_id=review.card_id)
174
+ .values_list("pk", flat=True)
175
+ .first()
176
+ )
177
+ if latest == review.pk:
178
+ state = CardState.objects.select_for_update().get(
179
+ user=review.user, card_id=review.card_id
180
+ )
181
+ _reschedule(state)
182
+ state.save(update_fields=["fsrs", "due"])
183
+ return claimed
184
+
185
+
186
+ def _reschedule(state):
187
+ """Schedules the card again from the user's latest review of it, as if that
188
+ review had been marked as it is now, with the card's present frequency.
189
+ Returns whether there was a review to do it from."""
190
+ review = Review.objects.filter(user_id=state.user_id, card_id=state.card_id).first()
191
+ if review is None:
192
+ return False
193
+ state.fsrs = schedule(
194
+ review.state_before,
195
+ effective_verdict(review.verdict, review.looked_up),
196
+ review.created,
197
+ state.card_id,
198
+ state.frequency,
199
+ )
200
+ state.due = due_of(state.fsrs)
201
+ return True
202
+
203
+
204
+ @transaction.atomic
205
+ def set_hidden(user, card, hidden):
206
+ """Hides a card from a user (it is never shown in practice), or shows it again."""
207
+ state = CardState.objects.select_for_update().filter(user=user, card=card).first()
208
+ if hidden:
209
+ if state is None:
210
+ CardState.objects.create(user=user, card=card, suspended=True)
211
+ elif not state.suspended:
212
+ state.suspended = True
213
+ state.save(update_fields=["suspended"])
214
+ elif state is not None and state.suspended:
215
+ if state.fsrs is None:
216
+ state.delete() # never answered, so it is a new card again
217
+ else:
218
+ state.suspended = False
219
+ state.save(update_fields=["suspended"])
220
+
221
+
222
+ @transaction.atomic
223
+ def set_frequency(user, card, frequency):
224
+ """Sets how often a card that the user has answered comes back, and schedules
225
+ it again at once."""
226
+ frequency = Frequency(frequency)
227
+ state = CardState.objects.select_for_update().filter(user=user, card=card).first()
228
+ if state is None or state.fsrs is None:
229
+ return
230
+ state.frequency = frequency
231
+ _reschedule(state)
232
+ state.save(update_fields=["frequency", "fsrs", "due"])
flashdeck/reference.py ADDED
@@ -0,0 +1,108 @@
1
+ """Reference pages, generated from the cards: a deck's cards as a table, and a
2
+ subject's *items*, each being the cards that share a key across its decks (for
3
+ verbs, each verb in every tense)."""
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+ from .marking import loosen
8
+ from .models import Card
9
+
10
+
11
+ @dataclass
12
+ class Form:
13
+ """One answer as shown in a reference: its label, its text, and the other
14
+ answers that are also right."""
15
+
16
+ label: str
17
+ text: str
18
+ alternatives: list
19
+
20
+ @property
21
+ def prefix(self):
22
+ """The label, with a space after it unless it ends in an apostrophe (j’)."""
23
+ if not self.label:
24
+ return ""
25
+ return self.label if self.label[-1] in "’'" else f"{self.label} "
26
+
27
+
28
+ def forms(card):
29
+ return [
30
+ Form(a.label, a.text, a.accepted()[1:])
31
+ for a in card.answers.all() # prefetched
32
+ ]
33
+
34
+
35
+ def rows(card):
36
+ """Rows of the forms grid: two columns, filled downwards, so that a verb's six
37
+ persons read je, tu, il down the first and nous, vous, ils down the second."""
38
+ return (len(card.answers.all()) + 1) // 2
39
+
40
+
41
+ def search_text(cards):
42
+ """The text that the search box matches, in the folded form that both it and
43
+ flashdeck.js compare (see marking.loosen): every prompt and answer."""
44
+ parts = []
45
+ for card in cards:
46
+ parts.append(card.prompt)
47
+ for answer in card.answers.all():
48
+ parts.extend(answer.accepted())
49
+ if answer.label:
50
+ parts.append(f"{answer.label} {answer.text}")
51
+ return " / ".join(loosen(part) for part in parts if part)
52
+
53
+
54
+ def name(card):
55
+ """A card's name in a reference. A card with an image (such as a circuit
56
+ symbol) is named by its answer, since its prompt is usually a question such as
57
+ "Name this symbol"; any other card by the first line of its prompt."""
58
+ answers = card.answers.all() # prefetched
59
+ if card.image and answers:
60
+ return answers[0].text
61
+ return card.prompt.split("\n")[0].strip() or card.key
62
+
63
+
64
+ @dataclass
65
+ class Item:
66
+ key: str
67
+ name: str
68
+ cards: list = field(default_factory=list)
69
+
70
+ @property
71
+ def search(self):
72
+ return search_text(self.cards)
73
+
74
+
75
+ def cards_in(decks):
76
+ return (
77
+ Card.objects.filter(deck__in=decks)
78
+ .select_related("deck__subject")
79
+ .prefetch_related("answers")
80
+ .order_by("deck__position", "deck__title", "deck_id", "position", "id")
81
+ )
82
+
83
+
84
+ def items(decks):
85
+ """The subject's items, in alphabetical order of name (ignoring accents)."""
86
+ found = {}
87
+ for card in cards_in(decks):
88
+ item = found.setdefault(card.key, Item(card.key, name(card)))
89
+ item.cards.append(card)
90
+ return sorted(found.values(), key=lambda item: loosen(item.name))
91
+
92
+
93
+ def short_titles(decks):
94
+ """Deck titles without the part they all share up to a colon, such as
95
+ "Irregular verbs: ", which repeats on an item's page."""
96
+ titles = {deck.pk: deck.title for deck in decks}
97
+ if len(titles) > 1:
98
+ # The prefix that the first and last in alphabetical order share is the
99
+ # one that they all do.
100
+ first, last = min(titles.values()), max(titles.values())
101
+ length = next(
102
+ (i for i, (a, b) in enumerate(zip(first, last, strict=False)) if a != b),
103
+ min(len(first), len(last)),
104
+ )
105
+ cut = first[:length].rfind(": ")
106
+ if cut > 0:
107
+ return {pk: title[cut + 2 :] for pk, title in titles.items()}
108
+ return titles
@@ -0,0 +1,75 @@
1
+ """Spaced repetition with FSRS (the Free Spaced Repetition Scheduler).
2
+
3
+ A right answer is rated Good, a nearly right one Hard and a wrong one Again. The
4
+ state of each card for each user is kept as the dictionary that the fsrs package
5
+ reads and writes.
6
+
7
+ How often a card comes back is set by the chance of remembering it that FSRS aims
8
+ for when it next comes back (its *target recall*). A lower target lengthens every
9
+ interval, and the effect compounds: after the second, third and fourth right
10
+ answers, a card comes back after about 2, 11 and 46 days normally, but after 1, 3
11
+ and 8 (more often), 4, 31 and 174 (less often) or 8, 76 and 525 (rarely).
12
+ """
13
+
14
+ from datetime import UTC, datetime
15
+
16
+ from django.db import models
17
+ from fsrs import Card as FsrsCard
18
+ from fsrs import Rating, Scheduler
19
+
20
+ from .marking import Verdict
21
+
22
+
23
+ class Frequency(models.TextChoices):
24
+ MORE = "more", "More often"
25
+ NORMAL = "normal", "Normally"
26
+ LESS = "less", "Less often"
27
+ RARELY = "rarely", "Rarely"
28
+
29
+
30
+ TARGET_RECALL = {
31
+ Frequency.MORE: 0.95,
32
+ Frequency.NORMAL: 0.9,
33
+ Frequency.LESS: 0.85,
34
+ Frequency.RARELY: 0.8,
35
+ }
36
+ _schedulers = {
37
+ frequency: Scheduler(desired_retention=recall)
38
+ for frequency, recall in TARGET_RECALL.items()
39
+ }
40
+
41
+ RATINGS = {
42
+ Verdict.RIGHT: Rating.Good,
43
+ Verdict.CLAIMED: Rating.Good,
44
+ Verdict.NEARLY: Rating.Hard,
45
+ Verdict.WRONG: Rating.Again,
46
+ }
47
+
48
+
49
+ def effective_verdict(verdict: str, looked_up: bool) -> Verdict:
50
+ """The verdict that schedules a card: a right answer given after looking at the
51
+ reference counts as nearly right, so that the card comes back sooner."""
52
+ verdict = Verdict(verdict)
53
+ if looked_up and verdict in (Verdict.RIGHT, Verdict.CLAIMED):
54
+ return Verdict.NEARLY
55
+ return verdict
56
+
57
+
58
+ def schedule(
59
+ state: dict | None,
60
+ verdict: str,
61
+ when: datetime,
62
+ card_id: int,
63
+ frequency: str = Frequency.NORMAL,
64
+ ) -> dict:
65
+ """The state after a review at `when`, from the state before it (None for a
66
+ card not seen before)."""
67
+ when = when.astimezone(UTC) # fsrs accepts only datetime.UTC
68
+ card = FsrsCard.from_dict(state) if state else FsrsCard(card_id=card_id, due=when)
69
+ scheduler = _schedulers[Frequency(frequency)]
70
+ card, _ = scheduler.review_card(card, RATINGS[Verdict(verdict)], when)
71
+ return card.to_dict()
72
+
73
+
74
+ def due_of(state: dict) -> datetime:
75
+ return datetime.fromisoformat(state["due"])
@@ -0,0 +1,241 @@
1
+ /* django-flashdeck
2
+ *
3
+ * The colours are custom properties, which a site can set on .flashdeck to match
4
+ * its own palette: --flashdeck-ink, -muted, -line, -surface, -input, -accent and
5
+ * -accent-on; -right, -nearly and -wrong (the colours of marks as text);
6
+ * -bar-right, -bar-nearly and -bar-wrong (the chart's bars); and -page (the
7
+ * reference dialog's background). The defaults follow the page's text colour and
8
+ * its color-scheme (light or dark).
9
+ */
10
+
11
+ .flashdeck {
12
+ --fd-ink: var(--flashdeck-ink, currentColor);
13
+ --fd-muted: var(--flashdeck-muted, color-mix(in srgb, currentColor 70%, transparent));
14
+ --fd-line: var(--flashdeck-line, color-mix(in srgb, currentColor 25%, transparent));
15
+ --fd-surface: var(--flashdeck-surface, color-mix(in srgb, currentColor 4%, transparent));
16
+ --fd-accent: var(--flashdeck-accent, light-dark(#1d4ed8, #93c5fd));
17
+ --fd-accent-on: var(--flashdeck-accent-on, light-dark(#ffffff, #0b1220));
18
+ --fd-right: var(--flashdeck-right, light-dark(#166534, #86efac));
19
+ --fd-nearly: var(--flashdeck-nearly, light-dark(#854d0e, #fde047));
20
+ --fd-wrong: var(--flashdeck-wrong, light-dark(#b91c1c, #fca5a5));
21
+ /* The chart's marks: blue, grey and red, validated as distinguishable with each
22
+ kind of colour blindness, on light and dark pages. Text never uses them. */
23
+ --fd-bar-right: var(--flashdeck-bar-right, light-dark(#2a78d6, #3987e5));
24
+ --fd-bar-nearly: var(--flashdeck-bar-nearly, light-dark(#8f8d87, #b0aea8));
25
+ --fd-bar-wrong: var(--flashdeck-bar-wrong, light-dark(#e34948, #e66767));
26
+ --fd-page: var(--flashdeck-page, Canvas);
27
+ color: var(--fd-ink);
28
+ line-height: 1.5;
29
+ }
30
+
31
+ .flashdeck h1 { font-size: 1.75rem; font-weight: 700; line-height: 1.2; margin: 0 0 1rem; }
32
+ .flashdeck h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.3; margin: 1.5rem 0 0.5rem; }
33
+ .flashdeck p { margin: 0.5rem 0; }
34
+ .flashdeck a { color: var(--fd-accent); }
35
+
36
+ .flashdeck-topbar {
37
+ display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between;
38
+ gap: 0.25rem 1rem; margin-bottom: 1rem; font-size: 0.875rem; color: var(--fd-muted);
39
+ }
40
+ .flashdeck-crumbs { font-size: 0.875rem; color: var(--fd-muted); margin-bottom: 1rem; }
41
+ .flashdeck-topbar .flashdeck-crumbs { margin-bottom: 0; }
42
+ .flashdeck-crumbs a { color: inherit; }
43
+ .flashdeck-muted { color: var(--fd-muted); font-size: 0.875rem; }
44
+
45
+ .flashdeck-decks { list-style: none; padding: 0; margin: 0; }
46
+ .flashdeck-decks li { padding: 0.375rem 0; border-top: 1px solid var(--fd-line); }
47
+ .flashdeck-due {
48
+ display: inline-block; margin-left: 0.5rem; padding: 0 0.5rem; border-radius: 999px;
49
+ font-size: 0.8125rem; font-weight: 600; vertical-align: middle;
50
+ background: var(--fd-accent); color: var(--fd-accent-on);
51
+ }
52
+
53
+ .flashdeck-card {
54
+ padding: 1.25rem; border: 1px solid var(--fd-line); border-radius: 0.75rem;
55
+ background: var(--fd-surface);
56
+ }
57
+ .flashdeck-prompt { margin-bottom: 1rem; }
58
+ .flashdeck-prompt img {
59
+ display: block; max-width: 100%; height: auto; max-height: 60vh;
60
+ margin: 0 auto 0.75rem; border-radius: 0.5rem;
61
+ }
62
+ .flashdeck .flashdeck-prompt-text { font-size: 1.375rem; font-weight: 600; line-height: 1.35; margin: 0; }
63
+
64
+ /* Answer boxes, each with its label (such as a pronoun) to the left. */
65
+ .flashdeck-row { display: flex; align-items: center; gap: 0.75rem; margin: 0.5rem 0; }
66
+ .flashdeck-row label,
67
+ .flashdeck-label { flex: 0 0 7.5rem; text-align: right; color: var(--fd-muted); }
68
+ .flashdeck-row input {
69
+ flex: 1; min-width: 0; padding: 0.5rem 0.625rem;
70
+ font: inherit; font-size: max(1rem, 16px); /* 16px or more stops phones zooming in */
71
+ color: inherit; background: var(--flashdeck-input, transparent);
72
+ border: 1px solid var(--fd-line); border-radius: 0.375rem;
73
+ }
74
+ .flashdeck-row input:focus { outline: 2px solid var(--fd-accent); outline-offset: 1px; }
75
+
76
+ .flashdeck-characters { display: flex; flex-wrap: wrap; gap: 0.375rem; margin: 0.75rem 0; }
77
+ .flashdeck-characters button {
78
+ min-width: 2.5rem; min-height: 2.5rem; font: inherit; color: inherit; cursor: pointer;
79
+ background: transparent; border: 1px solid var(--fd-line); border-radius: 0.375rem;
80
+ }
81
+
82
+ .flashdeck-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-top: 1rem; }
83
+ .flashdeck-primary,
84
+ .flashdeck-button {
85
+ display: inline-block; padding: 0.5rem 1.25rem; border-radius: 0.375rem;
86
+ font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
87
+ }
88
+ .flashdeck .flashdeck-primary { background: var(--fd-accent); color: var(--fd-accent-on); border: 1px solid var(--fd-accent); }
89
+ .flashdeck .flashdeck-button { background: transparent; color: var(--fd-accent); border: 1px solid var(--fd-line); }
90
+ .flashdeck-primary:focus-visible,
91
+ .flashdeck-button:focus-visible,
92
+ .flashdeck-claim:focus-visible { outline: 2px solid var(--fd-accent); outline-offset: 2px; }
93
+
94
+ /* Results. */
95
+ .flashdeck-verdict { font-size: 1.25rem; font-weight: 700; margin: 0.5rem 0 0.75rem; }
96
+ .flashdeck-verdict.flashdeck-right,
97
+ .flashdeck-verdict.flashdeck-claimed { color: var(--fd-right); }
98
+ .flashdeck-verdict.flashdeck-nearly { color: var(--fd-nearly); }
99
+ .flashdeck-verdict.flashdeck-wrong { color: var(--fd-wrong); }
100
+ .flashdeck-results { list-style: none; padding: 0; margin: 0; }
101
+ .flashdeck-result {
102
+ display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.75rem;
103
+ padding: 0.375rem 0; border-top: 1px solid var(--fd-line);
104
+ }
105
+ .flashdeck-mark { font-weight: 700; }
106
+ .flashdeck-right .flashdeck-mark,
107
+ .flashdeck-claimed .flashdeck-mark { color: var(--fd-right); }
108
+ .flashdeck-nearly .flashdeck-mark { color: var(--fd-nearly); }
109
+ .flashdeck-wrong .flashdeck-mark { color: var(--fd-wrong); }
110
+ .flashdeck-wrong .flashdeck-given { text-decoration: line-through; text-decoration-color: var(--fd-wrong); }
111
+ .flashdeck-expected { font-weight: 600; color: var(--fd-right); }
112
+ .flashdeck-claim {
113
+ margin-left: auto; padding: 0.125rem 0.625rem; font: inherit; font-size: 0.875rem;
114
+ color: var(--fd-accent); background: transparent; cursor: pointer;
115
+ border: 1px solid var(--fd-line); border-radius: 999px;
116
+ }
117
+ /* Card options: hiding a card, and how often it comes back. */
118
+ .flashdeck-options { margin-top: 1rem; font-size: 0.875rem; }
119
+ .flashdeck-options summary { cursor: pointer; color: var(--fd-muted); }
120
+ .flashdeck-choices { display: flex; flex-wrap: wrap; align-items: center; gap: 0.375rem; margin: 0.5rem 0; }
121
+ .flashdeck-choice {
122
+ padding: 0.125rem 0.625rem; font: inherit; font-size: 0.875rem;
123
+ color: var(--fd-accent); background: transparent; cursor: pointer;
124
+ border: 1px solid var(--fd-line); border-radius: 999px;
125
+ }
126
+ .flashdeck .flashdeck-choice[aria-pressed="true"] {
127
+ color: var(--fd-accent-on); background: var(--fd-accent); border-color: var(--fd-accent);
128
+ }
129
+ .flashdeck-choice:focus-visible,
130
+ .flashdeck-link:focus-visible { outline: 2px solid var(--fd-accent); outline-offset: 2px; }
131
+ .flashdeck-link {
132
+ padding: 0; font: inherit; color: var(--fd-accent); background: none; border: 0;
133
+ text-decoration: underline; cursor: pointer;
134
+ }
135
+ .flashdeck-minor { margin-top: 0.75rem; font-size: 0.875rem; text-align: right; }
136
+ .flashdeck-notice {
137
+ margin-bottom: 0.75rem; padding: 0.5rem 0.75rem; font-size: 0.875rem;
138
+ border: 1px solid var(--fd-line); border-radius: 0.5rem;
139
+ }
140
+ .flashdeck-account { margin-left: auto; }
141
+ .flashdeck-account form { display: inline; }
142
+ .flashdeck-setting { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; }
143
+ .flashdeck-setting form { margin: 0; }
144
+
145
+ .flashdeck-notes { margin-top: 1rem; padding-top: 0.5rem; border-top: 1px solid var(--fd-line); }
146
+ .flashdeck-credit { font-size: 0.8125rem; color: var(--fd-muted); }
147
+
148
+ .flashdeck-hidden {
149
+ position: absolute; width: 1px; height: 1px; overflow: hidden;
150
+ clip-path: inset(50%); white-space: nowrap;
151
+ }
152
+
153
+ @media (max-width: 30rem) {
154
+ .flashdeck-row label,
155
+ .flashdeck-label { flex-basis: 5.5rem; }
156
+ .flashdeck-card { padding: 1rem; }
157
+ }
158
+
159
+ /* Tables (the reference, the progress page and Markdown). */
160
+ .flashdeck table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
161
+ .flashdeck th,
162
+ .flashdeck td { padding: 0.375rem 0.5rem; text-align: left; vertical-align: top; border-top: 1px solid var(--fd-line); }
163
+ .flashdeck thead th { font-weight: 600; color: var(--fd-muted); border-top: 0; }
164
+ .flashdeck td { font-variant-numeric: tabular-nums; }
165
+ .flashdeck-scroll { overflow-x: auto; }
166
+ .flashdeck-prose { margin: 0.5rem 0 1rem; }
167
+ .flashdeck-prose table { width: auto; margin: 0.75rem 0; }
168
+ .flashdeck-prose ul, .flashdeck-prose ol { padding-left: 1.5rem; }
169
+ .flashdeck-prose ul { list-style: disc; }
170
+ .flashdeck-prose ol { list-style: decimal; }
171
+
172
+ /* Progress: three figures for today, the chart and its table. */
173
+ .flashdeck-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; list-style: none; padding: 0; margin: 0 0 1.5rem; }
174
+ .flashdeck-tiles li { padding: 0.75rem; border: 1px solid var(--fd-line); border-radius: 0.5rem; color: var(--fd-muted); font-size: 0.875rem; }
175
+ .flashdeck-tiles strong { display: block; font-size: 1.75rem; line-height: 1.2; color: var(--fd-ink); font-variant-numeric: tabular-nums; }
176
+ .flashdeck-chart { margin: 0 0 0.5rem; }
177
+ .flashdeck-chart figcaption { font-weight: 600; margin-bottom: 0.25rem; }
178
+ .flashdeck-legend { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; list-style: none; padding: 0; margin: 0 0 0.5rem; font-size: 0.875rem; color: var(--fd-muted); }
179
+ .flashdeck-legend li { display: flex; align-items: center; gap: 0.375rem; }
180
+ .flashdeck-swatch { display: inline-block; width: 0.75rem; height: 0.75rem; border-radius: 2px; }
181
+ .flashdeck-bar-right { background: var(--fd-bar-right); }
182
+ .flashdeck-bar-nearly { background: var(--fd-bar-nearly); }
183
+ .flashdeck-bar-wrong { background: var(--fd-bar-wrong); }
184
+ .flashdeck-plot { position: relative; height: 9rem; padding-top: 1.25rem; border-bottom: 1px solid var(--fd-line); }
185
+ .flashdeck-plot-max { position: absolute; top: 0; left: 0; font-size: 0.75rem; color: var(--fd-muted); }
186
+ .flashdeck-bars {
187
+ display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 2px;
188
+ height: 100%; margin: 0; padding: 0; list-style: none;
189
+ border-top: 1px dashed var(--fd-line); /* the busiest day */
190
+ }
191
+ .flashdeck-day { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; outline-offset: 1px; }
192
+ .flashdeck-day:focus-visible { outline: 2px solid var(--fd-accent); }
193
+ .flashdeck-stack { display: flex; flex-direction: column; gap: 2px; width: 70%; max-width: 24px; }
194
+ .flashdeck-stack > span { flex-basis: 0; min-height: 2px; }
195
+ .flashdeck-stack > span:first-child { border-radius: 4px 4px 0 0; }
196
+ .flashdeck-day:hover .flashdeck-stack,
197
+ .flashdeck-day:focus-visible .flashdeck-stack { filter: brightness(1.12); }
198
+ .flashdeck-plot-axis { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--fd-muted); margin-top: 0.25rem; }
199
+ .flashdeck-table-view { margin-bottom: 1.5rem; font-size: 0.875rem; }
200
+ .flashdeck-table-view summary { cursor: pointer; color: var(--fd-muted); }
201
+ .flashdeck-missed { padding-left: 1.5rem; }
202
+ .flashdeck-missed li { margin: 0.25rem 0; }
203
+ .flashdeck-today { margin-top: 0.75rem; }
204
+
205
+ /* The reference: search, the index, the forms of a card, and the dialog. */
206
+ .flashdeck-search { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin: 0.75rem 0; }
207
+ .flashdeck-search input {
208
+ flex: 1; min-width: 12rem; padding: 0.5rem 0.625rem; font: inherit; font-size: max(1rem, 16px);
209
+ color: inherit; background: var(--flashdeck-input, transparent);
210
+ border: 1px solid var(--fd-line); border-radius: 0.375rem;
211
+ }
212
+ .flashdeck-search input:focus { outline: 2px solid var(--fd-accent); outline-offset: 1px; }
213
+ .flashdeck-index { columns: 12rem; column-gap: 1.5rem; list-style: none; padding: 0; margin: 0; }
214
+ .flashdeck-index li { padding: 0.125rem 0; break-inside: avoid; }
215
+ .flashdeck-forms {
216
+ display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--flashdeck-rows, 1), auto);
217
+ grid-auto-columns: minmax(0, 1fr); gap: 0.125rem 1rem; list-style: none; padding: 0; margin: 0;
218
+ }
219
+ .flashdeck-reference-table th { width: 30%; font-weight: 600; }
220
+ .flashdeck-reference-table th a { color: inherit; }
221
+ .flashdeck-thumb { display: block; max-width: 6rem; max-height: 6rem; margin-bottom: 0.25rem; border-radius: 0.25rem; }
222
+ .flashdeck-section { margin-bottom: 1rem; }
223
+ .flashdeck-section h2 a { color: inherit; }
224
+ .flashdeck-dialog {
225
+ width: min(48rem, 100vw - 2rem); max-height: min(80vh, 48rem); padding: 0;
226
+ color: var(--fd-ink); background: var(--fd-page);
227
+ border: 1px solid var(--fd-line); border-radius: 0.75rem;
228
+ }
229
+ .flashdeck-dialog::backdrop { background: rgb(0 0 0 / 0.4); }
230
+ .flashdeck-dialog-bar {
231
+ position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 0.75rem;
232
+ padding: 0.5rem 1rem; background: var(--fd-page); border-bottom: 1px solid var(--fd-line);
233
+ }
234
+ .flashdeck-dialog-bar .flashdeck-muted { flex: 1; }
235
+ .flashdeck-dialog-body { padding: 0.5rem 1rem 1rem; overflow-y: auto; max-height: calc(min(80vh, 48rem) - 3.5rem); }
236
+ .flashdeck-dialog-body h1 { font-size: 1.375rem; }
237
+ @media (max-width: 40rem) {
238
+ .flashdeck-dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; border: 0; }
239
+ .flashdeck-dialog-body { max-height: calc(100dvh - 3.5rem); }
240
+ .flashdeck-tiles strong { font-size: 1.375rem; }
241
+ }