:root {
  --bg: #faf6ee; --panel: #fffdf8; --ink: #2b2118; --muted: #7d6e60; --line: #e7dccb;
  --accent: #7a4b25; --accent-2: #b5763c; --accent-soft: #f3e5d2;
  --hl-yellow: #fff1a8; --hl-green: #d4f1c9; --hl-blue: #cfe6fb; --hl-pink: #fbd5e3;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --fs: 18px; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1612; --panel: #241d17; --ink: #efe6da; --muted: #a8988a; --line: #3a2f26;
    --accent: #e0a96d; --accent-2: #c98a4b; --accent-soft: #3a2b1e;
    --hl-yellow: #5a4f1c; --hl-green: #29452a; --hl-blue: #1f3a52; --hl-pink: #4f2636;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1612; --panel: #241d17; --ink: #efe6da; --muted: #a8988a; --line: #3a2f26;
  --accent: #e0a96d; --accent-2: #c98a4b; --accent-soft: #3a2b1e;
  --hl-yellow: #5a4f1c; --hl-green: #29452a; --hl-blue: #1f3a52; --hl-pink: #4f2636;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); }
body { display: flex; min-height: 100vh; }
a { color: var(--accent); }
button, select, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: .45em .8em; }
button:hover { border-color: var(--accent-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] button.primary, button.primary { color: var(--bg); }
button.ghost { border-color: transparent; background: transparent; }
button:disabled { opacity: .5; cursor: default; }
select, input, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: .45em .6em; max-width: 100%; }
textarea { width: 100%; min-height: 6em; resize: vertical; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; }
.muted { color: var(--muted); }
.pad { padding: 1rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.stack > * + * { margin-top: .75rem; }
.tag { display: inline-block; font-size: .78em; padding: .1em .5em; border-radius: 99px; background: var(--accent-soft); color: var(--accent); }

/* Navegação */
.nav { width: 210px; flex-shrink: 0; background: var(--panel); border-right: 1px solid var(--line); padding: 1rem .6rem; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: .2rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-family: var(--serif); font-weight: 700; font-size: 1.1rem; padding: 0 .5rem 1rem; }
.brand img { width: 30px; height: 30px; }
.nav a { display: flex; gap: .7rem; align-items: center; padding: .6rem .7rem; border-radius: 8px; text-decoration: none; color: var(--ink); }
.nav a i { font-style: normal; width: 1.4em; text-align: center; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { flex: 1; min-width: 0; padding: 1.25rem clamp(1rem, 3vw, 2rem) 6rem; }
@media (max-width: 760px) {
  body { display: block; }
  .nav { position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: auto; height: auto; flex-direction: row; justify-content: space-around; padding: .3rem .2rem calc(.3rem + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line); z-index: 20; }
  .brand { display: none; }
  .nav a { flex-direction: column; gap: .1rem; font-size: .7rem; padding: .35rem .3rem; }
  .nav a i { font-size: 1.25rem; }
  main { padding: 1rem 16px 6rem; }
  .toolbar { position: static; }
  .toolbar select { max-width: 46vw; }
}

/* Leitor */
.reader { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 420px); gap: 1.5rem; align-items: start; }
@media (max-width: 1100px) { .reader { grid-template-columns: 1fr; } }
.toolbar { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: .5rem 0; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.text { font-family: var(--serif); font-size: var(--fs); line-height: 1.75; max-width: 46em; }
.text h2 { margin: .2em 0 .6em; }
.cols { display: grid; gap: 1.5rem; }
.cols.n2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 700px) { .cols.n2 { grid-template-columns: 1fr; } }
.col-title { font-family: var(--sans); font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4rem; }
.v { cursor: pointer; border-radius: 4px; padding: 0 .1em; }
.v sup { font-family: var(--sans); font-size: .62em; color: var(--accent-2); font-weight: 700; margin-right: .2em; }
.v.sel { outline: 2px solid var(--accent-2); background: var(--accent-soft); }
.v.has-note sup::after { content: "•"; color: var(--accent); }
.v[data-hl="yellow"] { background: var(--hl-yellow); } .v[data-hl="green"] { background: var(--hl-green); }
.v[data-hl="blue"] { background: var(--hl-blue); } .v[data-hl="pink"] { background: var(--hl-pink); }
[dir="rtl"] { direction: rtl; text-align: right; font-size: calc(var(--fs) * 1.2); }
.selbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: 1.2rem; z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 6px 28px rgba(0,0,0,.18); padding: .5rem; display: flex; gap: .3rem; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 32px); }
@media (max-width: 760px) { .selbar { bottom: 5rem; } }
.dot { width: 1.6em; height: 1.6em; border-radius: 50%; padding: 0; }
.side .tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: .75rem; overflow-x: auto; }
.side .tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: .5rem .6rem; white-space: nowrap; }
.side .tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.side { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow: auto; }
@media (max-width: 1100px) { .side { position: static; max-height: none; } }

/* Markdown gerado pela IA */
.md { line-height: 1.6; }
.md h1 { font-size: 1.5rem; } .md h2 { font-size: 1.15rem; margin-top: 1.3em; color: var(--accent); } .md h3 { font-size: 1.02rem; }
.md blockquote { border-left: 3px solid var(--accent-2); margin: .5em 0; padding: .2em .8em; color: var(--muted); }
.md ul, .md ol { padding-left: 1.3em; }
.md a.ref { text-decoration: none; border-bottom: 1px dotted var(--accent); }
.cursor::after { content: "▍"; animation: blink 1s infinite; color: var(--accent); }
@keyframes blink { 50% { opacity: 0; } }

/* Plano */
.progress { height: 10px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); }
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(34px, 1fr)); gap: 4px; }
.days button { padding: .35em 0; font-size: .75rem; }
.days button.done { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.days button.today { outline: 2px solid var(--accent-2); }
.chap-list a { display: inline-block; margin: .2rem .3rem .2rem 0; padding: .4rem .7rem; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; background: var(--panel); }

.list > * { border-bottom: 1px solid var(--line); padding: .7rem 0; }
.hit b { color: var(--accent); }
.toast { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 50; }
dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--panel); color: var(--ink); width: min(560px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.35); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem; }
label { display: block; font-size: .85rem; color: var(--muted); }
label > select, label > input, label > textarea { display: block; width: 100%; margin-top: .2rem; color: var(--ink); }
@media print { .nav, .toolbar, .no-print { display: none !important; } main { padding: 0; } }

/* App Android */
.v.reading { background: var(--accent-soft); box-shadow: 0 0 0 2px var(--accent-2); }
body { padding-top: env(safe-area-inset-top); }
details summary { cursor: pointer; font-weight: 600; }
@media (max-width: 760px) {
  .toolbar { gap: .35rem; }
  .toolbar .grow { display: none; }
  .toolbar button { padding: .35em .45em; }
  .toolbar #bsel { flex: 1 1 40%; min-width: 0; max-width: none; }
  .toolbar #vsel, .toolbar #cmpsel { flex: 1 1 30%; min-width: 0; max-width: none; font-size: .85rem; }
}
