:root {
  --bg: #f7f2e8;
  --paper: #fffaf0;
  --ink: #2d2418;
  --muted: #776b5c;
  --brand: #8a1f11;
  --brand-2: #b85b24;
  --line: #e5d7bf;
  --good: #1d7f4f;
  --warn: #b7791f;
  --shadow: 0 16px 40px rgba(84, 50, 20, .11);
}
* { box-sizing: border-box; }
html { overflow-x: hidden; }
body {
  margin: 0;
  overflow-x: hidden;
  font-family: "Noto Serif CJK SC", "Source Han Serif SC", "PingFang SC", "Microsoft YaHei", serif;
  color: var(--ink);
  background: radial-gradient(circle at top, #fff6df 0, var(--bg) 42%, #efe3d0 100%);
}
.hero {
  padding: 34px 18px 28px;
  background: linear-gradient(135deg, #7f1d13, #b85b24 58%, #d49a48);
  color: #fffdf7;
}
.hero-inner { max-width: 1120px; margin: 0 auto; min-width: 0; }
.eyebrow { font-size: 13px; letter-spacing: .18em; opacity: .86; }
h1 { margin: 8px 0 10px; font-size: clamp(32px, 6vw, 58px); letter-spacing: .08em; }
.hero p { max-width: 820px; margin: 0 0 22px; line-height: 1.7; opacity: .92; overflow-wrap: anywhere; }
.search-box { display: flex; gap: 10px; max-width: 900px; min-width: 0; }
.search-box input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  border: 0;
  border-radius: 18px;
  padding: 18px 20px;
  font-size: 18px;
  box-shadow: var(--shadow);
}
.search-box button, .wide-btn, .quick, .tab, .ghost, .progress-actions button {
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  font-weight: 700;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
.search-box button {
  padding: 0 28px;
  color: #fff;
  background: #35180f;
  font-size: 17px;
}
button:hover { transform: translateY(-1px); }
.status { margin-top: 14px; font-size: 14px; opacity: .9; }
.layout {
  width: min(1160px, calc(100% - 28px));
  min-width: 0;
  margin: 22px auto;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
}
.panel {
  min-width: 0;
  background: rgba(255, 250, 240, .92);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.sidebar { display: grid; gap: 16px; align-content: start; min-width: 0; }
.panel h2 { margin: 0 0 14px; font-size: 20px; }
.quick-grid, .char-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quick, .char-grid button, .wide-btn {
  padding: 12px;
  background: #f2e2c8;
  color: var(--ink);
  border: 1px solid #e4cfaa;
}
.char-grid { grid-template-columns: repeat(5, 1fr); }
.char-grid button { aspect-ratio: 1; font-size: 20px; border-radius: 14px; }
.wide-btn { width: 100%; margin-top: 12px; background: var(--brand); color: #fff; }
.progress-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.progress-stats div { border: 1px solid var(--line); border-radius: 14px; padding: 10px; text-align: center; background: #fff7e8; }
.progress-stats strong { display: block; font-size: 22px; color: var(--brand); }
.progress-stats span { font-size: 12px; color: var(--muted); }
.content { display: grid; gap: 16px; align-content: start; min-width: 0; }
.tabs { display: flex; gap: 10px; flex-wrap: wrap; }
.tab { padding: 10px 16px; background: #ead8bb; color: var(--ink); }
.tab.active { background: var(--brand); color: #fff; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.panel-head h2 { margin: 0; }
#resultsMeta { color: var(--muted); font-size: 14px; }
.results { display: grid; gap: 12px; min-width: 0; }
.result-card {
  scroll-margin-top: 16px;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: #fffdf7;
  cursor: pointer;
}
.result-card:hover { border-color: #c99b60; box-shadow: 0 10px 28px rgba(84, 50, 20, .08); }
.result-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; min-width: 0; }
.result-top > div:first-child { min-width: 0; }
.result-title { font-size: 19px; font-weight: 800; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 14px; margin-top: 3px; }
.snippet { margin: 10px 0 0; line-height: 1.75; overflow-wrap: anywhere; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; min-width: 0; }
.badge { padding: 4px 8px; border-radius: 999px; font-size: 12px; background: #f0ddbe; color: #5e4321; white-space: nowrap; }
.badge.core { background: #ffe0dc; color: #8a1f11; }
.badge.common { background: #e0f2e9; color: #176142; }
.badge.expand { background: #e7eefc; color: #284e9b; }
mark { background: #ffe082; color: inherit; padding: 0 2px; border-radius: 3px; }
.detail-panel.hidden { display: none; }
.ghost { padding: 8px 12px; background: transparent; border: 1px solid var(--line); }
.poem-content { font-size: 20px; line-height: 2; margin: 14px 0; }
.tag-list { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.progress-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.progress-actions button { padding: 9px 12px; background: #ead8bb; }
.progress-actions button.active { background: var(--good); color: #fff; }
.empty { color: var(--muted); padding: 22px; text-align: center; border: 1px dashed var(--line); border-radius: 18px; }
.footer { width: min(1160px, calc(100% - 28px)); margin: 20px auto 40px; color: var(--muted); font-size: 14px; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .search-box { flex-direction: column; }
  .search-box button { padding: 14px; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .char-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .result-top { flex-direction: column; }
  .badges { justify-content: flex-start; }
}
@media (max-width: 420px) {
  .layout { width: calc(100% - 24px); }
  .hero { padding-left: 14px; padding-right: 14px; }
  .panel { padding: 14px; border-radius: 18px; }
  .char-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}


/* Mobile overflow hardening: prevent search/results/sidebar cards from pushing past viewport. */
.quick, .char-grid button, .wide-btn, .tab, .progress-stats > div {
  min-width: 0;
  max-width: 100%;
}

@media (max-width: 820px) {
  .layout {
    width: 100%;
    max-width: 100%;
    margin: 22px 0;
    padding: 0 14px;
  }
  .quick-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .char-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .progress-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .tabs {
    width: 100%;
  }
  .tab {
    flex: 1 1 auto;
  }
}

@media (max-width: 360px) {
  .char-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .quick-grid {
    grid-template-columns: 1fr;
  }
}

/* Extra guard for narrow/mobile viewports and Chrome's minimum layout width. */
@media (max-width: 820px) {
  body, .hero, .layout, .sidebar, .content, .panel, .results-panel, .detail-panel {
    max-width: 100vw;
  }
  .layout {
    overflow-x: hidden;
    overflow-y: visible;
  }
  .panel, .result-card {
    width: 100%;
  }
  .progress-stats strong {
    font-size: clamp(18px, 5vw, 22px);
  }
}


/* Inline poem detail: expand full text directly below the clicked result. */
.result-card.expanded {
  border-color: #b85b24;
  box-shadow: 0 14px 34px rgba(138, 31, 17, .12);
}
.inline-detail-slot:empty {
  display: none;
}
.inline-detail {
  margin-top: 14px;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid #e2c59b;
  background: #fff8e8;
  cursor: default;
}
.inline-detail.loading {
  color: var(--muted);
}
.inline-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.inline-detail-head strong {
  font-size: 20px;
}
.inline-close {
  flex: 0 0 auto;
}
.inline-badges {
  justify-content: flex-start;
  margin: 8px 0;
}
@media (max-width: 820px) {
  .inline-detail {
    padding: 12px;
  }
  .inline-detail-head {
    flex-direction: column;
  }
  .inline-close {
    width: 100%;
  }
}
