:root {
  --bg: #f4f2ee; --ink: #22252b; --muted: #6b7079; --line: #e2ded6; --card: #ffffff;
  --accent: #2f6f6a; --accent-soft: #e3f0ee; --warn: #b5562f; --warn-soft: #f8e7df;
  --ok: #2e7d4f; --ok-soft: #e2f3e8; --speak: #c2410c; --type: #1d4ed8; --danger: #c0392b;
  --radius: 18px; --shadow: 0 10px 30px rgba(34, 37, 43, .10);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg);
       color: var(--ink); -webkit-text-size-adjust: 100%; }
#app { max-width: 480px; margin: 0 auto; height: 100dvh; min-height: 560px; position: relative; overflow: hidden; }
[hidden] { display: none !important; }
button, input { font: inherit; }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 14px; padding: 18px 18px 22px;
          padding-top: max(18px, env(safe-area-inset-top)); padding-bottom: max(22px, env(safe-area-inset-bottom));
          overflow-y: auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex: none; }
.brand { font-weight: 700; } .brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
h1 { font-size: 24px; margin: 6px 0 0; } h2 { font-size: 18px; margin: 4px 0; }
p { margin: 0; line-height: 1.45; } .muted { color: var(--muted); } .small { font-size: 13px; } .note { font-size: 12px; color: var(--muted); }
.center { text-align: center; } .grow { flex: 1; }
.panel { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
label { font-size: 13px; color: var(--muted); display: block; margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 16px; background: #fff; color: var(--ink); }
textarea { width: 100%; min-height: 120px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; font: 14px ui-monospace, Menlo, monospace; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--muted); margin-top: 10px; line-height: 1.4; }
.check input { margin-top: 2px; flex: none; width: 18px; height: 18px; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; min-height: 1px; }
.btn { width: 100%; padding: 13px; border-radius: 14px; border: 0; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.danger { background: var(--danger); } .btn.small { width: auto; padding: 9px 14px; font-size: 14px; }
.row { display: flex; gap: 10px; align-items: center; } .row > * { flex: 1; }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; background: none; border: 0; padding: 0; font-size: inherit; }
.pill { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 7px 13px; font-size: 14px; cursor: pointer; }
.iconbtn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; cursor: pointer; font-size: 17px; }
.banner { border-radius: 14px; padding: 12px 14px; font-size: 14px; background: #fff4d6; }

/* ---- lingue ---- */
.lang { display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 16px; background: var(--card); box-shadow: 0 3px 10px rgba(0,0,0,.05); cursor: pointer; border: 2px solid transparent; width: 100%; text-align: left; }
.lang:hover { border-color: var(--accent); } .flag { font-size: 28px; }

/* ---- home ---- */
.screen.home { overflow: hidden; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 2px 2px 10px;
          -webkit-mask-image: linear-gradient(to bottom, #000 calc(100% - 18px), transparent); mask-image: linear-gradient(to bottom, #000 calc(100% - 18px), transparent); }
.dock { flex: none; margin: 0 -18px -22px; padding: 12px 18px 22px; padding-bottom: max(22px, env(safe-area-inset-bottom)); background: var(--card);
        border-radius: 22px 22px 0 0; box-shadow: 0 -8px 24px rgba(34,37,43,.10); }
.ask-box { display: flex; gap: 8px; margin-top: 10px; } .ask-box input { flex: 1; }
.ask-box .btn { width: auto; padding: 0 18px; }
.swipe { position: relative; border-radius: 16px; overflow: hidden; flex: none; }
.swipe .del-bg { position: absolute; inset: 0 0 0 auto; width: 96px; background: var(--danger); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; cursor: pointer; border: 0; }
.swipe .del-bg.amber { background: #b7791f; }
.menu-item { display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 16px; padding: 14px; box-shadow: 0 3px 10px rgba(0,0,0,.05); cursor: pointer; position: relative; width: 100%; border: 0; text-align: left; color: inherit; }
.swipe .menu-item { transition: transform .22s ease; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.swipe.open .menu-item { transform: translateX(-96px); }
.menu-item .ic { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 19px; background: var(--accent-soft); flex: none; }
.menu-item .t { flex: 1; min-width: 0; } .menu-item .t small { display: block; color: var(--muted); font-size: 12px; }
.count { background: var(--accent); color: #fff; border-radius: 999px; padding: 2px 9px; font-size: 13px; }
.dots { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); font-size: 20px; cursor: pointer; flex: none; background: none; border: 0; }
.dots:hover { background: #f0ede7; }
@media (hover: none) { .dots { display: none; } }
.pop { position: absolute; right: 6px; top: 46px; z-index: 5; background: #fff; border-radius: 12px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 6px; min-width: 200px; }
.pop button { display: block; width: 100%; text-align: left; padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; background: none; border: 0; color: var(--danger); }
.pop button:hover { background: #f4f2ee; }
.sheet-bg { position: absolute; inset: 0; background: rgba(20,22,26,.45); display: flex; align-items: flex-end; z-index: 20; }
.sheet { background: #fff; width: 100%; border-radius: 22px 22px 0 0; padding: 20px 18px 24px; }

/* ---- scheda che si gira ---- */
.tag { display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; padding: 4px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.flip { perspective: 1400px; flex: 1; min-height: 300px; max-height: 520px; }
.flip-inner { position: relative; width: 100%; height: 100%; transition: transform .6s cubic-bezier(.3,.7,.3,1); transform-style: preserve-3d; }
.flip.turned .flip-inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; background: var(--card); border-radius: 24px;
        box-shadow: var(--shadow); padding: 20px; display: flex; flex-direction: column; align-items: center; justify-content: space-between; text-align: center; gap: 10px; overflow-y: auto; }
.face.back { transform: rotateY(180deg); }
.meaning { font-size: 26px; font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.question { font-size: 14px; color: var(--muted); }
.answer-word { font-size: 38px; font-weight: 750; overflow-wrap: anywhere; } .answer-phrase { font-size: 24px; font-weight: 700; line-height: 1.3; overflow-wrap: anywhere; }
.hint { font-family: ui-monospace, Menlo, monospace; font-size: 18px; letter-spacing: 1px; color: var(--accent); margin-top: 8px; }
.verdict { display: inline-flex; gap: 8px; align-items: center; border-radius: 999px; padding: 6px 14px; font-weight: 700; }
.verdict.ok { background: var(--ok-soft); color: var(--ok); } .verdict.no { background: var(--warn-soft); color: var(--warn); }
.noticebox { background: var(--accent-soft); border-radius: 12px; padding: 8px 12px; font-size: 13.5px; text-align: left; width: 100%; }
.chat { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.bubble { max-width: 86%; padding: 9px 12px; border-radius: 16px; font-size: 15px; line-height: 1.35; background: #f4f2ee; align-self: flex-start; text-align: left; border-bottom-left-radius: 4px; }
.bubble small { display: block; color: var(--muted); font-size: 12px; margin-top: 3px; }
.controls { width: 100%; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.typing { display: flex; gap: 8px; width: 100%; } .typing input { flex: 1; } .typing .btn { width: auto; padding: 0 18px; }
.yesno { display: flex; gap: 10px; width: 100%; } .yesno .btn { flex: 1; }
.helpers { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; flex: none; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 13px; font-size: 14px; cursor: pointer; }
.chip.warn { color: var(--warn); }

/* ---- varie ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; } td, th { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; width: min(440px, calc(100% - 28px)); background: #22252b; color: #fff; border-radius: 12px; padding: 11px 14px; display: flex; align-items: center; justify-content: space-between; z-index: 40; font-size: 14px; }
.toast-undo { background: none; border: 0; color: #f2b544; font-weight: 700; cursor: pointer; }
.loading { position: fixed; inset: 0; background: rgba(244,242,238,.82); display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; z-index: 50; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toggle { display: flex; align-items: flex-start; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); } .toggle:last-child { border-bottom: 0; }
.toggle .t { flex: 1; } .toggle .t small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ---- voce (passo D) ---- */
.action { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 100%; }
.big { width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center; font-size: 40px; border: 0; color: #fff; cursor: pointer;
       box-shadow: 0 8px 20px rgba(0,0,0,.18); }
.big.speak { background: var(--speak); } .big.type { background: var(--type); }
.what { font-weight: 700; font-size: 15px; } .speak-c { color: var(--speak); }
.listening .big, .listening .iconbtn { animation: pulse 1s infinite; }
.listening .iconbtn { background: var(--speak); color: #fff; border-color: var(--speak); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(194,65,12,.45); } 70% { box-shadow: 0 0 0 18px rgba(194,65,12,0); } 100% { box-shadow: 0 0 0 0 rgba(194,65,12,0); } }
.rep { display: flex; gap: 6px; justify-content: center; } .rep i { width: 26px; height: 6px; border-radius: 9px; background: var(--line); }
.rep i.done { background: var(--speak); }
.play { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 999px;
        padding: 6px 12px; font-size: 13px; cursor: pointer; color: var(--ink); }
.bubble .play { padding: 2px 7px; font-size: 12px; vertical-align: middle; }
.said { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.advice { width: 100%; text-align: left; background: #f6f3ff; border-radius: 14px; padding: 10px 12px; font-size: 13.5px; }
.advice.good { background: var(--ok-soft); } .advice.pending { background: #f1f1f1; color: var(--muted); }
.advice-tray { display: flex; flex-direction: column; gap: 6px; flex: none; }
.advice-tray:empty { display: none; }
.sw { width: 46px; height: 28px; border-radius: 99px; background: var(--line); position: relative; cursor: pointer; flex: none; border: 0; padding: 0; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.sw.on { background: var(--accent); } .sw.on::after { left: 21px; } .sw:disabled { cursor: default; }
.voice { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.voice:last-child { border-bottom: 0; } .voice .t { flex: 1; cursor: pointer; } .voice .t small { color: var(--muted); font-size: 12px; }
.radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; background: #fff; padding: 0; flex: none; }
.radio.on { border: 7px solid var(--accent); }
.mic-wrap { flex: none; display: flex; } .ask-box .iconbtn { width: 46px; height: 46px; }
