/* ── Palette: washi paper, sumi ink, shu vermilion, ai indigo ── */
:root {
  --paper: #f3ead6;
  --paper-deep: #e9dcc0;
  --card: #fbf6ea;
  --ink: #1d1b18;
  --ink-soft: #5b544a;
  --ink-faint: #8f8676;
  --shu: #b3261e;
  --shu-soft: #d9534a;
  --ai: #24395b;
  --line: rgba(29, 27, 24, .18);
  --kyu: #3f6b3a;   /* green kyu belt */
  --dan: #141414;   /* black belt */
  --serif-jp: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --serif: "Cormorant Garamond", "Shippori Mincho", Georgia, serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.45;
  background-color: var(--paper);
  /* washi fibre texture */
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .25 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    radial-gradient(ellipse at top, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(ellipse at bottom, var(--paper-deep), transparent 70%);
  background-attachment: fixed;
}

/* ── Masthead ── */
.masthead {
  position: relative;
  max-width: 1180px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 2rem;
  display: flex;
  align-items: center;
  gap: 1.75rem;
}
.enso {
  width: 120px;
  flex: none;
  color: var(--ink);
  opacity: .88;
}
.kicker {
  margin: 0;
  font-family: var(--serif-jp);
  letter-spacing: .35em;
  color: var(--shu);
  font-size: .95rem;
}
.masthead h1 {
  margin: .1rem 0 0;
  font-family: var(--serif-jp);
  font-weight: 800;
  font-size: clamp(2rem, 4.5vw, 3.2rem);
  letter-spacing: .02em;
  line-height: 1.1;
}
.subtitle {
  margin: .35rem 0 0;
  font-style: italic;
  color: var(--ink-soft);
  font-size: 1.15rem;
}
.hanko {
  margin-left: auto;
  flex: none;
  display: grid;
  place-items: center;
  width: 74px;
  height: 74px;
  border: 3px solid var(--shu);
  border-radius: 6px;
  background: var(--shu);
  color: var(--card);
  font-family: var(--serif-jp);
  font-weight: 800;
  font-size: 1.55rem;
  line-height: 1;
  writing-mode: vertical-rl;
  transform: rotate(-4deg);
  box-shadow: inset 0 0 0 3px var(--card), inset 0 0 0 5px var(--shu);
  opacity: .92;
}

/* ── Rank selector ── */
.ranks {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: center;
  gap: .5rem;
  padding: .85rem 1rem;
  flex-wrap: wrap;
  background: rgba(243, 234, 214, .92);
  backdrop-filter: blur(6px);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.rank-btn {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .36rem;
  min-width: 77px;
  padding: .66rem .72rem .54rem;
  border: 1px solid transparent;
  border-radius: 3px;
  background: none;
  color: var(--ink-soft);
  font: inherit;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
}
.rank-btn .kanji {
  font-family: var(--serif-jp);
  font-weight: 600;
  font-size: 1.38rem;
  writing-mode: vertical-rl;
  letter-spacing: .1em;
  line-height: 1;
}
.rank-btn .latin { font-size: .96rem; letter-spacing: .06em; }
.rank-btn .belt {
  width: 41px;
  height: 6px;
  border-radius: 1px;
  background: var(--kyu);
  opacity: .55;
}
.rank-btn[data-grade="dan"] .belt { background: var(--dan); }
.rank-btn:hover { color: var(--ink); border-color: var(--line); }
.rank-btn[aria-current="true"] {
  color: var(--card);
  background: var(--ink);
  border-color: var(--ink);
}
.rank-btn[aria-current="true"] .belt { opacity: 1; box-shadow: 0 0 0 1px var(--card); }
.rank-btn:focus-visible { outline: 2px solid var(--shu); outline-offset: 2px; }

/* ── Main ── */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 3rem;
}
.loading, .error { text-align: center; color: var(--ink-soft); font-style: italic; }
.error code { font-style: normal; background: var(--card); padding: .1em .4em; }

.rank-head {
  display: flex;
  align-items: flex-end;
  gap: 1.5rem;
  padding-bottom: 1.25rem;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--ink);
}
.rank-head .big-kanji {
  font-family: var(--serif-jp);
  font-weight: 800;
  font-size: clamp(3rem, 8vw, 5.2rem);
  line-height: .9;
  letter-spacing: .04em;
}
.rank-head h2 {
  margin: 0;
  font-family: var(--serif-jp);
  font-weight: 600;
  font-size: 1.9rem;
}
.rank-head .meta { margin: .2rem 0 0; color: var(--ink-soft); }
.rank-head .meta strong { color: var(--shu); font-weight: 600; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 2rem;
}
.segmented { display: inline-flex; border: 1px solid var(--ink); border-radius: 3px; overflow: hidden; }
.segmented button {
  padding: .35rem 1rem;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: .95rem;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--ink); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--card); }
.search {
  flex: 1 1 220px;
  max-width: 320px;
  padding: .4rem .75rem;
  border: 0;
  border-bottom: 1px solid var(--ink);
  background: transparent;
  font: inherit;
  color: var(--ink);
}
.search:focus { outline: none; border-bottom-color: var(--shu); }

/* ── Scroll (Ten / Chi / Jin) ── */
.scroll { margin-bottom: 3rem; }
.scroll-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.scroll-head .seal {
  display: grid;
  place-items: center;
  width: 3.1rem;
  height: 3.1rem;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--shu);
  color: var(--shu);
  font-family: var(--serif-jp);
  font-weight: 800;
  font-size: 1.6rem;
}
.scroll-head h3 {
  margin: 0;
  font-family: var(--serif-jp);
  font-weight: 600;
  font-size: 1.45rem;
  white-space: nowrap;
}
.scroll-head .brush {
  flex: 1;
  height: 2px;
  background: linear-gradient(90deg, var(--ink) 0%, rgba(29,27,24,.4) 55%, transparent 100%);
}

.categories {
  columns: 3 300px;
  column-gap: 1.25rem;
}

/* ── Category card ── */
.card {
  break-inside: avoid;
  margin: 0 0 1.25rem;
  padding: 1.1rem 1.25rem 1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 3px solid var(--ink);
  box-shadow: 0 1px 0 rgba(255,255,255,.7) inset, 0 6px 16px -12px rgba(60, 40, 10, .45);
  position: relative;
}
.card.is-new { border-top-color: var(--shu); }
.card h4 {
  margin: 0;
  font-family: var(--serif-jp);
  font-weight: 600;
  font-size: 1.12rem;
  line-height: 1.3;
}
.card .translation {
  display: block;
  font-style: italic;
  font-size: .95rem;
  color: var(--ink-faint);
}
.card .desc { margin: .15rem 0 0; font-size: .95rem; color: var(--ink-soft); font-style: italic; }
.card > .new-mark { position: absolute; top: .8rem; right: .9rem; }

.group-name {
  margin: .9rem 0 .2rem;
  font-family: var(--serif-jp);
  font-size: .85rem;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--ai);
  text-transform: uppercase;
}

ul.items { list-style: none; margin: .6rem 0 0; padding: 0; }
ul.items li {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  align-items: baseline;
  gap: 0 .35rem;
  padding: .3rem 0;
  border-bottom: 1px dotted var(--line);
}
ul.items li:last-child { border-bottom: 0; }
.items .num {
  font-family: var(--serif-jp);
  font-size: .82rem;
  color: var(--ink-faint);
  text-align: right;
  padding-right: .2rem;
}
.items .num:empty::before { content: "・"; color: var(--ink-faint); }
.items .name { font-weight: 600; }
.items .note { font-size: .88rem; font-style: italic; color: var(--ink-faint); }
.items .item-tr { display: block; font-size: .88rem; font-style: italic; color: var(--ink-soft); font-weight: 400; }
.items .body { grid-column: 2; }
.items .flag { grid-column: 3; }

.variants { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .3rem; }
.variant {
  padding: .05rem .5rem;
  font-size: .82rem;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--ai);
  background: rgba(36, 57, 91, .05);
}
.variant .note { margin-left: .25rem; }
.variant.is-new { border-color: var(--shu-soft); color: var(--shu); background: rgba(179, 38, 30, .05); }
.card > .variants { margin-top: .8rem; }

.new-mark {
  display: inline-grid;
  place-items: center;
  width: 1.35rem;
  height: 1.35rem;
  background: var(--shu);
  color: var(--card);
  font-family: var(--serif-jp);
  font-size: .75rem;
  font-weight: 800;
  border-radius: 2px;
  transform: rotate(-3deg);
  font-style: normal;
}
li.is-new .name { color: var(--shu); }

/* Filtering */
.only-new li:not(.is-new):not(.has-new) { display: none; }
.only-new .card:not(.has-new) { display: none; }
.only-new .scroll:not(.has-new) { display: none; }
.empty { color: var(--ink-faint); font-style: italic; text-align: center; padding: 2rem 0; }
mark { background: rgba(179, 38, 30, .15); color: inherit; padding: 0 .1em; }

/* ── Footer ── */
.colophon {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 1.5rem 3rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: .95rem;
}
.colophon .rule {
  display: block;
  width: 80px;
  height: 2px;
  margin: 0 auto 1.25rem;
  background: var(--shu);
}
.colophon .new-mark { vertical-align: -.2em; }
kbd {
  font-family: inherit;
  font-size: .85em;
  padding: 0 .35em;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--card);
}

/* ── Responsive ── */
@media (max-width: 640px) {
  body { font-size: 17px; }
  .masthead { padding-top: 2rem; gap: 1rem; }
  .enso { width: 70px; }
  .hanko { display: none; }
  .rank-head { gap: 1rem; }
  .ranks { position: static; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

/* ── Print: one clean sheet per rank ── */
@media print {
  body { background: #fff; font-size: 11pt; }
  .ranks, .toolbar, .colophon, .enso { display: none; }
  .masthead { padding: 0 0 1rem; }
  main { padding: 0; }
  .card { box-shadow: none; }
  .categories { columns: 2; }
}
