/* PolP-Prosition — shared styles (cards.html, graph.html) */
:root {
  --bg: #f6f4ef;
  --surface: #fffefb;
  --ink: #151515;
  --muted: #5d5a54;
  --line: #e7e2d7;
  --blue: #2340c8;
  --red: #c8283c;
  --gray: #b9b4a8;    /* neutral "sans vote" segment in the tally bars */
  --blue-soft: #c3d5ff;  /* light blue: progress fill on the reveal button */
  --blue-empty: #e6e2d8; /* neutral track behind the fill */
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Handwritten, self-hosted (no request to Google). Falls back to system handwriting fonts. */
  --hand: "Caveat", "Segoe Print", "Bradley Hand", "Chalkboard SE", cursive;
}

/* Self-hosted: 4 discrete weights, served from propositions/fonts/ (../fonts from css/). */
@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Caveat";
  src: url("../fonts/Caveat-Bold.ttf") format("truetype");
  font-weight: 700;
  font-display: swap;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 32px 32px;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 1200px; margin: 0 auto; padding-inline: 16px; }

/* Intro */
.intro { padding-block: 32px 16px; }
.kicker {
  margin: 0;
  font: 600 1.45rem/1 var(--hand);
  color: var(--muted);
}
h1 { margin: .4em 0 .3em; font-size: clamp(1.8rem, 5vw, 2.8rem); line-height: 1.1; }
h1 .hl { color: var(--blue); }
.intro p.lead { margin: 0; max-width: 60ch; color: var(--muted); }

/* Header: text on the left, big reveal button + actions in the top-right corner */
.intro { display: grid; grid-template-columns: 1fr auto; gap: 16px 32px; align-items: start; }
.reveal-box { display: flex; flex-direction: column; align-items: flex-end; gap: 14px; padding-top: 8px; }
.reveal-box .hint { text-align: right; }
.reveal-box .progress,
.reveal-box .actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.reveal-box .count { margin-right: 4px; }
#reveal { font-size: 1.6rem; padding: 22px 44px; border-width: 3px; box-shadow: 6px 6px 0 var(--ink); }
#reveal:active:not(:disabled) { transform: translate(6px, 6px); box-shadow: none; }

/* Floating "Révéler les partis" button: a compact copy that stays visible bottom-right
   while the user scrolls. JS toggles html.is-scrolled once the in-header button leaves
   the viewport. After the parties are revealed this compact copy becomes the "Total" button. */
.reveal-float {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  visibility: hidden;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}
html.is-scrolled .reveal-float {
  visibility: visible;
  opacity: 1;
  transform: none;
  transition: opacity .2s ease, transform .2s ease, visibility 0s;
}
.reveal-float .btn-primary {
  font-size: 1.05rem;
  padding: 14px 22px;
  box-shadow: 5px 5px 0 var(--ink);
}
/* After reveal the float is no longer hidden: it shows "Total" and opens the stats modal. */

/* Toolbar */
.toolbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--bg);
  border-block: 2px solid var(--ink);
}
.toolbar .wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding-block: 12px;
}
.progress { display: flex; gap: 8px; flex-wrap: wrap; }
.req {
  font: 600 .85rem/1 var(--mono);
  padding: 7px 10px;
  border: 2px dashed var(--red);
  border-radius: 999px;
  color: var(--red);
  white-space: nowrap;
}
.req.ok { border-style: solid; border-color: var(--ink); color: var(--ink); }
.req.ok::before { content: "✓ "; }
.hint { font: .85rem/1.3 var(--mono); color: var(--red); }

.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; margin-left: auto; }
.filters label { display: flex; align-items: center; gap: 6px; font: .85rem var(--mono); }
select {
  font: inherit;
  font-family: system-ui, sans-serif;
  padding: 6px 8px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}
.count { font: .85rem var(--mono); color: var(--muted); }

/* Buttons */
button { font: inherit; cursor: pointer; color: inherit; }
.btn-primary {
  padding: 10px 18px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  box-shadow: 3px 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s;
}
.btn-primary:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: none; }
.btn-primary:disabled {
  background: #e4e0d7;
  color: var(--muted);
  border-color: var(--muted);
  box-shadow: none;
  cursor: not-allowed;
}

/* "Révéler les partis": instead of going grey, the button fills left→right like a
   progress bar as the two quotas (10 votes / 6 d'accord) are met. --fill (0→1, the
   average, set by update()) drives the width of a light-blue layer; it interpolates to
   full --blue as it completes, so at 100% it's "blue like it is now" and then enabled. */
.reveal-toggle { --fill: 0; }
.btn-primary:disabled.reveal-toggle {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background: var(--blue-empty);
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: 3px 3px 0 var(--ink);
  cursor: not-allowed;
}
.btn-primary:disabled.reveal-toggle::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: calc(var(--fill) * 100%);
  z-index: -1;
  border-radius: inherit;
  background: var(--blue-soft);
  background: color-mix(in srgb, var(--blue-soft), var(--blue) calc(var(--fill) * 100%));
  transition: width .25s ease;
}
.btn-ghost {
  padding: 6px 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: 600 .9rem var(--sans);
  text-decoration: none;
}
.btn-ghost:hover { background: var(--surface); }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

/* Proposition content (cards + modal) */
.theme {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  font: 600 .72rem/1.6 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}
/* Tag icon (img/tag.svg) used as a mask so it takes the theme color (--tc) when set */
.theme::before {
  content: "";
  flex: none;
  width: 14px;
  height: 14px;
  background: var(--tc, currentColor);
  -webkit-mask: url("../img/tag.svg") center / contain no-repeat;
  mask: url("../img/tag.svg") center / contain no-repeat;
}
.text { margin: 0; flex: 1; font-size: 1.05rem; }
.votes { display: flex; gap: 8px; }
.vote {
  flex: 1;
  padding: 8px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
}
.vote:hover { background: #efece5; }
.vote[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

/* Thumbs up/down icons (img/thumbs*.svg) */
.thumb { height: 1.1em; width: auto; vertical-align: -0.2em; }
.vote[aria-pressed="true"] .thumb { filter: invert(1); }

.reveal { padding-top: 12px; border-top: 2px dashed var(--ink); animation: pop .25s ease-out; }
.reveal p { margin: 0; }
.by-label { font: .72rem var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.party { font-weight: 800; font-size: 1.1rem; }
.candidate { color: var(--muted); }
.source { display: inline-block; margin-top: 6px; font-size: .9rem; color: var(--blue); }
.source:not([href]) { color: var(--muted); text-decoration: none; }

.notice { padding-block: 24px; font-family: var(--mono); color: var(--muted); }
.notice.error { color: var(--red); }

/* Stats modal — opened by the "Total" button after the parties are revealed.
   Shared markup lives in both views; styles go here so cards + graph stay identical. */
#stats-modal {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 6px 6px 0 var(--ink);
}
#stats-modal[open] { animation: pop .2s ease-out; }
#stats-modal::backdrop { background: rgb(21 21 21 / .5); }
.sm-inner {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  max-height: calc(100dvh - 64px);
  overflow-y: auto;
}
.sm-head { display: flex; align-items: center; gap: 12px; }
.sm-head h2 { margin: 0; font-size: 1.4rem; }
.sm-close { line-height: 1; padding: 6px 10px; margin-left: auto; }

/* 1) Caution ↔ per-party tally (toggle the two panels) */
.sm-caution {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
  border: 2px dashed var(--red);
  border-radius: var(--radius);
}
.sm-warn {
  font: 700 .78rem/1.2 var(--mono);
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--red);
}
.sm-caution p { margin: 0; font-size: .95rem; }
.sm-h3 { margin: 0; font-size: 1.05rem; }
#sm-tally { display: flex; flex-direction: column; gap: 10px; }

/* Theme filter + color legend for the tally */
.sm-tally-tools { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; }
.sm-filter { display: flex; align-items: center; gap: 6px; font: 600 .85rem var(--mono); }
.sm-legend {
  display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 0;
  font: .8rem var(--mono); color: var(--muted);
}
.sm-legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 12px; height: 12px; flex: none; border: 2px solid var(--ink); border-radius: 3px; }
.lg-up { background: var(--blue); }
.lg-down { background: var(--red); }
.lg-none { background: var(--gray); }

.sm-party-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.sm-party {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--bg);
}
/* Compact header: candidate on the left (muted), then "·", then the bold party name */
.p-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.p-cand { font-size: .9rem; color: var(--muted); }
.p-sep { color: var(--muted); }
.p-name { font-weight: 800; }

/* Bar chart: a stacked 100%-width bar per party —
   d'accord = blue, pas d'accord = red, sans vote = neutral gray.
   Segments are sized proportionally by their count (flex-grow = count). */
.p-bar {
  display: flex;
  height: 24px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.p-bar .seg {
  display: flex; align-items: center; justify-content: center;
  min-width: 0;
  font: 700 .78rem var(--mono);
  color: var(--surface);
  overflow: hidden;
}
.seg-up   { background: var(--blue); }
.seg-down { background: var(--red); }
.seg-none { background: var(--gray); color: var(--ink); }

.sm-empty { margin: 0; font: .9rem var(--mono); color: var(--muted); }

/* 2) Feedback slider 1–10 (value persisted client-side; POST deferred to the backend) */
.sm-feedback { display: flex; flex-direction: column; gap: 8px; }
.sm-q { margin: 0; font-size: .95rem; font-weight: 600; }
.sm-slider-row { display: flex; align-items: center; gap: 12px; }
.sm-slider-row input[type="range"] { flex: 1; accent-color: var(--blue); }
.sm-slider-row output { min-width: 3ch; text-align: center; font: 700 1.1rem var(--mono); }

/* 3) Further info + 4) Credit */
.sm-info { display: flex; flex-direction: column; gap: 8px; font-size: .95rem; }
.sm-info a { color: var(--blue); }
.sm-muted a { color: var(--muted); text-decoration: underline; }
.sm-muted { color: var(--muted); }
.sm-credit { margin: 0; font: .85rem/1.4 var(--mono); color: var(--muted); }
.sm-credit a { color: var(--muted); text-decoration: underline; }

@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
@media (max-width: 640px) {
  .filters { margin-left: 0; width: 100%; }
  .intro { grid-template-columns: 1fr; }
  .reveal-box { align-items: stretch; padding-top: 0; }
  .reveal-box .hint { text-align: left; }
  .reveal-box .progress,
  .reveal-box .actions { justify-content: flex-start; }
}
