:root {
  --bg: #f4efe6;
  --surface: #fffdf8;
  --surface-2: #efe8db;
  --ink: #2a2620;
  --ink-2: #6b6357;
  --line: #e2d9c8;
  --accent: #d2552d;
  --accent-ink: #fff;
  --w1: #e07a3f;
  --w2: #4f9a6a;
  --w3: #3f7fbf;
  --w4: #a35bb0;
  --chip: #f1e6d3;
  --chip-ink: #6d5330;
  --shadow: 0 1px 2px rgba(60, 40, 10, .06), 0 6px 20px rgba(60, 40, 10, .06);
  --radius: 18px;
  --tabs-h: 64px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1a17;
    --surface: #25231f;
    --surface-2: #2f2c27;
    --ink: #f1ebe0;
    --ink-2: #a89f91;
    --line: #3a362f;
    --accent: #f0794f;
    --accent-ink: #1b1a17;
    --w1: #f0955f;
    --w2: #6dbb88;
    --w3: #6aa3dc;
    --w4: #c584d1;
    --chip: #3a3229;
    --chip-ink: #e5c99f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  padding-top: env(safe-area-inset-top);
}
.top-inner {
  max-width: 560px; margin: 0 auto;
  padding: 14px 16px 10px;
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
}
.eyebrow { margin: 0; font-size: 13px; color: var(--ink-2); font-weight: 500; }
h1 { margin: 2px 0 0; font-size: 28px; line-height: 1.1; letter-spacing: -.02em; font-weight: 750; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface);
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: var(--ink-2); stroke-width: 1.8; stroke-linecap: round; }

main { max-width: 560px; margin: 0 auto; padding: 8px 16px 0; outline: none; }

/* ---------- cards ---------- */
.stack { display: grid; gap: 12px; }
.card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card.link { transition: transform .12s ease; }
.card.link:active { transform: scale(.985); }
.card.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.card.past { opacity: .6; }
.card.hero { padding: 18px 18px 8px; margin-bottom: 8px; }
.card.hero h2 { font-size: 22px; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 6px; }
.card h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; font-weight: 700; }
.kicker {
  margin: 0 0 2px; font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--accent);
}
.wk {
  flex: none; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  color: var(--wc); background: color-mix(in srgb, var(--wc) 14%, transparent);
}
.w1 { --wc: var(--w1); } .w2 { --wc: var(--w2); } .w3 { --wc: var(--w3); } .w4 { --wc: var(--w4); }

.courses { list-style: none; margin: 0; padding: 0; }
.courses li {
  display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: center;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.courses li:first-child { border-top: 0; }
.ico {
  width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2);
  display: grid; place-items: center; font-size: 22px; line-height: 1;
}
.txt { display: grid; gap: 1px; min-width: 0; }
.hero .courses li { grid-template-columns: 52px 1fr; gap: 14px; padding: 12px 0; }
.hero .ico { width: 52px; height: 52px; border-radius: 16px; font-size: 30px; }
.hero .courses li:not(.minor) .dish { font-size: 18px; font-weight: 600; }
.courses li.minor .dish { color: var(--ink-2); }
.courses li.minor .ico { background: transparent; }
.lbl { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); }
.dish { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.courses.compact li { padding: 4px 0; border: 0; grid-template-columns: 30px 1fr; gap: 8px; }
.courses.compact .ico { width: 30px; height: 30px; font-size: 18px; border-radius: 9px; }
.courses.compact .dish { font-size: 15px; }

/* ---------- oggi senza mensa ---------- */
.rest {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 32px 20px 20px; text-align: center;
}
.rest-icon { font-size: 56px; line-height: 1; }
.rest p { font-size: 18px; font-weight: 600; margin: 14px 0 18px; }
.btn.ghost {
  display: block; background: var(--surface-2); color: var(--ink); font-weight: 600; text-align: center;
}

.chips { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.chip {
  font-size: 11px; font-weight: 600; text-decoration: none;
  padding: 1px 6px; border-radius: 6px;
  background: var(--chip); color: var(--chip-ink);
}

.empty { margin: 6px 0 6px; color: var(--ink-2); }
.notice {
  background: var(--surface-2); border-radius: 14px; padding: 12px 14px;
  color: var(--ink-2); margin-bottom: 12px; font-size: 15px;
}
.section {
  margin: 22px 2px 10px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2);
}
.back { display: inline-block; padding: 6px 0 12px; color: var(--accent); font-weight: 600; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 14px; }
.pg {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; font-size: 26px; line-height: 1;
  background: var(--surface); border: 1px solid var(--line);
}
.pg.off { opacity: .3; pointer-events: none; }
.pg-title { text-align: center; display: grid; }
.pg-title strong { font-size: 17px; }
.pg-title span { font-size: 13px; color: var(--ink-2); }

/* ---------- calendario ---------- */
.cal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 14px; box-shadow: var(--shadow); }
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dow span { text-align: center; font-size: 12px; font-weight: 600; color: var(--ink-2); padding: 4px 0; }
.cell {
  aspect-ratio: 1; border: 0; border-radius: 12px; background: transparent;
  display: grid; place-items: center; position: relative; cursor: pointer; padding: 0;
  font-size: 15px; font-weight: 500;
}
.cell.pad { pointer-events: none; }
.cell.none { color: var(--ink-2); opacity: .55; }
.cell.has { background: color-mix(in srgb, var(--wc) 12%, transparent); }
.cell.has::after {
  content: ""; position: absolute; bottom: 6px; width: 5px; height: 5px; border-radius: 50%; background: var(--wc);
}
.cell.is-today span { color: var(--accent); font-weight: 800; }
.cell.sel { background: var(--ink); color: var(--bg); opacity: 1; }
.cell.sel span { color: var(--bg); }
.cell.sel::after { background: var(--bg); }
.cal-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; padding: 10px 0 2px; font-size: 12px; color: var(--ink-2); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--wc); margin-right: 5px; vertical-align: 0; }

/* ---------- tab bar ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 186px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--ink-2);
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.active { color: var(--accent); }

/* ---------- dialog ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 20px; width: min(92vw, 400px);
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
dialog h2 { margin: 0 0 12px; font-size: 20px; }
.legend { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.legend li { display: flex; align-items: center; gap: 10px; }
.legend .chip { min-width: 38px; text-align: center; }
.fine { font-size: 13px; color: var(--ink-2); margin: 8px 0; }
.btn {
  width: 100%; margin-top: 8px; padding: 12px; border: 0; border-radius: 12px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; cursor: pointer;
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
