:root {
  --bg: #f4f6fb; --card: #ffffff; --text: #1d2433; --muted: #637087; --line: #e2e7f0;
  --accent: #1f6feb; --accent-2: #0b4fbf; --accent-soft: #e6efff; --ok: #1a8f4c; --warn: #b26a00; --err: #c62828;
  --hl: #fff1a8; --radius: 14px; --shadow: 0 2px 10px rgba(20, 30, 60, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141c; --card: #182030; --text: #e8edf5; --muted: #95a1b5; --line: #263044;
    --accent: #5b9bff; --accent-2: #8ab8ff; --accent-soft: #1d2b45; --hl: #4a4116; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141c; --card: #182030; --text: #e8edf5; --muted: #95a1b5; --line: #263044;
  --accent: #5b9bff; --accent-2: #8ab8ff; --accent-soft: #1d2b45; --hl: #4a4116; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.err { color: var(--err); }
.ok { color: var(--ok); }

/* barra superiore */
header.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
header.top .brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; text-decoration: none; color: var(--text); }
header.top .brand img { width: 30px; height: 30px; border-radius: 8px; }
header.top nav { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
header.top nav a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; }
header.top nav a.active, header.top nav a:hover { background: var(--accent-soft); color: var(--accent); }

main { max-width: 980px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.5rem; margin: 8px 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 16px; }

/* pulsanti */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

/* form */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: .875rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
textarea { min-height: 160px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* tab */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 40px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }

/* caricamento */
.drop { border: 2px dashed var(--line); border-radius: var(--radius); padding: 24px; text-align: center; cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .3s; }

/* libreria */
.continue { display: flex; gap: 12px; align-items: center; }
.doclist { display: grid; gap: 12px; }
.doc { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: center; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.doc .icon { width: 48px; height: 48px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 800; font-size: .75rem; text-transform: uppercase; }
.doc .title { font-weight: 700; word-break: break-word; }
.doc .meta { font-size: .85rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.doc .actions { display: flex; gap: 6px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.badge.private { background: #eee3ff; color: #6b3fc4; }
.badge.err { background: #fde7e7; color: var(--err); }
.badge.work { background: #fff3dc; color: var(--warn); }
@media (prefers-color-scheme: dark) { .badge.private { background: #2c2147; color: #c3a8ff; } .badge.err { background: #3d1b1b; } .badge.work { background: #3a2c10; } }
.listened { height: 4px; background: var(--line); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.listened > div { height: 100%; background: var(--ok); }
.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: 48px; z-index: 20; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); min-width: 230px; padding: 6px; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu-list button:hover { background: var(--accent-soft); }

/* lettore */
.player-head h1 { margin-bottom: 4px; }
.now { font-size: .95rem; color: var(--muted); min-height: 1.5em; }
.timeline { display: flex; align-items: center; gap: 10px; margin: 16px 0 8px; }
.timeline input[type=range] { flex: 1; accent-color: var(--accent); height: 28px; }
.controls { display: flex; justify-content: center; align-items: center; gap: 14px; margin: 8px 0 16px; }
.cbtn { width: 64px; height: 64px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 800; font-size: .95rem; }
.cbtn.big { width: 88px; height: 88px; background: var(--accent); color: #fff; border: 0; font-size: 2rem; }
.cbtn svg { width: 28px; height: 28px; fill: currentColor; vertical-align: middle; }
.cbtn.big svg { width: 40px; height: 40px; }
.opts { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.opts select { width: auto; }
.chapters { max-height: 50vh; overflow: auto; }
.chapter { display: flex; gap: 8px; padding: 10px 8px; border-radius: 10px; cursor: pointer; align-items: center; }
.chapter:hover { background: var(--accent-soft); }
.chapter.current { background: var(--accent-soft); font-weight: 700; }
.chapter.notready { opacity: .55; cursor: default; }
.chapter .t { flex: 1; }
.reader { font-size: 1.15rem; line-height: 1.8; max-height: 60vh; overflow: auto; padding-right: 6px; }
.reader.big { font-size: 1.45rem; }
.reader span.seg { cursor: pointer; border-radius: 4px; }
.reader span.seg.on { background: var(--hl); }
.reader p { margin: 0 0 1em; }
.summary-text { white-space: pre-wrap; line-height: 1.7; }

/* modalita' guida */
.drive { position: fixed; inset: 0; z-index: 100; background: #05080d; color: #f2f5fa; display: flex; flex-direction: column;
  justify-content: space-between; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
.drive .dt { font-size: 1.4rem; font-weight: 700; text-align: center; }
.drive .dc { font-size: 1.1rem; text-align: center; color: #9fb0c8; margin-top: 6px; }
.drive .dtime { font-size: 1.2rem; text-align: center; color: #9fb0c8; }
.drive .dbtns { display: grid; grid-template-columns: 1fr 1.3fr 1fr; gap: 14px; align-items: center; }
.drive button { background: #1a2333; color: #fff; border: 0; border-radius: 24px; min-height: 120px; font-size: 1.4rem; font-weight: 800; }
.drive button.play { background: #1f6feb; min-height: 160px; font-size: 3rem; }
.drive .drow { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.drive .drow button { min-height: 80px; font-size: 1.1rem; }

/* login */
.login { max-width: 380px; margin: 10vh auto; }
.login .logo { display: block; width: 84px; height: 84px; margin: 0 auto 12px; border-radius: 20px; }
.login h1 { text-align: center; }

/* tabelle admin */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.tablewrap { overflow-x: auto; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--bg); border-radius: 12px; padding: 12px; }
.stat b { display: block; font-size: 1.4rem; }

/* notifiche */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; background: #1d2433; color: #fff;
  padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.3); max-width: calc(100% - 32px); }
#toast.err { background: var(--err); }
dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text); max-width: 520px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.45); }

@media (max-width: 640px) {
  header.top { flex-wrap: wrap; }
  header.top nav { width: 100%; margin-left: 0; }
  .doc { grid-template-columns: 40px 1fr; }
  .doc .icon { width: 40px; height: 40px; }
  .doc .actions { grid-column: 1 / -1; justify-content: flex-end; }
  .cbtn { width: 58px; height: 58px; }
}
