/* Il Comune del giorno: mobile-first stylesheet, light and dark. */
:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --ink: #1d2b26;
  --muted: #64716c;
  --line: #d9d4c7;
  --accent: #1f6f5b;
  --accent-ink: #ffffff;
  --accent-soft: #dcefe7;
  --shape: #2f8f72;
  --shape-edge: #17564a;
  --warn: #b8432d;
  --ok: #1f6f5b;
  --chip: #ece8dd;
  --shadow: 0 6px 24px rgba(20, 40, 30, .12);
  --radius: 14px;
  --max: 500px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111715;
    --panel: #1a221f;
    --ink: #e9ede9;
    --muted: #9aa8a1;
    --line: #2d3833;
    --accent: #5fcfae;
    --accent-ink: #0d1a15;
    --accent-soft: #1e3a31;
    --shape: #3fae8c;
    --shape-edge: #8fe3c8;
    --warn: #f08a72;
    --ok: #5fcfae;
    --chip: #232d29;
    --shadow: 0 6px 24px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); font-size: .9rem; }

/* Header */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 10px 12px 6px;
}
.top h1 { font-size: 1.25rem; margin: 0; letter-spacing: .01em; text-align: center; flex: 1; }
.top h1 a { color: inherit; text-decoration: none; }
.top h1 span { color: var(--accent); }
.top-right { display: flex; gap: 4px; }
.icon-btn {
  width: 40px; height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem;
}
.icon-btn svg { width: 22px; height: 22px; fill: currentColor; }
.icon-btn:hover { border-color: var(--accent); }

/* Game */
.game {
  max-width: var(--max);
  width: 100%;
  margin: 0 auto;
  padding: 0 12px 24px;
  flex: 1;
}
.day-line { margin: 2px 0 8px; text-align: center; color: var(--muted); font-size: .9rem; }
.day-line a { margin-left: 6px; }

.outline {
  margin: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}
.outline svg { display: block; width: 100%; height: auto; max-height: 52vh; margin: 0 auto; }
#outline-path { fill: var(--shape); stroke: var(--shape-edge); stroke-width: 4; stroke-linejoin: round; }
#outline-centre { fill: var(--panel); stroke: var(--ink); stroke-width: 5; }
#scale-bar line { stroke: var(--ink); stroke-width: 6; stroke-linecap: butt; }
#scale-bar text { fill: var(--ink); font-size: 36px; font-weight: 600; }
.outline figcaption { display: flex; justify-content: space-between; gap: 8px; padding: 6px 4px 0; color: var(--muted); font-size: .85rem; }
.legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--ink); background: var(--panel); vertical-align: -1px; margin-right: 3px; }

/* Hints */
.hints { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.hints li {
  background: var(--chip);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: .82rem;
  color: var(--muted);
  display: inline-flex; gap: 6px; align-items: baseline;
}
.hints li b { font-weight: 600; color: inherit; }
.hints li.on { background: var(--accent-soft); color: var(--ink); }
.hints li.on b { color: var(--accent); }
.hints li.on span { font-weight: 600; }

.photo { margin: 10px 0 0; }
.photo img { width: 100%; height: auto; max-height: 260px; object-fit: cover; border-radius: var(--radius); border: 1px solid var(--line); display: block; }
.photo figcaption { font-size: .75rem; color: var(--muted); padding: 4px 2px 0; }

/* Guesses */
.guesses { list-style: none; margin: 10px 0 0; padding: 0; display: grid; gap: 6px; }
.guesses li {
  display: grid;
  grid-template-columns: 1.5em minmax(0, 1fr) auto auto auto auto;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 10px;
  font-size: .95rem;
  animation: pop .25s ease-out;
}
.guesses li.win { border-color: var(--accent); background: var(--accent-soft); }
.g-n { color: var(--muted); font-size: .8rem; }
.g-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.g-name small { color: var(--muted); font-weight: 400; }
.g-dist { font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: right; }
.g-dir { font-size: 1.1rem; }
.g-tag { font-size: .72rem; padding: 2px 6px; border-radius: 6px; background: var(--chip); color: var(--muted); white-space: nowrap; }
.g-tag.yes { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
@keyframes pop { from { transform: scale(.97); opacity: .4; } to { transform: none; opacity: 1; } }

/* Input */
.guess-form { display: flex; gap: 8px; margin-top: 10px; }
.combo { position: relative; flex: 1; }
#guess-input {
  width: 100%;
  font: inherit; font-size: 1rem;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
}
#guess-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
#guess-input:disabled { opacity: .6; }
.guess-form button {
  padding: 0 16px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700;
}
.guess-form button:disabled { opacity: .5; cursor: default; }
.suggestions {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 4px);
  list-style: none; margin: 0; padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  max-height: 260px; overflow: auto;
  z-index: 5;
}
.suggestions li { padding: 8px 10px; border-radius: 7px; display: flex; justify-content: space-between; gap: 8px; cursor: pointer; }
.suggestions li small { color: var(--muted); }
.suggestions li.active, .suggestions li:hover { background: var(--accent-soft); }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* Result */
.result {
  margin-top: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.result h2 { margin: 0 0 4px; font-size: 1.2rem; }
.result-name { margin: 0; font-size: 1.1rem; font-weight: 700; }
.result-facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 10px; margin: 10px 0; text-align: left; }
.result-facts div { background: var(--chip); border-radius: 8px; padding: 6px 8px; }
.result-facts dt { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.result-facts dd { margin: 0; font-weight: 600; }
.result-links { margin: 6px 0 10px; font-size: .9rem; }
.result-links a + a { margin-left: 12px; }
.result-actions { display: grid; gap: 6px; }
button.primary {
  padding: 11px 16px;
  border: 0; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 1rem;
}
.loading { text-align: center; color: var(--muted); margin: 24px 0; }

/* Footer */
.bottom { max-width: var(--max); width: 100%; margin: 0 auto; padding: 8px 12px 16px; color: var(--muted); font-size: .78rem; text-align: center; }
.bottom p { margin: 4px 0; }

/* Modals */
.modal { border: 0; padding: 0; background: transparent; max-width: min(92vw, 480px); width: 100%; }
.modal::backdrop { background: rgba(10, 20, 15, .55); }
.modal-body { position: relative; background: var(--panel); color: var(--ink); border-radius: var(--radius); padding: 18px 18px 14px; box-shadow: var(--shadow); max-height: 85vh; overflow: auto; }
.modal-body h2 { margin: 0 32px 10px 0; font-size: 1.2rem; }
.modal-body h3 { margin: 14px 0 6px; font-size: .95rem; }
.modal-body p { margin: 8px 0; }
.modal .close { position: absolute; top: 10px; right: 10px; width: 34px; height: 34px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; }
.stats-grid div { background: var(--chip); border-radius: 8px; padding: 8px 4px; }
.stats-grid b { display: block; font-size: 1.4rem; }
.stats-grid span { font-size: .72rem; color: var(--muted); }
.stats-dist { display: grid; gap: 4px; }
.stats-dist .row { display: grid; grid-template-columns: 1.2em 1fr; gap: 6px; align-items: center; font-size: .85rem; }
.stats-dist .bar { background: var(--chip); border-radius: 5px; height: 20px; position: relative; }
.stats-dist .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent); border-radius: 5px; min-width: 1.4em; }
.stats-dist .bar b { position: absolute; right: 6px; top: 0; line-height: 20px; font-size: .75rem; }
.archive { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.archive li a { display: grid; grid-template-columns: 3.5em 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border-radius: 8px; background: var(--chip); color: inherit; text-decoration: none; }
.archive li a:hover { background: var(--accent-soft); }
.archive .a-n { color: var(--muted); font-size: .85rem; }
.archive .a-date { font-size: .9rem; }
.archive .a-status { font-size: .85rem; font-weight: 600; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }

/* Standalone text pages */
.page { max-width: var(--max); margin: 0 auto; padding: 8px 16px 32px; width: 100%; }
.page h1 { font-size: 1.4rem; }
.page h2 { font-size: 1.1rem; margin-top: 20px; }
.page.wide { max-width: 1100px; }
.page ul { padding-left: 1.2em; }
.page li { margin: 6px 0; }

/* Forms: newsletter and stats token */
.field-row { display: flex; gap: 8px; }
.field-row input {
  flex: 1; min-width: 0;
  font: inherit; font-size: 1rem;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
}
.field-row input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary:disabled { opacity: .5; cursor: default; }
.form-msg { margin: 6px 0 0; font-size: .9rem; min-height: 1.2em; }
.form-msg.ok { color: var(--ok); }
.form-msg.ko { color: var(--warn); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.link-btn { border: 0; padding: 0; background: none; color: var(--accent); text-decoration: underline; font-size: inherit; }

.newsletter { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); text-align: left; }
.newsletter h3 { margin: 0 0 4px; font-size: 1rem; }
.newsletter p.muted { margin: 0 0 8px; }
.newsletter-done { margin: 0; }

/* Stats panel */
.panel-bar { margin: 0 0 4px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.kpi span { font-size: .8rem; color: var(--muted); }
.kpi b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.kpi small { font-size: .75rem; color: var(--muted); }
.kpi.ok { border-color: var(--ok); }
.kpi.ok b { color: var(--ok); }
.kpi.ko { border-color: var(--warn); }
.kpi.ko b { color: var(--warn); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.stats-table { border-collapse: collapse; width: 100%; font-size: .88rem; }
.stats-table th, .stats-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; text-align: left; }
.stats-table thead th { font-size: .75rem; color: var(--muted); font-weight: 600; background: var(--chip); }
.stats-table tbody tr:last-child > * { border-bottom: 0; }
.stats-table th[scope="row"] { font-weight: 600; }
.stats-table th small { color: var(--muted); font-weight: 400; }
.stats-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.stats-table .ok { color: var(--ok); font-weight: 700; }
.stats-table .ko { color: var(--warn); font-weight: 700; }
.stats-table .dist { color: var(--muted); font-variant-numeric: tabular-nums; }
.stats-table tr.running { background: var(--accent-soft); }
