/* Cosmoverso: tema scuro, colore d'accento per mondo (attributo data-mondo) */
:root {
  --bg: #0d1117;
  --bg2: #151b24;
  --bg3: #1e2633;
  --line: #2a3443;
  --txt: #e6e9ef;
  --muted: #95a0b2;
  --oro: #c9a227;
  --acc: var(--oro);
  --err: #ff7b72;
  --ok: #56d364;
  --r: 12px;
  --nav-h: 62px;
  color-scheme: dark;
}
[data-mondo='roshar'] { --acc: #5fb3f0; }
[data-mondo='scadrial'] { --acc: #d9774b; }
[data-mondo='sel'] { --acc: #8fd3c4; }
[data-mondo='nalthis'] { --acc: #c77dff; }
[data-mondo='taldain'] { --acc: #e8c170; }
[data-mondo='lumar'] { --acc: #3ccf91; }
[data-mondo='komashi'] { --acc: #ff8fab; }
[data-mondo='threnody'] { --acc: #9aa3bf; }
[data-mondo='primo-sole'] { --acc: #f2a65a; }
[data-mondo='canticle'] { --acc: #ffd166; }
[data-mondo='yolen'] { --acc: #b5e48c; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
}
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; font-family: Georgia, 'Times New Roman', serif; font-weight: 600; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; margin-top: 1.4em; }
h3 { font-size: 1.05rem; margin-top: 1.1em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.en { color: var(--muted); font-weight: 400; font-size: .85em; font-style: italic; }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 10px;
  padding: .55em 1em; cursor: pointer;
}
button:hover { border-color: var(--acc); }
button.primario { background: var(--acc); color: #0d1117; border-color: transparent; font-weight: 600; }
input[type=text], input[type=search], input[type=password], select, textarea {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: .6em .8em; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--acc); outline-offset: -1px; }

/* Testata */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem;
  padding: .55rem 1rem; padding-top: calc(.55rem + env(safe-area-inset-top));
  background: rgba(13, 17, 23, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.top .logo { display: flex; align-items: center; gap: .5rem; color: var(--txt); font-family: Georgia, serif; font-size: 1.1rem; }
.top .logo img { width: 28px; height: 28px; }
.top .spazio { flex: 1; }
.top button { padding: .35em .6em; font-size: .9rem; }

main { max-width: 860px; margin: 0 auto; padding: 1rem; }

/* Navigazione in basso (telefono) */
.nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(21, 27, 36, .97); border-top: 1px solid var(--line);
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .7rem; text-decoration: none;
}
.nav a .ic { font-size: 1.35rem; line-height: 1; }
.nav a.attivo { color: var(--oro); }

/* Griglie e card */
.griglia { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .7rem; }
.griglia.larga { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.card {
  display: block; background: var(--bg2); border: 1px solid var(--line); border-left: 3px solid var(--acc);
  border-radius: var(--r); padding: .8rem .9rem; color: var(--txt); text-decoration: none; position: relative;
}
a.card:hover { text-decoration: none; border-color: var(--acc); }
.card h3 { margin: 0 0 .25em; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: .88rem; }
.card .tipo { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--acc); }
.tile { text-align: center; padding: 1rem .6rem; }
.tile .ic { font-size: 1.8rem; display: block; margin-bottom: .3rem; }
.lista { display: flex; flex-direction: column; gap: .5rem; }

/* Etichette e filtri */
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .5rem 0 1rem; }
.chip {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 999px; padding: .25em .8em;
  font-size: .82rem; cursor: pointer; color: var(--txt);
}
.chip.on { background: var(--acc); color: #0d1117; border-color: transparent; }
.badge { display: inline-block; font-size: .7rem; border-radius: 6px; padding: .05em .45em; background: var(--bg3); color: var(--muted); vertical-align: middle; }
.badge.nt { background: #3a2a10; color: #f2c46d; }

/* Scheda di dettaglio */
.scheda-testa { display: flex; gap: 1rem; align-items: flex-start; margin-bottom: 1rem; }
.scheda-testa .tipo { color: var(--acc); font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; }
.figura { margin: 0 0 1rem; max-width: 100%; }
.figura img { max-width: 100%; max-height: 360px; border-radius: var(--r); display: block; background: var(--bg2); }
.figura figcaption { font-size: .75rem; color: var(--muted); margin-top: .3rem; }
.sintesi { font-size: 1.05rem; border-left: 3px solid var(--acc); padding-left: .8rem; }
.blocco { margin-bottom: .9rem; }
.fonte-libro { font-size: .72rem; color: var(--muted); margin-left: .3rem; white-space: nowrap; }
.fonti { font-size: .82rem; color: var(--muted); border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: .8rem; }
.fonti a { margin-right: .7rem; }
.sigla { display: inline-block; min-width: 1.4em; text-align: center; border-radius: 4px; font-weight: 700; font-size: .75em; padding: 0 .25em; background: var(--bg3); color: var(--oro); }
a.xref { color: var(--txt); border-bottom: 1px dotted var(--acc); }
a.xref:hover { text-decoration: none; color: var(--acc); }

/* Spoiler: sfocato finché non lo tocchi */
.spoiler { position: relative; cursor: pointer; border-radius: 8px; }
.spoiler > .sp-in { filter: blur(6px); user-select: none; pointer-events: none; }
.spoiler::after {
  content: attr(data-avviso); position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: .78rem; color: #f2c46d; text-align: center; padding: .3rem; background: rgba(13, 17, 23, .35);
}
.spoiler.aperto { cursor: auto; }
.spoiler.aperto > .sp-in { filter: none; user-select: auto; pointer-events: auto; }
.spoiler.aperto::after { display: none; }

/* Chat del bot */
.chat { display: flex; flex-direction: column; gap: .7rem; margin-bottom: 1rem; }
.msg { max-width: 92%; padding: .65rem .85rem; border-radius: 14px; }
.msg.io { align-self: flex-end; background: #233650; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bg2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.bot .card { margin-top: .5rem; }
.msg .azioni { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.msg .azioni button { font-size: .82rem; padding: .35em .7em; }
.chiedi { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + .5rem); display: flex; gap: .5rem; background: var(--bg); padding: .4rem 0; }
.chiedi input { flex: 1; }
.suggerimenti { display: flex; flex-wrap: wrap; gap: .4rem; margin: .4rem 0 1rem; }

/* Brani dei libri */
.brano { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: .7rem .9rem; margin-bottom: .6rem; }
.brano .dove { font-size: .75rem; color: var(--acc); margin-bottom: .3rem; }
.brano mark { background: #5a4710; color: #ffe8a3; border-radius: 3px; padding: 0 2px; }
.brano.pieno { white-space: pre-wrap; font-family: Georgia, serif; line-height: 1.65; }

/* Timeline */
.tl-lista { border-left: 2px solid var(--line); margin-left: .5rem; padding-left: 1rem; }
.tl-ev { position: relative; margin-bottom: 1rem; }
.tl-ev::before { content: ''; position: absolute; left: calc(-1rem - 6px); top: .45rem; width: 10px; height: 10px; border-radius: 50%; background: var(--acc); }
.tl-ev .quando { font-size: .75rem; color: var(--acc); text-transform: uppercase; letter-spacing: .04em; }
.tl-era { font-family: Georgia, serif; color: var(--oro); margin: 1.4rem 0 .6rem -1rem; font-size: 1.05rem; }
.tl-vis { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r); background: var(--bg2); -webkit-overflow-scrolling: touch; }
.tl-tela { position: relative; }
.tl-corsia { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--line); }
.tl-corsia span { position: sticky; left: 0; font-size: .7rem; color: var(--acc); padding: .1rem .4rem; background: var(--bg2); }
.tl-punto { position: absolute; width: 150px; font-size: .75rem; background: var(--bg3); border: 1px solid var(--line); border-top: 3px solid var(--acc); border-radius: 8px; padding: .3rem .45rem; color: var(--txt); cursor: pointer; }
.tl-punto:hover { border-color: var(--acc); }
.tl-zoom { display: flex; gap: .4rem; align-items: center; margin: .5rem 0; }

/* Tabelle */
.tab-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { text-align: left; padding: .45rem .55rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--acc); font-weight: 600; background: var(--bg2); position: sticky; top: 0; }

/* Flashcard e quiz */
.flash { perspective: 900px; height: 260px; margin: 1rem 0; cursor: pointer; }
.flash-in { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.flash.girata .flash-in { transform: rotateY(180deg); }
.flash-f, .flash-r {
  position: absolute; inset: 0; backface-visibility: hidden; border-radius: 16px; padding: 1.2rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--bg2); border: 1px solid var(--line); border-top: 4px solid var(--acc); overflow: auto;
}
.flash-r { transform: rotateY(180deg); }
.flash-f h2 { margin: 0; font-size: 1.5rem; }
.quiz-opz { display: flex; flex-direction: column; gap: .5rem; }
.quiz-opz button { text-align: left; }
.quiz-opz button.giusta { background: #173d24; border-color: var(--ok); }
.quiz-opz button.sbagliata { background: #4a1d1d; border-color: var(--err); }

/* Varie */
.riga { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.barra { height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden; }
.barra > div { height: 100%; background: var(--acc); }
.errore { color: var(--err); }
.ok { color: var(--ok); }
.vuoto { color: var(--muted); text-align: center; padding: 2rem 1rem; }
.cerca-box { margin-bottom: .8rem; }
.sezione-intro { color: var(--muted); margin-bottom: 1rem; }
details { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: .5rem .8rem; margin-bottom: .5rem; }
details summary { cursor: pointer; font-weight: 600; }
.legenda-voce { display: flex; gap: .7rem; align-items: baseline; margin-bottom: .45rem; }
.legenda-voce .ic { min-width: 2rem; text-align: center; font-size: 1.2rem; }

/* Pagina di accesso */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-box { text-align: center; width: 100%; max-width: 340px; }
.login-box form { display: flex; flex-direction: column; gap: .7rem; margin-top: 1.2rem; }
.login-box button { background: var(--oro); color: #0d1117; font-weight: 600; border: 0; padding: .7em; }

@media (min-width: 900px) {
  body { padding-bottom: 0; padding-left: 88px; }
  .nav { top: 0; right: auto; width: 88px; height: auto; flex-direction: column; justify-content: flex-start; padding-top: 70px; border-top: 0; border-right: 1px solid var(--line); }
  .nav a { flex: 0 0 72px; }
  .chiedi { bottom: .5rem; }
}
