:root {
  --ink: #172033;
  --muted: #677188;
  --line: #d7dce6;
  --paper: #ffffff;
  --canvas: #f3f5f9;
  --navy: #17243f;
  --wk: #e63f7a;
  --wk-dark: #bd245c;
  --beyond: #2679da;
  --beyond-dark: #175eaf;
  --future-bg: #dcecff;
  --future-ink: #24598d;
  --missing-bg: #e6e9ef;
  --missing-ink: #6d7585;
  --focus: #0f62fe;
  --radius: 0.8rem;
  --kanji-mincho: "Yu Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Noto Serif CJK JP", "Noto Serif JP", "IPAexMincho", "MS PMincho", serif;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-width: 20rem;
  background:
    radial-gradient(circle at 50% -12rem, rgba(38, 121, 218, 0.13), transparent 32rem),
    var(--canvas);
  color: var(--ink);
}

button, input { font: inherit; }

a { color: inherit; }

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 4.25rem;
  padding: 0.65rem max(1rem, calc((100vw - 76rem) / 2));
  color: #fff;
  background: rgba(23, 36, 63, 0.96);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 2.6rem;
  height: 2.6rem;
  place-items: center;
  border-radius: 0.65rem;
  background: linear-gradient(145deg, var(--wk), #a91d73);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans CJK JP", sans-serif;
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; line-height: 1.1; }
.brand small { margin-top: 0.16rem; color: #bfc8da; font-size: 0.75rem; }

.level-badge {
  padding: 0.45rem 0.72rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  color: #ced5e4;
  font-size: 0.82rem;
}

.level-badge strong { color: #fff; }

.page-shell {
  width: min(76rem, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.25rem 0 4rem;
}

.list-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding: 0.28rem;
  gap: 0.25rem;
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0.35rem 1.2rem rgba(25, 36, 60, 0.06);
}

.tab {
  min-width: 6.2rem;
  min-height: 2.55rem;
  padding: 0.55rem 1.1rem;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-weight: 760;
}

.tab[aria-pressed="true"] {
  color: #fff;
  background: var(--navy);
  box-shadow: 0 0.3rem 0.8rem rgba(23, 36, 63, 0.2);
}

.kanji-search {
  max-width: 58rem;
  margin: 1.25rem auto 0;
  padding: 1rem 1.1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 0.35rem 1.2rem rgba(25, 36, 60, 0.05);
}

.kanji-search label {
  display: block;
  margin-bottom: 0.55rem;
  font-size: 0.92rem;
  font-weight: 800;
}

.search-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.55rem;
}

#kanji-search-input {
  width: 100%;
  min-height: 2.85rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid #bfc7d5;
  border-radius: 0.55rem;
  color: var(--ink);
  background: #fff;
  font-family: var(--kanji-mincho);
  font-size: 1rem;
}

#kanji-search-input:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.12rem;
}

.search-submit,
.search-clear {
  min-height: 2.85rem;
  padding: 0.65rem 1rem;
  border: 1px solid var(--navy);
  border-radius: 0.55rem;
  cursor: pointer;
  font-weight: 780;
}

.search-submit { color: #fff; background: var(--navy); }
.search-clear { color: var(--navy); background: #fff; }
.search-submit:hover { background: #263b63; }
.search-clear:hover { background: #edf1f7; }

.search-submit:focus-visible,
.search-clear:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.12rem;
}

.kanji-search p {
  margin: 0.5rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.search-results { margin-top: 2rem; }

.search-results-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 1rem;
  gap: 1rem;
}

.search-results-heading h1 { font-size: clamp(1.6rem, 4vw, 2.25rem); }
.search-results-heading > p { margin: 0 0 0.25rem; color: var(--muted); font-size: 0.86rem; }
.search-list { display: grid; gap: 1rem; }

.search-card {
  display: grid;
  grid-template-columns: 10rem minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.85rem;
  background: var(--paper);
  box-shadow: 0 0.45rem 1.4rem rgba(25, 36, 60, 0.055);
}

.search-card-glyph-column {
  display: flex;
  min-height: 13rem;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  padding: 1rem;
  gap: 0.9rem;
  background: linear-gradient(150deg, #edf1f7, #f9fafc);
  border-right: 1px solid var(--line);
}

.search-card-kanji {
  font-family: var(--kanji-mincho);
  font-size: clamp(5rem, 11vw, 7rem);
  font-weight: 400;
  line-height: 1;
}

.search-status {
  max-width: 100%;
  padding: 0.35rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 780;
  line-height: 1.25;
  text-align: center;
}

.search-card-body { min-width: 0; padding: 1.15rem 1.2rem 1.2rem; }
.search-card-body h2 { margin: 0; font-size: 1.25rem; }
.search-card-meanings { margin: 0.4rem 0 0; color: #3f4b60; line-height: 1.55; }

.search-card-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 1rem 0 0;
  padding: 1px;
  gap: 1px;
  border-radius: 0.65rem;
  overflow: hidden;
  background: var(--line);
}

.search-card-details div { min-width: 0; padding: 0.65rem 0.72rem; background: var(--paper); }
.search-card-details dt { color: var(--muted); font-size: 0.72rem; }
.search-card-details dd { margin: 0.18rem 0 0; line-height: 1.4; overflow-wrap: anywhere; }
.search-card-memberships { margin-top: 0.85rem; }
.search-card-jisho { display: inline-block; min-width: 10rem; margin-top: 0.9rem; }

.search-empty {
  margin: 0;
  padding: 1.25rem;
  border: 1px dashed #b9c2d1;
  border-radius: 0.7rem;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.65);
  text-align: center;
}

.tab:focus-visible,
.kanji:focus-visible,
input[type="range"]:focus-visible,
.brand:focus-visible {
  outline: 0.2rem solid var(--focus);
  outline-offset: 0.18rem;
}

.title-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1.2rem;
  margin: 2.6rem 0 1.55rem;
  text-align: center;
}

.title-row > span { height: 1px; background: linear-gradient(90deg, transparent, #b8bfcd); }
.title-row > span:last-child { background: linear-gradient(90deg, #b8bfcd, transparent); }

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 780;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1, h2, p { overflow-wrap: anywhere; }
h1 { margin: 0; font-size: clamp(1.75rem, 4vw, 2.65rem); letter-spacing: -0.035em; }

.level-panel {
  max-width: 46rem;
  margin: 0 auto 1.2rem;
  padding: 1.1rem 1.25rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 0.45rem 1.6rem rgba(25, 36, 60, 0.06);
}

.level-copy {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

.level-copy h2 { margin: 0; font-size: 1.06rem; letter-spacing: -0.01em; }

#level-output {
  flex: none;
  color: var(--beyond-dark);
  font-size: 1rem;
  font-weight: 820;
}

input[type="range"] {
  width: 100%;
  height: 1.65rem;
  margin: 0.7rem 0 0;
  accent-color: var(--beyond);
  cursor: pointer;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.72rem;
}

.summary {
  display: grid;
  grid-template-columns: minmax(10rem, 0.75fr) minmax(0, 2.25fr);
  max-width: 58rem;
  margin: 0 auto 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
}

.summary-main {
  display: flex;
  min-height: 6rem;
  align-items: baseline;
  justify-content: center;
  padding: 1rem;
  gap: 0.45rem;
  color: #fff;
  background: linear-gradient(140deg, var(--navy), #244f86);
}

.summary-number { font-size: 2rem; font-weight: 840; letter-spacing: -0.045em; }
.summary-label { color: #cfdbed; font-size: 0.86rem; }

.summary-details {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  margin: 0;
}

.summary-details div {
  display: grid;
  place-content: center;
  padding: 0.75rem 0.85rem;
  text-align: center;
  border-left: 1px solid var(--line);
}

.summary-details dt { color: var(--muted); font-size: 0.72rem; }
.summary-details dd { margin: 0.2rem 0 0; font-size: 1.18rem; font-weight: 820; }

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem 1rem;
  margin: 1.15rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.legend span { display: inline-flex; align-items: center; gap: 0.38rem; }

.swatch {
  width: 0.86rem;
  height: 0.86rem;
  border: 1px solid rgba(23, 32, 51, 0.12);
  border-radius: 0.2rem;
}

.click-hint { margin: 0.85rem 0 1.4rem; color: var(--muted); text-align: center; font-size: 0.82rem; }

.groups { display: grid; gap: 1.15rem; }

.group {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  overflow: hidden;
  background: var(--paper);
  box-shadow: 0 0.35rem 1.2rem rgba(25, 36, 60, 0.045);
}

.group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0.62rem 0.85rem;
  gap: 1rem;
  background: #dfe3ea;
  border-bottom: 1px solid #cfd5df;
}

.group-header h2 { margin: 0; font-size: 0.96rem; }
.group-header span { color: #5f6878; font-size: 0.75rem; text-align: right; }

.kanji-grid {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  padding: 0.7rem;
  gap: 0.28rem;
}

.kanji {
  display: grid;
  width: 2.75rem;
  height: 2.75rem;
  place-items: center;
  border: 1px solid transparent;
  padding: 0;
  border-radius: 0.33rem;
  text-decoration: none;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  font-size: 1.28rem;
  font-weight: 650;
  line-height: 1;
  appearance: none;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.kanji-glyph { display: block; }

.has-priority {
  grid-template-rows: 1fr auto;
  padding: 0.15rem 0.1rem 0.12rem;
}

.has-priority .kanji-glyph {
  align-self: end;
  font-size: 1.08rem;
}

.priority-score {
  min-width: 1.65rem;
  padding: 0.08rem 0.18rem;
  border-radius: 999px;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 820;
  line-height: 1;
}

.priority-top { border-color: #9e1e3c; }
.priority-high { border-color: #d35b15; }
.priority-medium { border-color: #d39a08; }
.priority-low { border-color: #a58d45; }
.priority-top .priority-score { color: #fff; background: #9e1e3c; }
.priority-high .priority-score { color: #fff; background: #d35b15; }
.priority-medium .priority-score { color: #3c2a00; background: #f3bf35; }
.priority-low .priority-score { color: #4c421f; background: #e6dba8; }

.legend .priority-score { display: inline-block; text-align: center; }

.kanji:hover {
  z-index: 1;
  transform: translateY(-0.12rem) scale(1.07);
  filter: saturate(1.08);
  box-shadow: 0 0.35rem 0.8rem rgba(23, 32, 51, 0.2);
}

.status-wk { color: #fff; background: var(--wk); border-color: var(--wk-dark); }
.status-beyond { color: #fff; background: var(--beyond); border-color: var(--beyond-dark); }
.status-future { color: var(--future-ink); background: var(--future-bg); border-color: #a8cbee; }
.status-missing { color: var(--missing-ink); background: var(--missing-bg); border-color: #d4d8e0; }

.kanji-dialog {
  width: min(38rem, calc(100% - 1.5rem));
  max-height: min(46rem, calc(100dvh - 2rem));
  overflow: auto;
  padding: 1.4rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 1.5rem 4rem rgba(9, 18, 36, 0.35);
}

.kanji-dialog::backdrop { background: rgba(12, 20, 36, 0.64); backdrop-filter: blur(0.15rem); }
.kanji-dialog > form { position: absolute; top: 0.65rem; right: 0.65rem; }

.dialog-close {
  display: grid;
  width: 2.2rem;
  height: 2.2rem;
  place-items: center;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: #edf0f5;
  cursor: pointer;
  font-size: 1.4rem;
  line-height: 1;
}

.dialog-heading {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  padding-right: 2.4rem;
  gap: 1.2rem;
}

.dialog-kanji {
  min-width: 6rem;
  font-family: var(--kanji-mincho);
  font-size: clamp(4.5rem, 18vw, 7rem);
  font-weight: 400;
  line-height: 1;
  text-align: center;
}

.dialog-heading h2 { margin: 0; font-size: 1.35rem; }
.dialog-meanings { margin: 0.45rem 0 0; color: #3f4b60; line-height: 1.55; }

.dialog-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 1.2rem 0 0;
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  overflow: hidden;
}

.dialog-details div { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--line); }
.dialog-details div:nth-child(odd) { border-right: 1px solid var(--line); }
.dialog-details dt { color: var(--muted); font-size: 0.72rem; }
.dialog-details dd { margin: 0.18rem 0 0; line-height: 1.45; }

.dialog-memberships { display: flex; flex-wrap: wrap; margin-top: 1rem; gap: 0.4rem; }
.dialog-memberships span { padding: 0.3rem 0.55rem; border-radius: 999px; color: #40506c; background: #e9eef6; font-size: 0.75rem; }

.dialog-jisho {
  display: block;
  margin-top: 1.15rem;
  padding: 0.72rem 1rem;
  border-radius: 0.6rem;
  color: #fff;
  background: var(--navy);
  font-weight: 760;
  text-align: center;
  text-decoration: none;
}

.footer {
  padding: 1.5rem max(1rem, calc((100vw - 76rem) / 2)) 2.3rem;
  color: #aeb8cb;
  background: var(--navy);
  font-size: 0.76rem;
  line-height: 1.55;
  text-align: center;
}

.footer p { max-width: 65rem; margin: 0 auto 0.35rem; }
.footer a { color: #fff; text-underline-offset: 0.18em; }
.error-message { padding: 1rem; color: #8a1d3e; background: #ffe7ef; border-radius: 0.5rem; }

@media (max-width: 46rem) {
  .page-shell { width: min(100% - 1rem, 76rem); padding-top: 1.35rem; }
  .title-row { gap: 0.65rem; margin-top: 1.65rem; }
  .summary { grid-template-columns: 1fr; }
  .summary-main { min-height: auto; }
  .summary-details { border-top: 1px solid var(--line); }
  .summary-details div { border-left: 0; }
  .summary-details div + div { border-left: 1px solid var(--line); }
  .kanji-grid { padding: 0.55rem; gap: 0.23rem; }
  .kanji { width: 2.55rem; height: 2.55rem; font-size: 1.2rem; }
  .has-priority .kanji-glyph { font-size: 1rem; }
  .priority-score { font-size: 0.75rem; }
  .search-card { grid-template-columns: 7.5rem minmax(0, 1fr); }
  .search-card-glyph-column { min-height: 11rem; }
  .search-card-kanji { font-size: clamp(4.2rem, 15vw, 6rem); }
  .search-card-details { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 31rem) {
  .brand small { display: none; }
  .brand-mark { width: 2.35rem; height: 2.35rem; }
  .tab { min-width: 0; padding-inline: 0.85rem; }
  .level-copy { align-items: center; }
  .level-copy .eyebrow { display: none; }
  .summary-details { grid-template-columns: repeat(2, 1fr); }
  .summary-details div { border-top: 1px solid var(--line); }
  .summary-details div:nth-child(odd) { border-left: 0; }
  .summary-details div:last-child { grid-column: 1 / -1; }
  .group-header { align-items: center; }
  .kanji-dialog { padding: 1rem; }
  .dialog-heading { grid-template-columns: 1fr; gap: 0.55rem; text-align: center; }
  .dialog-kanji { min-width: 0; }
  .dialog-details { grid-template-columns: 1fr; }
  .dialog-details div:nth-child(odd) { border-right: 0; }
  .search-controls { grid-template-columns: 1fr 1fr; }
  #kanji-search-input { grid-column: 1 / -1; }
  .search-results-heading { align-items: start; flex-direction: column; gap: 0.25rem; }
  .search-card { grid-template-columns: 1fr; }
  .search-card-glyph-column { min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .search-card-kanji { font-size: 5.5rem; }
  .search-card-details { grid-template-columns: 1fr; }
  .search-card-jisho { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .kanji { transition: none; }
}
