/* ===== Italiano — Grammar Reference ===== */
:root {
  --primary: #c2185b;
  --primary-dark: #9a1150;
  --primary-soft: #e05c8f;
  --paper: #fdf2f7;
  --card: #ffffff;
  --ink: #35222b;
  --ink-soft: #86616f;
  --line: #f2dae5;
  --green: #2e8b57;
  --a1: #2e8b57;
  --a2: #2874a6;
  --b1: #d68910;
  --b2: #c0392b;
  --c1: #7d3c98;
  --c2: #1b4f72;
  --tick: #2e8b57;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(140, 40, 80, .12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--primary);
  color: #fff;
  padding: .55rem .9rem;
  padding-top: calc(.55rem + env(safe-area-inset-top));
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}

.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: 1.05rem;
  white-space: nowrap;
}
.brand-cup { font-size: 1.3rem; }
.brand-text small {
  display: block;
  font-weight: 400;
  font-size: .62rem;
  opacity: .75;
  letter-spacing: .04em;
}

.levelnav {
  display: flex;
  gap: .3rem;
  margin-left: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.levelnav::-webkit-scrollbar { display: none; }

.levelnav a {
  color: #fff;
  text-decoration: none;
  font-weight: 700;
  font-size: .85rem;
  padding: .3rem .6rem;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.35);
  opacity: .85;
}
.levelnav a.active, .levelnav a:hover { background: rgba(255,255,255,.18); opacity: 1; }
.levelnav a.home-link { border-style: dashed; }

.searchbtn {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
  padding: .3rem;
}

/* ---------- Search bar ---------- */
.searchbar {
  position: sticky;
  top: 0;
  z-index: 19;
  display: flex;
  gap: .5rem;
  padding: .6rem .9rem;
  background: var(--primary-dark);
}
.searchbar.hidden { display: none; }
.searchbar input {
  flex: 1;
  font-size: 1rem;
  padding: .5rem .8rem;
  border-radius: 8px;
  border: none;
}
.searchbar button {
  background: none;
  border: none;
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}

/* ---------- Layout ---------- */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem .9rem 3rem;
}

.footer {
  text-align: center;
  font-size: .75rem;
  color: var(--ink-soft);
  padding: 1rem 1rem 2rem;
}

h1 { font-size: 1.45rem; margin: .4rem 0 .2rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; color: var(--primary); }
.subtitle { color: var(--ink-soft); font-size: .9rem; margin: 0 0 1rem; }

/* ---------- Dashboard ---------- */
.attainment {
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: #fff;
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1.2rem;
  box-shadow: var(--shadow);
}
.attainment .headline { font-size: 1.25rem; font-weight: 800; margin: 0 0 .15rem; }
.attainment .sub { opacity: .85; font-size: .88rem; margin: 0; }

.levelgrid { display: grid; grid-template-columns: 1fr; gap: .8rem; }
@media (min-width: 640px) { .levelgrid { grid-template-columns: 1fr 1fr; } }

.levelcard {
  background: var(--card);
  border-radius: var(--radius);
  padding: .95rem 1.05rem;
  box-shadow: var(--shadow);
  border-left: 5px solid var(--lvl, var(--primary));
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: block;
  transition: transform .08s ease;
}
.levelcard:hover { transform: translateY(-1px); }
.levelcard .lc-top { display: flex; justify-content: space-between; align-items: baseline; }
.levelcard .lc-level { font-weight: 800; font-size: 1.15rem; color: var(--lvl, var(--primary)); }
.levelcard .lc-status { font-size: .78rem; font-weight: 700; }
.levelcard .lc-status.attained { color: var(--green); }
.levelcard .lc-status.progress { color: var(--ink-soft); }
.levelcard .lc-book { font-size: .8rem; color: var(--ink-soft); margin: .1rem 0 .55rem; }
.levelcard .lc-count { font-size: .8rem; color: var(--ink-soft); margin-top: .35rem; }

.bar {
  height: 10px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--lvl, var(--primary));
  border-radius: 999px;
  transition: width .3s ease;
}

.catgrid { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem .9rem; margin-top: .4rem; }
@media (min-width: 640px) { .catgrid { grid-template-columns: 1fr 1fr 1fr; } }
.catrow { font-size: .8rem; }
.catrow .cr-label { display: flex; justify-content: space-between; margin-bottom: .15rem; color: var(--ink-soft); }
.catrow .bar { height: 6px; }
.catrow .bar > span { background: var(--primary); }

.syncrow { font-size: .8rem; color: var(--ink-soft); margin-top: 1.3rem; }
.toolrow { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .5rem; }
.btn {
  font-size: .85rem;
  font-weight: 600;
  padding: .5rem .95rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn:hover { background: #fbeef4; }
.btn.danger { color: var(--b2); }

/* ---------- Level view ---------- */
.levelhead {
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  color: #fff;
  background: var(--lvl, var(--primary));
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.levelhead h1 { margin: 0; font-size: 1.3rem; }
.levelhead .lh-book { opacity: .9; font-size: .85rem; margin: .1rem 0 .6rem; }
.levelhead .bar { background: rgba(255,255,255,.3); }
.levelhead .bar > span { background: #fff; }
.levelhead .lh-count { font-size: .8rem; margin-top: .35rem; opacity: .9; }

.lessonhead {
  font-size: .8rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 1.3rem 0 .5rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.lessonhead::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Topic cards ---------- */
.topic {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: .55rem;
  border-left: 4px solid var(--lvl, var(--primary));
  overflow: hidden;
}
.topic.mastered { border-left-color: var(--tick); }
.topic.mastered .t-title { color: var(--ink-soft); }

.t-head {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .7rem .8rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.t-tick {
  flex: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: transparent;
  transition: all .15s ease;
  padding: 0;
}
.t-tick.on { background: var(--tick); border-color: var(--tick); color: #fff; }
.t-tick:hover { border-color: var(--tick); }

.t-titlewrap { flex: 1; min-width: 0; }
.t-title { font-weight: 700; font-size: .95rem; }
.t-title-en { font-weight: 400; font-size: .78rem; color: var(--ink-soft); font-style: italic; }
.t-meta { font-size: .72rem; color: var(--ink-soft); }
.t-meta .t-cat {
  display: inline-block;
  background: var(--paper);
  border-radius: 4px;
  padding: 0 .35rem;
  margin-right: .35rem;
}
.t-chev { flex: none; color: var(--ink-soft); font-size: .8rem; transition: transform .15s; }
.topic.open .t-chev { transform: rotate(90deg); }

.t-body { display: none; padding: 0 .9rem .9rem; border-top: 1px dashed var(--line); }
.topic.open .t-body { display: block; }

.t-body h4 {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-soft);
  margin: .9rem 0 .3rem;
}
.t-explanation { font-size: .9rem; margin: .6rem 0 0; white-space: pre-line; }

.extable { width: 100%; border-collapse: collapse; font-size: .87rem; }
.extable td { padding: .3rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.extable td.it { font-style: italic; color: var(--primary); font-weight: 600; width: 55%; }
.extable tr:last-child td { border-bottom: none; }

.t-pitfalls, .t-extra {
  font-size: .85rem;
  border-radius: 8px;
  padding: .55rem .7rem;
  margin-top: .3rem;
  white-space: pre-line;
}
.t-pitfalls { background: #fdf3e3; border: 1px solid #f0dcb4; }
.t-extra { background: #eef5ee; border: 1px solid #cfe3cf; }

/* ---------- Search results ---------- */
.sr-level {
  display: inline-block;
  font-size: .68rem;
  font-weight: 800;
  color: #fff;
  border-radius: 4px;
  padding: 0 .35rem;
  margin-right: .35rem;
  background: var(--lvl, var(--primary));
}
.noresults { color: var(--ink-soft); text-align: center; padding: 2rem 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-dark);
  color: #fff;
  font-size: .85rem;
  padding: .55rem 1rem;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0,0,0,.3);
  z-index: 50;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.toast.show { opacity: 1; }

@media (max-width: 480px) {
  .brand-text small { display: none; }
  main { padding: .8rem .6rem 3rem; }
}
