/* ---------- Tokens: Dark Dashboard ---------- */

:root {
  --bg: #090d18;
  --surface: #10162a;
  --surface-2: #0c1122;
  --ink: #eef2ff;
  --mute: #a4adc8;
  --tint: 255, 255, 255;
  --line: rgba(var(--tint), 0.08);
  --accent: #3fe6cc;
  --accent-ink: #04130f;
  --radius: 18px;
  --head: 'Inter', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
  --page-bg:
    radial-gradient(1200px 600px at 10% -10%, #17224f 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #2a1850 0%, transparent 60%),
    #060911;
  --ok-ink: #5fd38d;
  --bad-ink: #ff8a8e;

  --red: #ff7a90;
  --blue: #4cc9f0;
  --teal: #3fe6cc;
  --gold: #ffd166;
  --violet: #b08cff;

  /* Confidence ratings 1 to 5 */
  --r1: #e5484d;
  --r2: #f08c28;
  --r3: #e9b913;
  --r4: #7cc242;
  --r5: #2fa35a;

  --step-0: clamp(1rem, 0.96rem + 0.2vw, 1.1rem);
  --step-1: clamp(1.15rem, 1.05rem + 0.5vw, 1.4rem);
  --step-2: clamp(1.5rem, 1.3rem + 1vw, 2.1rem);
  --step-3: clamp(1.9rem, 1.5rem + 2vw, 2.9rem);

  color-scheme: dark;
}

/* ---------- Tokens: Light ----------
   Picked in Settings. "system" follows the device, so the same values sit under a media query. */

:root[data-theme='light'] {
  --bg: #f5f7fc;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --ink: #141a2e;
  --mute: #5a6380;
  --tint: 20, 28, 52;
  --accent: #0b8574;
  --accent-ink: #ffffff;
  --shadow: 0 20px 50px rgba(20, 28, 52, 0.1);
  --page-bg:
    radial-gradient(1200px 600px at 10% -10%, #e3e9ff 0%, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #efe6ff 0%, transparent 60%),
    #f5f7fc;
  --teal: #12a892;
  --ok-ink: #1d7f45;
  --bad-ink: #c4343a;
  color-scheme: light;
}

@media (prefers-color-scheme: light) {
  :root[data-theme='system'] {
    --bg: #f5f7fc;
    --surface: #ffffff;
    --surface-2: #f0f3f9;
    --ink: #141a2e;
    --mute: #5a6380;
    --tint: 20, 28, 52;
    --accent: #0b8574;
    --accent-ink: #ffffff;
    --shadow: 0 20px 50px rgba(20, 28, 52, 0.1);
    --page-bg:
      radial-gradient(1200px 600px at 10% -10%, #e3e9ff 0%, transparent 60%),
      radial-gradient(900px 500px at 110% 110%, #efe6ff 0%, transparent 60%),
      #f5f7fc;
    --teal: #12a892;
    --ok-ink: #1d7f45;
    --bad-ink: #c4343a;
    color-scheme: light;
  }
}

/* ---------- Base ---------- */

/* Components set display: grid or flex, which would otherwise beat the hidden attribute. */
[hidden] {
  display: none !important;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--ink);
  font: 400 var(--step-0) / 1.6 var(--body);
  letter-spacing: 0.02em;
  word-spacing: 0.05em;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3 {
  font-family: var(--head);
  line-height: 1.4;
  letter-spacing: 0.02em;
  margin: 0;
}

a {
  color: var(--accent);
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

input:not([type='checkbox']):not([type='file']),
textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
}

input[type='checkbox'] {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--accent);
}

kbd {
  font: 500 0.7em var(--body);
  padding: 0.1em 0.45em;
  border: 1px solid currentColor;
  border-radius: 5px;
  opacity: 0.6;
  margin-left: 0.4em;
}

.mute {
  color: var(--mute);
}

.error {
  color: var(--r1);
  font-size: 0.9em;
}

.error ul {
  margin: 0;
  padding-left: 1.1em;
}

/* ---------- Shell ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem max(16px, calc((100vw - 1160px) / 2));
  border-bottom: 1px solid var(--line);
}

.brand {
  font: 700 var(--step-1) var(--head);
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.015em;
}

.brand span {
  color: var(--accent);
}

a.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.brand .word {
  color: var(--ink);
}

.brand .word span {
  color: var(--accent);
}

a.brand img {
  width: 2.1em;
  height: auto;
}

.lockup {
  text-decoration: none;
  display: grid;
  justify-items: center;
  gap: 0.25rem;
}

.lockup img {
  width: 132px;
  height: auto;
  margin-bottom: 0.5rem;
}

.tagline {
  margin: 0;
  color: var(--mute);
  font-weight: 500;
  font-size: var(--step-1);
}

.brand.big {
  font-size: var(--step-3);
}

.nav {
  display: flex;
  gap: 0.25rem;
  margin-right: auto;
  margin-left: 1.5rem;
}

.nav a {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  color: var(--mute);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92em;
}

.nav a:hover {
  color: var(--ink);
}

.nav a[aria-current='page'] {
  background: rgba(63, 230, 204, 0.12);
  color: var(--accent);
}

@media (max-width: 560px) {
  .who {
    display: none;
  }

  .nav {
    margin-left: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
  }
}

.top-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 0;
}

.who {
  color: var(--mute);
  font-size: 0.9em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page {
  max-width: 1160px;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.5rem) 16px 4rem;
}

/* ---------- Pieces ---------- */

.panel {
  --hue: var(--accent);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  list-style: none;
}

.btn::-webkit-details-marker {
  display: none;
}

.btn:hover {
  border-color: rgba(var(--tint), 0.25);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.danger {
  color: var(--r1);
}

.btn.primary.danger,
form .btn.danger[type='submit'] {
  background: var(--r1);
  border-color: var(--r1);
  color: #fff;
}

.btn.big {
  padding: 0.8rem 1.5rem;
  font-size: var(--step-1);
}

.btn.small {
  padding: 0.3rem 0.8rem;
  font-size: 0.85em;
}

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.chip {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  background: rgba(63, 230, 204, 0.12);
  color: var(--accent);
  font-size: 0.8em;
  font-weight: 600;
}

.crumb {
  display: inline-block;
  color: var(--mute);
  text-decoration: none;
  margin-bottom: 0.4rem;
}

.crumb:hover {
  color: var(--ink);
}

.title {
  font-size: var(--step-3);
  letter-spacing: 0.015em;
}

.notice {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: rgba(63, 230, 204, 0.1);
  border: 1px solid rgba(63, 230, 204, 0.3);
}

.notice.is-error {
  background: rgba(229, 72, 77, 0.1);
  border-color: rgba(229, 72, 77, 0.4);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.dot {
  display: inline-block;
  flex: none;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 50%;
  background: rgba(var(--tint), 0.14);
}

.r1 { background: var(--r1); }
.r2 { background: var(--r2); }
.r3 { background: var(--r3); }
.r4 { background: var(--r4); }
.r5 { background: var(--r5); }

/* Mastery bar: one segment per rating, sized by card count */
.mbar {
  display: flex;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  gap: 2px;
  background: rgba(var(--tint), 0.06);
}

.mbar-empty {
  background: rgba(var(--tint), 0.1);
}

/* ---------- Dashboard ---------- */

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem 2rem;
  margin-bottom: 1.5rem;
}

.hero p {
  margin: 0.4rem 0 0;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  border-top: 3px solid var(--hue);
}

.stat.wide {
  grid-column: span 2;
}

@media (max-width: 520px) {
  .stat.wide {
    grid-column: 1 / -1;
  }
}

.stat-label {
  color: var(--mute);
  font-size: 0.8em;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  font: 700 var(--step-2) var(--head);
}

.stat-value small {
  font: 500 0.45em var(--body);
  color: var(--mute);
}

.dashboard-activity {
  margin-bottom: 2rem;
}

.activity {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  margin-bottom: 2rem;
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(28, 1fr);
  gap: 4px;
  flex: 1 1 320px;
}

.activity-grid span {
  aspect-ratio: 1;
  max-height: 22px;
  border-radius: 4px;
  background: rgba(var(--tint), 0.07);
}

.activity-grid span.on {
  background: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.toolbar h2 {
  font-size: var(--step-2);
}

.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Small forms that open in place, no script needed */
.pop {
  position: relative;
}

.pop-body {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  z-index: 10;
  width: min(340px, calc(100vw - 32px));
  display: grid;
  gap: 0.75rem;
}

.pop-body p {
  margin: 0;
  font-size: 0.9em;
}

.decks {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.deck {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  border-top: 3px solid var(--hue);
}

.deck:nth-child(8n + 1) { --hue: var(--blue); }
.deck:nth-child(8n + 2) { --hue: var(--teal); }
.deck:nth-child(8n + 3) { --hue: var(--violet); }
.deck:nth-child(8n + 4) { --hue: var(--gold); }
.deck:nth-child(8n + 5) { --hue: var(--red); }
.deck:nth-child(8n + 6) { --hue: #7cc242; }
.deck:nth-child(8n + 7) { --hue: #f08c28; }
.deck:nth-child(8n + 8) { --hue: #5ea2ff; }

.deck:has(input:checked) {
  outline: 2px solid var(--hue);
}

.deck-head {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.deck-name {
  font: 600 var(--step-1) var(--head);
  color: var(--ink);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.deck-name:hover {
  color: var(--hue);
}

.deck-progress {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
}

.deck-pct {
  font: 700 var(--step-2) var(--head);
}

.deck-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: auto;
}

.due {
  color: var(--red);
}

/* "Study selected" only shows once a deck is ticked */
.selected-bar {
  display: none;
  position: sticky;
  bottom: 1rem;
  justify-content: center;
  margin-top: 1rem;
}

.page:has(.deck input:checked) .selected-bar {
  display: flex;
}

.collection {
  display: grid;
  gap: 1rem;
  margin-bottom: 2.5rem;
  scroll-margin-top: 1rem;
}

.collection-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line);
}

.collection-title {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.collection-title h2 {
  font-size: var(--step-2);
  overflow-wrap: anywhere;
}

/* Collections collapse to their header. dashboard.js remembers which ones are open. */
.collection-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.collection-toggle svg {
  flex: none;
  width: 0.8em;
  height: 0.8em;
  fill: none;
  stroke: var(--mute);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform 0.15s;
}

.collection-toggle[aria-expanded='true'] svg {
  transform: rotate(90deg);
}

.collection-toggle:hover svg {
  stroke: var(--ink);
}

.collection.is-closed {
  gap: 0.6rem;
  margin-bottom: 1.25rem;
}

/* Recently studied, above everything else */
.recent {
  display: grid;
  gap: 1rem;
  margin-bottom: 2rem;
}

.recent h2 {
  font-size: var(--step-1);
}

.deck-collection {
  margin-top: -0.4rem;
  font-size: 0.88em;
}

.deck-search {
  width: min(320px, 100%);
}

.deck-search-empty {
  margin: 0 0 2rem;
}

.pop-body form {
  display: grid;
  gap: 0.6rem;
}

.pop-body form.row {
  display: flex;
  flex-wrap: nowrap;
}

/* ---------- Deck page ---------- */

.deck-summary {
  display: grid;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
}

.card-form {
  display: grid;
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.card-form label,
.form label {
  display: grid;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.9em;
}

.card-form .btn[type='submit'] {
  justify-self: start;
}

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
}

.card-row {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 0.9rem 1.1rem;
  box-shadow: none;
}

.card-row .dot {
  margin-top: 0.45rem;
}

.card-text {
  flex: 1;
  min-width: 0;
}

.card-text > * {
  margin: 0;
  overflow-wrap: anywhere;
}

.card-text .q {
  font-weight: 400;
}

.card-text .a {
  color: var(--mute);
  margin-top: 0.25rem;
}

.delete-card {
  margin-top: 1rem;
}

/* ---------- Study ---------- */

.study {
  max-width: 760px;
  margin: 0 auto;
}

.study-top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.study-top .crumb {
  margin: 0;
}

.round {
  display: flex;
  gap: 6px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.round li {
  width: clamp(14px, 4vw, 22px);
  height: 8px;
  border-radius: 999px;
  background: rgba(var(--tint), 0.1);
}

.round li.current {
  background: rgba(var(--tint), 0.4);
}

.round li.r1 { background: var(--r1); }
.round li.r2 { background: var(--r2); }
.round li.r3 { background: var(--r3); }
.round li.r4 { background: var(--r4); }
.round li.r5 { background: var(--r5); }

.round.big {
  flex-wrap: wrap;
}

.round.big li {
  width: 28px;
  height: 12px;
}

/* Timed study: countdown in place of the round dots, and the rounds or timer toggle */
/* LeetCode style: one pill with the clock, pause or play, and reset */
.study-timer {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.2rem 0.3rem 0.2rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.study-timer svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.study-timer-icon {
  color: var(--mute);
}

.study-clock {
  min-width: 3.4em;
  padding: 0 0.4rem;
  font: 600 1rem / 1.4 var(--head);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.study-timer-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--mute);
}

.study-timer-btn:hover {
  background: rgba(var(--tint), 0.08);
  color: var(--ink);
}

.study-timer-btn path[d^='M8 5'] {
  fill: currentColor;
}

.study-timer.is-paused .study-clock {
  color: var(--mute);
}

.study-timer.is-paused {
  border-color: var(--accent);
}

.study-timer.is-up .study-clock {
  color: var(--r4);
}

.study-count {
  margin-right: auto;
}

.study-mode {
  display: inline-flex;
  gap: 0.2rem;
  padding: 0.2rem;
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.study-mode button {
  border: 0;
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  background: transparent;
  color: var(--mute);
  font: 500 0.85rem var(--body);
  cursor: pointer;
}

/* Settings, laid out like GitHub's: a titled section per topic, one row per setting */
.settings {
  display: grid;
  gap: 2rem;
  max-width: 760px;
}

.settings-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.feedback-message {
  display: grid;
  gap: 0.5rem;
  padding: 1.1rem 0 0;
}

.feedback-message textarea {
  width: 100%;
  resize: vertical;
}

.feedback-send {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  font-size: 0.92em;
}

.settings-status {
  color: var(--accent);
  font-size: 0.92em;
  font-weight: 500;
}

.settings-note {
  margin: -1.5rem 0 0;
  font-size: 0.92em;
}

.settings-section h2 {
  font-size: var(--step-1);
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}

.settings-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 2rem;
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--line);
}

.settings-text {
  flex: 1 1 280px;
}

.settings-name {
  font-weight: 600;
}

.settings-text p {
  margin: 0.2rem 0 0;
  font-size: 0.9em;
}

.settings-minutes {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.settings-minutes input {
  width: 5.5rem;
}

.settings-row[data-off='true' i] {
  opacity: 0.45;
}

.settings-minutes input:disabled {
  cursor: not-allowed;
}

.settings > .btn {
  justify-self: start;
}

/* Segmented toggle built on radio buttons, so it still posts and works with the keyboard */
.seg {
  display: inline-flex;
  padding: 0.2rem;
  gap: 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg label {
  padding: 0.4rem 1rem;
  border-radius: 999px;
  color: var(--mute);
  font-weight: 500;
  font-size: 0.92em;
  white-space: nowrap;
  cursor: pointer;
}

.seg input:checked + label {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.seg input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.study-mode button[aria-pressed='true'] {
  background: var(--surface-2);
  color: var(--ink);
}

.flashcard {
  display: grid;
  gap: 1.25rem;
  padding: clamp(1.25rem, 4vw, 2.25rem);
}

.flashcard-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9em;
}

.flashcard-head .dot {
  vertical-align: -0.05em;
}

.flashcard-q {
  margin: 0;
  font: 400 var(--step-2) / 1.5 var(--head);
  overflow-wrap: anywhere;
}

.flashcard-a {
  margin: 0 0 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  font-size: var(--step-1);
  overflow-wrap: anywhere;
}

.reveal > summary {
  list-style: none;
  width: 100%;
}

.reveal > summary::-webkit-details-marker {
  display: none;
}

/* Open, the big Show answer button shrinks to a quiet Hide answer that flips back to the question. */
.reveal[open] > summary {
  width: auto;
  justify-self: start;
  margin-bottom: 1rem;
  padding: 0.35rem 0.9rem;
  font-size: 0.85em;
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--mute);
}

.reveal > summary .when-open,
.reveal[open] > summary .when-closed {
  display: none;
}

.reveal[open] > summary .when-open {
  display: inline;
}

.reveal {
  display: grid;
}

.rate {
  display: grid;
  gap: 0.6rem;
}

.rate-label {
  color: var(--mute);
  font-size: 0.9em;
  text-align: center;
}

.rate-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.rate-btn {
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  padding: 0.8rem 0.3rem;
  border: 2px solid transparent;
  border-radius: 14px;
  background: var(--surface-2);
  cursor: pointer;
  border-bottom: 4px solid;
}

.rate-btn.r1 { border-bottom-color: var(--r1); }
.rate-btn.r2 { border-bottom-color: var(--r2); }
.rate-btn.r3 { border-bottom-color: var(--r3); }
.rate-btn.r4 { border-bottom-color: var(--r4); }
.rate-btn.r5 { border-bottom-color: var(--r5); }

.rate-btn:hover,
.rate-btn.is-on {
  background: rgba(var(--tint), 0.08);
}

.rate-n {
  font: 700 var(--step-1) var(--head);
}

.rate-t {
  font-size: 0.75em;
  color: var(--mute);
  text-align: center;
  line-height: 1.4;
}

.checkpoint {
  max-width: 560px;
  margin: 0 auto;
  display: grid;
  gap: 1.1rem;
  padding: clamp(1.25rem, 4vw, 2.25rem);
}

.tally {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.25rem;
}

.empty {
  max-width: 560px;
  margin: 2rem auto;
  display: grid;
  gap: 0.75rem;
  justify-items: start;
}

.empty p {
  margin: 0;
}

/* ---------- Sign in ---------- */

.signin {
  max-width: 420px;
  margin: 0 auto;
  padding: clamp(2rem, 8vh, 5rem) 16px;
  text-align: center;
}

.form {
  display: grid;
  gap: 1rem;
  text-align: left;
  margin-top: 1.5rem;
}

.form h1 {
  font-size: var(--step-2);
}

.form label.inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
}

.form .link {
  justify-self: center;
}

select {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}

label.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9em;
  font-weight: 600;
}

/* ---------- Rich card text ---------- */

.field {
  display: grid;
  gap: 0.35rem;
}

.field > span {
  font-size: 0.9em;
  font-weight: 600;
}

.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }

.rich p,
.rich ul,
.rich ol,
.rich pre,
.rich blockquote,
.rich table {
  margin: 0 0 0.6em;
}

.rich ul,
.rich ol {
  padding-left: 1.4em;
}

.rich h3,
.rich h4 {
  margin: 0.6em 0 0.3em;
}

.rich blockquote {
  padding-left: 0.9em;
  border-left: 3px solid var(--accent);
  color: var(--mute);
}

.rich pre,
.rich code,
.jodit-wysiwyg pre,
.jodit-wysiwyg code {
  font-family: 'JetBrains Mono', ui-monospace, Consolas, monospace !important;
  font-size: 0.88em;
  letter-spacing: 0;
  word-spacing: 0;
}

.rich :not(pre) > code,
.jodit-wysiwyg :not(pre) > code {
  padding: 0.1em 0.35em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
}

.jodit-wysiwyg pre {
  margin: 0 0 0.6em;
  padding: 0.8em 1em;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
}

.rich pre {
  padding: 0.8em 1em;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow-x: auto;
  white-space: pre;
}

.rich table {
  border-collapse: collapse;
  width: auto !important;
  max-width: 100%;
  display: block;
  overflow-x: auto;
  font-size: 0.9em;
}

.rich th,
.rich td {
  border: 1px solid rgba(var(--tint), 0.18);
  padding: 0.4em 0.7em;
  text-align: left;
  vertical-align: top;
}

.rich th,
.rich tr:first-child td {
  background: rgba(var(--tint), 0.05);
  font-weight: 600;
}

.rich a {
  color: var(--accent);
}

/* The question is a heading in study, so keep its rich content from getting huge */
.flashcard-q.rich :is(h3, h4) {
  font-size: 1em;
}

.flashcard-q.rich :is(table, ul, ol) {
  font: 400 var(--step-0) / 1.5 var(--body);
}

.flashcard-q.rich pre {
  font-size: var(--step-0);
  line-height: 1.5;
}

.card-text .rich {
  white-space: normal;
}

.card-text .a.rich {
  max-height: 9em;
  overflow: hidden;
}

/* Jodit, tuned to the dark dashboard */
.jodit-container.jodit {
  border-color: var(--line) !important;
  border-radius: 10px !important;
  background: var(--surface-2) !important;
}

.jodit-container.jodit .jodit-workplace,
.jodit-container.jodit .jodit-wysiwyg {
  background: var(--surface-2) !important;
  color: var(--ink) !important;
  font: 400 var(--step-0) / 1.5 var(--body) !important;
  letter-spacing: 0.02em !important;
}

.jodit-container.jodit .jodit-toolbar__box {
  background: var(--surface) !important;
  border-color: var(--line) !important;
}

.jodit-container.is-invalid {
  border-color: var(--r1) !important;
}

a.stat-label {
  text-decoration: none;
}

a.stat-label:hover {
  color: var(--ink);
}

/* ---------- Insights ---------- */

.insights {
  display: grid;
  gap: 1.25rem;
}

.chart-panel {
  display: grid;
  gap: 0.9rem;
  min-width: 0;
}

.chart-head h2 {
  font-size: var(--step-1);
}

.chart-head p {
  margin: 0.25rem 0 0;
  font-size: 0.9em;
}

.chart {
  width: 100%;
}

.chart-curves { height: 340px; }
.chart-map { height: clamp(420px, 70vh, 680px); }
.chart-tree { height: 380px; }
.chart-calendar { height: 150px; min-width: 760px; }
.chart-clock { height: 260px; min-width: 620px; }

/* Wide charts scroll sideways on a phone instead of squashing */
.chart-scroll {
  overflow-x: auto;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 1rem;
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 0.85em;
  color: var(--mute);
}

.top .link {
  white-space: nowrap;
}

/* ---------- Billing ---------- */

.plan-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem 2rem;
  margin-bottom: 2rem;
  border-top: 3px solid var(--teal);
}

.plan-card.is-warning {
  border-top-color: var(--r2);
}

.plan-main h2 {
  font-size: var(--step-2);
  margin: 0.3rem 0;
}

.plan-main h2 .mute {
  font: 500 var(--step-0) var(--body);
}

.plan-status {
  margin: 0;
}

.plan-card.is-warning .plan-status {
  color: var(--r2);
  font-weight: 600;
}

.plan-facts {
  margin: 0;
  display: grid;
  gap: 0.6rem;
  align-content: start;
}

.plan-facts dt {
  color: var(--mute);
  font-size: 0.8em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.plan-facts dd {
  margin: 0;
  font-weight: 600;
}

.plan-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
}

@media (max-width: 560px) {
  .plan-card {
    grid-template-columns: 1fr;
  }
}

.plan-cancel {
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
  font-size: 0.92em;
}

.plan-cancel .link {
  color: var(--mute);
}

/* Cancelling, two steps */
.cancel-flow {
  display: grid;
  gap: 1rem;
  max-width: 640px;
}

.cancel-flow h1 {
  font-size: var(--step-2);
}

.cancel-flow h2 {
  font-size: var(--step-1);
  margin-top: 0.5rem;
}

.cancel-flow p {
  margin: 0;
}

.cancel-list {
  margin: 0;
  padding-left: 1.2em;
  display: grid;
  gap: 0.4rem;
}

.btn.danger-solid {
  background: var(--r1);
  border-color: var(--r1);
  color: #fff;
}

.plans {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1rem;
}

.plan-option {
  display: grid;
  gap: 0.5rem;
  border-top: 3px solid var(--teal);
}

.plan-option .btn {
  justify-self: start;
  margin-top: 0.5rem;
}

.fineprint {
  font-size: 0.85em;
}

.section-title {
  font-size: var(--step-1);
  margin: 2.5rem 0 1rem;
}

.table-wrap {
  padding: 0;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92em;
}

.table th,
.table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table th {
  color: var(--mute);
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tr:last-child td {
  border-bottom: 0;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table .links a {
  margin-right: 0.75rem;
}

.badge {
  display: inline-block;
  padding: 0.15em 0.6em;
  border-radius: 999px;
  font-size: 0.8em;
  font-weight: 600;
  text-transform: capitalize;
  background: rgba(var(--tint), 0.1);
}

.badge.s-paid {
  background: rgba(47, 163, 90, 0.2);
  color: var(--ok-ink);
}

.badge.s-open {
  background: rgba(76, 201, 240, 0.15);
  color: var(--blue);
}

.badge.s-uncollectible,
.badge.s-void {
  background: rgba(229, 72, 77, 0.15);
  color: var(--bad-ink);
}

.flashcard-tags {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-head:has(.chart-filter) {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.chart-filter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9em;
}

.chart-filter select {
  width: auto;
  min-width: 200px;
}

/* Card questions and answers: regular weight and 1.5 line height everywhere, study, deck list and demo. */
.flashcard-q,
.flashcard-a,
.card-text .q,
.card-text .a {
  font-family: 'Inter', system-ui, sans-serif;
  line-height: 1.5;
}
