/* ============================================================
   Karate Grading Syllabus — 剛柔
   ------------------------------------------------------------
   Built on Goju Ryu's own idea: 剛 hard and 柔 soft.

   HARD   stamped sumi blocks, square corners, condensed uppercase labels
          on wide tracking, tabular figures, hairline rules
   SOFT   warm washi paper, generous leading, high-contrast mincho display,
          the woven give of the obi

   Chrome is warm and achromatic so the belt colours are the only real chroma.
   Two accents, each with exactly one job: aizome indigo for anything
   interactive, shu vermilion for the grade seal and destructive actions.
   ============================================================ */

:root {
  /* --- sumi: warm ink. Never blue-black, never pure black. --- */
  --sumi:       #17150f;
  --sumi-2:     #413b30;
  --sumi-3:     #6f6858;
  --sumi-faint: #9a9382;

  /* --- washi: unbleached paper, olive-grey cast rather than cream --- */
  --washi:      #e6e2d3;
  --washi-deep: #d8d3c0;
  --card:       #f6f3e9;

  --rule:       #c4bda7;
  --rule-soft:  #d9d3c0;

  /* --- accents, one job each --- */
  --ai:   #1c3c66;   /* aizome indigo — interactive */
  --shu:     #b0392a;   /* seal vermilion — grade seal, destructive actions */
  --good:    #3c5a35;

  /* --- belt colours: literal, taken from the belt names --- */
  --belt-white:  #f4f1e6;
  --belt-yellow: #e3b93a;
  --belt-orange: #d0762a;
  --belt-red:    #a83029;
  --belt-green:  #2f6b40;
  --belt-purple: #5f4487;
  --belt-blue:   #26558f;
  --belt-brown:  #63432c;
  --belt-black:  #17150f;

  /* --- type: the subject's own vernacular --- */
  --mincho: "Zen Old Mincho", "Hiragino Mincho ProN", Georgia, serif;
  --gothic: "Zen Kaku Gothic New", "Hiragino Sans", system-ui, sans-serif;

  --gap:    1.5rem;
  --gap-sm: 0.75rem;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--gothic);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--sumi);
  background-color: var(--washi);
  /* tatami weave, barely there — grounds the paper without reading as noise */
  background-image:
    repeating-linear-gradient(0deg,  rgba(23,21,15,0.022) 0 1px, transparent 1px 4px),
    repeating-linear-gradient(90deg, rgba(23,21,15,0.014) 0 1px, transparent 1px 4px);
  min-height: 100vh;
}

[hidden] { display: none !important; }
body.booting > *:not(noscript) { visibility: hidden; }
body.mode-auth { background-color: var(--sumi); }

:focus-visible { outline: 2px solid var(--ai); outline-offset: 2px; }
body.mode-auth :focus-visible { outline-color: var(--belt-yellow); }

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

::selection { background: var(--belt-yellow); color: var(--sumi); }


/* ============================================================
   Type roles
   ============================================================ */

/* HARD: the stamped label. Every structural marker on the page uses it. */
.eyebrow {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.625rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--sumi-3);
}

/* SOFT: the certificate voice. Mincho, high contrast, never bold-and-tight. */
.h-display {
  font-family: var(--mincho);
  font-weight: 600;
  letter-spacing: 0.005em;
  line-height: 1.18;
}

.kyu {
  font-family: var(--gothic);
  font-weight: 500;
  font-size: 0.6875rem;
  letter-spacing: 0.09em;
  font-variant-numeric: tabular-nums;
  color: var(--sumi-3);
}

/* The stamp: solid sumi block, paper text. The page's hard device. */
.stamp {
  display: inline-block;
  background: var(--sumi);
  color: var(--card);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.625rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 0.3125rem 0.5625rem 0.25rem;
}


/* ============================================================
   THE OBI — signature element
   Woven cotton, not a flat swatch: warp and weft threads, a rounded
   highlight along the top, shadow beneath, tag stripes that read as
   wrapped bands.
   ============================================================ */
.belt-swatch {
  position: relative;
  flex: 0 0 auto;
  width: 56px;
  height: 16px;
  display: flex;
  justify-content: flex-end;   /* tags wrap at the tip */
  gap: 4px;                    /* belt colour shows through, so 2 tags read as 2 */
  overflow: hidden;
  background: var(--washi-deep);
  box-shadow:
    inset 0 0 0 1px rgba(23,21,15,0.32),
    0 1px 2px rgba(23,21,15,0.16);
}

/* threads */
.belt-swatch::before {
  content: "";
  position: absolute; inset: 0; z-index: 2;
  pointer-events: none;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,0.09) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(0deg,  rgba(23,21,15,0.10)  0 1px, transparent 1px 3px);
}

/* the cord's roundness: highlight above, shadow below */
.belt-swatch::after {
  content: "";
  position: absolute; inset: 0; z-index: 3;
  pointer-events: none;
  background: linear-gradient(
    180deg,
    rgba(255,255,255,0.24) 0%,
    rgba(255,255,255,0.04) 34%,
    rgba(23,21,15,0.05)   66%,
    rgba(23,21,15,0.20)   100%);
}

.belt-tag {
  flex: 0 0 7px;
  box-shadow:
    inset 1px 0 0 rgba(23,21,15,0.38),
    inset -1px 0 0 rgba(23,21,15,0.22);
}

/* the banner obi: thicker, with a sashiko stitch line along its length */
.obi-lg {
  width: 100%;
  height: 34px;
  margin-top: 0.25rem;
  box-shadow:
    inset 0 0 0 1px rgba(23,21,15,0.34),
    0 3px 8px rgba(23,21,15,0.20);
}
/* wider tags and gaps at banner scale, so they stay legible */
.obi-lg { gap: 7px; }
.obi-lg .belt-tag { flex-basis: 14px; }

/* Belt colours. Applied as classes (never inline styles) so the page can run
   under a strict Content-Security-Policy. */
.c-white  { background: var(--belt-white); }
.c-yellow { background: var(--belt-yellow); }
.c-orange { background: var(--belt-orange); }
.c-red    { background: var(--belt-red); }
.c-green  { background: var(--belt-green); }
.c-purple { background: var(--belt-purple); }
.c-blue   { background: var(--belt-blue); }
.c-brown  { background: var(--belt-brown); }
.c-black  { background: var(--belt-black); }

.noscript { padding: 2rem; font-family: Georgia, serif; }


/* ============================================================
   Masthead
   ============================================================ */
.masthead {
  background: var(--sumi);
  color: var(--card);
  position: sticky;
  /* positioning context for the narrow-screen actions menu */
  top: 0;
  z-index: 50;
  border-bottom: 2px solid var(--shu);
}

.masthead-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0.875rem var(--gap);
  display: flex;
  align-items: center;
  gap: var(--gap);
  flex-wrap: wrap;
  position: relative;
}

/* Secondary actions. Inline on desktop; a dropdown on narrow screens, where
   four dark rows of chrome before any content was the main thing wrong. */
.mast-actions { display: flex; align-items: center; gap: 0.5rem; }

.menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  background: none;
  border: 1px solid rgba(246,243,233,0.26);
  cursor: pointer;
  flex: 0 0 auto;
}
.menu-bars, .menu-bars::before, .menu-bars::after {
  display: block;
  width: 17px;
  height: 2px;
  background: #c0bcae;
  content: "";
}
.menu-bars { position: relative; }
.menu-bars::before { position: absolute; top: -6px; }
.menu-bars::after  { position: absolute; top: 6px; }
.menu-btn[aria-expanded="true"] { background: var(--card); border-color: var(--card); }
.menu-btn[aria-expanded="true"] .menu-bars,
.menu-btn[aria-expanded="true"] .menu-bars::before,
.menu-btn[aria-expanded="true"] .menu-bars::after { background: var(--sumi); }

.wordmark { display: flex; align-items: center; gap: 0.875rem; margin-right: auto; }
.wordmark img { height: 46px; width: auto; }
.wordmark-text { display: flex; flex-direction: column; line-height: 1.25; }

/* 剛柔流 in mincho above the Latin: the name in its own script. */
.wordmark .kanji {
  font-family: var(--mincho);
  font-size: 0.8125rem;
  letter-spacing: 0.42em;
  color: var(--belt-yellow);
}
.wordmark-text b {
  font-family: var(--mincho);
  font-weight: 600;
  font-size: 1.1875rem;
  letter-spacing: 0.02em;
}
.wordmark-text > span:last-child {
  font-family: var(--gothic);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--sumi-faint);
}

/* three fixed classes, so stamped tabs rather than a dropdown */
.classes { display: flex; gap: 1px; background: rgba(246,243,233,0.14); padding: 1px; }
.class-tab {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #c0bcae;
  background: none;
  border: 0;
  padding: 0.5rem 0.875rem 0.4375rem;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}
.class-tab span {
  display: block;
  font-size: 0.5625rem;
  letter-spacing: 0.08em;
  font-weight: 500;
  opacity: 0.6;
  font-variant-numeric: tabular-nums;
}
.class-tab:hover { color: var(--card); background: rgba(246,243,233,0.08); }
.class-tab[aria-selected="true"] { background: var(--card); color: var(--sumi); }

.masthead-search {
  display: flex;
  align-items: center;
  background: rgba(246,243,233,0.09);
  border: 1px solid rgba(246,243,233,0.20);
  padding: 0 0.625rem;
}
.masthead-search input {
  font-family: var(--gothic);
  font-size: 0.875rem;
  background: none;
  border: 0;
  color: var(--card);
  padding: 0.5rem 0.375rem;
  width: 200px;
}
.masthead-search input::placeholder { color: var(--sumi-faint); letter-spacing: 0.04em; }
.masthead-search input:focus { outline: none; }
.masthead-search:focus-within { border-color: var(--belt-yellow); }

.icon-btn {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.625rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #c0bcae;
  background: none;
  border: 1px solid rgba(246,243,233,0.26);
  padding: 0.5rem 0.75rem 0.4375rem;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}
.icon-btn:hover { color: var(--sumi); background: var(--card); border-color: var(--card); }


/* ============================================================
   Layout
   ============================================================ */
.shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: var(--gap);
  display: grid;
  grid-template-columns: 292px 1fr;
  gap: var(--gap);
  align-items: start;
}
/* No grid child may force the page wider than the viewport. */
.shell > * { min-width: 0; }
.shell-wide { grid-template-columns: 1fr; }


/* ============================================================
   The rack — belts hung in grade order, the chosen one pulled out
   ============================================================ */
.rail {
  background: var(--card);
  border: 1px solid var(--rule);
  padding: var(--gap-sm);
  position: sticky;
  top: 96px;
  /* Grid items default to min-width:auto and so refuse to shrink below their
     content. On narrow screens the rack turns into a horizontal scroller, and
     without this the rack's full width forces the whole page wider than the
     viewport — which makes the browser zoom out and every breakpoint below
     look like it did nothing. */
  min-width: 0;
}

.rail-head {
  padding: 0.375rem 0.5rem 0.75rem;
  border-bottom: 2px solid var(--sumi);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

/* The collapsed belt picker. Desktop shows the full list instead. */
.rail-toggle { display: none; }

.rail-toggle-text {
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  font-family: var(--gothic);
  font-size: 0.875rem;
  font-weight: 500;
  overflow-wrap: break-word;
}
.rail-toggle-chev {
  flex: 0 0 auto;
  color: var(--shu);
  transition: transform 170ms cubic-bezier(0.2,0.7,0.3,1);
}
.rail-toggle[aria-expanded="true"] .rail-toggle-chev { transform: rotate(90deg); }

.rail-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  max-height: 64vh;
  overflow-y: auto;
  /* Explicit: setting only overflow-y makes overflow-x compute to auto, which
     lets the vertical scrollbar's width produce a stray sideways scrollbar. */
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  min-width: 0;
}

.belt-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule-soft);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--sumi-2);
  transition: transform 180ms cubic-bezier(0.2,0.7,0.3,1),
              background 140ms ease, color 140ms ease;
}
.rail-list li:last-child .belt-btn { border-bottom: 0; }
.belt-btn:hover { background: var(--washi); }

/* pulled off the rack */
.belt-btn[aria-current="true"] {
  background: var(--sumi);
  color: var(--card);
  transform: translateX(6px);
  border-bottom-color: transparent;
}
.belt-btn[aria-current="true"] .belt-label { font-weight: 500; }
.belt-btn[aria-current="true"] .belt-label small { color: var(--belt-yellow); opacity: 1; }

.belt-label {
  font-family: var(--gothic);
  font-size: 0.8125rem;
  line-height: 1.35;
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: break-word;
}
.belt-label small {
  display: block;
  font-size: 0.5938rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0.62;
  font-variant-numeric: tabular-nums;
  margin-top: 0.0625rem;
}


/* ============================================================
   Panels
   ============================================================ */
.pane { display: flex; flex-direction: column; min-width: 0; }

.panel {
  background: var(--card);
  border: 1px solid var(--rule);
}
.stack { margin-bottom: var(--gap); }

.panel-head {
  padding: var(--gap-sm) var(--gap);
  border-bottom: 2px solid var(--sumi);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-sm);
  flex-wrap: wrap;
}
.panel-title {
  font-family: var(--mincho);
  font-weight: 600;
  font-size: 1.125rem;
  letter-spacing: 0.01em;
}
.panel-body { padding: var(--gap); }


/* ---------- the grade banner ---------- */
.belt-banner {
  padding: var(--gap);
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, var(--card) 0%, var(--washi) 100%);
}

.banner-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 1rem;
}
.banner-text { min-width: 0; }

/* the hanko: vermilion ring carrying the grade number and 級 or 段 */
.banner-seal {
  flex: 0 0 auto;
  width: 62px; height: 62px;
  display: grid;
  place-items: center;
  border: 2px solid var(--shu);
  border-radius: 50%;
  color: var(--shu);
  line-height: 1;
  transform: rotate(-4deg);
}
.banner-seal b {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 1.375rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.banner-seal i {
  display: block;
  font-family: var(--mincho);
  font-style: normal;
  font-size: 0.8125rem;
  text-align: center;
  margin-top: 0.0625rem;
}
/* provisional grades carry 補 as well, so the glyphs tighten to fit */
.banner-seal.has-ho i { font-size: 0.6875rem; letter-spacing: -0.03em; }
.banner-seal.has-ho b { font-size: 1.25rem; }

.belt-banner h1 {
  font-size: clamp(1.625rem, 4vw, 2.375rem);
  max-width: 32ch;
}
.banner-meta {
  display: block;
  margin-top: 0.5rem;
  font-family: var(--gothic);
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--sumi-3);
}


/* ---------- requirements: three stamped sections ---------- */
.sections {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(238px, 1fr));
  gap: var(--gap);
}
.section-block h3 { margin-bottom: 0.875rem; }

.section-block ol { list-style: none; counter-reset: req; }
.section-block li {
  counter-increment: req;
  overflow-wrap: break-word;
  display: flex;
  gap: 0.6875rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--rule-soft);
  font-size: 0.9375rem;
  line-height: 1.5;
}
.section-block li:last-child { border-bottom: 0; }
.section-block li::before {
  content: counter(req, decimal-leading-zero);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.5938rem;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--shu);
  padding-top: 0.375rem;
  flex: 0 0 1.375rem;
}
.spaced-block { margin-bottom: var(--gap); }


/* ---------- terminology ---------- */
.cat { border-bottom: 1px solid var(--rule-soft); }
.cat:last-child { border-bottom: 0; }

.cat-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap-sm);
  padding: 0.875rem 0;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.6875rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--sumi);
  text-align: left;
}
.cat-toggle:hover { color: var(--ai); }
.cat-toggle .count {
  font-weight: 500;
  font-size: 0.625rem;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  color: var(--sumi-faint);
}
.cat-toggle .chev {
  display: inline-block;
  transition: transform 170ms cubic-bezier(0.2,0.7,0.3,1);
  color: var(--shu);
  margin-right: 0.4375rem;
}
.cat-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.cat-panel { padding-bottom: 1rem; }

/* Typeface encodes language: the romaji term is mincho, the English
   meaning is gothic. The distinction needs no label. */
.terms { list-style: none; }
.terms li {
  display: grid;
  grid-template-columns: minmax(9.5rem, 15rem) 1fr;
  gap: 1rem;
  padding: 0.4375rem 0;
  align-items: baseline;
  border-top: 1px solid var(--rule-soft);
}
.terms li:first-child { border-top: 0; }

.terms .jp {
  font-family: var(--mincho);
  font-weight: 600;
  font-size: 1.0625rem;
  letter-spacing: 0.01em;
  color: var(--sumi);
}
.terms .en {
  font-family: var(--gothic);
  font-size: 0.9062rem;
  line-height: 1.55;
  color: var(--sumi-2);
  overflow-wrap: break-word;
}

/* prose rows (Dojo Kun) have no pair, so they run full width in mincho */
.terms li.prose { grid-template-columns: 1fr; }
.terms li.prose .en {
  font-family: var(--mincho);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--sumi);
  max-width: 62ch;
}

mark {
  background: var(--belt-yellow);
  color: var(--sumi);
  padding: 0 0.125rem;
}

.empty {
  padding: var(--gap) 0;
  font-family: var(--mincho);
  font-size: 1rem;
  color: var(--sumi-3);
}
.start-copy {
  margin-top: 0.625rem;
  max-width: 46ch;
  font-family: var(--mincho);
  font-size: 1.0625rem;
  line-height: 1.7;
  color: var(--sumi-2);
}


/* ============================================================
   Auth
   ============================================================ */
.view-auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--gap);
}

.auth-card {
  width: 100%;
  max-width: 27rem;
  background: var(--card);
  padding: 2.25rem 2rem 2rem;
  box-shadow: 0 18px 50px rgba(0,0,0,0.4);
}

/* the rack compressed to a strip: the whole grade ladder at a glance */
.auth-card .rail-strip {
  display: flex;
  height: 7px;
  margin-bottom: 1.75rem;
  box-shadow: inset 0 0 0 1px rgba(23,21,15,0.24);
}
.auth-card .rail-strip i { flex: 1; }

.auth-card h1 { font-size: 1.625rem; margin-top: 0.375rem; }
.auth-card .lede {
  font-family: var(--mincho);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--sumi-2);
  margin: 0.625rem 0 1.75rem;
}

.field { margin-bottom: 1.125rem; }
.field label {
  display: block;
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.625rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sumi-3);
  margin-bottom: 0.4375rem;
}
.field input, .field select, .field textarea {
  width: 100%;
  font-family: var(--gothic);
  font-size: 0.9375rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--rule);
  background: #fffdf7;
  color: var(--sumi);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--ai);
  box-shadow: inset 0 0 0 1px var(--ai);
}
.field .hint {
  font-family: var(--gothic);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--sumi-3);
  margin-top: 0.375rem;
}
.spaced { margin-top: 0.875rem; }

.btn {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.6875rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 0.75rem 1.25rem 0.6875rem;
  border: 1px solid var(--sumi);
  background: var(--sumi);
  color: var(--card);
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}
.btn:hover:not(:disabled) { background: var(--ai); border-color: var(--ai); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-wide { width: 100%; margin-top: 0.375rem; }
.btn-quiet { background: none; color: var(--sumi); }
.btn-quiet:hover:not(:disabled) { background: var(--sumi); color: var(--card); }
.btn-sm { font-size: 0.5938rem; padding: 0.4375rem 0.625rem 0.375rem; letter-spacing: 0.13em; }
.btn-bad { border-color: var(--shu); color: var(--shu); background: none; }
.btn-bad:hover:not(:disabled) { background: var(--shu); color: var(--card); border-color: var(--shu); }

.auth-foot {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule-soft);
  font-family: var(--gothic);
  font-size: 0.8125rem;
  color: var(--sumi-3);
  display: flex;
  justify-content: space-between;
  gap: var(--gap-sm);
  flex-wrap: wrap;
}

a, .linkish {
  color: var(--ai);
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover, .linkish:hover { color: var(--shu); }

.note {
  padding: 0.8125rem 0.875rem;
  font-family: var(--gothic);
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: 1.125rem;
  border-left: 3px solid;
}
.note-bad  { background: #f7e9e6; color: #8c2b1f; border-color: var(--shu); }
.note-good { background: #e9efe6; color: #2f4a29; border-color: var(--good); }
.note-plain { background: transparent; color: var(--sumi-2); border-color: transparent; padding-left: 0; padding-right: 0; text-align: center; }
.note-info { background: #e8ecf2; color: var(--sumi-2); border-color: var(--ai); }


/* ============================================================
   Admin
   ============================================================ */
.admin-tabs {
  display: flex;
  border-bottom: 2px solid var(--sumi);
  margin-bottom: var(--gap);
  flex-wrap: wrap;
}
.admin-tab {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: none;
  border: 1px solid transparent;
  border-bottom: 0;
  padding: 0.6875rem 1rem 0.625rem;
  color: var(--sumi-3);
  cursor: pointer;
  margin-bottom: -2px;
}
.admin-tab:hover { color: var(--sumi); }
.admin-tab[aria-selected="true"] {
  background: var(--sumi);
  color: var(--card);
  border-color: var(--sumi);
}
.admin-tab .kyu { color: inherit; opacity: 0.7; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
table.grid th {
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.5938rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--sumi-3);
  text-align: left;
  padding: 0.5rem 0.625rem;
  border-bottom: 2px solid var(--sumi);
  white-space: nowrap;
}
table.grid td {
  padding: 0.5rem 0.625rem;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: middle;
}
table.grid tr:hover td { background: var(--washi); }
table.grid td.actions { white-space: nowrap; text-align: right; }
table.grid input, table.grid select {
  font-family: var(--gothic);
  font-size: 0.875rem;
  width: 100%;
  padding: 0.3125rem 0.4375rem;
  border: 1px solid var(--rule);
  background: #fffdf7;
  color: var(--sumi);
}
table.grid input:focus, table.grid select:focus {
  outline: none;
  border-color: var(--ai);
  box-shadow: inset 0 0 0 1px var(--ai);
}

.pill {
  display: inline-block;
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.5625rem;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  padding: 0.1875rem 0.4375rem 0.125rem;
  border: 1px solid;
}
.pill-pending  { color: #8a5a12; border-color: #8a5a12; background: #f7efdd; }
.pill-approved { color: var(--good); border-color: var(--good); background: #e9efe6; }
.pill-rejected { color: var(--shu); border-color: var(--shu); background: #f7e9e6; }

.toolbar {
  display: flex;
  gap: var(--gap-sm);
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: var(--gap);
  padding-bottom: var(--gap);
  border-bottom: 1px solid var(--rule-soft);
}
.toolbar .field { margin: 0; }

.col-term    { width: 22%; }
.col-order   { width: 5rem; }
.col-section { width: 13rem; }
.col-swatch  { width: 4.5rem; }
.col-adv     { width: 8rem; }


/* ============================================================
   Motion — one orchestrated moment, on selecting a grade
   ============================================================ */
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}
/* the obi ties on, left to right */
@keyframes tie {
  from { clip-path: inset(0 100% 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}
@keyframes press {
  from { opacity: 0; transform: rotate(-14deg) scale(1.5); }
  to   { opacity: 1; transform: rotate(-4deg) scale(1); }
}

.rise { animation: rise 300ms cubic-bezier(0.2,0.7,0.3,1) both; }
.rise .obi-lg { animation: tie 520ms cubic-bezier(0.3,0.8,0.2,1) 60ms both; }
/* the seal is stamped down onto the page */
.rise .banner-seal { animation: press 300ms cubic-bezier(0.2,0.9,0.3,1) 340ms both; }
.rise .section-block { animation: rise 320ms cubic-bezier(0.2,0.7,0.3,1) both; }
.rise .section-block:nth-child(2) { animation-delay: 70ms; }
.rise .section-block:nth-child(3) { animation-delay: 140ms; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
  .belt-btn[aria-current="true"] { transform: none; }
  .banner-seal { transform: rotate(-4deg); }
}


/* ============================================================
   Update prompt & offline
   ============================================================ */
.update-bar {
  position: sticky;
  top: 0;
  z-index: 70;
  background: var(--belt-yellow);
  color: var(--sumi);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.875rem;
  padding: 0.4375rem 1rem;
  padding-top: calc(0.4375rem + env(safe-area-inset-top));
}
.update-bar button {
  font: inherit;
  background: var(--sumi);
  color: var(--card);
  border: 0;
  padding: 0.3125rem 0.6875rem;
  cursor: pointer;
}
.update-bar button:hover { background: var(--ai); }

.offline-bar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: var(--shu);
  color: var(--card);
  font-family: var(--gothic);
  font-weight: 700;
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  padding: 0.4375rem 1rem;
  padding-top: calc(0.4375rem + env(safe-area-inset-top));
}
/* the masthead sits below the bar rather than under it */
body.is-offline .masthead { top: 2rem; }


/* ============================================================
   Responsive
   ------------------------------------------------------------
   The phone layout is not the desktop one shrunk. Two structural
   changes: the rack turns into a horizontal rail and becomes the
   sticky element instead of the masthead (the rack is what you need
   constantly while reading; the header is not), and the admin tables
   turn into stacked cards rather than scrolling sideways.
   ============================================================ */

@media (max-width: 940px) {
  .shell { grid-template-columns: 1fr; }

  .rail { position: relative; padding: 0.5rem; }
  .rail-head { display: none; }

  /* A horizontal scroller hides most of the grades off-screen, which is
     exactly the wrong trade on a phone: you can't see what you're missing.
     The rack collapses to one full-width control instead, and opens into a
     plain vertical list — scrolling down being the gesture phones are for. */
  .rail-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 3rem;
    padding: 0.5rem 0.625rem;
    background: none;
    border: 1px solid var(--rule);
    cursor: pointer;
    color: var(--sumi);
    font: inherit;
  }
  .rail-toggle:hover { background: var(--washi); }
  .rail-toggle .belt-swatch { width: 3.5rem; }
  .rail-toggle .belt-swatch:empty { display: none; }

  .rail-list { display: none; }
  .rail.is-open .rail-list {
    display: flex;
    flex-direction: column;
    max-height: 55vh;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    margin-top: 0.5rem;
    border-top: 1px solid var(--rule-soft);
  }

  /* rows, not cards: full width, swatch then name, like the desktop rail */
  .belt-btn {
    flex-direction: row;
    align-items: center;
    width: 100%;
    min-height: 2.75rem;
    gap: 0.75rem;
    padding: 0.5rem;
    border-bottom: 1px solid var(--rule-soft);
    border-right: 0;
  }
  .belt-btn[aria-current="true"] { transform: none; }
  .rail-list .belt-swatch { width: 3.5rem; }
}

/* ------------------------------------------------------------
   Admin tables become stacked cards. A sideways-scrolling table on
   a phone is unusable, and approving a member at the dojo is exactly
   the sort of thing done on a phone.
   ------------------------------------------------------------ */
@media (max-width: 760px) {
  /* Five tabs can't share one row on a phone, and a sideways scroller hides
     the last of them entirely. A six-column grid gives two full-width rows:
     three tabs across the top, two across the bottom, no ragged gap. */
  .admin-tabs {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 0;
  }
  .admin-tab {
    padding: 0.625rem 0.375rem;
    min-height: 2.75rem;
    text-align: center;
    white-space: normal;        /* long labels wrap rather than force a scroll */
    min-width: 0;
    letter-spacing: 0.08em;
    font-size: 0.625rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
  }
  .admin-tab { grid-column: span 3; }

  .table-wrap { overflow-x: visible; }
  table.grid, table.grid tbody, table.grid tfoot, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid thead { display: none; }

  table.grid tr {
    background: var(--card);
    border: 1px solid var(--rule);
    margin-bottom: 0.75rem;
    padding: 0.25rem 0.75rem 0.5rem;
  }
  table.grid tr:hover td { background: none; }

  table.grid td {
    border-bottom: 1px solid var(--rule-soft);
    padding: 0.5rem 0;
    display: flex;
    align-items: center;
    gap: 0.875rem;
    /* `anywhere`, not `break-word`: only `anywhere` reduces the element's
       min-content contribution, which is what stops a long email address
       forcing the card — and the page — wider than the screen. */
    overflow-wrap: anywhere;
    min-width: 0;
  }
  table.grid tr td:last-child { border-bottom: 0; }

  /* the column header travels with the cell */
  table.grid td::before {
    content: attr(data-label);
    flex: 0 0 5.5rem;
    font-family: var(--gothic);
    font-weight: 700;
    font-size: 0.5938rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--sumi-3);
  }
  /* layout-only spacer cells carry no label and no controls */
  table.grid td:not([data-label]):not(.actions) { display: none; }
  table.grid td.actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 0.5rem;
    padding-top: 0.75rem;
  }
  table.grid td.actions::before { content: none; }
  table.grid input, table.grid select { font-size: 1rem; min-height: 2.75rem; min-width: 0; }
  table.grid .belt-swatch { flex: 0 0 auto; width: 3.5rem; }
  table.grid td.actions .btn-sm { min-height: 2.75rem; padding-left: 0.875rem; padding-right: 0.875rem; }

  table.grid tfoot .add-row td { border-top: 0; background: none; }
  table.grid tfoot tr {
    background: var(--washi);
    border: 2px solid var(--sumi);
  }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar .field, .toolbar .btn { width: 100%; }
}

/* ============================================================
   Print — a grading sheet to take to class
   ============================================================ */

@media (max-width: 640px) {
  /* --- the rack becomes the sticky element, not the header --- */
  .masthead { position: static; }
  .rail {
    position: sticky;
    top: 0;
    z-index: 40;
    border-left: 0;
    border-right: 0;
    margin: 0 -0.875rem;
    box-shadow: 0 4px 12px rgba(23,21,15,0.14);
  }

  /* --- masthead: two rows, not four ---
     row 1  wordmark + menu button
     row 2  class tabs
     row 3  search
     Everything else lives behind the menu. */
  .masthead-inner {
    padding: 0.625rem 0.875rem;
    padding-top: calc(0.625rem + env(safe-area-inset-top));
    gap: 0.5rem 0.625rem;
  }
  .wordmark { flex: 1 1 auto; gap: 0.625rem; margin-right: 0; }
  .wordmark img { height: 32px; }
  .wordmark .kanji { font-size: 0.625rem; letter-spacing: 0.3em; }
  .wordmark-text b { font-size: 0.9375rem; }
  .wordmark-text > span:last-child { display: none; }

  .menu-btn { display: inline-flex; }

  .mast-actions {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0.375rem;
    padding: 0.625rem 0.875rem;
    background: var(--sumi);
    border-top: 1px solid rgba(246,243,233,0.18);
    box-shadow: 0 10px 24px rgba(0,0,0,0.45);
    z-index: 60;
  }
  .mast-actions.is-open { display: flex; }
  .mast-actions .icon-btn { width: 100%; min-height: 2.75rem; }

  .classes { width: 100%; order: 3; }
  .class-tab { flex: 1 1 0; padding: 0.5rem 0.25rem 0.4375rem; min-height: 2.75rem; }

  .masthead-search { flex: 1 1 100%; order: 4; }
  .masthead-search input { width: 100%; font-size: 1rem; }  /* 16px stops iOS zooming on focus */

  /* --- content --- */
  .shell { padding: 0.875rem; gap: 0.875rem; }
  .panel-body, .belt-banner, .panel-head { padding-left: 0.875rem; padding-right: 0.875rem; }
  .panel-body { padding-top: 1rem; padding-bottom: 1rem; }
  .stack { margin-bottom: 0.875rem; }

  .belt-banner { padding: 1rem 0.875rem; }
  .banner-top { gap: 0.75rem; margin-bottom: 0.75rem; }
  .banner-seal { width: 46px; height: 46px; border-width: 1.5px; }
  .banner-seal b { font-size: 1rem; }
  .banner-seal i { font-size: 0.625rem; }
  .banner-seal.has-ho i { font-size: 0.5rem; }
  .belt-banner h1 { font-size: 1.5rem; }
  .obi-lg { height: 22px; margin-top: 0; }
  .obi-lg .belt-tag { flex-basis: 10px; }
  .obi-lg { gap: 5px; }

  .sections { grid-template-columns: 1fr; gap: 1.25rem; }
  .section-block li { padding: 0.4375rem 0; }

  /* term rows stack: romaji above, meaning below */
  .terms li { grid-template-columns: 1fr; gap: 0.0625rem; padding: 0.5625rem 0; }
  .terms .jp { font-size: 1rem; }
  .terms .en { font-size: 0.875rem; }
  .terms li.prose .en { font-size: 1rem; }

  .cat-toggle { padding: 0.9375rem 0; min-height: 2.75rem; font-size: 0.625rem; }
  .panel-title { font-size: 1rem; }

  /* --- forms and buttons reach a proper touch size --- */
  .field input, .field select, .field textarea {
    font-size: 1rem;              /* 16px: prevents the iOS zoom-on-focus jump */
    padding: 0.75rem;
    min-height: 2.75rem;
  }
  .masthead-search { min-height: 2.75rem; }
  .masthead-search input { min-height: 2.75rem; padding: 0.5rem 0.375rem; }
  .btn { min-height: 2.75rem; padding: 0.75rem 1rem; }
  .btn-sm { min-height: 2.5rem; font-size: 0.6875rem; }

  /* --- micro-type is a desktop luxury ---
     The 9-10px labels that read as precise on a monitor are simply hard to
     read at arm's length on a phone, so every label size steps up. Content
     text is already 15-16px and doesn't change. --- */
  .eyebrow { font-size: 0.6875rem; letter-spacing: 0.16em; }
  .stamp { font-size: 0.6875rem; letter-spacing: 0.14em; padding: 0.375rem 0.625rem 0.3125rem; }
  .kyu { font-size: 0.75rem; }
  .belt-label small { font-size: 0.6875rem; }
  .cat-toggle { font-size: 0.6875rem; }
  .cat-toggle .count { font-size: 0.6875rem; }
  .banner-meta { font-size: 0.75rem; }
  .field label { font-size: 0.6875rem; }
  .icon-btn { font-size: 0.6875rem; }
  .class-tab { font-size: 0.75rem; }
  .class-tab span { font-size: 0.625rem; }
  table.grid th { font-size: 0.6875rem; }
  table.grid td::before { font-size: 0.6875rem; }
  .pill { font-size: 0.625rem; }
  .hint { font-size: 0.8125rem; }

  .rail { padding: 0.5rem; }

  .auth-card { padding: 1.75rem 1.25rem 1.5rem; }
  .view-auth {
    padding: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
  .auth-card h1 { font-size: 1.375rem; }
  .auth-foot { gap: 0.25rem 0.875rem; }

  /* Link-styled buttons are only 21px of text. Give them a real tap area. */
  .linkish {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    font-size: 0.9375rem;
  }
}

@media (max-width: 420px) {
  .wordmark .kanji { display: none; }   /* last thing to go */
  .class-tab span { display: none; }    /* age ranges drop before the labels */
}

@media print {
  .masthead, .rail, .cat-toggle .chev, .cat-toggle .count { display: none !important; }
  body, body.mode-auth { background: #fff; }
  .shell { display: block; padding: 0; }
  .panel { border: 0; }
  .belt-banner { background: none; }
  .cat-panel[hidden] { display: block !important; }
  .cat-toggle { padding-bottom: 0.25rem; }
  .terms li, .section-block { break-inside: avoid; }
}

/* ------------------------------------------------------------
   Add rows — the foot of each admin table is where new records
   are typed, so the context is visible while you type.
   ------------------------------------------------------------ */
table.grid tfoot .add-row td {
  border-bottom: 0;
  border-top: 2px solid var(--sumi);
  background: var(--washi);
  padding-top: 0.6875rem;
  padding-bottom: 0.6875rem;
}
table.grid tfoot .add-row input::placeholder { color: var(--sumi-faint); }
.col-count { width: 5rem; }
