:root {
  --bg: #0b0c10;
  --panel: rgba(18, 19, 25, 0.94);
  --panel-2: #1c1d25;
  --line: rgba(255, 255, 255, 0.09);
  --text: #ece8df;
  --muted: #9a978f;
  --amber: #f0a840;
  --red: #ef4c4c;
  --green: #5bd46a;
  --me: #e04848;
  --display: "Anton", "Impact", "Arial Narrow", sans-serif;
  --cond: "Oswald", "Arial Narrow", sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.4 var(--body); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- buttons ---------- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px;
  font-family: var(--cond); letter-spacing: .04em; text-transform: uppercase; font-size: 13px; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: #272833; border-color: rgba(255,255,255,.2); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--amber); color: #18120a; border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: #ffbe5c; }
.btn.danger { background: #3a1416; border-color: #7a2a2a; color: #ffb3b3; }
.btn.danger:hover:not(:disabled) { background: #4d1a1d; }
.btn.small { padding: 5px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }

/* ---------- title ---------- */
#title { display: grid; place-items: center; overflow: auto; }
.title-bg { position: fixed; inset: 0; background: url(assets/map.png) center/cover; image-rendering: pixelated; filter: brightness(.55) saturate(1.1); }
.title-bg::after { content: ""; position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(11,12,16,.55), rgba(11,12,16,.97) 75%); }
.title-inner { position: relative; text-align: center; padding: 24px 16px; width: min(1000px, 100%); }
.logo { font-family: var(--display); font-size: clamp(56px, 13vw, 128px); margin: 0; letter-spacing: .03em; line-height: 1; text-shadow: 0 4px 0 #000, 0 0 40px rgba(240,168,64,.25); }
.logo span { color: var(--amber); }
.tagline { font-family: var(--cond); text-transform: uppercase; letter-spacing: .2em; color: var(--muted); margin: 8px 0 28px; font-size: 13px; }
.title-menu { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.title-menu > .btn { width: 240px; padding: 12px; font-size: 15px; }

.setup { text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; width: 100%; }
.setup h2 { font-family: var(--cond); text-transform: uppercase; letter-spacing: .08em; font-size: 13px; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.setup section + section { margin-top: 18px; }
.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.seg button { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.seg button b { display: block; font-family: var(--cond); font-size: 16px; text-transform: uppercase; letter-spacing: .04em; }
.seg button small { color: var(--muted); font-size: 12px; }
.seg button.on { border-color: var(--amber); box-shadow: inset 0 0 0 1px var(--amber); background: #241d12; }
.factions { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.fcard { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0; overflow: hidden; text-align: left; position: relative; }
.fcard img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; filter: grayscale(.35); }
.fcard .fc-body { padding: 6px 8px 8px; border-top: 3px solid var(--c); }
.fcard b { font-family: var(--cond); font-size: 14px; text-transform: uppercase; display: block; line-height: 1.1; }
.fcard small { color: var(--muted); font-size: 11px; }
.fcard.on { border-color: var(--c); box-shadow: 0 0 0 2px var(--c); }
.fcard.on img { filter: none; }
.fcard .side { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.7); border-radius: 4px; padding: 1px 5px; font-size: 10px; font-family: var(--cond); }
.blurb { margin-top: 10px; color: #cfcac0; min-height: 40px; font-size: 13px; }
.blurb b { color: var(--text); }
.setup-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 18px; }

/* ---------- HUD ---------- */
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#hud {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px 10px;
  background: linear-gradient(rgba(11,12,16,.96), rgba(11,12,16,.75)); border-bottom: 1px solid var(--line); flex-wrap: wrap; z-index: 5;
}
.hud-fac { display: flex; align-items: center; gap: 8px; margin-right: 6px; min-width: 0; }
.hud-fac img { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--c); object-fit: cover; }
.hud-fac b { font-family: var(--cond); text-transform: uppercase; font-size: 15px; letter-spacing: .03em; display: block; line-height: 1.1; white-space: nowrap; }
.hud-fac small { color: var(--muted); font-size: 11px; }
.stat { background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px; font-family: var(--cond); font-size: 15px; white-space: nowrap; }
.stat small { font-size: 11px; margin-left: 3px; }
.stat .up { color: var(--green); } .stat .down { color: var(--red); }
.stat.warn { border-color: var(--red); color: #ffb0b0; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { background: rgba(239,76,76,.2); } }
.hud-spacer { flex: 1; }
.turn-chip { font-family: var(--cond); color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }

/* ---------- side panel ---------- */
#panel {
  position: absolute; right: 10px; top: 64px; width: 300px; max-height: calc(100% - 80px); overflow: auto; z-index: 4;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px);
}
#panel:empty { display: none; }
.p-photo { height: 110px; background: center/cover; border-radius: 12px 12px 0 0; position: relative; }
.p-photo.none { background: repeating-linear-gradient(135deg, #1b1c24 0 10px, #16171e 10px 20px); }
.p-photo::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 30%, rgba(18,19,25,.97)); border-radius: inherit; }
.p-head { padding: 10px 12px 8px; position: relative; }
.p-photo + .p-head { margin-top: -46px; }
.p-head h3 { margin: 0; font-family: var(--cond); text-transform: uppercase; font-size: 19px; letter-spacing: .03em; line-height: 1.15; }
.p-head .sub { color: var(--muted); font-size: 12px; }
.owner-chip { display: inline-flex; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; background: rgba(255,255,255,.05); padding: 2px 8px 2px 4px; border-radius: 99px; }
.owner-chip i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.p-sec { border-top: 1px solid var(--line); padding: 10px 12px; }
.p-sec h4 { margin: 0 0 8px; font-family: var(--cond); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; }
.bld-row { display: flex; align-items: center; gap: 10px; }
.bld-icon { width: 36px; height: 36px; border-radius: 8px; display: grid; place-items: center; font-size: 19px; background: #111; border: 1.5px solid var(--c); flex: none; }
.bld-row .info { flex: 1; min-width: 0; }
.bld-row .info b { display: block; font-size: 13px; }
.bld-row .info small { color: var(--muted); font-size: 11.5px; display: block; }
.toggles { display: flex; gap: 6px; margin-top: 8px; }
.toggles button { flex: 1; }
.toggles button.on { border-color: var(--amber); color: var(--amber); }
.grid-btns { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.gbtn { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 4px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; }
.gbtn:hover:not(:disabled) { border-color: rgba(255,255,255,.3); }
.gbtn:disabled { opacity: .38; cursor: not-allowed; }
.gbtn .ic { font-size: 18px; line-height: 1.2; }
.gbtn img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.gbtn b { font-family: var(--cond); font-weight: 400; text-transform: uppercase; font-size: 11px; text-align: center; line-height: 1.1; }
.gbtn .cost { color: var(--amber); font-family: var(--cond); }
.units { display: flex; flex-direction: column; gap: 6px; }
.ucard { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 5px 8px 5px 5px; text-align: left; width: 100%; }
.ucard.on { border-color: #ffe28a; background: #2a2618; }
.ucard.spent { opacity: .55; }
.ucard .pf { position: relative; flex: none; }
.ucard .pf img { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--c); object-fit: cover; display: block; }
.ucard .rank { position: absolute; bottom: -3px; right: -4px; font-size: 9px; color: #e8c35a; letter-spacing: -1px; text-shadow: 0 0 2px #000; }
.ucard .mid { flex: 1; min-width: 0; }
.ucard .mid b { font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hpbar { height: 4px; background: rgba(255,255,255,.1); border-radius: 2px; overflow: hidden; margin: 3px 0 2px; }
.hpbar i { display: block; height: 100%; background: var(--green); }
.ucard .tags { font-size: 11px; color: var(--muted); display: flex; gap: 8px; }
.hint { color: var(--muted); font-size: 12px; }
.hint b { color: var(--text); }
.roster-row { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 4px 0; }
.roster-row img { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; }
.roster-row span { flex: 1; }
.panel-close { position: absolute; top: 8px; right: 8px; z-index: 2; background: rgba(0,0,0,.55); border: none; border-radius: 50%; width: 26px; height: 26px; line-height: 1; }

/* ---------- log & toasts ---------- */
#log { position: absolute; left: 10px; bottom: 10px; width: min(420px, calc(100% - 20px)); z-index: 3; pointer-events: none; display: flex; flex-direction: column; gap: 3px; }
#log div { background: rgba(11,12,16,.82); border-left: 3px solid #555; padding: 4px 8px; border-radius: 4px; font-size: 12px; animation: fadein .3s; }
#log div.good { border-color: var(--green); } #log div.bad { border-color: var(--red); } #log div.big { border-color: var(--amber); font-weight: 600; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }
#toasts { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); z-index: 6; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast { background: rgba(14,15,20,.96); border: 1px solid var(--line); border-radius: 10px; padding: 8px 14px; font-family: var(--cond); font-size: 15px; letter-spacing: .02em; animation: fadein .2s; display: flex; align-items: center; gap: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.5); }
.toast.win { border-color: var(--green); } .toast.loss { border-color: var(--red); }
.toast .faces { display: flex; }
.toast .faces img { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--c); margin-left: -6px; object-fit: cover; }
.toast .faces img.ko { filter: grayscale(1) brightness(.5); }
#busy { position: absolute; inset: auto 0 18px; margin: auto; width: max-content; z-index: 7; background: rgba(14,15,20,.95); border: 1px solid var(--line); padding: 8px 16px; border-radius: 99px; display: flex; gap: 10px; align-items: center; font-family: var(--cond); }
.spinner { width: 14px; height: 14px; border: 2px solid var(--amber); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; z-index: 20; background: rgba(4,5,8,.72); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(3px); }
.modal-card { background: #14151b; border: 1px solid var(--line); border-radius: 14px; width: min(860px, 100%); max-height: calc(100vh - 32px); overflow: auto; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal-card.narrow { width: min(480px, 100%); }
.m-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #14151b; z-index: 1; }
.m-head h2 { margin: 0; font-family: var(--cond); text-transform: uppercase; letter-spacing: .06em; font-size: 18px; }
.m-body { padding: 16px; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }

/* diplomacy */
.dip { display: grid; grid-template-columns: 220px 1fr; min-height: 420px; }
.dip-list { border-right: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.dip-item { display: flex; align-items: center; gap: 8px; padding: 6px; border-radius: 8px; background: transparent; border: 1px solid transparent; text-align: left; }
.dip-item:hover { background: rgba(255,255,255,.04); }
.dip-item.on { background: rgba(255,255,255,.07); border-color: var(--line); }
.dip-item.dead { opacity: .35; }
.dip-item img { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--c); object-fit: cover; flex: none; }
.dip-item b { font-size: 13px; display: block; line-height: 1.15; }
.dip-item small { font-size: 11px; }
.st-war { color: var(--red); } .st-alliance { color: var(--green); } .st-nap { color: #7fb8ff; } .st-peace { color: var(--muted); } .st-vassal { color: #d9a6ff; }
.relbar { height: 3px; background: rgba(255,255,255,.1); border-radius: 2px; margin-top: 3px; position: relative; width: 120px; }
.relbar i { position: absolute; top: 0; bottom: 0; left: 50%; background: var(--green); }
.relbar i.neg { background: var(--red); }
.dip-main { padding: 16px; }
.leader { display: flex; gap: 16px; align-items: flex-start; }
.leader > img { width: 150px; height: 150px; border-radius: 12px; object-fit: cover; border: 3px solid var(--c); flex: none; }
.leader h3 { margin: 0; font-family: var(--display); font-size: 28px; letter-spacing: .02em; font-weight: 400; line-height: 1.05; }
.leader .fac-name { color: var(--c); font-family: var(--cond); text-transform: uppercase; letter-spacing: .06em; font-size: 13px; }
.bubble { margin-top: 10px; background: #f2ede2; color: #18161a; border-radius: 12px; padding: 10px 12px; font-size: 14px; position: relative; font-style: italic; }
.bubble::before { content: ""; position: absolute; left: -7px; top: 14px; border: 7px solid transparent; border-right-color: #f2ede2; border-left: 0; }
.bubble.yes { background: #dff5dd; } .bubble.no { background: #f8dcdc; }
.facts { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.facts span { background: rgba(255,255,255,.05); border-radius: 6px; padding: 3px 8px; font-size: 12px; }
.dip-actions { margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.dip-sub { margin-top: 12px; background: var(--panel-2); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.dip-sub label { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.dip-sub label > span:first-child { width: 70px; color: var(--muted); }
.dip-sub input[type=range] { flex: 1; accent-color: var(--amber); }
.dip-sub output { width: 60px; text-align: right; font-family: var(--cond); font-size: 15px; }
.dip-sub .row { display: flex; gap: 6px; flex-wrap: wrap; }

/* event */
.event { display: flex; gap: 14px; align-items: flex-start; }
.event img { width: 96px; height: 96px; border-radius: 12px; object-fit: cover; border: 3px solid var(--c); flex: none; }
.event h3 { margin: 0 0 2px; font-family: var(--cond); text-transform: uppercase; font-size: 18px; }
.event .bubble { margin-top: 8px; }

.help h3 { font-family: var(--cond); text-transform: uppercase; letter-spacing: .05em; margin: 14px 0 4px; font-size: 15px; color: var(--amber); }
.help p, .help li { color: #d6d1c7; font-size: 13.5px; }
.help ul { padding-left: 18px; margin: 4px 0; }
.legend { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.slots { display: flex; flex-direction: column; gap: 6px; }
.slot { display: flex; align-items: center; gap: 10px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.slot span { flex: 1; font-size: 13px; }
.slot small { color: var(--muted); display: block; font-size: 11px; }
.endcard { text-align: center; padding: 26px 18px; }
.endcard h2 { font-family: var(--display); font-size: 54px; margin: 0; font-weight: 400; letter-spacing: .03em; }
.endcard.win h2 { color: var(--amber); } .endcard.loss h2 { color: var(--red); }

@media (max-width: 720px) {
  #hud { gap: 4px; padding: 6px; }
  .hud-fac small, .turn-chip .mode { display: none; }
  .stat { font-size: 13px; padding: 3px 6px; }
  #panel { left: 8px; right: 8px; width: auto; top: auto; bottom: 8px; max-height: 40%; }
  #log { bottom: auto; top: 96px; width: calc(100% - 20px); }
  #log div:nth-last-child(n+3) { display: none; }
  .dip { grid-template-columns: 1fr; }
  .dip-list { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .dip-item { flex: none; }
  .dip-item .txt { display: none; }
  .leader > img { width: 90px; height: 90px; }
  .leader h3 { font-size: 22px; }
}
.dip-sub .btn.on { border-color: var(--amber); color: var(--amber); }

/* menu & saves */
.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list .btn { padding: 11px; font-size: 14px; }
.save-form { display: flex; gap: 8px; margin-bottom: 16px; }
.save-form input { flex: 1; min-width: 0; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; color: var(--text); padding: 8px 10px; font: inherit; }
.save-form input:focus { outline: none; border-color: var(--amber); }
.save-year + .save-year { margin-top: 16px; }
.save-year h4 { margin: 0 0 8px; font-family: var(--cond); font-weight: 600; text-transform: uppercase; letter-spacing: .08em; font-size: 12px; color: var(--muted); }
.slot img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; border: 2px solid var(--c); flex: none; }
.slot span b { font-size: 13px; display: block; }
.slot .btn.danger { color: #ffb3b3; }
@media (max-width: 720px) {
  .slot { flex-wrap: wrap; }
  .slot > span { flex: 1 1 calc(100% - 50px); }
  .slot > .btn { flex: 1; }
  .slot > .btn.ghost { flex: 0 0 auto; }
}
.urow { display: flex; align-items: stretch; gap: 6px; }
.urow .ucard { flex: 1; min-width: 0; }
.ageout { font-size: 11px; padding: 4px 7px; flex: none; }

/* war status */
.war-chip { display: inline-flex; align-items: center; gap: 6px; color: #ffb3b3; border-color: rgba(239,76,76,.6); background: rgba(239,76,76,.12); cursor: pointer; }
.war-chip.peace { color: #a9e7b0; border-color: rgba(91,212,106,.4); background: rgba(91,212,106,.08); }
.war-chip .faces { display: flex; }
.war-chip .faces img { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--c); margin-left: -5px; object-fit: cover; }
.war-chip .faces img:first-child { margin-left: 0; }
.war-banner { background: repeating-linear-gradient(135deg, #5a1414 0 14px, #451010 14px 28px); color: #ffd6d6; font-family: var(--display); font-size: 34px; letter-spacing: .06em; text-align: center; padding: 14px; border-radius: 14px 14px 0 0; text-transform: uppercase; }
.war-banner.police { background: repeating-linear-gradient(90deg, #d4e23a 0 28px, #1e3278 28px 56px); color: #fff; text-shadow: 0 2px 0 #000, 0 0 12px #000; }
.war-row { display: flex; gap: 12px; align-items: flex-start; padding: 8px 0; }
.war-row + .war-row { border-top: 1px solid var(--line); }
.war-row img { width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--c); object-fit: cover; flex: none; }
.war-row b { font-family: var(--cond); text-transform: uppercase; letter-spacing: .03em; }
.war-row p { margin: 2px 0 0; font-size: 13.5px; color: #e6e1d8; }
@media (max-width: 720px) { .war-chip .faces { display: none; } }

/* ad consent + title links */
#consent { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 30; max-width: 760px; margin: 0 auto; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; background: rgba(20,21,27,.98); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 36px rgba(0,0,0,.6); }
#consent[hidden] { display: none; }
#consent p { margin: 0; flex: 1 1 320px; font-size: 12.5px; color: #cfcac0; }
#consent a { color: var(--amber); }
.consent-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.title-links { margin-top: 6px; font-size: 12px; color: var(--muted); }
.title-links a, .linkbtn { color: var(--muted); background: none; border: none; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }
.title-links a:hover, .linkbtn:hover { color: var(--text); }
.menu-list a.btn { text-decoration: none; text-align: center; color: inherit; display: block; }
