/* KRONEKRIG — udseende. Mørk, rolig middelalderstil med guld og pergament. */
:root {
  --bg: #14110d;
  --panel: rgba(22, 18, 14, 0.94);
  --panel-2: rgba(36, 29, 22, 0.96);
  --line: rgba(201, 162, 74, 0.28);
  --line-2: rgba(239, 230, 210, 0.12);
  --gold: #c9a24a;
  --gold-2: #e6c56b;
  --text: #efe6d2;
  --muted: #a99c84;
  --red: #c0392b;
  --green: #6fa35a;
  --blue: #5b8cc9;
  --serif: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 10px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 15px; overflow: hidden; -webkit-font-smoothing: antialiased; }
body { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; }
#labels { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#ui { position: absolute; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold-2); }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: 0.01em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.gold { color: var(--gold-2); }
.red { color: #e0705f; }
.green { color: #8fc27a; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- knapper ---------- */
.btn { appearance: none; border: 1px solid var(--line); background: linear-gradient(#3a2f22, #2a2219); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; letter-spacing: 0.01em; transition: filter .15s, transform .05s; white-space: nowrap; }
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; }
.btn.primary { background: linear-gradient(#d8b25a, #a9802f); color: #1b140a; border-color: #e6c56b; }
.btn.danger { background: linear-gradient(#9b2f24, #6f1f17); border-color: #c0392b; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.icon { padding: 7px 9px; line-height: 1; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; display: block; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line-2); background: rgba(255,255,255,0.04); font-size: 12.5px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- formularer ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--muted); }
.input, select.input { background: rgba(0,0,0,0.35); border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; outline: none; width: 100%; user-select: text; -webkit-user-select: text; }
.input:focus { border-color: var(--gold); }
input[type=range] { width: 100%; accent-color: var(--gold); }
.error { color: #f0907f; font-size: 13.5px; min-height: 18px; }

/* ---------- startskærm ---------- */
.splash { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(ellipse at center, rgba(20,17,13,0.35), rgba(20,17,13,0.9)); }
.splash-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 26px 26px 20px; max-height: calc(100% - 20px); overflow: auto; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 18px; text-align: center; }
.brand .title { font-family: var(--serif); font-size: 38px; letter-spacing: 0.18em; color: var(--gold-2); text-shadow: 0 2px 18px rgba(201,162,74,0.25); }
.brand .sub { color: var(--muted); font-size: 13.5px; letter-spacing: 0.04em; }
.bv { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; color: var(--muted); font-size: 12px; }
.bv img { width: 28px; height: 28px; }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tabs .btn { flex: 1; }
.tabs .btn.active { border-color: var(--gold); color: var(--gold-2); }

/* ---------- topbjælke ---------- */
.topbar { position: absolute; top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); right: calc(8px + var(--safe-r)); display: flex; align-items: center; gap: 8px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.nation-badge { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px 6px 6px; cursor: pointer; box-shadow: var(--shadow); max-width: 260px; }
.nation-badge .coat { width: 30px; height: 36px; flex: none; }
.nation-badge .name { font-family: var(--serif); font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nation-badge .ruler { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.resources { display: flex; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px; box-shadow: var(--shadow); overflow-x: auto; scrollbar-width: none; }
.res { display: flex; flex-direction: column; align-items: flex-start; padding: 3px 10px; border-radius: 8px; min-width: 76px; cursor: default; }
.res:hover { background: rgba(255,255,255,0.04); }
.res .v { font-weight: 700; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.res .d { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.res .d.neg { color: #e0705f; }
.res .ico { width: 15px; height: 15px; display: inline-block; }
.datebox { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 6px 12px; box-shadow: var(--shadow); text-align: right; }
.datebox .date { font-family: var(--serif); font-size: 15px; white-space: nowrap; }
.datebox .season { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.topbtns { display: flex; gap: 6px; }
.roundbtn { position: relative; width: 42px; height: 42px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: var(--shadow); color: var(--text); }
.roundbtn:hover { border-color: var(--gold); }
.roundbtn svg { width: 20px; height: 20px; }
.roundbtn .badge { position: absolute; top: -5px; right: -5px; }

.banner { position: absolute; top: calc(62px + var(--safe-t)); left: 50%; transform: translateX(-50%); background: rgba(40, 30, 14, 0.92); border: 1px solid var(--gold); color: var(--gold-2); padding: 6px 14px; border-radius: 99px; font-size: 13px; box-shadow: var(--shadow); white-space: nowrap; pointer-events: none; }

/* ---------- værktøjslinje ---------- */
.toolbar { position: absolute; right: calc(10px + var(--safe-r)); bottom: calc(10px + var(--safe-b)); display: flex; flex-direction: column; gap: 6px; }
.toolbar .roundbtn { width: 46px; height: 46px; }

/* ---------- sidepanel ---------- */
.panel { position: absolute; top: calc(64px + var(--safe-t)); left: calc(8px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); width: min(380px, calc(100% - 16px)); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; animation: slidein .18s ease-out; }
@keyframes slidein { from { transform: translateX(-12px); opacity: 0; } to { transform: none; opacity: 1; } }
.panel-head { padding: 14px 14px 10px; border-bottom: 1px solid var(--line-2); display: flex; gap: 10px; align-items: flex-start; }
.panel-head .coat { width: 40px; height: 48px; flex: none; }
.panel-head h2 { font-size: 21px; line-height: 1.15; }
.panel-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.panel-head .close { margin-left: auto; }
.panel-body { overflow-y: auto; padding: 10px 14px 16px; flex: 1; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.section { margin-top: 14px; }
.section > h3 { font-size: 14px; color: var(--gold-2); text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--sans); font-weight: 700; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.section > h3::after { content: ""; flex: 1; height: 1px; background: var(--line-2); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.stat { background: rgba(255,255,255,0.03); border: 1px solid var(--line-2); border-radius: 8px; padding: 6px 8px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { height: 6px; background: rgba(255,255,255,0.08); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 3px; }
.bar.red > i { background: var(--red); }
.bar.green > i { background: var(--green); }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { background: rgba(255,255,255,0.03); border: 1px solid var(--line-2); border-radius: 9px; padding: 8px 10px; }
.item.clickable { cursor: pointer; }
.item.clickable:hover { border-color: var(--line); }
.item .t { font-weight: 600; }
.item .s { font-size: 12.5px; color: var(--muted); }
.item .cost { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 3px; }
.item .cost .lack { color: #e0705f; }
.item.disabled { opacity: 0.55; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.slot { aspect-ratio: 1; border-radius: 9px; border: 1px dashed var(--line-2); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 11px; text-align: center; padding: 4px; color: var(--muted); }
.slot.full { border-style: solid; border-color: var(--line); color: var(--text); background: rgba(201,162,74,0.06); }
.slot .lv { font-weight: 700; color: var(--gold-2); font-size: 13px; }
.unitrow { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; }
.counter { display: flex; align-items: center; gap: 6px; }
.counter input { width: 64px; text-align: center; }
.segment { display: flex; gap: 4px; flex-wrap: wrap; }
.segment .btn { flex: 1; padding: 6px 8px; font-size: 12.5px; }
.segment .btn.active { border-color: var(--gold); color: var(--gold-2); background: linear-gradient(#4a3b25, #33291c); }
.progress-line { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- modal ---------- */
.modal-back { position: absolute; inset: 0; background: rgba(8, 6, 4, 0.6); display: flex; align-items: center; justify-content: center; padding: 14px; z-index: 20; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: min(760px, 100%); max-height: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { width: min(1080px, 100%); }
.modal-head { padding: 14px 16px; border-bottom: 1px solid var(--line-2); display: flex; align-items: center; gap: 10px; }
.modal-head h2 { font-size: 21px; }
.modal-body { padding: 14px 16px 18px; overflow-y: auto; touch-action: pan-y; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- valg af nation ---------- */
.picker { position: absolute; top: calc(10px + var(--safe-t)); bottom: calc(10px + var(--safe-b)); right: calc(10px + var(--safe-r)); width: min(400px, calc(100% - 20px)); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.picker-head { padding: 16px; border-bottom: 1px solid var(--line-2); }
.picker-head h2 { font-size: 23px; }
.picker-list { overflow-y: auto; padding: 10px 12px; touch-action: pan-y; }
.nrow { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; }
.nrow:hover { background: rgba(255,255,255,0.04); }
.nrow.active { border-color: var(--gold); background: rgba(201,162,74,0.08); }
.nrow.off { opacity: 0.5; }
.nrow .coat { width: 30px; height: 36px; flex: none; }
.nrow .nm { font-family: var(--serif); font-size: 16px; }
.nrow .meta { font-size: 12px; color: var(--muted); }
.picker-foot { padding: 12px 16px; border-top: 1px solid var(--line-2); }

/* ---------- kortets navne ---------- */
.lbl { position: absolute; left: 0; top: 0; transform-origin: 0 0; white-space: nowrap; will-change: transform; }
.lbl-nation { font-family: var(--serif); font-weight: 600; letter-spacing: 0.22em; text-transform: uppercase; color: rgba(255, 248, 230, 0.92); text-shadow: 0 0 6px rgba(0,0,0,0.85), 0 0 2px rgba(0,0,0,0.9); }
.lbl-prov { font-family: var(--serif); font-size: 12.5px; color: rgba(255, 250, 238, 0.95); text-shadow: 0 0 4px rgba(0,0,0,0.95), 0 0 2px #000; }
.lbl-prov.capital::before { content: "★ "; color: var(--gold-2); }
.lbl-sea { font-family: var(--serif); font-style: italic; font-size: 13px; letter-spacing: 0.12em; color: rgba(190, 215, 235, 0.75); text-shadow: 0 0 4px rgba(0,0,0,0.6); }
.lbl-army { font-size: 11.5px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: rgba(15,12,9,0.85); border: 1px solid rgba(255,255,255,0.25); color: #fff; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 4px; }
.lbl-army.mine { border-color: var(--gold-2); }
.lbl-army.sel { background: rgba(201,162,74,0.95); color: #1b140a; }
.lbl-army i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.lbl-mark { font-size: 18px; filter: drop-shadow(0 0 3px #000); }
.lbl-eta { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: rgba(201,162,74,0.95); color: #1b140a; }

/* ---------- beskeder ---------- */
#toasts { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; z-index: 30; width: min(520px, calc(100% - 120px)); }
.toast { background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 10px; padding: 10px 14px; box-shadow: var(--shadow); animation: toast .25s ease-out; pointer-events: auto; cursor: pointer; width: 100%; }
.toast.bad { border-left-color: var(--red); }
.toast .t { font-weight: 700; }
.toast .b { font-size: 13px; color: var(--muted); margin-top: 2px; }
@keyframes toast { from { transform: translateY(10px); opacity: 0; } }

/* ---------- slag ---------- */
.battle-view { display: flex; flex-direction: column; gap: 10px; }
.battle-canvas { width: 100%; aspect-ratio: 16 / 8; border-radius: 12px; background: #0d0b08; display: block; border: 1px solid var(--line-2); }
.battle-sides { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: start; }
.battle-side { background: rgba(255,255,255,0.03); border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 10px; }
.battle-side h4 { font-size: 16px; display: flex; align-items: center; gap: 6px; }
.battle-log { font-size: 13px; max-height: 160px; overflow-y: auto; }
.battle-log div { padding: 3px 0; border-bottom: 1px solid var(--line-2); }

/* ---------- våbenskjold ---------- */
.coat-editor { display: grid; grid-template-columns: 140px 1fr; gap: 14px; align-items: start; }
.coat-editor .preview { width: 140px; height: 168px; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 6px; border: 2px solid transparent; cursor: pointer; }
.swatch.active { border-color: #fff; }
.charges { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.charges .opt { aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line-2); display: flex; align-items: center; justify-content: center; cursor: pointer; background: rgba(255,255,255,0.03); padding: 4px; }
.charges .opt.active { border-color: var(--gold); }
.charges .opt svg { width: 100%; height: 100%; }

/* ---------- indlæsning ---------- */
.loading { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--bg); z-index: 50; }
.loading .title { font-family: var(--serif); font-size: 34px; letter-spacing: 0.2em; color: var(--gold-2); }
.loading .bar { width: 220px; }

/* ---------- telefon på tværs ---------- */
@media (max-height: 520px) {
  html, body { font-size: 14px; }
  .topbar { top: calc(4px + var(--safe-t)); }
  .nation-badge { padding: 4px 8px 4px 4px; }
  .nation-badge .coat { width: 24px; height: 29px; }
  .nation-badge .ruler { display: none; }
  .res { min-width: 62px; padding: 2px 7px; }
  .datebox { padding: 4px 9px; }
  .roundbtn { width: 36px; height: 36px; }
  .panel { top: calc(48px + var(--safe-t)); width: min(340px, 48%); }
  .toolbar .roundbtn { width: 40px; height: 40px; }
  .banner { top: calc(48px + var(--safe-t)); }
  .picker { width: min(360px, 50%); }
  .battle-canvas { aspect-ratio: 16 / 6; }
}
@media (max-width: 720px) {
  .resources .res:nth-child(n+4) { display: none; }
  .datebox .season { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .coat-editor { grid-template-columns: 1fr; }
}
