:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1b2430;
  --muted: #5f6b7a;
  --line: #dde3ea;
  --accent: #1f5f8b;
  --accent-ink: #ffffff;
  --accent-soft: #e3eef6;
  --star: #f0a500;
  --star-off: #c9d1db;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151b;
    --card: #19212a;
    --text: #e6ecf2;
    --muted: #98a6b4;
    --line: #2b3641;
    --accent: #5aa9e0;
    --accent-ink: #08192a;
    --accent-soft: #1d3346;
    --star: #ffc233;
    --star-off: #3a4653;
    --danger: #ff7a6e;
    --danger-soft: #3a1d1b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
[hidden] { display: none !important; }

/* 16px sui campi: sotto questa misura Safari iOS zooma al focus */
button, input, select, textarea { font: inherit; font-size: 16px; color: inherit; }

button {
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: .5; cursor: default; }
button.secondary { background: var(--accent-soft); color: var(--accent); }
button.danger { background: var(--danger); color: #fff; }
button.link {
  min-height: 36px;
  padding: 0 8px;
  background: none;
  color: var(--accent);
  font-weight: 500;
}
button.link.danger-text { color: var(--danger); }
.icon-btn { padding: 0; width: 44px; flex: 0 0 44px; font-size: 20px; }

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; color: var(--muted); }

.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; margin: 0; }
.stack { display: grid; gap: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* Barra in alto */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  display: flex;
  gap: 8px;
  max-width: 820px;
  margin: 0 auto;
  padding: 8px max(12px, env(safe-area-inset-left, 0px));
}
.search { position: relative; flex: 1 1 50%; min-width: 0; }
#student-select { flex: 1 1 40%; min-width: 0; }
.suggestions {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  max-height: 60vh;
  overflow-y: auto;
}
.suggestions li {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--accent-soft); }
.suggestions .none { color: var(--muted); cursor: default; }
.suggestions .none:hover { background: none; }

.menu {
  display: grid;
  gap: 4px;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 12px 10px;
}
.menu button { background: none; color: var(--text); text-align: left; font-weight: 500; }
.menu button:hover { background: var(--accent-soft); }

/* Contenuto */
.wrap {
  max-width: 820px;
  margin: 0 auto;
  padding: 16px max(12px, env(safe-area-inset-left, 0px)) 40px;
}
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }

.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.card-head h1 { font-size: 24px; margin: 4px 0 12px; overflow-wrap: anywhere; }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  padding: 14px 16px 16px;
  margin-bottom: 14px;
}
.panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin: 0 0 10px;
}

.plan-current {
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 17px;
}
.plan-current .muted { display: block; margin-top: 6px; white-space: normal; }
.plan-none { margin: 0 0 12px; }

details { margin-top: 12px; }
summary { cursor: pointer; color: var(--accent); font-weight: 500; min-height: 32px; }
.history { margin: 8px 0 0; padding-left: 20px; display: grid; gap: 10px; }
.history li { white-space: pre-wrap; overflow-wrap: anywhere; }
.history .muted { display: block; white-space: normal; }

/* Competenze e stelle */
.skills { list-style: none; margin: 0; padding: 0; }
.skills li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 0;
  border-bottom: 1px solid var(--line);
}
.skills li:last-child { border-bottom: 0; }
.skill-name { overflow-wrap: anywhere; }
.stars { display: flex; flex: 0 0 auto; }
.star {
  min-height: 44px;
  width: 40px;
  padding: 0;
  background: none;
  color: var(--star-off);
  font-size: 26px;
  line-height: 1;
}
.star.on { color: var(--star); }

/* Note */
.notes { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 10px; }
.note {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 6px;
}
.note-meta { font-size: 13px; color: var(--muted); }
.note-text { margin: 6px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.note audio { width: 100%; margin: 8px 0 2px; }
.note-actions { display: flex; justify-content: flex-end; gap: 4px; }
.note .stack { margin: 6px 0; }
.rec-status { font-variant-numeric: tabular-nums; color: var(--danger); font-weight: 600; }
#rec-btn.recording { background: var(--danger); color: #fff; }

.danger-zone {
  margin-top: 28px;
  padding: 16px;
  border: 1px dashed var(--danger);
  border-radius: var(--radius);
  background: var(--danger-soft);
}
.danger-zone p { margin: 8px 0 0; }

/* Dialoghi */
dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(10, 15, 20, .45); }
.dlg-body { padding: 18px; display: grid; gap: 12px; }
.dlg-body h2 { margin: 0; font-size: 20px; }
.dlg-body p { margin: 0; }
.dlg-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.manage { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.manage li { display: flex; align-items: center; gap: 6px; }
.manage li.off input[type="text"] { color: var(--muted); text-decoration: line-through; }
.manage .move { width: 40px; flex: 0 0 40px; padding: 0; }
.manage .toggle { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; font-size: 13px; }
.manage .toggle input { width: 22px; min-height: 22px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: #1b2430;
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  z-index: 100;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.toast.error { background: var(--danger); }

/* Login */
.login-page { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-box {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: var(--shadow);
}
.login-box img { border-radius: 16px; }
.login-box h1 { margin: 8px 0 20px; font-size: 22px; }
.login-box form { text-align: left; }

@media (max-width: 420px) {
  .star { width: 34px; font-size: 24px; }
  .card-head h1 { font-size: 21px; }
}
