:root {
  --bg: #f3f4f1;
  --surface: #ffffff;
  --surface-2: #f2f3ef;
  --surface-3: #e9ebe5;
  --border: #e1e4dd;
  --border-strong: #cdd2c8;
  --text: #191c1a;
  --muted: #5b635d;
  --faint: #8a928c;
  --accent: #0a7a54;
  --accent-hover: #086646;
  --accent-soft: #e0f1e8;
  --accent-softer: #f0f8f4;
  --on-accent: #ffffff;
  --warn: #a86400;
  --warn-soft: #fbf0dc;
  --danger: #bf3a2b;
  --danger-soft: #fbe8e5;
  --shadow: 0 1px 2px rgb(20 28 24 / 0.05), 0 6px 20px rgb(20 28 24 / 0.05);
  --shadow-pop: 0 10px 40px rgb(20 28 24 / 0.16), 0 2px 6px rgb(20 28 24 / 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1211;
    --surface: #171b19;
    --surface-2: #1d2220;
    --surface-3: #252b28;
    --border: #2a302d;
    --border-strong: #3a423e;
    --text: #e7ebe8;
    --muted: #a0a9a3;
    --faint: #737c76;
    --accent: #3fcf93;
    --accent-hover: #5ad9a4;
    --accent-soft: #163327;
    --accent-softer: #12261d;
    --on-accent: #06281a;
    --warn: #f0b34a;
    --warn-soft: #2f2412;
    --danger: #f07a68;
    --danger-soft: #341a16;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.2);
    --shadow-pop: 0 12px 40px rgb(0 0 0 / 0.5), 0 2px 6px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, Cantarell, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.i {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  padding: 32px 20px 48px;
}

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.logo { width: 44px; height: 44px; flex: none; border-radius: 12px; }
h1 { font-size: 21px; line-height: 1.2; margin: 0; letter-spacing: -0.015em; font-weight: 700; }
.tagline { margin: 2px 0 0; color: var(--muted); font-size: 14px; }

/* ---------- Banner ---------- */

.banner {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; margin-bottom: 16px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft); color: var(--danger);
  font-weight: 500;
}

/* ---------- Drop zone ---------- */

.drop {
  display: flex; align-items: center; justify-content: center; gap: 20px;
  padding: 44px 24px;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color .15s, background .15s, padding .25s;
}
.drop:hover, body.dragging .drop { border-color: var(--accent); background: var(--accent-softer); }
.drop-icon {
  display: grid; place-items: center;
  width: 60px; height: 60px; flex: none;
  border-radius: 18px;
  background: var(--accent-soft); color: var(--accent);
}
.drop-icon .i { width: 28px; height: 28px; }
.drop-text { display: flex; flex-direction: column; gap: 3px; }
.drop-text strong { font-size: 17px; font-weight: 650; }
.drop-text span { color: var(--muted); }
.drop-text u { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.drop-text small { color: var(--faint); font-size: 12.5px; margin-top: 2px; }

body.has-items .drop { padding: 18px 22px; justify-content: flex-start; }
body.has-items .drop-icon { width: 44px; height: 44px; border-radius: 13px; }
body.has-items .drop-icon .i { width: 22px; height: 22px; }
body.has-items .drop-text strong { font-size: 15px; }
body.has-items .drop-text small { display: none; }

.drag-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.drag-overlay div {
  padding: 22px 34px; border-radius: var(--radius);
  background: var(--accent); color: var(--on-accent);
  font-size: 18px; font-weight: 650;
  box-shadow: var(--shadow-pop);
}
body.dragging .drag-overlay { opacity: 1; }

/* ---------- List header ---------- */

.list-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin: 28px 0 12px;
}
.count { font-weight: 600; color: var(--muted); }
.list-actions { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.switch { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; cursor: pointer; color: var(--muted); font-weight: 500; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track { width: 32px; height: 18px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .15s; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / .25); transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 13px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 550; font-size: 14px;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn .i { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-3); color: var(--text); }
.btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.btn.done { color: var(--accent); border-color: var(--accent-soft); background: var(--accent-softer); }

.icon-btn {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  border: 0; border-radius: 8px;
  background: transparent; color: var(--faint);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- Cards ---------- */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
  overflow: hidden;
  animation: card-in .25s ease-out;
}
.card::before {
  content: ""; position: absolute; left: 0; top: 0; height: 3px;
  width: calc(var(--progress, 0) * 100%);
  background: var(--accent);
  transition: width .5s ease;
  opacity: 0;
}
.card[data-status="running"] { border-color: color-mix(in srgb, var(--accent) 35%, var(--border)); }
.card[data-status="running"]::before { opacity: 1; }

.card-head { display: flex; align-items: flex-start; gap: 14px; }

.play {
  display: grid; place-items: center;
  width: 44px; height: 44px; flex: none;
  border-radius: 50%;
  border: 0;
  background: var(--accent); color: var(--on-accent);
  transition: transform .1s, background .12s;
}
.play:hover { background: var(--accent-hover); }
.play:active { transform: scale(.94); }
.play svg { width: 20px; height: 20px; fill: currentColor; }
.play.paused svg { margin-left: 3px; }

.info { flex: 1; min-width: 0; }
.title-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.title { font-weight: 650; font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.meta { color: var(--faint); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; flex: none;
  margin-left: auto;
  font-size: 12.5px; font-weight: 600;
  padding: 3px 9px; border-radius: 99px;
  background: var(--surface-3); color: var(--muted);
  white-space: nowrap; font-variant-numeric: tabular-nums;
}
.badge .i { width: 13px; height: 13px; stroke-width: 2.5; }
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.busy { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--danger-soft); color: var(--danger); }
.badge.busy::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }

.player { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.time { font-size: 12.5px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 78px; text-align: right; }

.seek {
  --fill: 0%;
  flex: 1; min-width: 0; height: 18px; margin: 0;
  appearance: none; -webkit-appearance: none;
  background: transparent; cursor: pointer;
}
.seek::-webkit-slider-runnable-track {
  height: 5px; border-radius: 99px;
  background: linear-gradient(to right, var(--accent) var(--fill), var(--surface-3) var(--fill));
}
.seek::-moz-range-track { height: 5px; border-radius: 99px; background: var(--surface-3); }
.seek::-moz-range-progress { height: 5px; border-radius: 99px; background: var(--accent); }
.seek::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 13px; height: 13px; margin-top: -4px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--accent);
  transform: scale(0); transition: transform .12s;
}
.seek::-moz-range-thumb {
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  transform: scale(0); transition: transform .12s;
}
.card:hover .seek::-webkit-slider-thumb, .seek:focus-visible::-webkit-slider-thumb, .card.is-current .seek::-webkit-slider-thumb { transform: scale(1); }
.card:hover .seek::-moz-range-thumb, .seek:focus-visible::-moz-range-thumb, .card.is-current .seek::-moz-range-thumb { transform: scale(1); }
.seek:focus-visible { outline: none; }
.seek:focus-visible::-webkit-slider-runnable-track { outline: 2px solid var(--accent); outline-offset: 3px; }

/* ---------- Transcript ---------- */

.transcript {
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 16px; line-height: 1.7;
  overflow-wrap: anywhere;
}
.transcript p { margin: 0 0 .7em; }
.transcript p:last-child { margin-bottom: 0; }

.seg { border-radius: 4px; cursor: pointer; transition: background .15s; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
.seg:hover { background: var(--surface-2); }
.seg.active { background: var(--accent-soft); }

.transcript.timed .seg { display: flex; gap: 14px; padding: 3px 8px; margin: 0 -8px; }
.ts {
  flex: none; font-size: 12.5px; font-weight: 600; color: var(--accent);
  font-variant-numeric: tabular-nums; padding-top: 4px; min-width: 38px;
}

.placeholder { color: var(--faint); font-style: italic; }
.empty-note { color: var(--muted); }
.err-box { display: flex; gap: 10px; align-items: flex-start; color: var(--danger); font-size: 15px; }
.err-box .i { margin-top: 4px; }

.caret {
  display: inline-block; width: 2px; height: 1.1em; margin-left: 3px;
  vertical-align: -0.15em; background: var(--accent);
  animation: blink 1s steps(1) infinite;
}

.skeleton { display: flex; flex-direction: column; gap: 10px; padding: 4px 0; }
.skeleton span {
  height: 11px; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 50%, var(--surface-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton span:nth-child(1) { width: 92%; }
.skeleton span:nth-child(2) { width: 78%; }
.skeleton span:nth-child(3) { width: 55%; }

.editor {
  display: block; width: 100%;
  margin: 16px 0 0; padding: 12px 14px;
  min-height: 120px; resize: vertical;
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 16px; line-height: 1.7;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.editor:focus { outline: none; }

.actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.actions:empty { display: none; }
.actions .spacer { flex: 1; }
.actions .note { font-size: 12.5px; color: var(--faint); }

/* ---------- Footer & toast ---------- */

.foot {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 36px; color: var(--faint); font-size: 13px; text-align: center;
}
.foot .i { width: 14px; height: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 99px;
  background: var(--text); color: var(--bg);
  font-weight: 550; font-size: 14px;
  box-shadow: var(--shadow-pop);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Animations ---------- */

@keyframes pulse { 50% { opacity: .35; } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Small screens ---------- */

@media (max-width: 640px) {
  .app { padding: 20px 16px 40px; }
  .top { flex-direction: column; align-items: stretch; }
  .drop { flex-direction: column; text-align: center; padding: 32px 18px; }
  body.has-items .drop { flex-direction: row; text-align: left; }
  .tagline { font-size: 13px; }
  .card { padding: 14px 14px 12px; }
  .title-row { flex-wrap: wrap; gap: 4px 10px; }
  .title { white-space: normal; }
  .badge { margin-left: 0; }
  .time { min-width: 0; }
}

/* ---------- Vocabolario ---------- */

.vocab {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.vocab summary {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  cursor: pointer; list-style: none;
  color: var(--muted);
  border-radius: var(--radius-sm);
}
.vocab summary::-webkit-details-marker { display: none; }
.vocab summary:hover { background: var(--surface-2); }
.vocab summary .i { width: 16px; height: 16px; }
.vocab-title { font-weight: 600; color: var(--text); white-space: nowrap; }
.vocab-summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.vocab-summary.set { color: var(--accent); font-weight: 500; }
.vocab[open] .chevron { transform: rotate(180deg); }
.vocab-body { padding: 2px 14px 14px; }
.vocab textarea {
  display: block; width: 100%; resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2);
  line-height: 1.5;
}
.vocab textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--faint); }

/* ---------- Utente (servizio online) ---------- */

.user { display: flex; align-items: center; gap: 2px; flex: none; }
.user-name {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 600; font-size: 14px; color: var(--muted);
  padding: 0 6px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-name .i { width: 16px; height: 16px; }

/* ---------- Pagina di accesso ---------- */

.login-body { display: grid; place-items: center; padding: 24px 16px; }
.login {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 36px 28px 30px;
  text-align: center;
}
.login-logo { width: 56px; height: 56px; border-radius: 15px; }
.login h1 { margin-top: 16px; }
.login-sub { color: var(--muted); margin: 6px 0 24px; }
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
  padding: 11px 13px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface-2);
  font-size: 16px;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
.login-error {
  margin: 0; padding: 10px 12px; border-radius: 9px;
  background: var(--danger-soft); color: var(--danger);
  font-size: 14px; font-weight: 500;
}
.login-btn { justify-content: center; padding: 11px 16px; font-size: 15px; margin-top: 4px; }
.login-btn:disabled { opacity: .7; cursor: progress; }


/* ---------- Suggerimento per telefono ---------- */

.phone-hint {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 10px; padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--accent-softer);
  border: 1px solid var(--accent-soft);
  color: var(--text); font-size: 14px; line-height: 1.45;
}
.phone-hint > .i { color: var(--accent); }
.phone-hint > span { flex: 1; min-width: 200px; }
.phone-hint b { font-weight: 650; }

/* ---------- Finestra cambio password ---------- */

.dialog {
  width: min(400px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-pop);
}
.dialog::backdrop { background: rgb(0 0 0 / 0.4); }
.dialog h2 { margin: 0 0 4px; font-size: 18px; letter-spacing: -0.01em; }
.dialog form { display: flex; flex-direction: column; gap: 14px; }
.dialog .hint { margin: 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---------- Vocali senza audio (già trascritti o aperti da un altro dispositivo) ---------- */

.card.no-audio .play,
.card.no-audio .player { display: none; }
.card.no-audio .seg { cursor: text; }
.card.no-audio .seg:hover { background: transparent; }

/* ---------- Login: resta collegato ---------- */

.remember {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; color: var(--muted); cursor: pointer; user-select: none;
}
.remember input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }

/* ---------- Condivisione da iPhone (Comando Rapido) ---------- */

.link-btn {
  border: 0; background: none; padding: 0; margin-left: 4px;
  color: var(--accent); font: inherit; text-decoration: underline; text-underline-offset: 3px;
}
.dialog.wide {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  overflow: hidden;
}
.dialog.wide[open] { display: flex; flex-direction: column; }
.dialog-body { padding: 22px 22px 14px; overflow-y: auto; }
.dialog.wide .dialog-actions { padding: 12px 22px 16px; border-top: 1px solid var(--border); }
.dialog-intro { color: var(--muted); margin: 8px 0 16px; font-size: 14.5px; }
.steps {
  margin: 0; padding-left: 22px;
  display: flex; flex-direction: column; gap: 18px;
  font-size: 14.5px; line-height: 1.55;
}
.steps > li::marker { font-weight: 700; color: var(--accent); }
.substeps { margin: 8px 0 0; padding-left: 20px; display: flex; flex-direction: column; gap: 7px; }
.substeps ul { margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.key-box { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; }
.key-box .hint { margin: 0; }
.key-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.key-fields { display: flex; flex-direction: column; gap: 10px; }
.copy-field { display: flex; flex-direction: column; gap: 4px; }
.copy-field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.copy-row { display: flex; gap: 6px; }
.copy-row input {
  flex: 1; min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--border-strong); border-radius: 8px;
  background: var(--surface-2);
  font: 13px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
code {
  font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2); padding: 1px 5px; border-radius: 5px;
}

.lang-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 9px; background: var(--surface-2); margin-bottom: 14px; }
.lang-switch button {
  border: 0; background: transparent; padding: 5px 12px; border-radius: 7px;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
.lang-switch button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.steps + .steps { margin-top: 18px; }
.steps .aside { color: var(--faint); font-size: 13px; }
.sym { font-size: 1.05em; }
.fallback { margin: 18px 0 0; }

/* Fase 0: quota, eliminazione account */
.quota { margin: 10px 2px 0; font-size: 13px; color: var(--faint); font-variant-numeric: tabular-nums; }
.dialog-actions .spacer { flex: 1; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-fill:hover { filter: brightness(1.08); background: var(--danger); color: #fff; }
