:root { --ink: #231d16; --muted: #6f6556; --paper: rgba(253, 250, 243, .96); --accent: #8c2f1b; --accent-dark: #6d2414; --ground: #e9e1cc; --soft: #f1eadb; }
body.future { --ink: #e7ecf3; --muted: #93a0b3; --paper: rgba(24, 29, 39, .95); --accent: #2f9bd6; --accent-dark: #2079ab; --ground: #141922; --soft: #222a37; }
* { box-sizing: border-box; }
html, body, #map { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, Segoe UI, sans-serif; color: var(--ink); background: var(--ground); }
[hidden] { display: none !important; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: #c0392b; }
.panel { position: absolute; background: var(--paper); border-radius: 10px; box-shadow: 0 3px 14px rgba(0, 0, 0, .3); padding: 12px 14px; }
#hud { z-index: 3; top: 10px; left: 10px; width: 290px; max-height: calc(100% - 20px); overflow: auto; }
#card { z-index: 3; top: 10px; right: 54px; width: 310px; max-height: calc(100% - 20px); overflow: auto; }
#orders { z-index: 4; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 10px; align-items: center; padding: 8px 12px; border: 2px solid var(--accent); }
.realm { display: flex; align-items: center; gap: 8px; font-size: 17px; }
.realm i, .chip { width: 14px; height: 14px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0, 0, 0, .25); flex: none; }
.realm #rank { margin-left: auto; font-size: 13px; }
.day { font-size: 22px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 6px 0; }
.stats div { background: var(--soft); border-radius: 6px; padding: 4px 8px; }
.lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.stats b { font-size: 17px; font-variant-numeric: tabular-nums; }
.actions { display: flex; align-items: center; gap: 8px; margin: 8px 0 4px; }
.actions .lbl { display: inline; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; background: var(--accent); margin-right: 3px; }
.dot.used { background: rgba(128, 128, 128, .3); }
#army { margin: 6px 0; }
#army .kinds { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
#army .kinds span { background: var(--soft); border-radius: 5px; padding: 1px 7px; font-size: 13px; }
#army button { width: 100%; margin-top: 4px; }
.buttons { display: flex; gap: 6px; margin: 8px 0; }
.buttons button { flex: 1; }
button { font: inherit; color: var(--ink); border: 1px solid rgba(128, 118, 100, .45); background: var(--paper); border-radius: 7px; padding: 5px 10px; cursor: pointer; }
button:hover:not(:disabled) { background: var(--soft); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: var(--accent-dark); }
button.on { outline: 2px solid var(--accent); }
button.big { font-size: 17px; padding: 8px 22px; margin-top: 10px; }
select { font: inherit; color: var(--ink); background: var(--paper); border: 1px solid rgba(128, 118, 100, .45); border-radius: 5px; }
.view { margin: 6px 0; }
#legend div { display: flex; align-items: center; gap: 6px; }
#legend .n { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
#legend .me { font-weight: 700; }
#legend .ramp { height: 10px; border-radius: 3px; flex: 1; background: linear-gradient(90deg, #ffffcc, #fd8d3c, #bd0026); }
.rel { font-size: 11px; border-radius: 4px; padding: 0 5px; text-transform: uppercase; letter-spacing: .04em; }
.rel.war { background: #c0392b; color: #fff; }
.rel.peace { background: #9aa0a6; color: #fff; }
.rel.ally { background: #2e8b57; color: #fff; }
.links { margin-top: 8px; font-size: 12px; }
h2 { margin: 0 24px 2px 0; font-size: 18px; }
h3 { margin: 12px 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.close { position: absolute; top: 6px; right: 8px; border: 0; font-size: 20px; padding: 0 6px; background: none; }
.bar { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.bar .track { flex: 1; height: 8px; background: rgba(128, 128, 128, .2); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; }
.bar .v { width: 40px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 0 10px; font-variant-numeric: tabular-nums; }
.opt { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.opt button { flex: 1; text-align: left; }
.opt .cost { font-size: 12px; color: var(--muted); white-space: nowrap; }
.troops div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.troops .hp { flex: 0 0 50px; height: 6px; background: rgba(128, 128, 128, .25); border-radius: 3px; overflow: hidden; }
.troops .hp i { display: block; height: 100%; background: #3c9a5f; }
.troops .where { margin-left: auto; font-size: 12px; color: var(--muted); }
.troops button { padding: 1px 8px; font-size: 12px; }

/* Troops on the map: the troop's icon in a ring of its realm's colour */
.troop { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; background: #111 center / cover no-repeat;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .6); cursor: pointer; }
.troop.mine { width: 34px; height: 34px; border-width: 4px; box-shadow: 0 0 0 2px #fff, 0 1px 5px rgba(0, 0, 0, .7); }
.troop.selected { box-shadow: 0 0 0 3px #ffd54a, 0 0 14px 5px rgba(255, 213, 74, .85); }
.troop small { position: absolute; right: -10px; top: -9px; color: #fff; border: 1.5px solid #fff; border-radius: 8px; padding: 0 4px; font: 700 10px/14px system-ui, sans-serif; text-shadow: 0 1px 1px rgba(0, 0, 0, .6); }
.ico { width: 20px; height: 20px; border-radius: 5px; vertical-align: middle; margin-right: 6px; flex: none; }
.opt button { display: flex; align-items: center; }
.opt .ico { width: 24px; height: 24px; border-radius: 50%; }
.troops .ico { width: 18px; height: 18px; margin-right: 0; }
#army .kinds span { display: inline-flex; align-items: center; }
#army .kinds .ico { width: 18px; height: 18px; margin-right: 4px; }
.stats div { display: grid; grid-template-columns: auto 1fr; column-gap: 5px; align-items: center; }
.stats .lbl { grid-column: 1 / -1; }
.stats img { grid-row: 2; width: 18px; height: 18px; border-radius: 50%; }
.era-icons { display: inline-flex; gap: 3px; margin-left: 6px; vertical-align: middle; }
.era-icons img { width: 22px; height: 22px; border-radius: 50%; }
.cup { display: block; width: 96px; height: 96px; border-radius: 50%; margin: 6px auto 4px; box-shadow: 0 2px 12px rgba(0, 0, 0, .4); }
.troop .hpbar { position: absolute; left: 2px; right: 2px; bottom: -6px; height: 3px; background: rgba(0, 0, 0, .45); border-radius: 2px; overflow: hidden; }
.troop .hpbar i { display: block; height: 100%; background: #7ee08f; }
.battle { font-size: 20px; pointer-events: none; animation: pulse 1s ease-in-out infinite alternate; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); }
@keyframes pulse { from { transform: scale(.85); } to { transform: scale(1.15); } }
.tip { position: absolute; z-index: 5; pointer-events: none; background: rgba(20, 18, 26, .88); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; }

/* Research */
#research { margin: 6px 0; }
#research .bar span:first-child { min-width: 80px; }
#research button { width: 100%; margin-top: 4px; }
#research .fill { background: var(--accent); }
.sheet.wide { max-width: 1100px; position: relative; }
.tree { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; }
.tree .col { display: flex; flex-direction: column; gap: 8px; min-width: 190px; flex: 1; }
.tech { display: flex; flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; padding: 8px 10px; }
.tech .what { font-size: 12px; color: var(--muted); }
.tech .fx { font-size: 12px; }
.tech .needs { font-size: 11px; color: var(--muted); font-style: italic; }
.tech.known { border-color: #3c9a5f; background: rgba(60, 154, 95, .12); opacity: 1; }
.tech.current { border: 2px solid var(--accent); opacity: 1; }
.tech.open { border-color: var(--accent); }
.tech.locked { opacity: .55; }

/* Crests (Italia) */
.crest { width: 16px; height: 18px; object-fit: contain; flex: none; vertical-align: middle; }
.realms .crest { width: 20px; height: 22px; }
#realmColor.has-crest { width: 22px; height: 26px; border: 0; border-radius: 0; background-color: transparent !important;
  background-size: contain; background-position: center; background-repeat: no-repeat; }
.seat-crest { width: 30px; height: 34px; background: center / contain no-repeat; filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .6)); pointer-events: none; }

/* Several players */
.lobby { margin: 10px 0; padding: 10px 12px; border: 2px solid var(--accent); border-radius: 10px; background: var(--soft); }
.lobby .code { font-size: 18px; }
.lobby .code b { font-family: ui-monospace, monospace; letter-spacing: .12em; font-size: 22px; }
.lobby .seats { margin: 8px 0; }
.lobby .seats div, #players div { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
.lobby .n, #players .n { margin-left: auto; color: var(--muted); font-size: 13px; }
.lobby button { padding: 1px 10px; }
#players { margin: 6px 0; }
#players .me { font-weight: 700; }
#players button { padding: 0 6px; font-size: 11px; margin-left: 4px; }
.lobby .pace, #players .small { margin: 6px 0; }
#clock { font-size: 15px; font-weight: 400; font-variant-numeric: tabular-nums; }
#joinCode { font: inherit; text-transform: uppercase; letter-spacing: .1em; width: 7em; }
#turn h2 { display: flex; align-items: center; gap: 8px; }

#news { position: absolute; z-index: 2; left: 10px; bottom: 28px; width: 290px; display: flex; flex-direction: column; gap: 4px; pointer-events: none; }
#news div { background: rgba(29, 27, 34, .9); color: #fff; border-radius: 7px; padding: 4px 10px; font-size: 13px; animation: fade 9s forwards; }
#news div.bad { background: rgba(140, 32, 20, .92); }
#news div.good { background: rgba(32, 104, 60, .92); }
@keyframes fade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }
.overlay { position: fixed; inset: 0; background: rgba(20, 18, 26, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.sheet { background: var(--paper); border-radius: 14px; max-width: 580px; width: 100%; max-height: calc(100% - 32px); overflow: auto; padding: 22px 26px; box-shadow: 0 10px 40px rgba(0, 0, 0, .35); }
.sheet h1 { margin: 0; font-size: 32px; letter-spacing: .02em; }
.lead { font-size: 17px; margin: 4px 0 10px; color: var(--muted); }
.choices label { display: block; margin: 3px 0; }
.realms { display: flex; flex-wrap: wrap; gap: 6px; }
.realms button { display: flex; align-items: center; gap: 6px; }
.realms button.on { outline: 3px solid var(--ink); }
.seed { margin-top: 10px; }
.seed input { width: 110px; font: inherit; }
ol li { margin-bottom: 6px; }
.fold { display: none; }
@media (max-width: 720px) {
  #hud { width: calc(100% - 20px); max-height: 50%; padding: 8px 10px; }
  #hud .day { font-size: 18px; margin: 0; }
  #hud .stats b { font-size: 15px; }
  #hud .fold { display: block; width: 100%; margin: 4px 0; }
  #hud:not(.open) .view, #hud:not(.open) #legend, #hud:not(.open) .links, #hud:not(.open) #army .kinds { display: none; }
  #card { top: auto; bottom: 10px; right: 10px; left: 10px; width: auto; max-height: 42%; }
  #orders { top: auto; bottom: 10px; left: 10px; right: 10px; transform: none; justify-content: space-between; }
  #news { left: 10px; right: 10px; width: auto; bottom: auto; top: 52%; }
  .troop { width: 24px; height: 24px; border-width: 2px; }
  .troop.mine { width: 28px; height: 28px; border-width: 3px; }
}

/* The treasury */
.stats .money { cursor: pointer; }
.stats .money:hover { outline: 1px solid var(--accent); }
.stats .delta { grid-column: 1 / -1; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats .delta::after { content: ' a day'; }
.good { color: #2e7d32; }
.bad { color: #c62828; }
body.future .good { color: #6fd08c; }
body.future .bad { color: #ff7b72; }
.stats .delta.good, .stats .delta.bad { font-weight: 600; }
.warn { background: rgba(198, 40, 40, .12); border-left: 3px solid #c62828; padding: 4px 8px; margin: 4px 0; font-size: 12px; border-radius: 4px; }
button.link { background: none; border: none; padding: 2px 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: 12px; }
#treasury .cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
#treasury h4 { margin: 4px 0; color: var(--muted); font-weight: 600; }
#treasury .res { margin-bottom: 14px; }
table.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }
table.ledger td { padding: 2px 4px; border-bottom: 1px solid rgba(128, 128, 128, .18); }
table.ledger td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.ledger tr.total td { font-weight: 600; border-bottom: none; }
#legend .ramp.mood { background: linear-gradient(90deg, #a50026, #d73027 15%, #fdae61 35%, #ffffbf 50%, #a6d96a 75%, #1a9850); }
@media (max-width: 640px) { #treasury .cols { grid-template-columns: 1fr; } }
