/* 16px = 1rem。手机端只用 rem；safe-area 用 env() */
:root {
  --paper: #f3ebdd;
  --paper-2: #ebe1d0;
  --ink: #1b1610;
  --ink-soft: #5c5348;
  --rule: #c9bba6;
  --seal: #9c2b18;
  --seal-soft: #c45c3e;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --pad: max(1.25rem, env(safe-area-inset-left));
  --pad-r: max(1.25rem, env(safe-area-inset-right));
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; height: 100%; }
body {
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background: var(--paper);
  height: 100dvh;
  overflow: hidden;
  line-height: 1.55;
}
body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.04;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#app {
  position: relative;
  z-index: 1;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  flex-shrink: 0;
  padding: calc(1rem + env(safe-area-inset-top)) var(--pad-r) 0.75rem var(--pad);
  border-bottom: 0.0625rem solid var(--rule);
  background: var(--paper);
}
.eyebrow {
  font-size: 0.6875rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--seal);
  font-weight: 500;
}
h1 {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin: 0.2rem 0 0.9rem;
}

.search-shell {
  display: flex;
  align-items: stretch;
  background: #fffdf8;
  border: 0.0625rem solid var(--ink);
  min-height: 3rem;
}
.search-kicker {
  display: flex;
  align-items: center;
  padding: 0 0.85rem;
  font-size: 0.75rem;
  letter-spacing: 0.16em;
  color: #fffdf8;
  background: var(--ink);
  writing-mode: horizontal-tb;
}
#q {
  flex: 1;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 1rem;
  padding: 0.7rem 0.9rem;
  color: var(--ink);
  outline: none;
  min-width: 0;
}
#q::placeholder { color: #9a8f80; }
.search-shell, .filters button, .hit, .recall-draw, .back, .recall-reveal, .recall-next, .recall-grade button, .assoc-item, .examples button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(156, 43, 24, 0.12);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.filters button {
  font: inherit;
  font-size: 0.8125rem;
  color: var(--ink-soft);
  background: transparent;
  border: 0.0625rem solid transparent;
  padding: 0.3rem 0.7rem;
  cursor: pointer;
  letter-spacing: 0.06em;
  transition: color 0.35s var(--ease), border-color 0.35s var(--ease), background 0.35s var(--ease);
}
.filters button[aria-selected="true"] {
  color: var(--seal);
  border-color: var(--seal);
  background: rgba(156, 43, 24, 0.06);
}
.filters button:active { opacity: 0.7; }

.recall-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem 0.9rem;
  margin-top: 0.75rem;
}
.recall-draw {
  font: inherit;
  font-size: 0.875rem;
  letter-spacing: 0.14em;
  color: #fffdf8;
  background: var(--seal);
  border: 0.0625rem solid var(--seal);
  padding: 0.45rem 1rem;
  cursor: pointer;
}
.recall-draw:active { opacity: 0.75; }
.recall-meta {
  font-size: 0.75rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.recall-stage {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  color: var(--seal);
  margin-bottom: 0.45rem;
}
.recall-prompt {
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin: 0.35rem 0 0.9rem;
  max-width: 40rem;
}
.recall-reveal,
.recall-next,
.recall-grade button {
  font: inherit;
  cursor: pointer;
  border: 0.0625rem solid var(--ink);
  background: #fffdf8;
  color: var(--ink);
  padding: 0.55rem 0.9rem;
}
.recall-reveal {
  letter-spacing: 0.12em;
  background: var(--ink);
  color: #fffdf8;
  border-color: var(--ink);
}
.recall-reveal:active,
.recall-next:active,
.recall-grade button:active { opacity: 0.75; }
.recall-answer { margin-top: 0.35rem; }
.recall-grade {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.4rem;
  margin-top: 1.1rem;
  max-width: 40rem;
}
.recall-grade button:disabled { opacity: 0.45; cursor: default; }
.recall-grade button[data-grade="again"] {
  border-color: var(--rule);
  color: var(--ink-soft);
}
.recall-grade button[data-grade="good"] {
  background: var(--seal);
  border-color: var(--seal);
  color: #fffdf8;
}
.recall-next {
  margin-top: 0.85rem;
  letter-spacing: 0.12em;
}
.recall-feedback {
  font-size: 0.8125rem;
  color: var(--seal);
  margin-top: 0.75rem;
}
.is-hidden { display: none !important; }

.place-box { margin: 0.35rem 0 0.85rem; max-width: 40rem; }
.place-where {
  font-size: 0.8125rem;
  letter-spacing: 0.08em;
  color: var(--seal);
  margin-bottom: 0.4rem;
}
.place-intro {
  font-size: 0.875rem;
  color: var(--ink-soft);
  line-height: 1.6;
  margin-top: 0.4rem;
}
.place-img {
  display: block;
  width: 100%;
  max-width: 22rem;
  height: auto;
  margin: 0.5rem 0;
  background: var(--paper-2);
}

.stage {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 22rem) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.pane {
  min-height: 0;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}
.list-pane {
  border-right: 0.0625rem solid var(--rule);
  display: flex;
  flex-direction: column;
}
.pane-head {
  flex-shrink: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem var(--pad) 0.4rem;
  background: var(--paper);
}
.pane-head h2 {
  font-family: "Noto Serif SC", serif;
  font-size: 1.05rem;
  font-weight: 600;
}
.meta { font-size: 0.75rem; color: var(--ink-soft); }

.results {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0.25rem 0 1.5rem;
}
.hit {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  background: transparent;
  border: 0;
  border-bottom: 0.0625rem solid rgba(201, 187, 166, 0.7);
  padding: 0.85rem var(--pad);
  cursor: pointer;
  color: inherit;
  transition: background 0.35s var(--ease);
}
.hit:hover { background: rgba(255, 253, 248, 0.7); }
.hit[aria-current="true"] { background: #fffdf8; }
.hit:active { opacity: 0.85; }
.hit-kicker {
  font-size: 0.6875rem;
  letter-spacing: 0.12em;
  color: var(--seal-soft);
  margin-bottom: 0.2rem;
}
.hit-title {
  font-family: "Noto Serif SC", serif;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
}
.hit-body {
  font-size: 0.8125rem;
  color: var(--ink-soft);
  margin-top: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
mark {
  background: rgba(156, 43, 24, 0.16);
  color: inherit;
  padding: 0 0.08rem;
}

.detail-pane {
  display: flex;
  flex-direction: column;
  padding: 1rem var(--pad-r) 1.5rem 1.25rem;
  overflow: hidden;
  background: #fffdf8;
}
.detail-toolbar {
  display: none;
  flex-shrink: 0;
  align-items: center;
  gap: 0.5rem;
  padding: 0;
  background: var(--paper);
}
.detail-actions {
  flex-shrink: 0;
  padding: 0.75rem 0 0;
  max-width: 40rem;
}
.detail-actions .recall-grade { margin-top: 0.55rem; }
.detail-actions .recall-next { width: 100%; }
.detail-actions .recall-reveal { width: 100%; }

.dock {
  display: none;
}
.detail-pane .detail {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.back {
  display: none;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--seal);
  background: none;
  border: 0;
  padding: 0.4rem 0 0.8rem;
  cursor: pointer;
}
.back:active { opacity: 0.7; }
.recall-back {
  display: inline-block;
  font: inherit;
  font-size: 0.8125rem;
  color: var(--seal);
  background: none;
  border: 0.0625rem solid var(--seal);
  padding: 0.35rem 0.75rem;
  margin-bottom: 0.85rem;
  cursor: pointer;
  letter-spacing: 0.08em;
}
.recall-back:active { opacity: 0.7; }

.detail.empty .hint {
  color: var(--ink-soft);
  max-width: 28rem;
  font-size: 0.9375rem;
}
.crumb {
  font-size: 0.75rem;
  color: var(--ink-soft);
  letter-spacing: 0.04em;
  margin-bottom: 0.6rem;
}
.detail h3 {
  font-family: "Noto Serif SC", serif;
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 0.75rem;
}
.kind {
  display: inline-block;
  font-size: 0.6875rem;
  letter-spacing: 0.14em;
  color: var(--seal);
  margin-left: 0.5rem;
  vertical-align: middle;
}
.detail-body {
  font-size: 0.9375rem;
  line-height: 1.7;
  max-width: 40rem;
  white-space: pre-wrap;
}
.assoc {
  margin-top: 1.75rem;
  padding-top: 1rem;
  border-top: 0.0625rem solid var(--rule);
  max-width: 40rem;
}
.assoc h4 {
  font-family: "Noto Serif SC", serif;
  font-size: 1rem;
  margin-bottom: 0.65rem;
}
.assoc-item {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.6rem;
  width: 100%;
  text-align: left;
  font: inherit;
  background: #fffdf8;
  border: 0.0625rem solid var(--rule);
  padding: 0.7rem 0.8rem;
  margin-bottom: 0.45rem;
  cursor: pointer;
  color: inherit;
  transition: border-color 0.35s var(--ease);
}
.assoc-item:hover { border-color: var(--ink); }
.assoc-item:active { opacity: 0.85; }
.assoc-why {
  font-size: 0.6875rem;
  letter-spacing: 0.08em;
  color: var(--seal);
  align-self: start;
  padding-top: 0.15rem;
}
.assoc-title { font-weight: 600; font-size: 0.9rem; }
.assoc-sub { font-size: 0.75rem; color: var(--ink-soft); margin-top: 0.15rem; }

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem var(--pad) 1rem;
}
.examples button {
  font: inherit;
  font-size: 0.8125rem;
  background: #fffdf8;
  border: 0.0625rem solid var(--rule);
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  color: var(--ink);
}
.examples button:active { opacity: 0.7; }

.empty-list {
  padding: 1.25rem var(--pad);
  color: var(--ink-soft);
  font-size: 0.9rem;
}

@media (max-width: 52rem) {
  .stage { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  html, body, #app { height: 100dvh; overflow: hidden; }

  .eyebrow { display: none; }
  h1 {
    font-size: 1.125rem;
    margin: 0 0 0.5rem;
    letter-spacing: 0.06em;
  }
  .top {
    padding: calc(0.45rem + env(safe-area-inset-top)) var(--pad-r) 0.5rem var(--pad);
  }
  .search-kicker { display: none; }
  .search-shell { min-height: 2.75rem; }
  #q { font-size: 1rem; padding: 0.55rem 0.75rem; }
  .filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 0.5rem;
    padding-bottom: 0.1rem;
  }
  .filters button {
    flex-shrink: 0;
    min-height: 2.25rem;
    padding: 0.4rem 0.8rem;
  }
  .recall-bar { display: none; }

  .pane-head { padding: 0.55rem var(--pad) 0.25rem; }
  .pane-head h2 { font-size: 0.95rem; }
  .hit {
    padding: 0.95rem var(--pad);
    min-height: 4.25rem;
  }
  .hit-title { font-size: 1.0625rem; }
  .results { padding: 0.15rem 0 5.5rem; }

  .dock {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 3;
    padding: 0.55rem var(--pad) calc(0.55rem + env(safe-area-inset-bottom));
    background: var(--paper);
    border-top: 0.0625rem solid var(--rule);
  }
  .dock .recall-draw {
    min-height: 2.75rem;
    min-width: 6.5rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.9375rem;
  }
  .dock .recall-meta { flex: 1; min-width: 0; }
  body.showing-detail .dock { display: none; }

  .detail-pane {
    position: fixed;
    inset: 0;
    z-index: 4;
    height: 100dvh;
    background: var(--paper);
    padding: 0;
    display: flex;
    flex-direction: column;
  }
  .detail-toolbar {
    display: flex;
    padding: calc(0.35rem + env(safe-area-inset-top)) var(--pad) 0.35rem;
    border-bottom: 0.0625rem solid var(--rule);
  }
  .back {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
    padding: 0.4rem 0.2rem;
    font-size: 0.9375rem;
  }
  .detail-pane .detail {
    padding: 0.85rem var(--pad) 1rem;
  }
  .detail h3 { font-size: 1.25rem; }
  .detail-body { font-size: 1rem; line-height: 1.7; }
  .detail-actions {
    max-width: none;
    padding: 0.65rem var(--pad) calc(0.65rem + env(safe-area-inset-bottom));
    border-top: 0.0625rem solid var(--rule);
    background: var(--paper);
  }
  .recall-grade {
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.4rem;
    margin-top: 0.5rem;
  }
  .recall-grade button,
  .recall-reveal,
  .recall-next {
    min-height: 2.75rem;
    font-size: 0.8125rem;
    padding: 0.5rem 0.3rem;
  }
  .assoc-item {
    grid-template-columns: 1fr;
    gap: 0.25rem;
    min-height: 3.5rem;
    padding: 0.75rem 0.8rem;
  }
  .assoc-why { padding-top: 0; }

  body.showing-detail .list-pane { visibility: hidden; }
  body:not(.showing-detail) .detail-pane { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
