/* app/css/brutal.css — neo-brutalist design system: fonts, tokens, shell, shared b-* components
   Owner: A1. Spec: docs/redesign/plan.md §1. Exact values: docs/redesign/mockups/mock.css. Class contract: docs/tasks/redesign/README.md §4–§5.
   Loaded after legacy CSS, so these rules win. Screen-specific rules live in screens-*.css, not here. */

/* ── 1. Fonts (bundled offline, SIL OFL; licences in app/vendor/fonts/) ───────────────────────────────── */
@font-face {
  font-family: "Archivo";
  src: url("../vendor/fonts/archivo-latin-wdth-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../vendor/fonts/jetbrains-mono-latin-500-normal.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "JetBrains Mono";
  src: url("../vendor/fonts/jetbrains-mono-latin-700-normal.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}

/* ── 2. Tokens ────────────────────────────────────────────────────────────────────────────────────────── */
:root,
html[data-theme="light"] {
  --paper: #f3f0e6;
  --paper-2: #e9e5d8;
  --grid: rgba(17, 17, 17, 0.055);
  --ink: #111111;
  --ink-2: #2b2b29;
  --muted: #4d4b45;
  --on-ink: #f3f0e6;

  --fill-sand: #e8d6b2;
  --fill-sage: #b9c2b0;
  --fill-sky: #bfd2dd;
  --fill-rose: #e6c3bb;
  --fill-lilac: #cdc5e1;
  --fill-mint: #c3dcc9;
  --fill-butter: #efe2a6;

  --fill-1: var(--fill-sand);
  --fill-2: var(--fill-sage);
  --fill-3: var(--fill-sky);
  --fill-4: var(--fill-rose);
  --fill-5: var(--fill-lilac);
  --fill-6: var(--fill-mint);
  --fill-7: var(--fill-butter);

  --rule: 2.5px;
  --radius: 7px;
  --radius-sm: 6px;
  --shadow: 7px 7px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);

  --font-display: "Archivo", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --tabbar-h: 76px;
  --topbar-h: 78px;

  /* Compatibility aliases for legacy untouched CSS components */
  --bg-canvas: var(--paper);
  --bg-elevated: var(--paper-2);
  --bg-surface: var(--paper-2);
  --bg-surface-hover: var(--paper);
  --bg-glass: rgba(243, 240, 230, 0.95);
  --border-subtle: rgba(17, 17, 17, 0.15);
  --border-strong: var(--ink);
  --text-primary: var(--ink);
  --text-secondary: var(--ink-2);
  --text-muted: var(--muted);
}

html[data-theme="dark"] {
  --paper: #161512;
  --paper-2: #201f1b;
  --grid: rgba(243, 240, 230, 0.06);
  --ink: #f1ede2;
  --ink-2: #d9d4c7;
  --muted: #b4ae9f;
  --on-ink: #161512;

  --fill-sand: #4a3f2b;
  --fill-sage: #3a4236;
  --fill-sky: #2f3e48;
  --fill-rose: #4a3430;
  --fill-lilac: #3b3550;
  --fill-mint: #2f4536;
  --fill-butter: #4a4426;

  --fill-1: var(--fill-sand);
  --fill-2: var(--fill-sage);
  --fill-3: var(--fill-sky);
  --fill-4: var(--fill-rose);
  --fill-5: var(--fill-lilac);
  --fill-6: var(--fill-mint);
  --fill-7: var(--fill-butter);

  --rule: 2.5px;
  --radius: 7px;
  --radius-sm: 6px;
  --shadow: 7px 7px 0 var(--ink);
  --shadow-sm: 4px 4px 0 var(--ink);

  --font-display: "Archivo", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --tabbar-h: 76px;
  --topbar-h: 78px;

  /* Compatibility aliases for legacy untouched CSS components */
  --bg-canvas: var(--paper);
  --bg-elevated: var(--paper-2);
  --bg-surface: var(--paper-2);
  --bg-surface-hover: var(--paper);
  --bg-glass: rgba(22, 21, 18, 0.95);
  --border-subtle: rgba(241, 237, 226, 0.15);
  --border-strong: var(--ink);
  --text-primary: var(--ink);
  --text-secondary: var(--ink-2);
  --text-muted: var(--muted);
}

/* Subject accents per data-subject (contract §4) */
body[data-subject="math"] { --subject-accent: var(--fill-sand); }
body[data-subject="mp"]   { --subject-accent: var(--fill-mint); }
body[data-subject="cg"]   { --subject-accent: var(--fill-lilac); }
body[data-subject="toc"]  { --subject-accent: var(--fill-sky); }
body[data-subject="eng"]  { --subject-accent: var(--fill-rose); }
body[data-subject="ds"]   { --subject-accent: var(--fill-sage); }

/* ── 3. Page Layout ───────────────────────────────────────────────────────────────────────────────────── */
body {
  font-family: var(--font-display);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 18px 18px;
  line-height: 1.5;
  overflow-x: clip;
}

.b-page {
  max-width: 46rem;
  margin: 0 auto;
  padding: 22px 20px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 800px) {
  .b-page {
    padding: 32px 32px calc(var(--tabbar-h) + 40px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── 4. Shell: Top Bar (.b-topbar) ─────────────────────────────────────────────────────────────────────── */
.b-topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 14px;
  border-bottom: var(--rule) solid var(--ink);
  background: var(--paper);
}

.b-topbar__home {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
  min-height: 48px;
}

.b-topbar__logo {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--on-ink);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 26px;
  flex-shrink: 0;
  user-select: none;
}

.b-topbar__text {
  line-height: 1.15;
}

.b-topbar__name {
  display: block;
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.b-topbar__by {
  font-size: 15px;
  color: var(--ink-2);
}

.b-topbar__actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.b-topbar__btn {
  width: 48px;
  height: 48px;
  min-width: 48px;
  min-height: 48px;
  display: grid;
  place-items: center;
  position: relative;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--ink);
  padding: 0;
  touch-action: manipulation;
}

.b-ico {
  width: 28px;
  height: 28px;
  stroke: var(--ink);
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.b-topbar__dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 0 2px var(--paper);
}

@media (max-width: 380px) {
  .b-topbar {
    padding-left: 14px;
    padding-right: 14px;
  }
  .b-topbar__name {
    font-size: 18px;
  }
  .b-topbar__by {
    font-size: 13px;
  }
  .b-topbar__actions {
    gap: 6px;
  }
}

/* ── 5. Shell: Bottom Tab Bar (.b-tabbar) ─────────────────────────────────────────────────────────────── */
.b-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  border-top: var(--rule) solid var(--ink);
  background: var(--paper);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 100;
}

.b-tab {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  min-height: 64px;
  padding: 10px 0 12px;
  border-right: 2px solid var(--ink);
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
  overflow: hidden;
  touch-action: manipulation;
}

.b-tab:last-child {
  border-right: none;
}

.b-tab__label {
  font-family: var(--font-display);
  font-stretch: 85%;
  font-weight: 850;
  font-size: 11px;
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  letter-spacing: 0.02em;
}

@media (min-width: 600px) {
  .b-tab__label {
    font-size: 14px;
  }
}

.b-tab .b-ico {
  width: 26px;
  height: 26px;
  stroke: var(--ink);
  fill: none;
  stroke-width: 2.4;
}

.b-tab.is-active {
  background: var(--ink);
  color: var(--on-ink);
}

.b-tab.is-active .b-ico {
  stroke: var(--on-ink);
}

.b-tab:focus-visible,
.b-topbar__btn:focus-visible {
  outline: 3px solid var(--ink);
  outline-offset: -5px;
}

body.is-keyboard-open .b-tabbar {
  transform: translateY(100%);
  transition: transform 200ms var(--ease);
}

/* ── 6. Shared Components (contract §5) ───────────────────────────────────────────────────────────────── */
.b-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.b-h1 {
  font-size: 40px;
  line-height: 1.02;
  font-weight: 850;
  letter-spacing: -0.025em;
  margin: 0;
}

@media (max-width: 380px) {
  .b-h1 {
    font-size: 32px;
  }
}

.b-h2 {
  font-size: 26px;
  line-height: 1.1;
  font-weight: 850;
  letter-spacing: -0.02em;
  margin: 0 0 10px;
}

.b-crumb {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 8px;
  display: block;
}

.b-chip {
  font-family: var(--font-display);
  font-stretch: 80%;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 5px 10px;
  background: var(--paper);
  white-space: nowrap;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.b-badge {
  font-stretch: 78%;
  font-weight: 850;
  font-size: 17px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 4px 10px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 380px) {
  .b-badge {
    font-size: 14px;
    padding: 3px 8px;
  }
}

.b-stamp {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 2px solid var(--ink);
  border-radius: 4px;
  padding: 3px 8px;
  background: var(--paper);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.b-stamp.is-done {
  background: var(--ink);
  color: var(--on-ink);
}

.b-stamp.is-progress {
  background: var(--fill-butter);
  color: var(--ink);
}

.b-stamp.is-soon {
  background: var(--paper-2);
  color: var(--muted);
  border-style: dashed;
}

.b-mono {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ink);
}

.b-card {
  position: relative;
  border: var(--rule) solid var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
  margin-bottom: 22px;
  background: var(--paper);
  color: var(--ink);
}

.b-card--fill-1 { background: var(--fill-1); }
.b-card--fill-2 { background: var(--fill-2); }
.b-card--fill-3 { background: var(--fill-3); }
.b-card--fill-4 { background: var(--fill-4); }
.b-card--fill-5 { background: var(--fill-5); }
.b-card--fill-6 { background: var(--fill-6); }
.b-card--fill-7 { background: var(--fill-7); }

.b-card.is-link {
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}

.b-card.is-link a:first-of-type::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
}

.b-card.is-link:active {
  transform: translate(3px, 3px);
  box-shadow: var(--shadow-sm);
}

.b-bar {
  display: inline-flex;
  border: 2px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
  height: 16px;
  width: 140px;
  max-width: 100%;
  flex-shrink: 0;
  background: var(--paper);
}

.b-bar i {
  flex: 1;
  border-right: 1.5px solid var(--ink);
  height: 100%;
}

.b-bar i:last-child {
  border-right: 0;
}

.b-bar i.on {
  background: var(--ink);
}

.b-glyph {
  height: 44px;
  margin: 12px 0 2px;
  display: flex;
  align-items: center;
  color: var(--ink);
}

.b-glyph svg {
  height: 44px;
  stroke: currentColor;
  fill: none;
  stroke-width: 4;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.b-glyph__t {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 40px;
  line-height: 1;
  letter-spacing: -0.04em;
}

.b-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 16px;
  text-decoration: none;
  color: var(--ink);
  border: var(--rule) solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  min-height: 48px;
  background: var(--paper);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms var(--ease), box-shadow 120ms var(--ease);
}

.b-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 var(--ink);
}

.b-btn--solid {
  background: var(--ink);
  color: var(--on-ink);
  box-shadow: 4px 4px 0 var(--fill-sand);
}

.b-btn--solid:active {
  box-shadow: 2px 2px 0 var(--fill-sand);
}

.b-btn--block {
  display: flex;
  width: 100%;
  text-align: center;
}

.b-cta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--ink);
  color: var(--on-ink);
  border: var(--rule) solid var(--ink);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-weight: 800;
  font-size: 18px;
  text-decoration: none;
  box-shadow: 5px 5px 0 var(--fill-sand);
  margin: 4px 0 24px;
  min-height: 52px;
}

.b-cta small {
  display: block;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  opacity: 0.8;
}

.b-cta svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.b-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 18px;
}

.b-pills::-webkit-scrollbar {
  display: none;
}

.b-pill {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  text-decoration: none;
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--paper);
  white-space: nowrap;
  scroll-snap-align: start;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

.b-pill.is-active,
.b-pill.on {
  background: var(--ink);
  color: var(--on-ink);
}

.b-section-label {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin: 0 0 10px;
  display: block;
}

.b-empty {
  border: 2px dashed var(--ink);
  border-radius: var(--radius);
  padding: 24px 18px;
  text-align: center;
  color: var(--ink-2);
  background: transparent;
  margin-bottom: 22px;
}

.b-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  justify-content: flex-end; /* sheet sits at the bottom */
  align-items: center; /* and is centred across */
  /* The ONE base rule for the backdrop. screens-calendar.css only adds the slide-in (.is-open) state.
     Frosted blur is set in motion.css (one owner), inside @supports */
}

.b-sheet {
  width: 100%;
  max-width: 46rem;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--paper);
  color: var(--ink);
  border-top: var(--rule) solid var(--ink);
  border-left: var(--rule) solid var(--ink);
  border-right: var(--rule) solid var(--ink);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.25);
}

.b-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.b-label {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}

.b-input {
  min-height: 48px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 17px;
  outline: none;
}

.b-input:focus {
  box-shadow: var(--shadow-sm);
}

.b-check {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  cursor: pointer;
  user-select: none;
  font-size: 16px;
}

.b-check input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 4px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ── 7. Home (.hm-*) and Chapters (.ch-*) Screens ─────────────────────────────────────────────────────── */
.hm-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  margin-bottom: 22px;
}

@media (min-width: 600px) {
  .hm-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.hm-subject {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.hm-subject__row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.hm-subject__title {
  font-size: 26px;
  line-height: 1.1;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 14px 0 16px;
}

.hm-subject__title a {
  color: inherit;
  text-decoration: none;
}

.hm-subject__foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.hm-next {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 12px 18px;
  margin-bottom: 22px;
  background: var(--ink);
  color: var(--on-ink);
  border: var(--rule) solid var(--ink);
  border-radius: var(--radius);
  text-decoration: none;
  box-shadow: 5px 5px 0 var(--fill-butter);
  font-size: 16px;
}

.hm-next .b-mono {
  color: var(--fill-butter);
  font-size: 12px;
}

.hm-next b {
  font-weight: 800;
}

/* Chapters Screen (.ch-*) */
.ch-list {
  display: flex;
  flex-direction: column;
  gap: 22px;
  margin-bottom: 22px;
}

.ch-card {
  margin-bottom: 0;
}

.ch-card__row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.ch-card__mid {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: -12px;
  margin-bottom: 4px;
}

.ch-card__meta {
  font-size: 15px;
  color: var(--ink-2);
  text-align: right;
}

.ch-card__title {
  font-size: 28px;
  line-height: 1.08;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin: 14px 0 12px;
}

.ch-card__title a {
  color: inherit;
  text-decoration: none;
}

.ch-card__status {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.ch-tools {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 28px;
}

@media (min-width: 400px) {
  .ch-tools {
    grid-template-columns: repeat(2, 1fr);
  }
}

.ch-card__anchor {
  display: block;
  position: relative;
  top: -80px;
  visibility: hidden;
}

/* ── 8. Motion ────────────────────────────────────────────────────────────────────────────────────────── */
.view-enter {
  animation: viewEnter 280ms var(--ease) backwards;
}

.card-stagger-enter {
  animation: cardEnter 280ms var(--ease) backwards;
  animation-delay: var(--card-delay, 0ms);
}

@keyframes viewEnter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .view-enter,
  .card-stagger-enter,
  .b-btn,
  .b-card.is-link {
    animation: none !important;
    transition: none !important;
    transform: none !important;
  }
}

/* Back/"Chapters" links styled as a breadcrumb must still be a 48px touch target (A6 sweep, 2026-11-07) */
a.b-crumb {
  display: inline-flex;
  align-items: center;
  min-height: 48px;
}
