/* Readcrumbs – stili */
:root {
  --bg: #121419;
  --surface: #1C1F26;
  --surface-2: #252932;
  --line: #2E333D;
  --line-2: #3A404C;
  --text: #EEEAE3;
  --text-2: #CFCBC4;
  --muted: #A4A9B4;
  --accent: #F0B25A;
  --accent-ink: #1A1408;
  --accent-soft: #2A2418;
  --teal: #7CCBC0;
  --teal-soft: #253330;
  --twist: #F2A27A;
  --twist-line: #5A3A2A;
  --twist-soft: #33221A;
  --danger: #C9363B;
  --danger-text: #F08A8E;
  --serif: Literata, Georgia, 'Times New Roman', serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--sans); }
body { min-height: 100vh; min-height: 100dvh; -webkit-text-size-adjust: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }

.screen {
  max-width: 560px; margin: 0 auto;
  min-height: 100vh; min-height: 100dvh;
  padding: calc(var(--safe-top) + 20px) 20px calc(var(--safe-bottom) + 112px);
  display: flex; flex-direction: column; gap: 18px;
}
.screen.form { padding-bottom: calc(var(--safe-bottom) + 40px); }

/* ---------- testata ---------- */
.brand { display: flex; align-items: center; gap: 8px; }
.brand span { font-family: var(--serif); font-size: 27px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.h-section { font-family: var(--serif); font-size: 22px; font-weight: 600; color: var(--text-2); line-height: 1.2; }
.book-title { font-family: var(--serif); font-size: 26px; font-weight: 600; line-height: 1.2; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-wrap: balance; }
.sub { font-size: 13px; color: var(--muted); }
.form-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.form-head h1 { font-family: var(--serif); font-size: 20px; font-weight: 600; text-align: center; }
.form-head .left { justify-self: start; }
.form-head .right { justify-self: end; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.text-btn { height: 44px; border: none; background: none; padding: 0 2px; font-size: 15px; color: var(--muted); }
.text-btn.primary { color: var(--accent); font-weight: 600; }
.text-btn:disabled { opacity: .4; }

.label { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }
.kicker { font-size: 11px; font-weight: 600; color: var(--teal); letter-spacing: .06em; text-transform: uppercase; }

/* ---------- pillole ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip {
  height: 36px; padding: 0 14px; border-radius: 18px;
  border: 1px solid var(--line); background: transparent; color: var(--text-2);
  font-size: 14px; display: inline-flex; align-items: center; gap: 6px;
}
.chip[aria-pressed="true"], .chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip.teal { border-color: #3C5C57; background: var(--teal-soft); color: var(--teal); font-weight: 600; font-size: 13px; }
.chip.twist[aria-pressed="true"] { border-color: #E8885A; background: var(--twist-soft); color: var(--twist); }
.tag { font-size: 12px; padding: 4px 10px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.badge { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 8px; background: var(--twist-soft); color: var(--twist); flex-shrink: 0; }

.segmented { display: flex; gap: 6px; padding: 4px; border-radius: 14px; background: var(--surface); }
.segmented button { flex: 1; height: 40px; border-radius: 10px; border: none; background: transparent; color: var(--muted); font-size: 14px; font-weight: 500; }
.segmented button[aria-pressed="true"] { background: var(--line); color: var(--text); font-weight: 600; }
.segmented.inset { background: var(--bg); }
.segmented.inset button { height: 36px; font-size: 13px; }

/* ---------- card libro ---------- */
.card { border-radius: 16px; background: var(--surface); border: 1px solid var(--line); }
.book-card { display: flex; gap: 16px; padding: 14px; text-decoration: none; color: var(--text); width: 100%; text-align: left; }
.cover {
  width: 64px; height: 92px; border-radius: 6px; flex-shrink: 0;
  display: flex; align-items: flex-end; padding: 8px;
  font-family: var(--serif); font-size: 11px; line-height: 1.2; color: var(--text);
  background-size: cover; background-position: center; overflow: hidden; word-break: break-word;
}
.book-card .info { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.book-card .t { font-family: var(--serif); font-size: 18px; font-weight: 600; }
.progress { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.progress > div { height: 6px; border-radius: 3px; background: var(--accent); }
.meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); gap: 8px; }
.list { display: flex; flex-direction: column; gap: 12px; }

/* ---------- posizione ---------- */
.pos-card { display: flex; flex-direction: column; gap: 12px; padding: 16px; border-radius: 18px; background: var(--surface); border: 1px solid var(--line); }
.pos-value {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0;
  border: none; background: none; font-family: var(--serif); font-size: 30px; font-weight: 600; color: var(--accent);
}
.pos-value svg { width: 16px; height: 16px; }
.step-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 22px; }

/* ---------- linea temporale ---------- */
.timeline { position: relative; display: flex; flex-direction: column; padding-left: 4px; }
.timeline::before { content: ''; position: absolute; left: 61px; top: 8px; bottom: 0; width: 2px; background: var(--line); }
.tl-row { display: grid; grid-template-columns: 46px 22px 1fr; align-items: center; column-gap: 4px; min-height: 52px; text-decoration: none; color: var(--text); background: none; border: none; padding: 0; text-align: left; width: 100%; }
.tl-row .when { font-size: 12px; color: var(--muted); text-align: right; padding-right: 6px; }
.tl-row .dot { width: 12px; height: 12px; border-radius: 6px; background: var(--bg); border: 2px solid var(--teal); justify-self: center; position: relative; }
.tl-row .body { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; background: var(--surface); margin: 3px 0 3px 6px; min-width: 0; }
.tl-row.twist { min-height: 44px; }
.tl-row.twist .when { color: var(--twist); }
.tl-row.twist .dot { width: 10px; height: 10px; border-radius: 0; border: none; background: #E8885A; transform: rotate(45deg); }
.tl-row.twist .body { background: none; border: 1px solid var(--twist-line); font-size: 13px; padding: 8px 10px; }
.tl-row.twist .body svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--twist); }
.tl-here { display: grid; grid-template-columns: 46px 22px 1fr; align-items: center; column-gap: 4px; height: 40px; }
.tl-here .when { font-size: 12px; color: var(--accent); font-weight: 600; text-align: right; padding-right: 6px; }
.tl-here .dot { width: 16px; height: 16px; border-radius: 8px; background: var(--accent); justify-self: center; position: relative; }
.tl-here .line { height: 2px; background: var(--accent); margin-left: 6px; display: flex; align-items: center; }
.tl-here .line span { background: var(--bg); color: var(--accent); font-size: 12px; font-weight: 600; padding: 0 8px; margin-left: 8px; }
.tl-section { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; padding: 10px 0 6px; position: relative; background: var(--bg); }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #121419; font-weight: 600; font-size: 13px; background-size: cover; background-position: center;
}
.avatar.lg { width: 84px; height: 84px; font-size: 28px; }
.avatar.md { width: 36px; height: 36px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.name-col { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.name-col .n { font-size: 15px; font-weight: 600; }
.name-col .r { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- liste raggruppate ---------- */
.group { display: flex; flex-direction: column; border-radius: 14px; background: var(--surface); overflow: hidden; }
.group > * + * { border-top: 1px solid var(--line); }
.group-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 0 14px; color: var(--text); text-decoration: none; background: none; border: none; width: 100%; text-align: left; }
.group-row.tight { padding: 4px 4px 4px 14px; }
.group-row .pg { font-size: 12px; color: var(--teal); flex-shrink: 0; }
.letter { font-family: var(--serif); font-size: 16px; font-weight: 600; color: var(--accent); margin-bottom: 6px; }

/* ---------- scheda personaggio ---------- */
.hero { display: flex; align-items: center; gap: 16px; }
.hero h1 { font-family: var(--serif); font-size: 28px; font-weight: 600; line-height: 1.1; }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px; border-radius: 14px; background: var(--surface); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-family: var(--serif); font-size: 20px; font-weight: 600; }
.block { display: flex; flex-direction: column; gap: 8px; }
.prose { font-size: 15px; line-height: 1.45; white-space: pre-wrap; }
.note-row { display: flex; gap: 12px; align-items: baseline; }
.note-row .pg { font-size: 12px; color: var(--teal); width: 52px; flex-shrink: 0; }
.note-row .tx { font-size: 14px; line-height: 1.4; white-space: pre-wrap; flex: 1; }
.evo { position: relative; display: flex; flex-direction: column; gap: 16px; }
.evo::before { content: ''; position: absolute; left: 7px; top: 10px; bottom: 10px; width: 2px; background: var(--line); }
.evo-item { display: flex; gap: 14px; position: relative; }
.evo-item .mk { width: 12px; height: 12px; border-radius: 6px; background: var(--bg); border: 2px solid var(--teal); flex-shrink: 0; margin-top: 3px; position: relative; }
.evo-item.twist .mk { border: none; background: #E8885A; border-radius: 0; transform: rotate(45deg); width: 11px; height: 11px; margin: 4px 1px 0; }
.evo-item .h { font-size: 12px; color: var(--teal); font-weight: 600; }
.evo-item.twist .h { color: var(--twist); }
.evo-item .tx { font-size: 14px; line-height: 1.4; white-space: pre-wrap; }
.actions { display: flex; gap: 10px; }
.btn {
  height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font-size: 15px; font-weight: 600; padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; flex: 1; white-space: nowrap; min-width: 0;
}
.actions .btn { padding: 0 10px; font-size: 14px; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border: none; }
.btn.dashed { border-style: dashed; border-color: #4A5160; background: transparent; }
.btn.twist { border: 1px dashed var(--twist-line); background: transparent; color: var(--twist); }
.btn.danger { border-color: #7A3236; background: transparent; color: var(--danger-text); }
.btn.danger-fill { background: var(--danger); color: #fff; border: none; }
.btn.tall { height: 52px; font-size: 16px; }

.fab {
  position: fixed; right: max(20px, calc(50vw - 260px)); bottom: calc(var(--safe-bottom) + 28px);
  height: 56px; padding: 0 22px; border-radius: 28px; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 16px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 5;
}
.fab svg { width: 20px; height: 20px; }

/* ---------- moduli ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .lbl { font-size: 13px; color: var(--muted); }
.input, .textarea, .select {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 16px; min-width: 0;
}
.textarea { height: auto; min-height: 84px; padding: 12px 14px; resize: vertical; line-height: 1.4; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); }
.input.accent { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.hint.teal { color: var(--teal); }
.hint.warn { color: var(--twist); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.photo-pick { display: flex; align-items: center; gap: 14px; }
.photo-btn {
  width: 72px; height: 72px; border-radius: 36px; border: 1px dashed #4A5160; background: var(--surface) center/cover no-repeat;
  color: var(--muted); display: flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 0;
}
.photo-btn.cover-btn { width: 80px; height: 116px; border-radius: 8px; flex-direction: column; gap: 6px; font-size: 12px; }
.photo-btn svg { width: 24px; height: 24px; }
.tokens { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 48px; padding: 6px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.tokens .tok { font-size: 13px; padding: 5px 4px 5px 10px; border-radius: 10px; background: var(--surface-2); display: inline-flex; align-items: center; gap: 2px; }
.tokens .tok button { border: none; background: none; color: var(--muted); width: 28px; height: 28px; padding: 0; font-size: 16px; }
.tokens input { flex: 1; min-width: 90px; height: 34px; border: none; background: transparent; font-size: 15px; outline: none; }
.mini-btn { width: 44px; height: 44px; border: none; background: transparent; color: var(--muted); display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; padding: 0; }
.mini-btn.del { color: var(--danger-text); }
.mini-btn svg { width: 18px; height: 18px; }

/* ---------- vuoto ---------- */
.empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px 16px 40px; }
.empty h2 { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.empty p { font-size: 15px; line-height: 1.5; color: var(--muted); text-wrap: pretty; max-width: 320px; }

/* ---------- finestre ---------- */
#overlay:empty { display: none; }
.backdrop { position: fixed; inset: 0; background: rgba(8, 9, 11, .72); z-index: 20; display: flex; flex-direction: column; animation: fade .15s ease-out; }
.backdrop.top { justify-content: flex-start; padding: calc(var(--safe-top) + 72px) 16px 0; }
.backdrop.bottom { justify-content: flex-end; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); display: flex; flex-direction: column; gap: 14px; }
.backdrop.top .sheet { border-radius: 24px; padding: 22px 20px; }
.backdrop.bottom .sheet { border-radius: 24px 24px 0 0; padding: 20px 20px calc(var(--safe-bottom) + 28px); animation: up .2s ease-out; max-height: 88vh; overflow-y: auto; }
.sheet h2 { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.sheet .grab { align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); }
.sheet .input { background: var(--bg); }
.sheet .textarea { background: var(--bg); }
.big-input { height: 72px; font-family: var(--serif); font-size: 40px; font-weight: 600; color: var(--accent); border: 2px solid var(--accent); }
.check-list { display: flex; flex-direction: column; gap: 10px; }
.check-list div { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; line-height: 1.4; color: var(--text-2); }
.check-list svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; color: var(--teal); }
.menu { position: fixed; z-index: 21; width: 240px; border-radius: 16px; background: var(--surface-2); border: 1px solid var(--line-2); overflow: hidden; box-shadow: 0 12px 32px rgba(0,0,0,.45); }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 16px; border: none; background: none; color: var(--text); font-size: 15px; text-align: left; }
.menu button + button { border-top: 1px solid var(--line-2); }
.menu button.del { color: var(--danger-text); }
.menu svg { width: 20px; height: 20px; color: var(--accent); flex-shrink: 0; }
.menu button.del svg { color: var(--danger-text); }

#toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 100px); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; background: var(--surface-2); border: 1px solid var(--line-2); color: var(--text); padding: 12px 18px; border-radius: 14px; font-size: 14px; transition: .2s; z-index: 30; max-width: calc(100vw - 40px); }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.settings-group { display: flex; flex-direction: column; border-radius: 16px; background: var(--surface); overflow: hidden; }
.settings-group > * + * { border-top: 1px solid var(--line); }
.settings-group .srow { display: flex; align-items: center; justify-content: space-between; min-height: 56px; padding: 0 16px; font-size: 15px; background: none; border: none; color: var(--text); width: 100%; text-align: left; }
.settings-group.disabled { opacity: .55; }
.switch { width: 46px; height: 28px; border-radius: 14px; background: var(--line); display: flex; align-items: center; padding: 3px; }
.switch span { width: 22px; height: 22px; border-radius: 11px; background: var(--muted); }

.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.steps li { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 16px; background: var(--surface); font-size: 15px; line-height: 1.4; }
.steps .num { width: 32px; height: 32px; border-radius: 16px; background: var(--accent); color: var(--accent-ink); font-weight: 600; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.steps li > span:nth-child(2) { flex: 1; }
.steps svg { width: 22px; height: 22px; color: var(--text-2); flex-shrink: 0; }

mark { background: none; color: var(--accent); font-weight: 600; }

@keyframes fade { from { opacity: 0 } }
@keyframes up { from { transform: translateY(30px); opacity: .6 } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
