:root {
  --bg: #f6f1ea;
  --surface: #fffdf9;
  --surface-2: #efe8de;
  --text: #2a2420;
  --muted: #74685e;
  --line: #e2d8cb;
  --accent: #c2552d;
  --accent-text: #ffffff;
  --accent-soft: #f7e3d9;
  --warn: #9a5b00;
  --warn-soft: #fdf0d5;
  --ok: #2f7a4b;
  --ok-soft: #e1f2e6;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 6%), 0 4px 16px rgb(60 40 20 / 6%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1916;
    --surface: #25221e;
    --surface-2: #302c27;
    --text: #f1ebe4;
    --muted: #a99d91;
    --line: #3b362f;
    --accent: #e2774d;
    --accent-text: #1b1916;
    --accent-soft: #3d2a20;
    --warn: #f1b44c;
    --warn-soft: #3a2f1a;
    --ok: #6cc28c;
    --ok-soft: #1f3327;
    --danger: #ff8a80;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1916; --surface: #25221e; --surface-2: #302c27; --text: #f1ebe4; --muted: #a99d91; --line: #3b362f;
  --accent: #e2774d; --accent-text: #1b1916; --accent-soft: #3d2a20; --warn: #f1b44c; --warn-soft: #3a2f1a;
  --ok: #6cc28c; --ok-soft: #1f3327; --danger: #ff8a80; --shadow: none; color-scheme: dark;
}

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

h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; font-size: 1.75rem; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1.05rem; }
.lead { color: var(--muted); font-size: 1.05rem; margin: 10px 0 24px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.hint { color: var(--muted); font-size: 0.875rem; margin-top: 16px; }
.eyebrow { margin: 0 0 2px; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; max-width: 640px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.mark {
  width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-family: Georgia, serif; font-size: 1.1rem;
}

main { max-width: 640px; margin: 0 auto; padding: 8px 16px 48px; }
.screen.center { text-align: center; padding-top: 18vh; }
.screen.center h2 { margin-top: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 44px; padding: 10px 18px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.big { width: 100%; min-height: 54px; font-size: 1.05rem; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.875rem; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.link { background: none; border: 0; padding: 6px 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; }
.link.small { font-size: 0.875rem; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 1.2rem; cursor: pointer; flex: none;
}
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

.error { color: var(--danger); font-weight: 500; margin-top: 12px; }
.warn { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 10px; font-size: 0.9rem; margin: 12px 0 0; }

/* caricamento */
.drop {
  display: grid; place-items: center; min-height: 240px; margin-bottom: 16px;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  color: var(--muted); cursor: pointer; overflow: hidden; position: relative;
}
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-text { display: grid; justify-items: center; gap: 8px; font-weight: 600; }
.drop.has-img { border-style: solid; padding: 8px; }
.drop img { max-width: 100%; max-height: 50vh; border-radius: 8px; display: block; }

.spinner {
  width: 44px; height: 44px; margin: 0 auto; 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); } }

/* revisione */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 4px; scrollbar-width: none; }
.tab {
  flex: none; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); font: inherit; font-size: 0.9rem; cursor: pointer;
}
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.week-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.date-edit { display: grid; gap: 2px; font-size: 0.75rem; color: var(--muted); }
.date-edit input, .seg input {
  font: inherit; font-size: 1rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-height: 44px;
}

.summary {
  list-style: none; padding: 0; margin: 18px 0 28px; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); overflow: hidden;
}
.sum-row {
  display: grid; grid-template-columns: 76px 1fr 28px; align-items: center; gap: 8px;
  padding: 12px 14px; border-top: 1px solid var(--line); cursor: pointer;
}
.sum-row:first-child { border-top: 0; }
.sum-row:hover { background: var(--surface-2); }
.sum-day { color: var(--muted); font-variant-numeric: tabular-nums; }
.sum-day b { color: var(--text); }
.sum-val { font-weight: 600; font-variant-numeric: tabular-nums; }
.sum-row.riposo .sum-val, .sum-row.altro .sum-val { color: var(--muted); font-weight: 400; }
.sum-flag {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 0.8rem; font-weight: 700;
}
.sum-row.doubt { background: var(--warn-soft); }
.sum-row.doubt .sum-flag { background: var(--warn); color: var(--surface); }
.sum-row.checked .sum-flag { background: var(--ok-soft); color: var(--ok); }

.section-title { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.badge {
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; background: var(--warn); color: var(--surface);
  font-size: 0.8rem; display: inline-grid; place-items: center;
}
.ok-all { background: var(--ok-soft); color: var(--ok); padding: 12px 14px; border-radius: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--warn);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 14px 0; scroll-margin-top: 16px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
#editor .card { border-left-color: var(--accent); }
.card.is-checked { border-left-color: var(--ok); }
.card.flash { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 45%, transparent); }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; margin-bottom: 12px; }
.raw { color: var(--muted); font-size: 0.8rem; font-family: ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }

.zoom { margin: 0 0 12px; }
.zoom-img {
  display: block; width: 100%; max-height: 300px; object-fit: contain; background: var(--surface-2);
  border-radius: 10px; cursor: zoom-in; min-height: 120px;
}
.zoom figcaption { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; }
.zoom-label { color: var(--muted); font-size: 0.85rem; }

.reasons { margin: 0 0 14px; padding: 10px 12px 10px 30px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; font-size: 0.9rem; }
.reasons li + li { margin-top: 4px; }

.seg-control { display: grid; grid-template-columns: 1fr 1fr 1.6fr; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; margin-bottom: 12px; }
.seg-control button {
  min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted);
  font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.seg-control button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.segments { display: grid; gap: 8px; margin-bottom: 12px; }
.seg { display: flex; align-items: center; gap: 8px; }
.seg input { flex: 1; min-width: 0; font-variant-numeric: tabular-nums; }
.dash { color: var(--muted); }

.btn.check { width: 100%; }
.btn.check.on { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.confirm-bar {
  position: sticky; bottom: 0; margin: 28px -16px 0; padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); display: grid; gap: 6px;
}
.confirm-bar p { margin: 0; }
.restart { width: 100%; margin-top: 8px; }

/* fatto */
.done-mark {
  width: 64px; height: 64px; border-radius: 50%; background: var(--ok-soft); color: var(--ok);
  display: grid; place-items: center; font-size: 2rem; margin: 24px 0 16px;
}
.done-list { list-style: none; padding: 0; margin: 0 0 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.done-list li { padding: 10px 14px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.done-list li:first-child { border-top: 0; }
#screen-done .btn { width: 100%; margin-bottom: 10px; }

/* visore */
.viewer { position: fixed; inset: 0; background: rgb(0 0 0 / 92%); z-index: 10; display: flex; flex-direction: column; }
.viewer-bar { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top)); }
.viewer-scroll { flex: 1; overflow: auto; padding: 0 8px 16px; }
.viewer-scroll img { display: block; margin: 0 auto; max-width: none; }

@media (max-width: 380px) {
  .seg-control { grid-template-columns: 1fr 1fr; }
  .seg-control button:last-child { grid-column: span 2; }
}
