:root {
  --font: "EB Garamond", "Cormorant Garamond", Garamond, "Iowan Old Style", "Palatino Linotype", Palatino, "Noto Serif", Georgia, serif;
  --fs: 19px;
  --outer: #2a2420;
  --bg: #f5ecd7;
  --ink: #2b231b;
  --soft: #7a6a55;
  --rule: #d9c9a8;
  --accent: #8a4b1f;
  --chip: #eadfc4;
  --chip-on: #3a2e22;
  --chip-on-ink: #f5ecd7;
  --star: #c98a14;
}
html[data-theme="night"] {
  --outer: #0d0c0b;
  --bg: #1e1b18;
  --ink: #e6dac1;
  --soft: #9d8f78;
  --rule: #3a342c;
  --accent: #d9a066;
  --chip: #2a2622;
  --chip-on: #e6dac1;
  --chip-on-ink: #1e1b18;
  --star: #e3b23c;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--outer);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs);
  line-height: 1.5;
}
.page {
  max-width: 720px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  box-shadow: 0 0 40px rgba(0, 0, 0, .35);
}

/* cabeçalho */
#hdr {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(.5rem + env(safe-area-inset-top)) .9rem .55rem;
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
  transition: transform .2s ease;
}
#hdr.hide { transform: translateY(-100%); }
.row1 { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
h1 { margin: 0; font-size: 1.35rem; font-weight: 600; letter-spacing: .01em; }
h1 small { font-size: .65em; font-weight: 400; color: var(--soft); margin-left: .35rem; }
.tools { display: flex; gap: .35rem; }
button { font: inherit; color: inherit; cursor: pointer; }
.tool {
  min-width: 2.4rem; height: 2.4rem; padding: 0 .6rem;
  border: 1px solid var(--rule); border-radius: .6rem;
  background: var(--chip); font-size: 1rem;
}
.tool[aria-pressed="true"] { background: var(--chip-on); color: var(--chip-on-ink); }

.seg { display: flex; gap: 0; margin-top: .5rem; border: 1px solid var(--rule); border-radius: .6rem; overflow: hidden; }
.seg button {
  flex: 1; padding: .4rem .2rem; border: 0; border-right: 1px solid var(--rule);
  background: var(--chip); font-size: .95rem;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--chip-on); color: var(--chip-on-ink); }

.searchrow { margin-top: .5rem; }
#q {
  width: 100%; padding: .45rem .7rem; font: inherit; font-size: 1rem;
  color: var(--ink); background: var(--chip);
  border: 1px solid var(--rule); border-radius: .6rem;
}
#q::placeholder { color: var(--soft); }

.chips { display: flex; gap: .4rem; margin-top: .5rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: .15rem .7rem; font-size: .9rem; white-space: nowrap;
  border: 1px solid var(--rule); border-radius: 999px; background: var(--chip);
}
.chip.on { background: var(--chip-on); color: var(--chip-on-ink); border-color: var(--chip-on); }
.chips .gap { flex: 0 0 .4rem; }

/* lista */
main { padding: 0 1.1rem 5rem; }
#list { overflow-anchor: none; }
.sec {
  margin: 1.6rem 0 .3rem; padding-bottom: .2rem;
  font-size: 1.05rem; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); border-bottom: 2px solid var(--rule);
}
.entry { padding: .75rem 0; border-bottom: 1px dotted var(--rule); }
.entry .w { font-size: 1.3rem; font-weight: 600; }
.star {
  border: 0; background: none; padding: 0 .35rem; font-size: 1.15rem; line-height: 1;
  color: var(--soft); vertical-align: baseline;
}
.star.on { color: var(--star); }
.pos { color: var(--soft); margin-right: .15rem; }
.n { color: var(--accent); font-weight: 600; margin-right: .1rem; }
.ex { display: block; margin: .15rem 0 .1rem 1.1rem; font-style: italic; color: var(--soft); }
#status { text-align: center; color: var(--soft); padding: 2rem 0; }

/* diálogos */
dialog {
  width: min(92vw, 420px); max-height: 85vh; padding: 1rem 1.1rem;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--rule); border-radius: .9rem;
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h2 { margin: 0 0 .6rem; font-size: 1.3rem; }
dialog h3 { margin: 1rem 0 .3rem; font-size: .85rem; letter-spacing: .08em; text-transform: uppercase; color: var(--soft); }
dialog .seg { margin-top: 0; }
.note { margin: .4rem 0; font-size: .85rem; color: var(--soft); }
.note a { color: var(--accent); }
.close {
  width: 100%; margin-top: 1rem; padding: .5rem; border: 1px solid var(--rule);
  border-radius: .6rem; background: var(--chip);
}
.idx { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; max-height: 58vh; overflow-y: auto; }
.idx.one { grid-template-columns: 1fr; }
.idx button {
  padding: .45rem .5rem; text-align: left; font-size: .95rem;
  border: 1px solid var(--rule); border-radius: .5rem; background: var(--chip);
}
