:root {
  --bg1: #2a2118; --bg2: #3b2e20; --parch: #f6ecd2; --parch2: #ead9ad; --ink: #3a2d1e; --wood: #7a5230; --gold: #f2c230;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 30% 20%, #4a3a28 0%, var(--bg1) 70%);
  color: var(--ink); font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif; overflow-x: hidden;
}
.hidden { display: none !important; }
#app { display: flex; gap: 14px; padding: 8px; align-items: flex-start; justify-content: center; min-height: 100%; }
#stage { position: relative; flex: none; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 4px #5a3d22, 0 0 0 7px #2b1d10, 0 14px 40px rgba(0,0,0,.55); line-height: 0; }
#map { display: block; cursor: default; }
#stage.targeting #map { cursor: crosshair; }
#stage::after { content: ""; position: absolute; inset: 0; pointer-events: none; box-shadow: inset 0 0 90px rgba(20,12,4,.45); }
#banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(40,28,16,.92); color: #ffe9a8; padding: 8px 16px; border-radius: 20px; font-weight: 700; font-size: 14px; line-height: 1.3; z-index: 3; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
#toast { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); background: #b3362c; color: #fff; padding: 7px 14px; border-radius: 16px; font-weight: 700; font-size: 13px; line-height: 1.3; z-index: 3; }
#pausetag { position: absolute; top: 10px; right: 12px; background: rgba(40,28,16,.88); color: #fff; padding: 5px 12px; border-radius: 14px; font-weight: 800; font-size: 13px; line-height: 1.3; z-index: 3; letter-spacing: .08em; }

#panel { flex: none; width: 360px; display: flex; flex-direction: column; gap: 10px; }
#panel > header, #panel > section, .controls, #tileinfo { background: var(--parch); border-radius: var(--radius); box-shadow: 0 0 0 2px #8a6a3f inset, 0 4px 14px rgba(0,0,0,.35); }
#panel > header { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; }
.brand { font-family: Georgia, "Times New Roman", serif; font-weight: 800; font-size: 19px; color: #5a3d22; }
.brand em { color: #b3362c; font-style: italic; }
.clock { font-family: Georgia, serif; font-weight: 800; font-size: 28px; color: #3a2d1e; font-variant-numeric: tabular-nums; }
.controls { display: flex; align-items: center; gap: 6px; padding: 7px 10px; }
.controls button { border: 0; border-radius: 9px; padding: 6px 12px; font: inherit; font-weight: 800; background: var(--parch2); color: var(--ink); cursor: pointer; box-shadow: 0 2px 0 #b79a63; }
.controls button:hover { filter: brightness(1.06); }
.controls button.on { background: var(--gold); box-shadow: 0 2px 0 #a07d0a; }
.doctrine { margin-left: auto; font-size: 12px; font-weight: 700; color: #7a4a1a; text-align: right; }

#board { padding: 8px 10px; display: flex; flex-direction: column; gap: 5px; }
.row-civ { display: grid; grid-template-columns: 14px 1fr 54px; align-items: center; gap: 8px; font-size: 13px; }
.row-civ .dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(0,0,0,.45); }
.row-civ .nm { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-civ .nm small { font-weight: 600; color: #7a6a52; }
.row-civ .bar { height: 7px; background: rgba(0,0,0,.12); border-radius: 4px; margin-top: 3px; overflow: hidden; }
.row-civ .bar i { display: block; height: 100%; border-radius: 4px; transition: width .4s; }
.row-civ .st { text-align: right; font-size: 12px; font-weight: 700; color: #5c4a30; line-height: 1.2; }
.row-civ.dead { opacity: .45; text-decoration: line-through; }
.row-civ.me .nm { color: #8a2a20; }

#res { display: flex; justify-content: space-around; padding: 7px 10px; font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
#res span small { font-weight: 600; font-size: 11px; color: #7a6a52; margin-left: 2px; }

#hand { padding: 8px; display: flex; flex-direction: column; gap: 7px; min-height: 120px; }
#hand h4 { margin: 0 2px 1px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: #7a6a52; display: flex; justify-content: space-between; align-items: center; }
#hand h4 button { border: 0; background: transparent; font: inherit; font-size: 11px; font-weight: 700; color: #7a4a1a; cursor: pointer; text-decoration: underline; text-transform: none; letter-spacing: 0; }
.card { position: relative; display: grid; grid-template-columns: 46px 1fr; gap: 10px; padding: 9px 10px; border-radius: 11px; background: #fffaf0; border: 2px solid #c9a96a; cursor: pointer; transition: transform .12s, box-shadow .12s; animation: pop .35s ease-out backwards; }
.card:nth-child(3) { animation-delay: .07s; } .card:nth-child(4) { animation-delay: .14s; }
.card:hover { transform: translateY(-2px) rotate(-.4deg); box-shadow: 0 6px 14px rgba(0,0,0,.28); }
.card.sel { outline: 3px solid var(--gold); transform: translateX(-4px); }
.card .ic { font-size: 30px; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.06); border-radius: 9px; }
.card .nm { font-weight: 800; font-size: 14px; line-height: 1.15; }
.card .ds { font-size: 12px; line-height: 1.3; color: #55442f; margin-top: 3px; }
.card .tg { position: absolute; top: -8px; right: 9px; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 1px 8px; border-radius: 9px; color: #fff; }
.card .key { position: absolute; bottom: 5px; right: 8px; font-size: 10px; font-weight: 800; color: #9a8559; }
.k-eco { border-color: #d9b43a; } .k-eco .tg { background: #c9961a; }
.k-mil { border-color: #d9665a; } .k-mil .tg { background: #c2453a; }
.k-def { border-color: #6a94c9; } .k-def .tg { background: #3f6fb0; }
.k-terr { border-color: #6fb86a; } .k-terr .tg { background: #3f8f3a; }
.k-chaos { border-color: #b57acf; } .k-chaos .tg { background: #8a4fb0; }
.k-doc { border-color: #8a7a60; background: #f3ead4; } .k-doc .tg { background: #5a4a30; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.96); } to { opacity: 1; transform: none; } }
.wait { text-align: center; padding: 14px 8px; color: #6a5a40; font-size: 13px; }
.wait .meter { height: 8px; background: rgba(0,0,0,.14); border-radius: 5px; margin: 8px 18px 4px; overflow: hidden; }
.wait .meter i { display: block; height: 100%; background: linear-gradient(90deg, #f2c230, #e0873a); border-radius: 5px; }

#log { padding: 8px 12px; font-size: 12px; line-height: 1.35; display: flex; flex-direction: column; gap: 3px; min-height: 90px; }
#log div { display: flex; gap: 6px; }
#log div i { flex: none; width: 8px; height: 8px; border-radius: 50%; margin-top: 4px; border: 1px solid rgba(0,0,0,.4); }
#tileinfo { padding: 6px 12px; font-size: 12px; color: #55442f; min-height: 30px; }

.overlay { position: fixed; inset: 0; background: rgba(22,14,6,.78); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 12px; overflow: auto; backdrop-filter: blur(3px); }
.sheet { background: var(--parch); border-radius: 18px; padding: 24px 28px; width: min(720px, 100%); box-shadow: 0 0 0 3px #8a6a3f inset, 0 20px 60px rgba(0,0,0,.6); text-align: center; }
.sheet h1 { margin: 0; font-family: Georgia, serif; font-size: 40px; color: #5a3d22; }
.sheet h1 em { color: #b3362c; }
.sheet h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .1em; color: #7a6a52; }
.sub { margin: 6px 0 0; color: #6a5a40; }
.hint { font-size: 12px; color: #7a6a52; line-height: 1.7; margin-bottom: 0; }
kbd { background: #fffaf0; border: 1px solid #c9a96a; border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font-size: 11px; font-weight: 800; }
#civPick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.civ { cursor: pointer; border: 3px solid transparent; border-radius: 12px; padding: 10px 8px; background: #fffaf0; text-align: center; transition: transform .12s; }
.civ:hover { transform: translateY(-2px); }
.civ.on { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242,194,48,.4); }
.civ .flagc { width: 34px; height: 34px; border-radius: 50%; margin: 0 auto 6px; border: 3px solid rgba(0,0,0,.4); }
.civ b { display: block; font-size: 13px; line-height: 1.2; }
.civ small { display: block; color: #7a6a52; margin-top: 3px; font-size: 11px; line-height: 1.3; }
.civ em { display: block; font-size: 11px; color: #8a2a20; margin-top: 4px; font-weight: 700; font-style: normal; }
.seg { display: inline-flex; gap: 6px; }
.seg button { border: 0; width: 52px; padding: 8px 0; border-radius: 10px; font: inherit; font-weight: 800; background: var(--parch2); cursor: pointer; box-shadow: 0 2px 0 #b79a63; }
.seg button.on { background: var(--gold); box-shadow: 0 2px 0 #a07d0a; }
.big { margin-top: 18px; border: 0; padding: 12px 32px; border-radius: 14px; font: inherit; font-size: 17px; font-weight: 800; background: #b3362c; color: #fff; cursor: pointer; box-shadow: 0 4px 0 #6f1f18; }
.big:hover { filter: brightness(1.08); }
.big.alt { background: #6a5a40; box-shadow: 0 4px 0 #3a2d1e; }
.row { display: flex; gap: 12px; justify-content: center; }
#endRank { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; text-align: left; }
.rk { display: grid; grid-template-columns: 30px 18px 1fr auto; gap: 10px; align-items: center; background: #fffaf0; border-radius: 10px; padding: 8px 12px; font-size: 14px; }
.rk .n { font-family: Georgia, serif; font-weight: 800; font-size: 20px; color: #b3362c; }
.rk .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(0,0,0,.4); }
.rk small { color: #7a6a52; }
.rk.me { outline: 2px solid var(--gold); }

@media (max-width: 979px) {
  #news { font-size: 12px; }
  #app { flex-direction: column; align-items: center; }
  #panel { width: min(560px, 100%); }
  .sheet h1 { font-size: 30px; }
}

/* ---- Ajouts : chronique, cartes rares/combos, mode spectateur, fin de partie ---- */
#news { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); max-width: 88%; background: rgba(40,28,16,.94); color: #ffe9a8; padding: 9px 18px; border-radius: 18px; font-weight: 700; font-size: 14px; line-height: 1.3; z-index: 4; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,.5); animation: newsIn .45s ease-out; }
#news b { font-size: 18px; margin-right: 4px; }
@keyframes newsIn { from { opacity: 0; transform: translate(-50%, -14px); } to { opacity: 1; transform: translate(-50%, 0); } }
#banner { top: auto; bottom: 12px; }
#toast { bottom: 52px; }
.controls { flex-wrap: wrap; }
.controls .hidden { display: none; }
#hand h4 { flex-wrap: wrap; gap: 4px; }
.card .pin { position: absolute; top: 5px; right: 8px; border: 0; background: transparent; font-size: 15px; opacity: .3; cursor: pointer; padding: 0 2px; filter: grayscale(1); }
.card .pin:hover, .card.pinned .pin { opacity: 1; filter: none; }
.card.pinned { box-shadow: 0 0 0 3px rgba(242,194,48,.55); }
.card .ds { padding-right: 18px; }
.card .cb { margin-top: 4px; font-size: 11px; font-weight: 800; color: #a05a00; background: rgba(255,200,60,.25); border-radius: 6px; padding: 2px 6px; }
.card.combo { animation: pop .35s ease-out backwards, glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 0 3px rgba(255,180,40,.7); } }
.card.rare { background: linear-gradient(135deg, #fffaf0 0%, #fff0c4 100%); border-color: #d4a017; }
.card.rare .tg { background: linear-gradient(90deg, #b8860b, #e0a800); }
.k-diplo { border-color: #5fb0a8; } .k-diplo .tg { background: #2f8a80; }
.wait #pinTxt { margin-top: 6px; font-weight: 700; color: #8a5a10; }
#log { gap: 4px; }
#log div { border-left: 4px solid #999; padding-left: 6px; align-items: baseline; }
#log time { flex: none; font-size: 10px; font-weight: 800; color: #8a7a5c; width: 28px; font-variant-numeric: tabular-nums; }
#log b { flex: none; width: 18px; text-align: center; }
#log div i { display: none; }
#seedbar { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: #bfae8a; padding: 0 6px; }
#seedbar button { border: 0; background: rgba(255,255,255,.12); color: #f3e6c4; border-radius: 8px; padding: 3px 9px; font: inherit; cursor: pointer; }
#seedbar button:hover { background: rgba(255,255,255,.22); }
body.spectator #hand, body.spectator #res { display: none; }
body.spectator #log { min-height: 200px; }
.row-civ .nm small { color: #8a5a10; }
.sheet h4 { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: #7a6a52; text-align: left; }
.sheet .chartT { margin-top: 16px; }
#endChart { width: 100%; height: auto; background: #fffaf0; border-radius: 10px; }
#endChron { text-align: left; font-size: 13px; }
#endChron div { display: flex; gap: 8px; padding: 2px 0; }
#endChron time { flex: none; width: 34px; font-weight: 800; color: #8a7a5c; font-variant-numeric: tabular-nums; }
#endChron b { flex: none; width: 20px; text-align: center; }
.rk { grid-template-columns: 30px 18px 1fr auto; }
.rk .sm { text-align: right; line-height: 1.35; }
.opts { display: flex; gap: 30px; justify-content: center; flex-wrap: wrap; }
.seg.wide button { width: auto; padding: 8px 16px; }
.seedrow { display: flex; gap: 6px; justify-content: center; }
.seedrow input { width: 120px; border: 2px solid #c9a96a; border-radius: 10px; background: #fffaf0; padding: 7px 10px; font: inherit; font-weight: 700; text-align: center; }
.seedrow button { border: 0; background: var(--parch2); border-radius: 10px; padding: 0 12px; cursor: pointer; box-shadow: 0 2px 0 #b79a63; font-size: 17px; }
.row { flex-wrap: wrap; }
.big { padding: 12px 22px; font-size: 15px; }
.civ small + em, .civ em { margin-top: 5px; }
