:root {
  color-scheme: light dark;
  /* A cool off-white page with white cards on it. Kept as components too, so a
     scrim can fade the same colour out. */
  --bg-rgb: 247 247 250;
  --bg: rgb(var(--bg-rgb));
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8a8a93;
  --faint: #b6b6c0;
  /* Indigo. The one saturated colour in the app, spent on the two grade
     buttons and nothing else. */
  --accent: #4c3fd6;
  --accent-pressed: #4134b8;
  --on-accent: #ffffff;
  /* Semantic, and separate from the accent: a miss is not an error and is not
     styled like one, but it is not the same as a pass either. */
  --miss: #b8412f;
  --hairline: rgba(0, 0, 0, 0.1);
  --border: rgba(0, 0, 0, 0.14);
  --chip-bg: #ffffff;
  --chip-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  --card-shadow: 0 1px 2px rgba(20, 20, 40, 0.06), 0 10px 30px -18px rgba(20, 20, 40, 0.4);

  --bar-h: 52px;
  /* One number for the grade bar's height, because the card's available space
     is the viewport minus this and the header. */
  --grade-h: 92px;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-rgb: 0 0 0;
    --bg: rgb(var(--bg-rgb));
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #93939c;
    --faint: #55555e;
    --accent: #7c6ffb;
    --accent-pressed: #6b5ef0;
    --on-accent: #ffffff;
    --miss: #ff7c66;
    --hairline: rgba(255, 255, 255, 0.12);
    --border: rgba(255, 255, 255, 0.16);
    --chip-bg: #2c2c2e;
    --chip-shadow: none;
    --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 12px 32px -18px rgba(0, 0, 0, 0.8);
  }
}

* {
  box-sizing: border-box;
}

/* An author `display` beats the UA stylesheet's `[hidden] { display: none }`
   whatever the specificity, so any element given a display here stops
   responding to the hidden attribute. Measured the hard way: .rv-done is a
   flex overlay across the whole card, and with it inert-but-visible every tap
   meant to reveal an answer landed on the end-of-session screen instead. */
[hidden] {
  display: none !important;
}

/* Nothing at document level ever scrolls: both views are position: fixed and
   carry their own scroller. */
html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.view {
  position: fixed;
  inset: 0;
  /* dvh, not vh. Safari's toolbar overlays the bottom of the viewport and
     changes height as you scroll; a grade bar positioned against 100vh sits
     underneath it. */
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --------------------------------------------------------------------------
   Home
   -------------------------------------------------------------------------- */

.view--home {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: max(env(safe-area-inset-top, 0px), 12px) 16px
           max(env(safe-area-inset-bottom, 0px), 12px);
}

.home-head {
  padding: 18px 4px 10px;
}

.home-title {
  margin: 0;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.home-build {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.decks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Two hit targets, not one with a mode inside it: the row body starts a
   review and the caret opens the deck. Siblings rather than nested buttons,
   which is invalid markup and untappable in practice. */
.deck-item {
  display: flex;
  gap: 6px;
}

.deck-open {
  flex: none;
  width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  touch-action: manipulation;
}

.deck-open:active {
  background: color-mix(in srgb, var(--card) 92%, var(--text));
}

.deck-open svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.deck-row {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  /* Removes the double-tap-to-zoom delay. Invisible until someone moves
     quickly, and then it is the whole experience. */
  touch-action: manipulation;
}

.deck-row:disabled {
  cursor: default;
  opacity: 0.55;
}

.deck-row:not(:disabled):active {
  background: color-mix(in srgb, var(--card) 92%, var(--text));
}

.deck-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.deck-name {
  font-size: 17px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-sub {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.deck-badge {
  flex: none;
  min-width: 30px;
  height: 26px;
  padding: 0 9px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  justify-content: center;
}

.deck-badge--empty {
  background: transparent;
}

.deck-item--all {
  margin-top: 10px;
}

.new-deck {
  width: 100%;
  margin-top: 8px;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font: inherit;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}

.new-deck svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.deck-row--all {
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  background: transparent;
  border-style: dashed;
  border-color: var(--border);
}

.home-note {
  margin: 14px 4px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--miss);
}

.home-foot {
  margin-top: auto;
  padding: 22px 4px 8px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.home-account {
  margin: 0;
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--muted);
}

.sync-btn {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--chip-bg);
  box-shadow: var(--chip-shadow);
  color: inherit;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.sync-btn:disabled {
  opacity: 0.5;
}

/* --------------------------------------------------------------------------
   Review
   --------------------------------------------------------------------------
   Parked off the window rather than merely translated, so a closed review
   screen is not sitting in the gutter in full view on a wide display. */

.view--review {
  background: var(--bg);
  transform: translateX(100vw);
  visibility: hidden;
  transition: transform 220ms ease, visibility 0s linear 220ms;
  /* Nothing in the review screen is text you select; a fast tap on the card
     should not start a selection. */
  user-select: none;
  -webkit-user-select: none;
}

.view--review.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 220ms ease, visibility 0s;
}

@media (prefers-reduced-motion: reduce) {
  .view--review {
    transition: none;
  }
}

.rv-bar {
  flex: none;
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: center;
  gap: 10px;
  height: calc(var(--bar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 12px 0;
}

.chip {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 17px;
  background: var(--chip-bg);
  box-shadow: var(--chip-shadow);
  color: var(--text);
  cursor: pointer;
  touch-action: manipulation;
}

.chip:disabled {
  opacity: 0.35;
  cursor: default;
}

.chip svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rv-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.rv-deck {
  font-size: 15px;
  font-weight: 600;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rv-counts {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.rv-body {
  flex: 1;
  min-height: 0;
  position: relative;
  padding: 6px 16px 0;
}

.rv-stack {
  position: relative;
  height: 100%;
}

/* The two cards behind. Insets rather than transforms so they cannot be
   dragged out of alignment by the live card's leave animation. */
.rv-behind {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -7px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--hairline);
}

.rv-behind--2 {
  left: 16px;
  right: 16px;
  bottom: -13px;
}

.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 20px 20px 12px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--hairline);
  box-shadow: var(--card-shadow);
  cursor: pointer;
  touch-action: manipulation;
  overflow: hidden;
}

.card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card.is-leaving {
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 130ms ease, transform 130ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .card.is-leaving {
    transition: none;
  }
}

.card-image-wrap {
  flex: none;
  margin-bottom: 14px;
}

.card-image {
  display: block;
  width: 132px;
  height: 88px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.card-q {
  flex: none;
  font-size: 21px;
  line-height: 1.35;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: pre-wrap;
}

/* The rule is the whole flip animation this app has. Above it is what was
   asked; below it is what the answer turned out to be, and both stay on
   screen so one can be checked against the other. */
.card-a {
  position: relative;
  flex: 1;
  min-height: 0;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
  overflow: hidden;
}

.card-answer {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 18px;
  line-height: 1.5;
  white-space: pre-wrap;
  opacity: 0;
  /* Not display:none. The answer occupies its space from the start, so
     revealing it cannot resize the card or move the buttons. */
  visibility: hidden;
}

.card.is-revealed .card-answer {
  opacity: 1;
  visibility: visible;
}

/* Tiled across the answer region until the answer arrives. It fills the dead
   space every review screen has between the prompt and the buttons, removes a
   target to aim at, and teaches the gesture without a tooltip. */
.card-veil {
  position: absolute;
  inset: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 7px;
  overflow: hidden;
  font-size: 15px;
  color: var(--faint);
  /* Fades out downwards so the tiling reads as texture rather than as a wall
     of repeated text. */
  -webkit-mask-image: linear-gradient(#000 0%, #000 22%, transparent 92%);
  mask-image: linear-gradient(#000 0%, #000 22%, transparent 92%);
  pointer-events: none;
  transition: opacity 100ms ease;
}

.card.is-revealed .card-veil {
  opacity: 0;
}

/* nowrap and allowed to run past both edges -- the clipping is what makes it
   read as a field of text rather than a list of instructions. */
.veil-row {
  flex: none;
  white-space: nowrap;
}

/* Where the card is, not when it is next due. Five stops, no dates. */
.card-track {
  flex: none;
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  gap: 4px;
  opacity: 0;
  transition: opacity 140ms ease;
}

.card.is-revealed .card-track {
  opacity: 1;
}

.track-stop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  position: relative;
}

.track-stop b {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--faint);
  white-space: nowrap;
}

.track-stop i {
  width: 7px;
  height: 7px;
  border-radius: 4px;
  background: var(--faint);
}

/* The connecting line, drawn from each stop to the next rather than as a
   separate element that would have to be positioned against them. */
.track-stop::after {
  content: "";
  position: absolute;
  left: 50%;
  right: -50%;
  bottom: 3px;
  height: 1px;
  background: var(--faint);
  opacity: 0.5;
}

.track-stop:last-child::after {
  display: none;
}

.track-stop.is-past i,
.track-stop.is-past b {
  color: var(--accent);
  background: var(--accent);
}

.track-stop.is-past b {
  background: none;
}

.track-stop.is-here b {
  color: var(--accent);
  font-weight: 700;
}

.track-stop.is-here i {
  background: var(--accent);
  width: 10px;
  height: 10px;
  border-radius: 5px;
  margin-bottom: -1.5px;
}

/* --------------------------------------------------------------------------
   Editing
   --------------------------------------------------------------------------
   Both editing views share the review screen's bar and slide in the same way.
   They scroll, which the review screen deliberately does not. */

.view--deck,
.view--card {
  background: var(--bg);
  transform: translateX(100vw);
  visibility: hidden;
  transition: transform 220ms ease, visibility 0s linear 220ms;
}

.view--deck.is-open,
.view--card.is-open {
  transform: translateX(0);
  visibility: visible;
  transition: transform 220ms ease, visibility 0s;
}

@media (prefers-reduced-motion: reduce) {
  .view--deck,
  .view--card {
    transition: none;
  }
}

.chip--danger {
  color: var(--miss);
}

/* Armed by the first tap, fired by the second. A destructive action behind a
   single tap on a phone is a destructive action taken by accident. */
.chip--danger.is-armed {
  background: var(--miss);
  color: #ffffff;
}

.edit-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 16px max(env(safe-area-inset-bottom, 0px), 20px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-input {
  width: 100%;
  padding: 11px 13px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  color: var(--text);
  font: inherit;
  font-size: 16px;   /* 16px or iOS zooms the page on focus */
  line-height: 1.45;
}

.field-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.field-area {
  resize: vertical;
  min-height: 76px;
  white-space: pre-wrap;
}

.field-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  min-height: 20px;
}

.edit-preview {
  align-self: flex-start;
  max-width: 160px;
  max-height: 110px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.list-head {
  margin: 4px 0 -8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.cardlist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cardlist-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  background: var(--card);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.cardlist-row:active {
  background: color-mix(in srgb, var(--card) 92%, var(--text));
}

.cardlist-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cardlist-front,
.cardlist-back {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cardlist-front {
  font-size: 15px;
  font-weight: 500;
}

.cardlist-back {
  font-size: 13px;
  color: var(--muted);
}

/* Where the card stands with the scheduler, so the list is also an answer to
   "why have I not seen this one". */
.cardlist-state {
  flex: none;
  font-size: 11px;
  letter-spacing: 0.03em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.cardlist-thumb {
  flex: none;
  width: 34px;
  height: 24px;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.cardlist-empty {
  padding: 14px 2px;
  font-size: 14px;
  color: var(--muted);
}

.add-btn {
  width: 100%;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.add-btn svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}

/* --------------------------------------------------------------------------
   Grading
   -------------------------------------------------------------------------- */

.rv-grade {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  /* A real gap, not two buttons sharing an invisible edge. The full-width
     four-button strips in the teardown all put their targets flush against
     each other, which is exactly where a mis-tap comes from. */
  gap: 10px;
  padding: 16px 16px max(env(safe-area-inset-bottom, 0px), 16px);
}

.grade {
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 10px 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 120ms ease, background-color 120ms ease;
}

/* Present, sized and positioned before the reveal -- just not usable. The
   layout never shifts when the answer lands. */
.grade:disabled {
  cursor: default;
  opacity: 0.28;
}

.grade:not(:disabled):active {
  background: var(--accent-pressed);
}

.grade--fail {
  background: color-mix(in srgb, var(--accent) 14%, var(--card));
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 26%, transparent);
}

.grade--fail:not(:disabled):active {
  background: color-mix(in srgb, var(--accent) 24%, var(--card));
}

.grade-top {
  display: flex;
  align-items: center;
  gap: 7px;
}

.grade-icon {
  width: 17px;
  height: 17px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.grade-label {
  font-size: 15px;
  font-weight: 600;
}

/* "Back in 10 minutes", not "<10m". Empty until the reveal prices both
   outcomes, so the button carries no promise it has not yet computed. */
.grade-when {
  font-size: 11.5px;
  opacity: 0.82;
  font-variant-numeric: tabular-nums;
  min-height: 14px;
}

/* --------------------------------------------------------------------------
   End of session
   -------------------------------------------------------------------------- */

.rv-done {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 24px;
  background: var(--bg);
  text-align: center;
}

.rv-done-text {
  margin: 0;
  font-size: 19px;
  font-weight: 500;
  line-height: 1.45;
  max-width: 22ch;
}

.rv-done-btn {
  padding: 11px 28px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

/* The laptop. The app keeps its shape and takes the middle of the screen: a
   card is one column of text, and at 1440px that column was 1400px of empty. */
@media (min-width: 720px) {
  .view {
    left: 50%;
    right: auto;
    width: 620px;
    transform: translateX(-50%);
    border-left: 1px solid var(--hairline);
    border-right: 1px solid var(--hairline);
  }

  .view--review,
  .view--deck,
  .view--card {
    transform: translateX(calc(-50% + 100vw));
  }

  .view--review.is-open,
  .view--deck.is-open,
  .view--card.is-open {
    transform: translateX(-50%);
  }
}
