:root {
  --bg: #f4efe7;
  --panel: rgba(255, 251, 246, 0.8);
  --text: #20201f;
  --muted: #595247;
  --line: rgba(39, 34, 27, 0.14);
  --accent: #c74f1c;
  --accent-soft: #ffe1d4;
  --card: #fffaf3;
  --good: #21643f;

  --h1: clamp(1.8rem, 4vw, 3.1rem);
  --radius-lg: 24px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Be Vietnam Pro", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, #ffe7c6 0 20%, transparent 48%),
    radial-gradient(circle at 92% 4%, #ffd1cc 0 22%, transparent 45%),
    linear-gradient(160deg, #f7f1e7 0%, #f2ede5 45%, #eee7dd 100%);
  min-height: 100vh;
}

.bg-shapes {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}

.shape {
  position: absolute;
  border-radius: 50%;
  filter: blur(30px);
  opacity: 0.45;
}

.shape-a {
  width: 330px;
  height: 330px;
  top: -80px;
  left: -40px;
  background: #ffcc8f;
}

.shape-b {
  width: 300px;
  height: 300px;
  bottom: -70px;
  right: -40px;
  background: #ffb19d;
}

.shape-c {
  width: 180px;
  height: 180px;
  top: 45%;
  right: 20%;
  background: #ffc97d;
}

.app-shell {
  width: min(1200px, calc(100% - 2rem));
  margin: 1.25rem auto 2.5rem;
}

.hero,
.controls,
.results-head {
  background: var(--panel);
  border: 1px solid var(--line);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-lg);
  padding: 1rem 1.2rem;
  box-shadow: 0 10px 30px rgba(58, 43, 28, 0.08);
}

.hero {
  padding: 1.2rem 1.5rem;
  animation: rise 550ms ease;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
}

h1 {
  margin: 0.45rem 0;
  font-size: var(--h1);
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  color: var(--muted);
}

.controls {
  margin-top: 0.9rem;
  animation: rise 650ms ease;
  display: grid;
  gap: 0.7rem;
}

.search-wrap {
  display: grid;
  gap: 0.35rem;
}

.level-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.level-bar .block-title {
  margin: 0;
  white-space: nowrap;
}

.search-wrap span,
.block-title {
  font-weight: 700;
  font-size: 0.88rem;
  margin: 0;
}

input,
button {
  font: inherit;
}

input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffcf8;
  padding: 0.63rem 0.8rem;
}

input:focus,
button:focus {
  outline: 2px solid #ffbf9f;
  outline-offset: 2px;
}

.level-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.level-pill {
  border: 1px solid var(--line);
  background: #fffdf9;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  font-size: 0.86rem;
  cursor: pointer;
  transition: all 160ms ease;
}

.level-pill.active {
  background: #24211f;
  border-color: #24211f;
  color: #fff8f0;
}

button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fffefc;
  padding: 0.55rem 0.9rem;
  cursor: pointer;
}

.results-head {
  margin-top: 0.9rem;
  padding: 0.8rem 1.2rem;
}

#resultCount {
  margin: 0;
  font-weight: 700;
}

.load-more-section {
  margin-top: 1.2rem;
  text-align: center;
}

.load-more-btn {
  padding: 0.65rem 1.4rem;
  font-weight: 600;
  background: var(--accent-soft);
  border-color: #f7b89b;
}

.load-more-btn:hover {
  background: #ffccb8;
}

.card-grid {
  margin-top: 0.9rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.grammar-card {
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0.85rem;
  box-shadow: 0 7px 18px rgba(60, 47, 30, 0.08);
  display: grid;
  gap: 0.5rem;
  transform-origin: top center;
  animation: card-in 280ms ease;
}

.card-top {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.badge {
  border-radius: 999px;
  padding: 0.16rem 0.52rem;
  font-size: 0.75rem;
  border: 1px solid var(--line);
  background: #fff;
}

.badge.level {
  color: #5e2f15;
  background: var(--accent-soft);
  border-color: #f7b89b;
}

.title {
  margin: 0;
  font-family: "Noto Sans SC", "Be Vietnam Pro", sans-serif;
  font-size: 1.02rem;
  line-height: 1.35;
}

.formula,
.explain {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.examples {
  display: grid;
  gap: 0.55rem;
  font-size: 0.87rem;
}

.example-trigger {
  margin-top: 0.25rem;
  justify-self: start;
  background: #fff4ea;
  border-color: #f4b99f;
  color: #5e2f15;
  font-weight: 600;
}

.example-trigger:hover {
  background: #ffe8da;
}

.example {
  background: rgba(255, 255, 255, 0.6);
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 0.45rem;
}

.cn {
  font-family: "Noto Sans SC", sans-serif;
  font-size: 0.95rem;
}

.py,
.vi {
  color: var(--muted);
  margin-top: 0.15rem;
}

mark {
  background: #ffd184;
  padding: 0.02rem 0.16rem;
  border-radius: 4px;
}

.empty {
  padding: 1rem;
  border-radius: 18px;
  background: rgba(255, 250, 242, 0.85);
  border: 1px dashed var(--line);
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  display: none;
  z-index: 1000;
}

.modal.is-open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(32, 24, 15, 0.45);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  width: min(760px, calc(100% - 2rem));
  max-height: min(80vh, 720px);
  overflow: auto;
  margin: 8vh auto;
  background: #fffaf3;
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 24px 50px rgba(31, 23, 12, 0.28);
  padding: 1rem;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--line);
}

.modal-head h3 {
  margin: 0;
  font-size: 1.05rem;
  font-family: "Noto Sans SC", "Be Vietnam Pro", sans-serif;
}

.modal-close {
  padding: 0.4rem 0.8rem;
}

.modal-body {
  display: grid;
  gap: 0.65rem;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(7px) scale(0.99);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 860px) {
  .modal-panel {
    margin: 5vh auto;
    max-height: min(88vh, 720px);
  }
}
