/* Charte du jeu : un formulaire administratif des années 90, papier et tampon rouge.
   Polices système uniquement : aucune requête vers un service extérieur. */
:root {
  color-scheme: light;
  --paper: #f4efe2;
  --sheet: #fbf8ef;
  --ink: #23272e;
  --muted: #5d6068;
  --line: #bdb6a3;
  --blue: #1f4e8c;
  --red: #b3261e;
  --green: #2f7d4f;
  --form-font: "Courier New", Courier, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 15px/1.4 system-ui, "Segoe UI", Roboto, sans-serif;
}

h1, h2, p { margin: 0; }

button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, canvas:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
}
[hidden] { display: none !important; }

/* En-tête */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 8px 16px;
  background: var(--blue);
  color: #fff;
}
.brand h1 { font-size: 24px; letter-spacing: 1px; line-height: 1.1; }
.brand p { font-size: 12px; opacity: .85; }

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin: 0;
  flex: 1;
  justify-content: flex-end;
}
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; opacity: .85; }
.stats dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats dd.bad, .stats span.bad { color: #ffc9c4; }

.gauge {
  display: inline-block;
  position: relative;
  width: 70px;
  height: 8px;
  margin-left: 4px;
  background: rgba(255, 255, 255, .25);
  border-radius: 4px;
  overflow: hidden;
  vertical-align: middle;
}
.gauge span { display: block; height: 100%; width: 50%; background: #fff; }
/* Le trait marque les 50 % : le seuil de l'élection. */
.gauge i { position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; background: #ffd34d; }

/* Bulle du budget : elle s'ouvre sous l'en-tête, au survol ou au clic. */
.budget-box { position: relative; }
.budget-btn {
  padding: 0;
  background: none;
  border: 0;
  color: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.stat-tip {
  position: absolute;
  z-index: 6;
  top: calc(100% + 6px);
  left: 0;
  width: min(390px, calc(100vw - 32px));
  padding: 12px 14px;
  background: var(--sheet);
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, .25);
  font-size: 14px;
  font-weight: 400;
}
.stat-tip-right { left: auto; right: 0; }
.stat-tip h3 { margin: 0 0 4px; font-size: 16px; }
.stat-tip h4 { margin: 10px 0 2px; font: 700 12px var(--form-font); text-transform: uppercase; }
.stat-tip p { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* Frise du mandat */
.timeline-wrap {
  display: flex;
  align-items: stretch;
  gap: 8px;
  max-width: 1800px;
  margin: 10px auto 0;
  padding: 0 16px;
}
.timeline {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  flex: 1;
  gap: 2px;
  min-width: 0;
}
.year {
  position: relative;
  min-height: 44px;
  padding: 4px 8px;
  overflow: hidden;
  background: var(--sheet);
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.25;
}
.year .fill {
  position: absolute;
  inset: 0 auto 0 0;
  background: #d8e5f6;
}
.year .label { position: relative; display: block; font-weight: 700; font-variant-numeric: tabular-nums; }
.year .detail { position: relative; display: block; color: var(--muted); font-size: 12px; }
.year.current { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.year.good .detail { color: var(--green); font-weight: 600; }
.year.bad .detail { color: var(--red); font-weight: 600; }

.election-box { position: relative; flex: 0 0 auto; }
.election-btn {
  height: 100%;
  min-height: 44px;
  padding: 4px 12px;
  background: var(--red);
  border: 0;
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
}
.election-tip {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  right: 0;
  width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  background: var(--sheet);
  border: 2px solid var(--ink);
  box-shadow: 6px 6px 0 rgba(0, 0, 0, .25);
  font-size: 14px;
}
.election-tip h3 { margin: 0 0 4px; font-size: 16px; }
.election-tip p { margin-bottom: 8px; }
.forecast { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.forecast td { padding: 2px 0; border-bottom: 1px dotted var(--line); }
.forecast td:last-child { text-align: right; font-weight: 700; white-space: nowrap; padding-left: 10px; }
.forecast .plus { color: var(--green); }
.forecast .minus { color: var(--red); }
.forecast tr.total td { border-bottom: 0; border-top: 2px solid var(--ink); font-size: 16px; font-weight: 700; }

/* Disposition générale */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "board side" "gazette side";
  gap: 10px 12px;
  max-width: 1800px;
  margin: 0 auto;
  padding: 8px 16px 12px;
}
.board { grid-area: board; position: relative; min-width: 0; }
.side { grid-area: side; }
.gazette { grid-area: gazette; }

canvas {
  display: block;
  /* Le plan grandit avec la fenêtre, sans jamais repousser la Gazette hors de l'écran. */
  width: min(100%, calc((100vh - 340px) * 960 / 580));
  min-width: min(100%, 500px);
  aspect-ratio: 960 / 580;
  height: auto;
  margin: 0 auto;
  background: var(--sheet);
  border: 1px solid var(--line);
  touch-action: manipulation;
}

/* La bande d'événements garde toujours sa place : le plan ne bouge jamais sous le curseur. */
.crisis {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 4px 10px;
  margin-bottom: 6px;
  background: #e9e3d2;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
}
.crisis.active { background: var(--red); color: #fff; font-weight: 600; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}
.controls button {
  padding: 4px 10px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 3px;
}
#achievements-btn { font-weight: 600; }
.controls button[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }
.promise-line { margin-left: auto; font-size: 13px; color: var(--muted); text-align: right; }
.promise-line.ok { color: var(--green); font-weight: 600; }

/* Bon de commande */
.side h2, .gazette h2 {
  font: 700 14px var(--form-font);
  text-transform: uppercase;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 4px;
  margin-bottom: 8px;
}
.side h2 small { display: block; font-weight: 400; text-transform: none; color: var(--muted); }

.actions-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.tool-action {
  white-space: nowrap;
  padding: 6px 2px;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-weight: 600;
  font-size: 13px;
}
.tool-action[aria-pressed="true"] { background: #e8f0fb; outline: 3px solid var(--blue); outline-offset: -1px; }
kbd { font: 11px var(--form-font); color: var(--muted); }

.campaign-btn {
  display: block;
  width: 100%;
  margin-bottom: 8px;
  padding: 5px 8px;
  text-align: left;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.3;
}
.campaign-btn strong { display: block; font-size: 14px; }
.campaign-btn.buyable { box-shadow: 0 0 0 2px var(--green); }
.campaign-btn.locked { background: #ece7d9; color: var(--muted); }
.campaign-btn.active { background: #fff3c9; border-color: #b58a12; }

.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; margin-bottom: 6px; }
.tab {
  padding: 5px 2px;
  background: #e9e3d2;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
}
.tab[aria-pressed="true"] { background: var(--blue); border-color: var(--blue); color: #fff; }

.tools { display: grid; gap: 5px; max-height: 520px; overflow-y: auto; padding: 3px; }
.tool {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 0 8px;
  width: 100%;
  padding: 5px 8px;
  text-align: left;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-left: 5px solid var(--swatch, var(--line));
  border-radius: 3px;
}
.tool .icon { font-size: 20px; grid-row: span 3; align-self: center; }
.tool .name { font-weight: 600; font-size: 14px; }
.tool .cost { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }
.tool .figures { grid-column: 2 / 4; font-size: 12px; font-weight: 600; color: var(--blue); line-height: 1.25; }
.tool .desc { grid-column: 2 / 4; font-size: 12px; color: var(--muted); line-height: 1.25; }
.tool[aria-pressed="true"] { outline: 3px solid var(--blue); outline-offset: -1px; background: #e8f0fb; }
.tool.poor .cost { color: var(--red); }
.tool.needed { box-shadow: 0 0 0 2px var(--red); }
.wing-btn:disabled { background: #e6efe0; cursor: default; }
.tool.locked { background: #ece7d9; }
.tool.locked .name, .tool.locked .icon { opacity: .6; }
.tool.locked .cost { color: var(--blue); }
.tool.buyable { box-shadow: 0 0 0 2px var(--green); }

/* La fiche flotte sur le coin vide du plan : le catalogue ne bouge pas quand elle s'ouvre. */
.info {
  position: absolute;
  z-index: 3;
  top: 56px;
  left: 8px;
  width: min(290px, calc(100% - 16px));
  max-height: 340px;
  overflow-y: auto;
  padding: 8px 10px;
  background: var(--sheet);
  border: 1px solid var(--ink);
  box-shadow: 3px 3px 0 rgba(0, 0, 0, .2);
  font-size: 13px;
}
.info h3 { margin: 0 20px 2px 0; font-size: 14px; }
.info h4 { margin: 8px 0 2px; font: 700 12px var(--form-font); text-transform: uppercase; }
.info p { margin: 0; }
.info .hint { color: var(--muted); margin-top: 4px; }
.info ul { list-style: none; margin: 0; padding: 0; }
.info li { display: flex; justify-content: space-between; gap: 8px; font-variant-numeric: tabular-nums; }
.info li.done { color: var(--muted); }
.info li.current { font-weight: 700; color: var(--blue); }
.info .plus { color: var(--green); font-weight: 600; white-space: nowrap; }
.info .minus { color: var(--red); font-weight: 600; white-space: nowrap; }
.info-close { position: absolute; top: 4px; right: 4px; padding: 0 6px; background: none; border: 0; font-size: 16px; }
.patience-gauge { height: 10px; margin: 2px 0 4px; background: #e2dccb; border: 1px solid var(--line); }
.patience-gauge span { display: block; height: 100%; }

/* Le guide de la première année : il flotte sur le coin vide du plan. */
.tutorial {
  position: absolute;
  z-index: 3;
  right: 8px;
  bottom: 52px;
  width: min(340px, calc(100% - 16px));
  padding: 10px 12px;
  background: #fff7d6;
  border: 2px solid var(--ink);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, .2);
  font-size: 14px;
  line-height: 1.35;
}
.tutorial h3 { margin: 0 0 4px; font: 700 12px var(--form-font); text-transform: uppercase; }
.tutorial p { margin: 0 0 8px; }
.tutorial .tutorial-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tutorial button { padding: 3px 10px; background: var(--sheet); border: 1px solid var(--ink); border-radius: 3px; font-size: 13px; }
.tutorial button.tutorial-ok { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 700; }
.hint-target { outline: 3px solid #d08a12; outline-offset: -1px; animation: hint-pulse 1.1s ease-in-out infinite; }
@keyframes hint-pulse { 50% { outline-color: #ffd34d; } }
@media (prefers-reduced-motion: reduce) { .hint-target { animation: none; } }

/* Le bilan de défaite */
.report { margin: 6px 0 12px; padding: 8px 10px; background: #fff; border: 1px solid var(--line); }
.report p { margin: 8px 0 0; }

/* Succès */
.toast {
  position: fixed;
  z-index: 10;
  right: 16px;
  bottom: 16px;
  width: min(330px, calc(100vw - 32px));
  padding: 10px 12px;
  background: var(--ink);
  color: #fff;
  box-shadow: 4px 4px 0 rgba(0, 0, 0, .25);
  font-size: 14px;
}
.toast strong { display: block; color: #ffd34d; }
.trophies { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px; max-height: 50vh; overflow-y: auto; padding: 2px; }
.trophy { padding: 6px 8px; background: #fff; border: 1px solid var(--line); font-size: 13px; line-height: 1.3; }
.trophy strong { display: block; font-size: 14px; }
.trophy.locked { background: #ece7d9; color: var(--muted); }

.version { margin: 0; padding: 0 16px 10px; font: 12px var(--form-font); color: var(--muted); text-align: center; }

/* Gazette */
#news {
  list-style: none;
  margin: 0;
  padding: 0;
  height: 76px;
  overflow-y: auto;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
}
#news li { padding: 3px 0; border-bottom: 1px dotted var(--line); }
#news li:first-child { font-weight: 700; }

/* Fenêtres de décision */
dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 22px 24px;
  background: var(--sheet);
  color: var(--ink);
  border: 2px solid var(--ink);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(30, 34, 42, .55); }
dialog .ref {
  font: 12px var(--form-font);
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
  margin-bottom: 10px;
}
dialog h2 { font-size: 24px; margin-bottom: 8px; line-height: 1.2; }
dialog h3 { margin: 12px 0 4px; font-size: 15px; }
dialog p { margin-bottom: 10px; }
dialog ul { margin: 0 0 12px; padding-left: 20px; }
dialog li { margin-bottom: 4px; }

.choices { display: grid; gap: 8px; margin-top: 10px; }
.choice {
  display: block;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 5px solid var(--blue);
}
.choice:hover { background: #e8f0fb; }
.choice strong { display: block; font-size: 16px; }
.choice .flavor { display: block; color: var(--muted); font-size: 14px; }
.choice .effect { display: block; margin-top: 2px; font-weight: 600; font-size: 14px; }

.review-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.review-grid div { padding: 6px 8px; background: #fff; border: 1px solid var(--line); }
.review-grid b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.review-grid span { font-size: 12px; color: var(--muted); }

.shop { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 5px; max-height: 240px; overflow-y: auto; padding: 2px; }
.shop button {
  padding: 5px 8px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
}
.shop button:disabled { opacity: .55; cursor: not-allowed; }
.shop button b { color: var(--blue); float: right; padding-left: 6px; }

.primary {
  padding: 10px 18px;
  background: var(--blue);
  color: #fff;
  border: 0;
  font-weight: 700;
}
.secondary {
  padding: 10px 18px;
  background: transparent;
  border: 1px solid var(--blue);
  color: var(--blue);
  font-weight: 700;
}
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

#access-input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--ink);
  font: 16px var(--form-font);
}
.access-error { min-height: 1.4em; margin: 6px 0 0; color: var(--red); font-weight: 600; }

.result { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.1; }
.result.won { color: var(--green); }
.result.lost { color: var(--red); }
.stamp {
  display: inline-block;
  padding: 2px 12px;
  margin: 2px 0 10px;
  border: 3px solid currentColor;
  font: 700 22px var(--form-font);
  transform: rotate(-3deg);
}
.stamp.won { color: var(--green); }
.stamp.lost { color: var(--red); }

textarea {
  width: 100%;
  height: 110px;
  font: 13px var(--form-font);
  padding: 6px;
  resize: none;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

@media (max-width: 1000px) {
  /* Sur petit écran, les bulles s'étalent en largeur pour ne jamais sortir de la page. */
  .budget-box { position: static; }
  .stat-tip, .stat-tip-right { position: fixed; top: 96px; left: 16px; right: 16px; width: auto; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "board" "side" "gazette"; }
  .tools { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); max-height: none; }
  .stats { justify-content: flex-start; }
  .promise-line { margin-left: 0; text-align: left; }
  .timeline-wrap { flex-wrap: wrap; }
  .timeline { flex-basis: 100%; }
  .year .detail { display: none; }
  .election-box { flex: 1; }
  .election-btn { width: 100%; }
  .election-tip { left: 0; right: auto; }
  .review-grid { grid-template-columns: repeat(2, 1fr); }
}
