/*
 * Même palette que la carte (bois, laiton, brique, charbon) et cadres à angles droits,
 * pour que l'interface prolonge le pixel art au lieu de s'en distinguer.
 */
:root {
  --soot: #17130f;
  --coal: #120f0b;
  --wood-dk: #2c241c;
  --wood: #3a2c1f;
  --plank: #4a3524;
  --line: #5a3b22;
  --paper: #efe4cc;
  --muted: #a8977b;
  --brass: #c8964a;
  --brass-hi: #e3b56a;
  --brick: #a24b30;
  --up: #9fe07a;
  --down: #ff8a6a;
  --pixel: 'VT323', 'Courier New', monospace;      /* chiffres et logo : pixel mais lisible */
  --title: 'Spectral SC', Georgia, serif;           /* titres : serif d'époque, très lisible */
  --sans: system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--soot);
  background-image: repeating-linear-gradient(0deg, transparent 0 15px, rgba(255, 255, 255, 0.015) 15px 16px),
    repeating-linear-gradient(90deg, transparent 0 15px, rgba(255, 255, 255, 0.015) 15px 16px);
  color: var(--paper);
  font: 14px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
  min-height: 100vh;
}

h1, h2, h3, .obj-title, .banner, .ctx-name, .howto-step > b, .winner { font-family: var(--title); font-weight: 700; }
.brand, .big, .howto-step .n, .sector-head b { font-family: var(--pixel); font-weight: 400; }
h2 { margin: 0 0 8px; font-size: 17px; letter-spacing: 0.5px; color: var(--brass-hi); }
h3 { margin: 0 0 8px; font-size: 16px; color: var(--brass-hi); }
b { font-weight: 600; }
.muted { color: var(--muted); }
.up { color: var(--up); }
.ico { width: 18px; height: 18px; image-rendering: pixelated; vertical-align: -3px; margin-right: 5px; }
kbd {
  font: 600 11px var(--sans); padding: 0 5px; border: 1px solid var(--brass); border-bottom-width: 3px;
  color: var(--brass-hi); background: var(--coal);
}
.portrait {
  display: inline-block; flex: none; width: 32px; height: 32px; image-rendering: pixelated;
  background-repeat: no-repeat; background-color: var(--plank); border: 2px solid var(--coal); outline: 2px solid var(--line);
}

/* Cadre pixel : double filet bois + laiton, coins droits */
.frame, .panel, .viewport, .context, .sheet, .help {
  background: var(--wood-dk);
  border: 2px solid var(--coal);
  outline: 2px solid var(--line);
  outline-offset: 0;
  box-shadow: inset 0 0 0 2px var(--wood), 4px 4px 0 rgba(0, 0, 0, 0.45);
}

/* ---------- Bande supérieure ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 26px;
  padding: 6px 18px;
  background: var(--wood);
  border-bottom: 4px solid var(--coal);
  box-shadow: inset 0 -2px 0 var(--brass);
}
.brand { font-size: 32px; line-height: 0.9; letter-spacing: 4px; color: var(--brass-hi); margin-right: auto; text-shadow: 2px 2px 0 var(--coal); }
.brand span { display: block; font: 11px var(--sans); letter-spacing: 1px; color: var(--muted); text-shadow: none; }
.stat { display: flex; flex-direction: column; min-width: 92px; }
.label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); white-space: nowrap; }
.label .ico { width: 12px; height: 12px; vertical-align: -1px; margin-right: 4px; }
.big { font-size: 30px; line-height: 1; text-shadow: 2px 2px 0 var(--coal); }
#clock.urgent { color: var(--brass-hi); }
#clock.critical { color: var(--down); animation: pulse 0.5s steps(2) infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.chrono { width: 220px; }
.small-big { font-size: 24px; color: var(--muted); }
.bar { height: 10px; margin-top: 5px; background: var(--coal); border: 1px solid var(--line); }
#time-bar { height: 100%; width: 100%; background: repeating-linear-gradient(90deg, var(--brass) 0 6px, var(--brass-hi) 6px 8px); transition: width 0.25s steps(4); }
#time-bar.low { background: repeating-linear-gradient(90deg, var(--brick) 0 6px, var(--down) 6px 8px); }
.dilemma { background: var(--wood); border-left: 4px solid var(--brass); padding: 10px 12px; margin: 14px 0 6px; }
.dilemma b { color: var(--brass-hi); }
dd.up { color: var(--up); }

/* ---------- Disposition ---------- */
/* Tout tient dans un écran : la carte prend la place disponible, la colonne défile seule si besoin. */
.topbar { flex: none; }
.layout {
  flex: 1; min-height: 0; width: 100%;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr); gap: 16px;
  padding: 12px 16px; max-width: 1600px; margin: 0 auto;
}
.stage { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; min-width: 0; min-height: 0; }
.side { min-height: 0; overflow-y: auto; padding: 2px 6px 6px 2px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
@media (max-width: 980px) {
  body { overflow: auto; height: auto; }
  .layout { grid-template-columns: 1fr; grid-template-rows: auto; }
  .side { overflow: visible; }
}

.viewport { position: relative; padding: 2px; background: var(--coal); line-height: 0; max-width: 100%; }
#world { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }

.banner {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  padding: 6px 18px; line-height: 1.3;
  background: var(--coal); border: 2px solid var(--brass);
  font-size: 20px; color: var(--brass-hi); white-space: nowrap;
  opacity: 0; pointer-events: none;
}
.banner.show { opacity: 1; }
.banner.critical { color: var(--down); border-color: var(--down); }

#toasts { position: absolute; left: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; pointer-events: none; line-height: 1.4; }
.toast {
  background: var(--coal); border: 2px solid var(--brass);
  padding: 5px 10px; font-size: 13px; animation: fade 2.6s steps(6, end) forwards;
}
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Barre d'action sous la carte ---------- */
.context { max-width: 100%; height: 56px; padding: 0 14px; display: flex; align-items: center; overflow: hidden; flex: none; }
.context > * { width: 100%; }
.offer {
  position: absolute; right: 10px; bottom: 10px; width: min(430px, calc(100% - 20px)); line-height: 1.35;
  background: rgba(34, 28, 22, 0.96); border: 2px solid var(--coal); outline: 2px solid var(--brass);
  box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.5); padding: 10px 12px; font-size: 13px;
}
.offer h3 { font-size: 15px; margin-bottom: 6px; }
.offer dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0 0 8px; }
.offer dt { color: var(--muted); }
.offer dd { margin: 0; }
.offer dd.neg { color: var(--down); }
.hint { margin: 2px 0; color: var(--paper); }
.ctx-line { display: flex; align-items: center; gap: 8px 16px; white-space: nowrap; }
.ctx-line > span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; }
.hint { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-name { font-size: 17px; color: var(--brass-hi); }
.ctx-line button { margin-left: auto; }
.ctx-panel dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 16px; margin: 0 0 10px; }
.ctx-panel dt { color: var(--muted); }
.ctx-panel dd { margin: 0; }
.ctx-panel dd.neg { color: var(--down); }
.ctx-actions { display: flex; gap: 8px; }

/* ---------- Colonne latérale ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.panel { padding: 10px 12px; }
.objective { background: #33281a; box-shadow: inset 0 0 0 2px var(--brass), 4px 4px 0 rgba(0, 0, 0, 0.45); }
.objective p { margin: 4px 0 8px; }
.obj-title { font-size: 17px; color: var(--paper); }
.steps { display: flex; gap: 4px; margin-bottom: 8px; }
.steps span { width: 22px; height: 6px; background: var(--coal); border: 1px solid var(--line); }
.steps span.done { background: var(--brass); }
.steps span.now { background: var(--brass-hi); animation: pulse 0.8s steps(2) infinite; }

.sector { padding: 7px 0; border-bottom: 2px dotted var(--line); }
.sector:last-child { border-bottom: 0; }
.sector-head { display: flex; justify-content: space-between; font-size: 14px; }
.sector-head b { font-size: 22px; line-height: 1; color: var(--brass-hi); }
.sector-trend { display: flex; align-items: center; gap: 8px; margin: 2px 0; font-size: 12px; }
.spark { width: 96px; height: 24px; flex: none; background: var(--coal); border: 1px solid var(--line); }
.spark path { stroke: var(--muted); }
.spark.up path { stroke: var(--up); }
.spark.down path { stroke: var(--down); }
.sector-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; font-size: 12px; color: var(--muted); }
.sector-meta .chip { margin-left: auto; }
.trend.up { color: var(--up); }
.trend.down { color: var(--down); }
.trend.flat { color: var(--muted); }

.asset { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 2px dotted var(--line); }
.asset:last-child { border-bottom: 0; }
.asset small { display: block; color: var(--muted); font-size: 11px; margin-left: 23px; }
.asset.building { grid-template-columns: 1fr auto; color: var(--muted); }
.num { text-align: right; }
.empty { color: var(--muted); font-style: italic; margin: 4px 0; }

.rival { display: flex; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 2px dotted var(--line); }
.rival:last-child { border-bottom: 0; }
.rival-meta { font-size: 12px; }
.rival-meta .ico { width: 14px; height: 14px; margin-right: 2px; }

#journal { list-style: none; margin: 0; padding: 0; font-size: 12px; }
#journal li { padding: 2px 0; color: var(--muted); }
#journal li b { color: var(--paper); font-weight: normal; }
#journal .ico { width: 13px; height: 13px; margin-right: 2px; }

button {
  font: 600 14px var(--sans); cursor: pointer;
  border: 2px solid var(--coal); outline: 2px solid var(--brass-hi); outline-offset: -4px;
  background: var(--brass); color: var(--coal);
  padding: 7px 14px; box-shadow: 3px 3px 0 var(--coal);
}
button:hover:not(:disabled) { background: var(--brass-hi); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--coal); }
button:disabled { cursor: not-allowed; background: var(--wood); color: var(--muted); outline-color: var(--line); }
button.ghost { background: var(--wood); color: var(--brass-hi); outline-color: var(--line); }
button.ghost:hover:not(:disabled) { background: var(--plank); }
button.small, button.chip { padding: 2px 9px; font-size: 12px; box-shadow: 2px 2px 0 var(--coal); }
button.chip { background: var(--plank); color: var(--paper); outline-color: var(--line); margin: 2px 2px 2px 0; }
button.chip .ico { width: 14px; height: 14px; }
button kbd { border-color: currentColor; color: inherit; background: transparent; }

/* ---------- Aide (non bloquante) ---------- */
.help { position: fixed; right: 20px; top: 84px; z-index: 6; max-width: 360px; padding: 14px 16px; }
.help ul { margin: 6px 0; padding-left: 18px; }
.help li { margin: 4px 0; }
.hidden { display: none !important; }

/* ---------- Accueil / résultats ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(18, 15, 11, 0.72);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet { max-width: 780px; width: 100%; max-height: 92vh; overflow: auto; padding: 26px 28px; }
.sheet h1 { margin: 0; font-family: var(--pixel); font-weight: 400; font-size: 64px; line-height: 1; color: var(--brass-hi); letter-spacing: 6px; text-shadow: 3px 3px 0 var(--coal); }
.sheet .sub { color: var(--muted); margin: 6px 0 14px; }
.sheet .sub b { color: var(--paper); }
.sheet .actions { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 20px; }
.sheet input[type=text], .sheet input:not([type]) { font: inherit; background: var(--coal); color: var(--paper); border: 2px solid var(--line); padding: 6px; width: 130px; margin-left: 6px; }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--brass); width: 16px; height: 16px; }

.howto { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
@media (max-width: 640px) { .howto { grid-template-columns: 1fr; } }
.howto-step { background: var(--wood); border: 2px solid var(--coal); padding: 10px 12px; position: relative; }
.howto-step .n {
  font-size: 20px;
  position: absolute; top: -10px; left: -6px; width: 24px; height: 24px; line-height: 22px; text-align: center;
  background: var(--brass); color: var(--coal); border: 2px solid var(--coal);
}
.howto-step > b { display: block; font-size: 17px; color: var(--brass-hi); margin-left: 14px; }
.howto-step p { margin: 6px 0 0; font-size: 13px; }

.sectors-intro { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
@media (max-width: 640px) { .sectors-intro { grid-template-columns: 1fr; } }
.sectors-intro p { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.rivals-intro { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; }
.rivals-intro span { display: inline-block; vertical-align: middle; margin-left: 6px; font-size: 13px; line-height: 1.2; }

.winner { font-size: 22px; margin: 8px 0 14px; color: var(--paper); }
.winner .ico { width: 24px; height: 24px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: normal; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; padding: 4px 6px; border-bottom: 2px solid var(--line); }
td { padding: 6px; border-bottom: 2px dotted var(--wood); }
td.who { display: flex; align-items: center; gap: 8px; }
td small { color: var(--muted); }
tr.me td { color: var(--brass-hi); }

/* ---------- Page d'accueil et dialogues ---------- */
:focus-visible { outline: 3px solid var(--brass-hi) !important; outline-offset: 2px !important; }
.home-top { display: flex; margin: -8px 0 6px; }
.back { display: inline-flex; align-items: center; min-height: 44px; padding: 0 4px; color: var(--brass-hi); text-decoration: none; font-weight: 600; }
.back:hover { text-decoration: underline; }
.tagline { margin: 2px 0 0; font-family: var(--pixel); font-size: 20px; letter-spacing: 2px; color: var(--muted); }
.home-menu { display: flex; flex-direction: column; align-items: center; gap: 14px; max-width: 420px; margin: 20px auto 4px; }
.home-menu button { min-height: 44px; width: 100%; }
button.play { font-family: var(--pixel); font-weight: 400; font-size: 30px; padding: 6px 14px; min-height: 60px; letter-spacing: 3px; }
button.play kbd { font-size: 12px; vertical-align: 5px; letter-spacing: 0; }
.home-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; width: 100%; }
.home-row button { font-size: 15px; }
.home-opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 20px; align-items: center; }
.home-opts .check, .home-opts .seed { min-height: 44px; display: flex; align-items: center; }
.home-opts .check input { width: 22px; height: 22px; }
@media (max-width: 480px) {
  .sheet { padding: 20px 16px; max-height: 96vh; }
  .sheet h1 { font-size: 52px; }
  .home-row { grid-template-columns: 1fr; }
  .overlay { padding: 8px; }
}
.dialog-wrap { z-index: 20; }
.dialog { max-width: 640px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 4px; }
.dialog-head h2 { margin: 0; font-size: 22px; }
#dialog-close { min-width: 44px; min-height: 44px; font-size: 18px; padding: 0; }
.dialog h3 { margin: 16px 0 6px; }
.keys { margin: 4px 0; padding-left: 18px; }
.keys li { margin: 5px 0; }
.acc-form { display: flex; flex-direction: column; gap: 12px; }
.acc-form label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.sheet .acc-form input { font: inherit; background: var(--coal); color: var(--paper); border: 2px solid var(--line); padding: 6px 8px; width: 100%; margin: 0; min-height: 44px; font-size: 16px; }
.acc-form .actions { margin-top: 4px; }
.acc-form button, .dialog .actions button { min-height: 44px; }
.form-error { min-height: 1.4em; margin: 0; color: var(--down); }
.friends { margin: 4px 0; padding-left: 18px; }

/* ---------- Finance (Bourse & banque, Gare) ---------- */
.offer { max-height: calc(100% - 20px); overflow-y: auto; }
.offer p { margin: 2px 0 6px; }
.fin-title { margin-top: 8px !important; font-family: var(--title); font-weight: 700; color: var(--brass-hi); }
.bet-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.bet-row > .muted { margin-right: auto; }
.bets-open { margin: 4px 0 0; padding-left: 18px; font-size: 12px; color: var(--muted); }
.fin-summary { font-size: 12px; padding: 4px 0 6px; border-bottom: 2px dotted var(--line); }
.neg { color: var(--down); }
.home-opts select, .sheet select {
  font: inherit; background: var(--coal); color: var(--paper); border: 2px solid var(--line); padding: 4px 6px; margin-left: 6px;
}
