:root {
  color-scheme: light;
  --bg: #f7f4ef;
  --ink: #1d2321;
  --muted: #64706b;
  --line: #d8d0c3;
  --panel: #fffdf9;
  --panel-strong: #f0ece3;
  --accent: #a23b2a;
  --accent-dark: #74281f;
  --green: #2d6855;
  --shadow: 0 12px 30px rgb(34 29 20 / 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(190px, auto) minmax(220px, 520px);
  gap: 20px;
  align-items: center;
  padding: 14px clamp(16px, 4vw, 48px);
  background: rgb(247 244 239 / 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  background: var(--ink);
  color: var(--panel);
  border-radius: 8px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 30px;
  line-height: 1;
}

.brand-title,
.brand-subtitle {
  display: block;
}

.brand-title {
  font-size: 18px;
  font-weight: 760;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 13px;
}

.search-wrap input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 14px;
  outline: none;
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.7);
}

.search-wrap input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgb(45 104 85 / 0.15);
}

main {
  padding: 22px clamp(16px, 4vw, 48px) 44px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.stats {
  color: var(--muted);
  font-weight: 700;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.filter-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.filter,
.back-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
}

.filter.active,
.filter:hover,
.back-button:hover,
.stroke-tab.active,
.stroke-tab:hover,
.radical-tab.active,
.radical-tab:hover {
  border-color: var(--accent);
  background: #fff5f1;
  color: var(--accent-dark);
}

.shape-toggle.active {
  border-color: var(--green);
  background: #eef8f3;
  color: var(--green);
}

.component-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.component-toggle,
.component-clear {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 820;
}

.component-toggle:hover,
.component-toggle[aria-expanded="true"],
.component-clear:hover:not(:disabled) {
  border-color: var(--green);
  background: #eef8f3;
  color: var(--green);
}

.component-clear:disabled {
  cursor: default;
  opacity: 0.45;
}

.component-summary {
  min-width: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stroke-tabs {
  display: flex;
  gap: 6px;
  align-items: center;
}

.stroke-tab {
  flex: 0 0 auto;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 780;
}

.radical-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0 0 10px;
  margin-bottom: 8px;
  scrollbar-width: thin;
}

.radical-tabs.expanded {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(66px, 1fr));
  overflow: visible;
  padding-bottom: 8px;
}

.radical-tab {
  display: inline-grid;
  grid-template-columns: auto auto;
  gap: 5px;
  align-items: baseline;
  justify-content: center;
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px;
}

.radical-tab span {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: 18px;
  line-height: 1;
}

.radical-tab small {
  color: var(--muted);
  font-size: 10px;
  font-weight: 760;
}

.kanji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 10px;
}

.kanji-card {
  display: grid;
  grid-template-rows: 58px 22px 36px;
  gap: 4px;
  width: 100%;
  min-height: 134px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 12px 9px;
  text-align: center;
  box-shadow: 0 1px 0 rgb(255 255 255 / 0.7);
  touch-action: manipulation;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
  user-select: none;
  -webkit-touch-callout: none;
}

.kanji-card:hover,
.kanji-card:focus-visible {
  border-color: var(--accent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
  outline: none;
}

.kanji-card.pressing,
.kanji-card.copied {
  border-color: var(--green);
  background: #eef8f3;
  box-shadow: inset 0 0 0 1px rgb(33 104 78 / 0.16);
}

.kanji-char {
  align-self: center;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: 48px;
  line-height: 1;
}

.kanji-readings {
  color: var(--green);
  font-size: 13px;
  font-weight: 740;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kanji-meaning {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  overflow: hidden;
}

.detail-view {
  max-width: 1100px;
  margin: 0 auto;
}

.back-button {
  margin-bottom: 16px;
}

.detail-panel {
  display: grid;
  gap: 18px;
}

.detail-hero,
.readings-panel,
.meta-grid,
.usage-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.detail-hero {
  display: grid;
  grid-template-columns: minmax(160px, 240px) 1fr;
  gap: clamp(18px, 4vw, 34px);
  align-items: center;
  padding: clamp(18px, 4vw, 34px);
}

.detail-kanji {
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 49%, rgb(162 59 42 / 0.12) 49% 51%, transparent 51%),
    linear-gradient(0deg, transparent 49%, rgb(162 59 42 / 0.12) 49% 51%, transparent 51%),
    var(--panel-strong);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: clamp(104px, 18vw, 180px);
  line-height: 1;
}

.detail-kicker {
  color: var(--green);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.detail-summary h1 {
  margin: 8px 0 8px;
  font-size: clamp(30px, 5vw, 52px);
  line-height: 1.05;
}

.detail-summary h1 span {
  color: var(--muted);
  font-size: 0.44em;
  font-weight: 650;
}

.detail-summary p {
  max-width: 680px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
}

.copy-button {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.copy-button:hover,
.copy-button.copied {
  border-color: var(--green);
  background: #eef8f3;
  color: var(--green);
}

.variant-line {
  margin-top: 10px !important;
}

.readings-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.compact-heading {
  margin: 0;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.readings-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
}

.reading-block {
  margin: 0;
  padding: 18px;
}

.reading-block + .reading-block {
  border-left: 1px solid var(--line);
}

.reading-block dt {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.reading-block dd {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

.reading-block span {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 0 10px;
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
}

.meta-grid div {
  display: grid;
  gap: 6px;
  padding: 16px;
}

.meta-grid div + div {
  border-left: 1px solid var(--line);
}

.meta-grid span,
.section-heading span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-transform: uppercase;
}

.meta-grid strong {
  overflow-wrap: anywhere;
}

.usage-section {
  padding: 18px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-heading h2 {
  margin: 0;
  font-size: 20px;
}

.usage-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.usage-groups {
  display: block;
}

.usage-group + .usage-group {
  margin-top: 18px;
}

.usage-group h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
}

.usage-card {
  min-height: 108px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf4;
  padding: 14px;
}

.usage-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.icon-copy {
  min-height: 26px;
  border-radius: 6px;
  padding: 0 8px;
  font-size: 11px;
}

.usage-card ruby {
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif CJK JP", serif;
  font-size: 25px;
  font-weight: 750;
}

.usage-card rt {
  color: var(--green);
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
  font-size: 11px;
}

.usage-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}

.usage-tags span {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel-strong);
  color: var(--green);
  padding: 0 7px;
  font-size: 11px;
  font-weight: 800;
}

.usage-card p,
.empty-state {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.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;
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 8px 10px 10px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 6px;
    font-size: 23px;
  }

  .brand-title {
    font-size: 16px;
  }

  .brand-subtitle {
    font-size: 11px;
  }

  .search-wrap input {
    height: 36px;
    border-radius: 7px;
    padding: 0 10px;
    font-size: 15px;
  }

  main {
    padding: 10px 8px 24px;
  }

  .toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 6px;
    width: 100%;
  }

  .stats {
    font-size: 14px;
  }

  .control-row {
    display: flex;
    gap: 3px;
    width: 100%;
    overflow: hidden;
    padding-bottom: 2px;
  }

  .sort-group {
    display: flex;
    flex: 0 0 auto;
    gap: 3px;
  }

  .sort-group {
    width: 100%;
  }

  .filter {
    min-height: 30px;
    border-radius: 6px;
    padding: 0 3px;
    font-size: 9.8px;
    font-weight: 750;
  }

  .sort-group .filter {
    min-width: 37px;
  }

  .radical-tabs {
    gap: 3px;
    margin-right: -8px;
    margin-bottom: 5px;
    padding-bottom: 5px;
    scrollbar-width: none;
  }

  .radical-tabs::-webkit-scrollbar {
    display: none;
  }

  .radical-tabs.expanded {
    grid-template-columns: repeat(auto-fill, minmax(43px, 1fr));
    margin-right: 0;
  }

  .stroke-tabs {
    flex: 0 0 auto;
    gap: 3px;
  }

  .stroke-tab {
    min-height: 30px;
    border-radius: 5px;
    padding: 0 5px;
    font-size: 10px;
  }

  .component-controls {
    gap: 6px;
    margin-bottom: 5px;
  }

  .component-toggle,
  .component-clear {
    min-height: 28px;
    border-radius: 5px;
    padding: 0 8px;
    font-size: 11px;
  }

  .component-summary {
    font-size: 11px;
  }

  .radical-tab {
    min-height: 29px;
    border-radius: 5px;
    gap: 3px;
    padding: 0 6px;
  }

  .radical-tab span {
    font-size: 15px;
  }

  .radical-tab small {
    font-size: 8px;
  }

  .kanji-grid {
    grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
    gap: 2px;
  }

  .kanji-card {
    grid-template-rows: 28px 20px;
    gap: 1px;
    min-height: 53px;
    border-radius: 4px;
    padding: 2px 1px;
  }

  .kanji-char {
    font-size: 24px;
  }

  .kanji-readings {
    font-size: 7px;
    font-weight: 780;
    line-height: 1.25;
    white-space: normal;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  .kanji-meaning {
    display: none;
  }

  .shape-only .kanji-grid {
    grid-template-columns: repeat(auto-fill, minmax(29px, 1fr));
  }

  .shape-only .kanji-card {
    grid-template-rows: 34px;
    min-height: 36px;
    padding: 1px;
  }

  .shape-only .kanji-char {
    font-size: 27px;
  }

  .shape-only .kanji-readings {
    display: none;
  }

  .usage-section {
    padding: 12px;
  }

  .usage-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .usage-card {
    min-height: 0;
    padding: 10px;
  }

  .detail-hero,
  .readings-panel,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .detail-kanji {
    width: min(100%, 240px);
    margin: 0 auto;
  }

  .compact-heading {
    padding: 12px;
  }

  .copy-button {
    min-height: 28px;
    border-radius: 6px;
    padding: 0 8px;
    font-size: 11px;
  }

  .reading-block + .reading-block,
  .meta-grid div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }
}
