:root {
  color-scheme: light;
  --paper: #f4efe6;
  --paper-light: #fbf8f2;
  --ink: #1f2421;
  --muted: #6e7169;
  --line: rgba(31, 36, 33, 0.14);
  --red: #a8392b;
  --red-dark: #7e291f;
  --moss: #355947;
  --shadow: 0 22px 60px rgba(43, 35, 29, 0.12);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.26), rgba(255, 255, 255, 0.26)),
    radial-gradient(circle at 8% 14%, rgba(168, 57, 43, 0.08), transparent 26rem),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

button,
a,
select {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(168, 57, 43, 0.3);
  outline-offset: 3px;
}

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

.site-header {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  background: var(--red);
  color: white;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 24px;
  line-height: 1;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  letter-spacing: 0.08em;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.12em;
}

.database-status {
  color: var(--muted);
  font-size: 12px;
}

.database-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 50%;
  background: #b88d53;
}

.database-status.connected::before {
  background: #4f866a;
}

main {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
}

.hero {
  padding: clamp(76px, 11vw, 148px) 0 clamp(68px, 9vw, 110px);
}

.eyebrow,
.section-kicker {
  margin: 0 0 14px;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2em;
}

.hero h1 {
  max-width: 920px;
  margin: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", "Yu Mincho", serif;
  font-size: clamp(43px, 7.3vw, 86px);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -0.04em;
}

.hero h1::first-line {
  color: var(--ink);
}

.hero-copy {
  max-width: 600px;
  margin: 32px 0 42px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.9;
}

.search-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  max-width: 920px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(251, 248, 242, 0.82);
  box-shadow: 0 12px 40px rgba(43, 35, 29, 0.08);
  backdrop-filter: blur(16px);
}

.search-field {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 0 14px;
}

.search-icon {
  color: var(--red);
  font-family: serif;
  font-size: 30px;
  transform: rotate(-20deg);
}

.search-field input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 17px;
}

.search-field input::placeholder {
  color: #9b9a92;
}

.clear-button,
.ghost-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.clear-button {
  padding: 8px;
  font-size: 12px;
}

.primary-button {
  min-width: 132px;
  border: 0;
  background: var(--red);
  color: white;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.08em;
  transition:
    background 160ms ease,
    transform 160ms ease;
}

.primary-button:hover {
  background: var(--red-dark);
}

.primary-button:active {
  transform: translateY(1px);
}

.catalog {
  padding: 72px 0 90px;
  border-top: 1px solid var(--line);
}

.catalog-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
}

.catalog-toolbar h2 {
  margin: 0;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: clamp(34px, 5vw, 54px);
  font-weight: 500;
}

.result-count {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.filters {
  display: flex;
  align-items: end;
  gap: 12px;
  margin: 34px 0 28px;
}

.filters label {
  display: grid;
  gap: 8px;
}

.filters label > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.filters select {
  min-width: 150px;
  height: 44px;
  padding: 0 38px 0 13px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--paper-light);
  color: var(--ink);
}

.ghost-button {
  height: 44px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.notice {
  margin: 0 0 24px;
  padding: 16px 18px;
  border-left: 3px solid var(--red);
  background: rgba(168, 57, 43, 0.07);
  color: var(--red-dark);
}

.hidden {
  display: none !important;
}

.grammar-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.grammar-card {
  position: relative;
  min-height: 300px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: rgba(251, 248, 242, 0.72);
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  transition:
    transform 180ms ease,
    box-shadow 180ms ease,
    border-color 180ms ease;
}

.grammar-card:hover {
  z-index: 1;
  transform: translateY(-4px);
  border-color: rgba(168, 57, 43, 0.35);
  box-shadow: var(--shadow);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
}

.level-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.level-badge,
.semantic-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid currentColor;
  color: var(--red);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.level-n1 {
  color: #8e2e27;
}

.level-n2 {
  color: #a25b31;
}

.level-n3 {
  color: #85702d;
}

.level-n4 {
  color: #4d7457;
}

.level-n5 {
  color: #426878;
}

.level-badge.muted {
  color: var(--muted);
}

.card-arrow {
  color: var(--muted);
  font-size: 17px;
}

.grammar-card h3 {
  margin: 28px 0 5px;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: 25px;
  font-weight: 600;
  line-height: 1.35;
}

.grammar-card h3 small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
}

.card-reading {
  min-height: 18px;
  margin: 0 0 19px;
  color: var(--red);
  font-size: 12px;
}

.card-summary {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: #4e514b;
  line-height: 1.75;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.card-translation {
  position: absolute;
  right: 24px;
  bottom: 21px;
  left: 24px;
  margin: 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.loading-card {
  cursor: default;
}

.loading-card span {
  display: block;
  height: 13px;
  margin: 18px 0;
  background: linear-gradient(
    90deg,
    rgba(31, 36, 33, 0.05),
    rgba(31, 36, 33, 0.12),
    rgba(31, 36, 33, 0.05)
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

.loading-card span:nth-child(1) {
  width: 24%;
}

.loading-card span:nth-child(2) {
  width: 70%;
  height: 30px;
  margin-top: 42px;
}

.loading-card span:nth-child(3) {
  width: 90%;
}

@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

.empty-state {
  grid-column: 1 / -1;
  min-height: 310px;
  display: grid;
  place-items: center;
  align-content: center;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
}

.empty-state h3,
.empty-state p {
  margin: 6px;
}

.empty-mark {
  color: var(--red);
  font-family: serif;
  font-size: 58px;
}

.pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 36px;
}

.page-button {
  min-width: 42px;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--paper-light);
  color: var(--ink);
  cursor: pointer;
}

.page-button.current {
  border-color: var(--red);
  background: var(--red);
  color: white;
}

.page-button:disabled {
  cursor: not-allowed;
  opacity: 0.35;
}

footer {
  min-height: 140px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 30px max(20px, calc((100% - 1180px) / 2));
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

footer a {
  color: inherit;
}

.detail-dialog {
  width: min(880px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  margin: auto;
  padding: 0;
  border: 0;
  background: var(--paper-light);
  box-shadow: 0 34px 90px rgba(22, 21, 18, 0.3);
}

.detail-dialog::backdrop {
  background: rgba(27, 28, 26, 0.68);
  backdrop-filter: blur(5px);
}

.detail-shell {
  position: relative;
  min-height: 300px;
  padding: clamp(28px, 6vw, 64px);
}

.dialog-close {
  position: sticky;
  z-index: 2;
  top: 18px;
  float: right;
  width: 42px;
  height: 42px;
  margin: -40px -40px 0 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--paper-light);
  color: var(--ink);
  cursor: pointer;
  font-size: 25px;
  line-height: 1;
}

.detail-header {
  padding-right: 36px;
}

.detail-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 22px;
}

.semantic-badge {
  color: var(--moss);
}

.detail-header h2 {
  margin: 0;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "Songti SC", serif;
  font-size: clamp(36px, 7vw, 64px);
  font-weight: 500;
  line-height: 1.2;
}

.detail-header h2 small {
  display: block;
  margin-top: 12px;
  color: var(--muted);
  font-family: "PingFang SC", sans-serif;
  font-size: 17px;
  font-weight: 400;
}

.detail-reading {
  margin: 12px 0 28px;
  color: var(--red);
  font-size: 14px;
}

.detail-summary {
  max-width: 660px;
  margin: 0;
  color: #444841;
  font-family: "Songti SC", serif;
  font-size: 21px;
  line-height: 1.8;
}

.translation-panel {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 16px;
  margin: 38px 0;
  padding: 21px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.translation-panel span {
  color: var(--muted);
  font-size: 12px;
}

.translation-panel p {
  margin: 0;
  font-weight: 650;
  line-height: 1.7;
}

.detail-overview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.detail-text-block {
  padding: 22px;
  background: var(--paper);
}

.detail-text-block h3,
.detail-section > h3 {
  margin: 0 0 12px;
  font-family: "Songti SC", serif;
  font-size: 20px;
  font-weight: 600;
}

.detail-text-block p {
  margin: 0;
  color: #52554f;
  line-height: 1.85;
  white-space: pre-wrap;
}

.detail-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--line);
}

.form-list,
.example-list,
.compact-list {
  display: grid;
  gap: 10px;
}

.form-item,
.example-item,
.compact-item,
.related-item {
  padding: 19px 20px;
  border: 1px solid var(--line);
  background: white;
}

.form-item h4 {
  margin: 0 0 13px;
  font-family: "Yu Mincho", serif;
  font-size: 20px;
}

.form-item h4 small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.construction-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) 1fr;
  gap: 16px;
  padding: 8px 0;
  border-top: 1px solid rgba(31, 36, 33, 0.08);
  color: var(--muted);
  font-size: 13px;
}

.construction-row strong {
  color: var(--ink);
}

.form-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.example-item {
  display: grid;
  grid-template-columns: 36px 1fr;
  column-gap: 12px;
}

.example-number {
  grid-row: 1 / 4;
  color: var(--red);
  font-family: serif;
  font-size: 12px;
}

.example-item p {
  margin: 0;
}

.example-japanese {
  font-family: "Yu Mincho", serif;
  font-size: 19px;
  line-height: 1.7;
}

.example-reading {
  margin-top: 5px !important;
  color: var(--red);
  font-size: 12px;
}

.example-chinese {
  margin-top: 8px !important;
  color: var(--muted);
  line-height: 1.7;
}

.compact-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-item,
.related-item {
  display: grid;
  gap: 5px;
  text-align: left;
}

.compact-item span,
.related-item span {
  color: var(--muted);
  line-height: 1.5;
}

.compact-item small {
  color: var(--red);
}

.related-item {
  color: inherit;
  cursor: pointer;
}

.related-item:hover {
  border-color: var(--red);
}

.detail-meta {
  margin: 48px 0 0;
  color: var(--muted);
  font-size: 10px;
  overflow-wrap: anywhere;
}

.detail-loading,
.detail-error {
  min-height: 240px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.detail-error {
  color: var(--red);
}

@media (max-width: 900px) {
  .grammar-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .site-header,
  main {
    width: min(100% - 28px, 1180px);
  }

  .site-header {
    min-height: 74px;
  }

  .database-status {
    max-width: 130px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .hero {
    padding-top: 66px;
  }

  .hero h1 br {
    display: none;
  }

  .search-panel {
    grid-template-columns: 1fr;
  }

  .primary-button {
    min-height: 52px;
  }

  .catalog-toolbar {
    align-items: start;
    flex-direction: column;
  }

  .filters {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .filters select {
    width: 100%;
    min-width: 0;
  }

  .ghost-button {
    grid-column: 1 / -1;
  }

  .grammar-grid {
    grid-template-columns: 1fr;
  }

  footer {
    align-items: start;
    flex-direction: column;
  }

  .detail-shell {
    padding: 42px 20px 30px;
  }

  .dialog-close {
    top: 10px;
    margin: -32px -8px 0 0;
  }

  .detail-overview,
  .compact-list {
    grid-template-columns: 1fr;
  }

  .translation-panel {
    grid-template-columns: 1fr;
  }

  .construction-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

