:root {
  --bg: #f6f3ec; --card: #fffdf8; --ink: #1f2421; --muted: #6b716c; --line: #e3ddd0;
  --green: #1b7f4b; --green-d: #14532d; --red: #c8102e; --blue: #2457a6; --amber: #b7791f;
  --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(20,40,30,.06);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151917; --card: #1e2421; --ink: #ecebe6; --muted: #9aa39d; --line: #2f3733;
    --green: #3fb07a; --green-d: #a7e3c3; --red: #f2637a; --blue: #7aa7ec; --amber: #e2b04a; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; padding-bottom: 84px; }
h1, h2, h3 { font-family: Georgia, "Iowan Old Style", serif; line-height: 1.2; }
h2 { margin: .6em 0 .5em; font-size: 1.5rem; }
h3 { margin: 0 0 .6em; font-size: 1.15rem; }
h4 { margin: 1.2em 0 .4em; font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
a { color: var(--blue); }

.top { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.top h1 { margin: 0; font-size: 1.2rem; color: var(--green-d); }
.top small { font-weight: 400; color: var(--muted); font-size: .85rem; }
.logo { display: inline-flex; border-radius: 4px; overflow: hidden; }
.logo i { width: 7px; height: 20px; display: block; }
.logo i:nth-child(1) { background: var(--green); } .logo i:nth-child(2) { background: #f4f1ea; } .logo i:nth-child(3) { background: var(--red); }

main { max-width: 720px; margin: 0 auto; padding: .5rem 1rem 1rem; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 10; }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; padding: .45rem 0 .5rem;
  font-size: .72rem; color: var(--muted); text-decoration: none; gap: 2px; }
.tabs a span { font-size: 1.3rem; }
.tabs a.on { color: var(--green); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.1rem; margin: .8rem 0; box-shadow: var(--shadow); position: relative; }
.center { text-align: center; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.huge { font-size: 3rem; margin: 0; }
.big { font-size: 1.2rem; }

button, .button { font: inherit; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 10px; padding: .6rem 1rem; cursor: pointer; text-decoration: none; display: inline-block;
  min-height: 44px; }
button:disabled { opacity: .55; cursor: default; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: 600; }
.wide { width: 100%; margin-top: .8rem; }
.back { border: none; background: none; padding: .3rem 0; color: var(--blue); }
.linklike { border: none; background: none; padding: 0; min-height: 0; color: var(--blue); text-decoration: underline; }
.danger { color: var(--red); margin-left: .5rem; }

input, select { font: inherit; width: 100%; padding: .7rem .8rem; border: 1px solid var(--line);
  border-radius: 10px; background: var(--card); color: var(--ink); min-height: 46px; }
input.answer { font-size: 1.2rem; }
label { display: block; margin: .6rem 0; font-size: .9rem; color: var(--muted); }
label input, label select { margin-top: .25rem; color: var(--ink); }
.row { display: flex; gap: .5rem; flex: 1; min-width: 240px; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: .5rem; }
.toolbar select { width: auto; flex: 1; }

.msg { margin: .6rem 0 0; } .msg.err { color: var(--red); } .msg.ok { color: var(--green); }
.login { max-width: 380px; margin: 2rem auto; }
.login button { width: 100%; margin-top: .6rem; }

.pill { display: inline-block; padding: .2rem .7rem; border-radius: 999px; background: var(--line); font-size: .85rem; }
.pill.blue { background: color-mix(in srgb, var(--blue) 18%, transparent); }
.pill.green { background: color-mix(in srgb, var(--green) 18%, transparent); }
.counter { display: flex; gap: .4rem; flex-wrap: wrap; }
.badge { display: inline-block; font-size: .72rem; padding: .1rem .5rem; border-radius: 6px; margin-left: .4rem;
  background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green-d); vertical-align: middle; }
.badge.red { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red); }
.flash .badge.new { position: absolute; top: .8rem; right: .8rem; }
.deck { font-size: .78rem; color: var(--muted); }

.flash { text-align: center; padding: 1.6rem 1rem; }
.face { margin: 1rem 0; display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.face .word { font-size: 2rem; font-family: Georgia, serif; }
.face.pl .word { color: var(--blue); }
.note { color: var(--muted); font-size: .95rem; }
.flash hr { border: none; border-top: 1px dashed var(--line); }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; margin-top: 1rem; }
.grades button { padding: .6rem .2rem; font-size: .9rem; font-weight: 600; }
.grades .again { border-color: var(--red); color: var(--red); }
.grades .hard { border-color: var(--amber); color: var(--amber); }
.grades .good { border-color: var(--green); color: var(--green); }
.grades .easy { border-color: var(--blue); color: var(--blue); }

.audio { display: inline-flex; gap: .3rem; vertical-align: middle; }
.audio button, .audio a { min-height: 36px; min-width: 36px; padding: .2rem .45rem; font-size: 1rem; line-height: 1.4;
  border-radius: 8px; border: 1px solid var(--line); background: var(--card); text-align: center; }
.audio a.g { font-weight: 700; text-decoration: none; color: var(--blue); font-family: Arial, sans-serif; }
.audio .rec { border-color: var(--green); }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .5rem 0; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .3rem; }
.chip { border-radius: 999px; padding: .35rem .9rem; min-height: 38px; white-space: nowrap; font-size: .92rem; }
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }
.chip.static { display: inline-block; min-height: 0; padding: .15rem .6rem; border: 1px solid var(--line); margin: .15rem; }

.prompt { font-size: 1.25rem; margin: .4rem 0 1rem; }
.it { font-family: Georgia, serif; }
.pl { color: var(--blue); }
.options { display: grid; gap: .5rem; }
.option { text-align: left; font-family: Georgia, serif; font-size: 1.1rem; }
.tokens { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 54px; padding: .5rem; border-radius: 10px; margin-bottom: .6rem; }
.tokens.line { border: 2px dashed var(--line); }
.token { font-family: Georgia, serif; font-size: 1.1rem; padding: .35rem .75rem; min-height: 40px; }
.answer-form { display: grid; gap: .5rem; }
.accents { display: flex; gap: .3rem; flex-wrap: wrap; }
.accents button { min-width: 42px; min-height: 40px; padding: .2rem; font-size: 1.1rem; }
.listen { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.big-audio { font-size: 1.1rem; flex: 1; min-height: 56px; }

.feedback { border-radius: 10px; padding: .8rem 1rem; margin-top: 1rem; }
.feedback p { margin: .4rem 0 0; }
.feedback.ok { background: color-mix(in srgb, var(--green) 14%, transparent); }
.feedback.warn { background: color-mix(in srgb, var(--amber) 18%, transparent); }
.feedback.bad { background: color-mix(in srgb, var(--red) 12%, transparent); }

.results { display: grid; gap: .4rem; margin-top: .8rem; }
.result { display: grid; grid-template-columns: auto auto 1fr; gap: .15rem .5rem; align-items: baseline;
  text-align: left; padding: .7rem .9rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink); text-decoration: none; }
.result .lemma { font-family: Georgia, serif; font-size: 1.15rem; font-weight: 600; }
.result .pos, .result .form { font-size: .8rem; color: var(--muted); }
.result .tr { grid-column: 1 / -1; color: var(--muted); font-size: .95rem; }
.lang { font-size: .68rem; font-weight: 700; padding: .1rem .35rem; border-radius: 5px; color: #fff; align-self: center; }
.lang.it { background: var(--green); } .lang.pl { background: var(--red); }
.entry-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.entry-head .lemma { margin: 0; font-size: 1.9rem; }
.entry ol { padding-left: 1.3rem; margin: 0; }
.entry li { margin: .25rem 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 1rem 0 .2rem; }
.examples { list-style: none; padding: 0; margin: 0; }
.examples li { display: flex; flex-direction: column; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.attrib { font-size: .78rem; color: var(--muted); margin-top: 1.5rem; }

.conj { display: grid; gap: .2rem 1rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.conj table { border-collapse: collapse; width: 100%; }
.conj th { text-align: left; font-weight: 400; color: var(--muted); width: 4.5rem; font-size: .9rem; }
.conj td, .conj th { padding: .2rem .3rem; border-bottom: 1px solid var(--line); }
.conj td.it { font-size: 1.08rem; }
.conj .audio button, .conj .audio a { min-height: 30px; min-width: 30px; font-size: .85rem; padding: .1rem .3rem; }
.conj .audio button:nth-child(2) { display: none; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .8rem; text-align: center; }
.tile b { display: block; font-size: 1.5rem; font-family: Georgia, serif; }
.tile span { font-size: .8rem; color: var(--muted); }
.mycards { list-style: none; padding: 0; margin: 0; }
.mycards li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
a.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none;
  display: inline-flex; align-items: center; }
a.chip.on { color: #fff; }

/* --- Raffaello e livelli --- */
.avatar { width: 40px; height: 40px; border-radius: 50%; }
.lvl { margin-left: auto; font-weight: 700; text-decoration: none; color: #fff; background: var(--green);
  border-radius: 999px; padding: .25rem .8rem; font-size: .95rem; }
.lvl-inline { font-size: .9rem; font-family: system-ui, sans-serif; font-weight: 400; margin-left: .4rem; }
.raff { display: flex; align-items: flex-start; gap: .6rem; margin: .6rem 0; text-align: left; }
.raff img { border-radius: 50%; flex: none; }
.raff.big { justify-content: center; }
.bubble { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: .5rem .8rem; box-shadow: var(--shadow); }
.bubble::before { content: ""; position: absolute; left: -7px; top: 18px; width: 12px; height: 12px;
  background: inherit; border-left: 1px solid var(--line); border-bottom: 1px solid var(--line); transform: rotate(45deg); }
.bubble p { margin: 0; }
.bubble .it { font-size: 1.05rem; }
.feedback .raff { margin-top: 0; }
.feedback .label { font-size: .85rem; color: var(--muted); margin: .5rem 0 0; }
.badge.new { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.badge.lv { margin-left: 0; font-weight: 700; color: #fff; }
.lv-A1 { background: #2e9d5b !important; } .lv-A2 { background: #1f7a8c !important; }
.lv-B1 { background: #c27c0e !important; } .lv-B2 { background: #b4233a !important; }
.level-head { display: flex; gap: .8rem; align-items: center; }
.level-head h3 { margin: 0; }
.lvbig { color: #fff; font-weight: 800; font-size: 1.3rem; border-radius: 12px; padding: .5rem .7rem; }
.card.level.current { border: 2px solid var(--green); }
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; margin: .8rem 0 .4rem; }
.bar i { display: block; height: 100%; background: var(--green); }
details.later { margin-top: 1rem; }
details.later summary { cursor: pointer; color: var(--blue); padding: .4rem 0; }
.tense-pl { text-transform: none; letter-spacing: 0; font-weight: 400; }
.conj h4 { display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.raff.angry .bubble { border-color: var(--red); }
.raff.happy .bubble { border-color: var(--green); }
.raff .say { font-weight: 700; font-size: 1.15rem; }
.raff .expl { font-size: .95rem; margin: .15rem 0; }
.flash .raff { justify-content: center; }
.toast { position: fixed; left: .8rem; right: .8rem; bottom: 86px; z-index: 20; max-width: 520px; margin: 0 auto;
  animation: pop .25s ease-out; }
.toast .raff { background: transparent; margin: 0; }
@keyframes pop { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
