/* ============================================================
   EU Conqueror — Grand Strategy Map Styling
   Stylized after classic strategy-game aesthetics
   (parchment-meets-staff-room map). No copyrighted assets.
   ============================================================ */

:root {
    --bg-deep:        #1a242e;
    --bg-panel:       #233241;
    --bg-panel-2:     #2d4054;
    --line-strong:    #0d141b;
    --line-soft:      #2a3a4c;
    --gold:           #f5d36b;
    --gold-dim:       #b69b3f;
    --ink:            #e6dec5;
    --ink-dim:        #a89e84;
    --danger:         #c8553d;
    --water:          #3a5e7d;

    --tt-bg:          rgba(20, 28, 38, 0.97);
    --tt-border:      #f5d36b;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    color: var(--ink);
    font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
    font-size: 14px;
    /* Drag-to-pan on the map otherwise paints text blue across labels,
       country names, and HUD chips. Disable text selection globally for
       the game UI and only re-enable on real text inputs (re-enabled in
       a more specific rule below if/when we add any). */
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
input, textarea {
    -webkit-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ---------- Top header bar ---------- */
#top-bar {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 18px;
    background:
        linear-gradient(90deg, rgba(245, 211, 107, 0.10), transparent 18%, transparent 82%, rgba(245, 211, 107, 0.07)),
        linear-gradient(180deg, #273747 0%, #172532 56%, #101923 100%);
    border-bottom: 2px solid var(--gold-dim);
    box-shadow:
        0 2px 10px rgba(0,0,0,0.62),
        inset 0 -1px 0 rgba(245, 211, 107, 0.18),
        inset 0 1px 0 rgba(255,255,255,0.04);
    z-index: 30;
    position: relative;
}

/* HOI4-style player block: large flag + country name on the left.
   Pre-selection it shows the game title; post-selection swaps to the
   chosen country's flag + name. */
.title-block {
    display: flex;
    align-items: center;
    gap: 14px;
}
.player-flag {
    height: 44px;
    width: 66px;
    object-fit: cover;
    border: 1px solid var(--gold-dim);
    border-radius: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.55), inset 0 0 0 1px rgba(0,0,0,0.4);
    flex-shrink: 0;
    background: #14202b;
}
.player-meta { display: flex; flex-direction: column; gap: 2px; }
#top-bar h1 {
    font-family: Georgia, "Times New Roman", serif;
    font-size: 20px;
    margin: 0;
    color: var(--gold);
    letter-spacing: 3px;
    text-shadow: 0 1px 0 #000;
    line-height: 1.1;
}
.subtitle {
    font-size: 12px;
    color: var(--ink-dim);
    font-style: italic;
}

.header-controls { display: flex; gap: 14px; align-items: center; }

.clock-hud {
    display: grid;
    min-width: 146px;
    padding: 5px 11px;
    background:
        linear-gradient(180deg, rgba(35, 50, 65, 0.92), rgba(13, 20, 27, 0.92)),
        rgba(0,0,0,0.25);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
    font-variant-numeric: tabular-nums;
    text-align: center;
}
/* Hour:minute display is hidden — with 24h/tick the time field
   would always read 00:00. The date itself is the meaningful clock
   information; we promote it to the prominent gold style that the
   time field used to have. */
.clock-time {
    display: none;
}
.clock-date {
    color: var(--gold);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 1.2px;
    line-height: 1;
    text-shadow: 0 1px 0 #000;
    white-space: nowrap;
}

/* ---------- Treasury HUD (top bar) ---------- */
.treasury-hud {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}
.treasury-icon { width: 22px; height: 22px; flex-shrink: 0; }
.treasury-value {
    font-weight: 700;
    color: var(--gold);
    min-width: 50px;
    text-align: right;
    font-size: 14px;
}
.treasury-rate {
    font-size: 11px;
    color: var(--ink-dim);
    min-width: 40px;
}
.treasury-rate.positive { color: #7ec97e; }
.treasury-rate.negative { color: var(--danger); }

/* HUD hover tooltips. Anchored beneath each HUD chip; the parent has
   position:relative (set on .treasury-hud above) so the absolute
   positioning here pins to the HUD bottom-right corner. */
.treasury-hud { position: relative; }
.hud-tooltip {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 240px;
    padding: 10px 12px;
    background: var(--tt-bg);
    border: 1px solid var(--tt-border);
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.65);
    font-size: 12px;
    color: var(--ink);
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
    z-index: 100;
    font-variant-numeric: tabular-nums;
}
.treasury-hud:hover .hud-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}
.hud-tooltip .tt-title {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 800;
    color: var(--gold);
    border-bottom: 1px solid var(--gold-dim);
    padding-bottom: 5px;
    margin-bottom: 6px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.hud-tooltip .tt-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
    padding: 2px 0;
    color: var(--ink-dim);
}
.hud-tooltip .tt-row b {
    color: var(--ink);
    font-weight: 700;
}
.hud-tooltip .tt-row.positive b { color: #7ec97e; }
.hud-tooltip .tt-row.negative b { color: var(--danger); }
.hud-tooltip .tt-row.net b      { color: var(--gold); }
.hud-tooltip .tt-divider {
    height: 1px;
    background: rgba(245, 211, 107, 0.25);
    margin: 6px 0;
}
.hud-tooltip .tt-section {
    font-size: 10px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 4px 0 2px;
}

/* ---------- Unit cards (HOI4-style chits) ---------- */
/* One card per unit type. Shows the owner's flag, the unit icon,
   the unit name + cost, and the count stationed in this state. On
   player-owned states each card also has a +1 recruit button. */
.unit-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.unit-card {
    display: grid;
    grid-template-columns: 38px 44px 1fr auto;
    align-items: center;
    gap: 9px;
    padding: 7px 9px;
    background: linear-gradient(180deg, var(--bg-panel-2), #243443);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    position: relative;
}
.unit-card-flag {
    width: 38px;
    height: 26px;
    object-fit: cover;
    border: 1px solid #000;
    border-radius: 2px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}
.unit-card-icon {
    width: 44px;
    height: 44px;
    background: radial-gradient(circle, #2a3a4c 0%, #1a242e 100%);
    border-radius: 50%;
    border: 1px solid var(--gold-dim);
    box-shadow: inset 0 0 6px rgba(0,0,0,0.6), 0 1px 2px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
}
.unit-card-icon img { width: 38px; height: 38px; display: block; }
.unit-card-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.unit-card-name {
    font-family: Georgia, serif;
    font-weight: 700;
    font-size: 13px;
    color: var(--ink);
    line-height: 1.1;
}
.unit-card-cost {
    font-size: 10px;
    color: var(--ink-dim);
    font-variant-numeric: tabular-nums;
    line-height: 1.2;
}
.unit-card-cost b { color: var(--gold); font-weight: 600; }
.unit-card-stats {
    display: flex;
    gap: 7px;
    font-size: 9.5px;
    color: var(--ink-dim);
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
    line-height: 1.1;
}
.unit-card-stats span { white-space: nowrap; }
.unit-card-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
}
.unit-card-count {
    font-family: Georgia, serif;
    font-weight: 760;
    font-size: 18px;
    color: var(--gold);
    font-variant-numeric: tabular-nums;
    line-height: 1;
    text-shadow: 0 1px 0 #000;
    min-width: 32px;
    text-align: right;
}
.unit-card-count.zero { color: var(--ink-dim); text-shadow: none; }
.unit-card-btn {
    background: var(--gold);
    color: #1a1a1a;
    border: 1px solid var(--gold-dim);
    padding: 2px 10px;
    font-weight: 700;
    font-size: 12px;
    border-radius: 3px;
    cursor: pointer;
    line-height: 1.1;
    box-shadow: 0 1px 0 rgba(0,0,0,0.4);
}
.unit-card-btn:hover:not([disabled]) { background: #ffe27d; }
.unit-card-btn[disabled] {
    background: #4a4a4a;
    color: #888;
    border-color: #333;
    cursor: not-allowed;
    box-shadow: none;
}

/* ---------- Division counters on the map (HOI4-style chits) ---------- */
.division-counter {
    cursor: pointer;
    pointer-events: all;
}
/* Foreign counters (anyone but the player): clicks fall through to the
   underlying state path so the player can still inspect via the side panel. */
.division-counter.relation-neutral,
.division-counter.relation-enemy,
.division-counter.relation-ally {
    cursor: default;
    pointer-events: none;
}
.division-counter .div-hitbox {
    fill: transparent;
    stroke: none;
}
.division-counter .div-bg {
    stroke: var(--gold-dim);
    stroke-width: 0.28;
    vector-effect: non-scaling-stroke;
}
/* Diplomatic relation -> background color.
   self = olive green, neutral = original dark grey, enemy = dark red,
   ally = teal. Diplomacy isn't wired yet so only self + neutral fire today. */
.division-counter.relation-self    .div-bg { fill: rgba(40, 76, 40, 0.94); }
.division-counter.relation-neutral .div-bg { fill: rgba(20, 28, 38, 0.94); }
.division-counter.relation-enemy   .div-bg { fill: rgba(120, 30, 30, 0.94); }
.division-counter.relation-ally    .div-bg { fill: rgba(35, 95, 95, 0.94); }
.division-counter:hover .div-bg {
    stroke: var(--gold);
    stroke-width: 0.55;
}
.division-counter.selected .div-bg {
    stroke: var(--gold);
    stroke-width: 0.85;
    filter: drop-shadow(0 0 2px rgba(245, 211, 107, 0.9));
}
.selection-box {
    fill: rgba(245, 211, 107, 0.10);
    stroke: var(--gold);
    stroke-width: 0.8;
    stroke-dasharray: 1.5 1;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 0 2.5px rgba(245, 211, 107, 0.85));
    pointer-events: none;
}
/* In-transit stacks: dashed gold border is the "marching" cue — the fill
   stays at full opacity so the chit reads cleanly against the map. (Earlier
   versions dropped opacity + fill alpha, producing a washed-out counter
   that felt like a bug rather than a signal. Dashed border alone is enough.) */
.division-counter.moving .div-bg {
    stroke-dasharray: 1.5 1;
    stroke: var(--gold);
}
.division-counter.moving.relation-self    .div-bg { fill: rgba(40, 76, 40, 0.94); }
.division-counter.moving.relation-neutral .div-bg { fill: rgba(20, 28, 38, 0.94); }
.division-counter.moving.relation-enemy   .div-bg { fill: rgba(120, 30, 30, 0.94); }
.division-counter.moving.relation-ally    .div-bg { fill: rgba(35, 95, 95, 0.94); }

/* Movement path indicator: smooth green line tracing the planned route,
   visible while a stack is in transit. Marches with a dash animation. */
.movement-path {
    fill: none;
    stroke: #4ec46e;
    stroke-width: 1.7;
    stroke-linejoin: round;
    stroke-linecap: round;
    stroke-dasharray: 3 2;
    opacity: 0.9;
    pointer-events: none;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 0 1.5px rgba(78, 196, 110, 0.55));
    animation: movement-march 0.7s linear infinite;
}
@keyframes movement-march {
    to { stroke-dashoffset: -5; }
}

.division-counter .div-count {
    font-family: Georgia, serif;
    font-weight: 800;
    fill: #fff;
    font-size: 2.25px;
    text-anchor: middle;
    pointer-events: none;
}
.division-counter .div-count-bg {
    fill: rgba(0,0,0,0.85);
    stroke: var(--gold-dim);
    stroke-width: 0.18;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
}
.division-counter .div-flag-frame {
    fill: none;
    stroke: rgba(0,0,0,0.85);
    stroke-width: 0.18;
    vector-effect: non-scaling-stroke;
}

/* "Move target" hint - applied to states while division counters are selected
   so the player can see where they'd be moving to. */
body.has-selected-stack .state,
body.has-selected-divisions .state {
    cursor: crosshair;
}

.unit-grid-empty {
    padding: 10px;
    text-align: center;
    font-style: italic;
    color: var(--ink-dim);
    font-size: 12px;
}

.recruit-maint {
    margin-top: 8px;
    font-size: 11px;
    color: var(--ink-dim);
    font-style: italic;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
/* HOI4-style diplomacy notification strip — centered below the
   top-bar. Each tile is a small panel with the event icon filling
   most of it, plus the relevant country's flag overlaid in the
   bottom-right corner so the player can read at a glance which
   nation triggered the notification. Tiles slide in from above
   on creation and fade out after a few seconds. */
.diplomacy-notifications {
    position: absolute;
    top: 70px;                   /* top-bar height (64) + 6px gap */
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 6px;
    z-index: 25;
    pointer-events: none;        /* tiles individually re-enable */
}
.diplomacy-notification {
    position: relative;
    width: 44px;
    height: 44px;
    background: linear-gradient(180deg, #273747, #101923);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    cursor: default;
    animation: diplomacyNotificationIn 0.28s ease;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.diplomacy-notification:hover {
    border-color: var(--gold);
}
.diplomacy-notification.fading {
    opacity: 0;
    transform: translateY(-8px);
}
.diplomacy-notification-icon {
    position: absolute;
    inset: 4px;
    width: calc(100% - 8px);
    height: calc(100% - 8px);
    object-fit: contain;
    pointer-events: none;
}
.diplomacy-notification-flag {
    position: absolute;
    right: -3px;
    bottom: -3px;
    width: 20px;
    height: 13px;
    border: 1px solid #000;
    background: #555 center/cover no-repeat;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
    pointer-events: none;
}
@keyframes diplomacyNotificationIn {
    from { opacity: 0; transform: translateY(-12px) scale(0.92); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.toggle {
    font-size: 12px;
    color: var(--ink-dim);
    cursor: pointer;
    user-select: none;
}
.toggle input { vertical-align: middle; margin-right: 4px; accent-color: var(--gold); }

/* ---------- Stage / map container ---------- */
/* Stage background matches the SVG sea, so wide/tall viewports and
   camera edges read as ocean instead of the page backdrop. */
#stage {
    position: absolute;
    top: 64px; left: 0; right: 0; bottom: 0;
    overflow: hidden;
    background: radial-gradient(circle at 50% 42%, #456a89 0%, #385c7a 54%, #2c465f 100%);
}

#map {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    cursor: grab;
    background: transparent;
    touch-action: none;
    z-index: 1;
}
#map.dragging { cursor: grabbing; }

/* Canvas backing layer. Sits behind the SVG, paints all the heavy bulk
   visuals (sea, landmass, country fills, state polygons, borders, coast).
   pointer-events:none so the SVG above still gets all clicks/hovers. */
#map-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    background: #3a5e7d;
    filter: saturate(1.03) contrast(1.015);
}

/* Canvas paints the sea now — the SVG sea rect would be a redundant
   full-screen pattern fill on every viewBox change. Hidden, not removed,
   so a future revert is a one-line CSS change. */
#sea {
    display: none;
}

/* Same logic: state polygons in SVG are now invisible click targets only.
   Country fill stays in canvas. The :hover and .selected stroke rules from
   .state below still light up via the transparent path's outline. */
.state-underlay {
    display: none;
}
body.box-selecting #map { cursor: crosshair; }

/* ---------- States (SVG polygons) ---------- */
/* The default stroke is set INLINE in JS to match the country fill color.
   Why: adjacent same-country sub-state polygons often have vertex
   mismatches (especially after merges), and at sub-pixel scale the sea
   color leaks through those hairline gaps as faint dark seams. A 0.5px
   non-scaling stroke in the fill color closes those gaps invisibly.
   Hover / selected / state-borders / deep-zoom rules override the stroke. */
.state-underlay {
    stroke-width: 4;
    stroke-linejoin: round;
    stroke-linecap: round;
    pointer-events: none;
    shape-rendering: geometricPrecision;
}
.state {
    stroke-width: 2;
    stroke-linejoin: round;
    stroke-linecap: round;
    cursor: pointer;
    /* crispEdges disables anti-aliasing on the polygon edges. Anti-aliased
       semi-transparent pixels are what produce the visible seams between
       adjacent states; turning them off makes the seams vanish. Trade-off:
       state borders look slightly pixelated at deep zoom (wargame-poster
       aesthetic, not necessarily a downgrade). */
    shape-rendering: crispEdges;
    vector-effect: non-scaling-stroke;
    transition: stroke-width 0.08s ease, stroke 0.08s ease;
}
.state:hover {
    stroke: var(--gold);
    stroke-width: 1.4;
}
.state.selected {
    stroke: var(--gold);
    stroke-width: 2;
}
/* "State borders" toggle OR deep zoom (set in zoom.js when zoom >= 5):
   thin neutral seam between same-country states. stroke-width is in device
   pixels because of vector-effect: non-scaling-stroke on .state, so values
   under ~0.8 disappear into sub-pixel alpha. */
.show-state-borders .state,
body.deep-zoomed .state {
    stroke: rgba(0, 0, 0, 0.4);
    stroke-width: 1;
}
.show-state-borders .state:hover,
body.deep-zoomed .state:hover {
    stroke: var(--gold);
    stroke-width: 1.4;
}

.landmass {
    fill: rgba(219, 214, 186, 0.08);
    pointer-events: none;
}

/* National border overlays - rendered dynamically by js/modules/borders.js
   from state polygon edges, ONLY where two adjacent states have different
   owners. Updates whenever a state changes hands. Styled like HOI4's map:
   a soft dark bed, muted campaign-map color, then a thin ink center line. */
.national-border {
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
}
.national-border-shadow {
    stroke: rgba(4, 7, 9, 0.54);
    stroke-width: 2.25;
}
.national-border-rim {
    stroke: rgba(199, 170, 100, 0.56);
    stroke-width: 1.35;
    mix-blend-mode: multiply;
}
.national-border-core {
    stroke: rgba(8, 9, 9, 0.88);
    stroke-width: 0.72;
}
.hide-borders .national-border { display: none; }

/* Real coastline polylines from NE 50m, loaded via js/data/coastlines.json
   - thinner + distinct from national borders so they read separately. */
.coastline {
    fill: none;
    stroke: rgba(9, 14, 18, 0.85);
    stroke-width: 1.0;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    pointer-events: none;
}

/* State / city labels.
   Default: NO labels. The map relies on dots + stars + tooltips. The
   "All state names" toggle is still the way to bring every label back.
   City labels are deliberately smaller and lighter than capital
   labels — capitals are the "headline" cities (gold star + bold white
   text), regular cities are reference text. */
.state-label {
    display: none;
    font-family: Georgia, serif;
    font-size: 6px;
    fill: #1a1a1a;
    text-anchor: middle;
    pointer-events: none;
    paint-order: stroke;
    stroke: rgba(245,235,200,0.65);
    stroke-width: 1px;
    stroke-linejoin: round;
    font-weight: 400;
    letter-spacing: 0.2px;
}
.show-all-names .state-label { display: inline; }
/* Country-capital labels are an exception to the "no labels" default - they
   sit beside the gold star always so the player can identify each country
   at a glance. Slightly larger, bolder, and with a thicker parchment halo
   for legibility against any country fill. */
/* Capital labels: hidden when the whole-Europe view is up; revealed once
   zoom passes the threshold (body.zoomed-in, set in zoom.js). White fill
   with black halo so they read against any country color. */
.state-label-capital {
    display: none;
    font-weight: 700;
    font-size: var(--label-font-size, 8px);
    fill: #fff;
    stroke: rgba(0, 0, 0, 0.92);
    stroke-width: var(--label-stroke-width, 1.4px);
    letter-spacing: 0.4px;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.55));
}
body.zoomed-in .state-label-capital { display: inline; }

/* ---------- Country labels (HOI4 / Vic3 style curved atlas text) ---------- */
/* One fitted <textPath> per country. White serif on black halo for the same
   atlas-map feel as the capital labels. */
.country-label {
    font-family: 'Libre Baskerville', Georgia, "Times New Roman", serif;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 6px;
    fill: #fffaf0;
    stroke: rgba(0, 0, 0, 0.88);
    stroke-width: 2px;
    paint-order: stroke;
    pointer-events: none;
    text-transform: uppercase;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.48));
}
.country-label-secondary {
    font-size: 9px;
    letter-spacing: 3px;
    fill: rgba(232, 225, 205, 0.92);
    stroke-width: 1.4px;
}
/* Curve definitions live in <defs> and are non-rendering. */
.country-label-curve { fill: none; stroke: none; }
/* Hide country labels at deep zoom - at that scale the player is looking
   at provinces, not the country as a whole. */
body.deep-zoomed .country-label { display: none; }
/* Keep them visible during pan/zoom - one textPath per country is cheap. */

/* City marker - small black dot at every state's anchor. Always visible
   so the player can see "there's a city here" even when the label is hidden. */
.city-dot {
    fill: #1a1a1a;
    pointer-events: none;
}

/* Country-capital star marker - replaces the dot at the 28 country capitals. */
.capital-star {
    fill: var(--gold);
    stroke: #1a1a1a;
    stroke-width: 0.5;
    stroke-linejoin: round;
    pointer-events: none;
    vector-effect: non-scaling-stroke;
    filter:
        drop-shadow(0 1px 0 rgba(0,0,0,0.8))
        drop-shadow(0 0 3px rgba(245,211,107,0.48));
}

/* ---------- Pan/zoom perf optimizations ---------- */
/* During an active wheel/drag the browser must re-rasterize every visible
   SVG path on each viewBox change. We cut that cost by:
     1. Hiding labels and capital markers entirely (they re-show ~180ms after
        the last input event - same pattern HoI4/Civ use during pan).
     2. Switching state polygon shape-rendering to optimizeSpeed (skips
        antialiasing for fills - imperceptible while moving, restored at idle).
     3. Killing the stroke transition so hover doesn't trigger paints in the
        middle of a zoom. */
/* Stars + capital labels (and the city-dot replacement that appears once
   a capital is captured) stay visible during pan/zoom — they're few
   enough that the paint cost is negligible, and flickering markers/names
   feel jarring. Only the regular minor-state labels get hidden. */
body.interacting .state-label:not(.state-label-capital) {
    visibility: hidden;
}
body.interacting .state {
    shape-rendering: optimizeSpeed;
    transition: none;
    pointer-events: none;
}
body.interacting .state-underlay {
    shape-rendering: optimizeSpeed;
}
body.interacting .national-border {
    shape-rendering: optimizeSpeed;
}
body.interacting .state:hover {
    stroke: transparent;
    stroke-width: 0.5;
}

/* CSS containment lets the browser skip layout / paint work for offscreen
   subtrees during viewBox changes. `paint` is the safe one for SVG groups. */
#layer-states,
#layer-state-underlay,
#layer-borders,
#layer-coast,
#layer-labels,
#layer-capitals,
#layer-land {
    contain: paint;
}

/* ---------- Zoom controls ---------- */
#zoom-controls {
    position: absolute;
    left: 14px; top: 14px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 20;
}
#zoom-controls button {
    width: 36px; height: 36px;
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.5);
    transition: background 0.15s;
}
#zoom-controls button:hover { background: var(--bg-panel-2); }
#zoom-controls button:active { transform: translateY(1px); }

/* ---------- Left-side action buttons (Industry, Missions, ...) ---------- */
/* Vertically-stacked icon buttons pinned to the middle of the left edge.
   Each button has data-toggle-panel="<panel-id>" wired by main.js. */
#left-actions {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 20;
}
.left-action-button {
    width: 76px;
    height: 76px;
    padding: 0;
    overflow: hidden;
    background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
    border: 2px solid var(--gold);
    border-radius: 10px;
    cursor: pointer;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.55),
        0 0 0 1px rgba(0,0,0,0.4) inset,
        0 1px 0 rgba(255, 240, 200, 0.08) inset,
        0 0 14px rgba(245, 211, 107, 0.18);
    /* Spring-y transition: rises on hover, presses on click. transform
       transition is intentionally faster than the others so the click
       feedback is crisp. */
    transition:
        background 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.18s ease,
        transform 0.08s ease;
    will-change: transform;
}
.left-action-button:hover {
    background: linear-gradient(180deg, #3d556b, var(--bg-panel-2));
    border-color: #ffe27d;
    transform: translateY(-2px) scale(1.04);
    box-shadow:
        0 8px 18px rgba(0,0,0,0.6),
        0 0 0 1px rgba(0,0,0,0.4) inset,
        0 1px 0 rgba(255, 240, 200, 0.12) inset,
        0 0 22px rgba(245, 211, 107, 0.45);
}
.left-action-button:active {
    /* Press-in feel: shrink, drop shadow, brief gold flash via inset glow. */
    transform: translateY(1px) scale(0.96);
    box-shadow:
        0 1px 4px rgba(0,0,0,0.5),
        0 0 0 1px rgba(0,0,0,0.4) inset,
        0 0 14px rgba(245, 211, 107, 0.7) inset;
    transition-duration: 0.04s;
}
.left-action-button.active {
    background: linear-gradient(180deg, #46607a, var(--bg-panel-2));
    border-color: #ffe27d;
    box-shadow:
        0 4px 14px rgba(0,0,0,0.55),
        0 0 0 1px var(--gold) inset,
        0 0 24px rgba(245, 211, 107, 0.55);
}
.left-action-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    display: block;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6));
    transition: transform 0.15s ease;
}
.left-action-button:hover img { transform: scale(1.06); }
.left-action-button:active img { transform: scale(0.94); }

/* ---------- Left-side slide-in panels (Industry, Missions, ...) ---------- */
.left-panel {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 340px;
    background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-deep) 100%);
    border-right: 2px solid var(--gold-dim);
    box-shadow: 6px 0 24px rgba(0,0,0,0.55);
    z-index: 25;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.22s ease, visibility 0.22s;
    overflow: hidden;
}
.left-panel.hidden {
    transform: translateX(-100%);
    visibility: hidden;
}
.left-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(180deg, #233241, #1a242e);
    border-bottom: 1px solid var(--gold-dim);
    flex-shrink: 0;
}
.left-panel-header h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    color: var(--gold);
    letter-spacing: 2px;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #000;
}
.left-panel-close {
    background: transparent;
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}
.left-panel-close:hover {
    background: var(--bg-panel-2);
    border-color: var(--gold);
}
.left-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
}

/* ---------- Diplomacy left panel ---------- */
.diplomacy-intro {
    margin: 14px 16px 12px;
    font-size: 12px;
    line-height: 1.4;
    color: var(--ink-dim);
}
.diplomacy-legend {
    margin: 0 16px 16px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.20);
    border: 1px solid var(--gold-dim);
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.diplomacy-legend-row {
    display: grid;
    grid-template-columns: 18px 1fr;
    align-items: center;
    gap: 10px;
    font-size: 12px;
    color: var(--ink);
}
.dip-swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.55);
    box-shadow: 0 0 0 1px rgba(245, 211, 107, 0.22) inset;
}

/* ---------- Diplomacy detail (right-click) panel ---------- */
#diplomacy-detail-panel {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 340px;
    background: linear-gradient(180deg, var(--bg-panel) 0%, #1a2632 100%);
    border-left: 2px solid var(--gold-dim);
    box-shadow: -6px 0 24px rgba(0, 0, 0, 0.55);
    z-index: 30;
    display: flex;
    flex-direction: column;
    transform: translateX(0);
    transition: transform 0.22s ease, visibility 0.22s;
    overflow: hidden;
}
#diplomacy-detail-panel.hidden {
    transform: translateX(100%);
    visibility: hidden;
}
.diplomacy-detail-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    width: 28px;
    height: 28px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}
.diplomacy-detail-close:hover { border-color: var(--gold); }
#diplomacy-detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 48px 14px 16px;
    background: linear-gradient(180deg, #233241, #1a242e);
    border-bottom: 1px solid var(--gold-dim);
}
.diplomacy-detail-flag {
    display: block;
    width: 56px;
    height: 38px;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.6);
    box-shadow: 0 0 0 1px rgba(245, 211, 107, 0.22) inset;
    flex-shrink: 0;
}
#diplomacy-detail-name {
    margin: 0;
    color: var(--gold);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    letter-spacing: 1.3px;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #000;
}
.diplomacy-detail-sub {
    margin: 2px 0 0;
    color: var(--ink-dim);
    font-size: 11px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}
.diplomacy-detail-body {
    padding: 14px 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.diplomacy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(245, 211, 107, 0.18);
    border-radius: 5px;
    font-size: 13px;
}
.diplomacy-row-label {
    color: var(--ink-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.diplomacy-row-value {
    color: var(--ink);
    font-variant-numeric: tabular-nums;
    font-weight: bold;
}
.diplomacy-row-value.positive { color: #6ed089; }
.diplomacy-row-value.negative { color: #d96868; }
.diplomacy-row-value.controller-player { color: #6ed089; }
.diplomacy-row-value.controller-ai     { color: #b8a87a; }
.diplomacy-justify-status {
    margin-top: 2px;
    padding: 8px 10px;
    color: #9fc7e6;
    background: rgba(106, 150, 181, 0.12);
    border: 1px solid rgba(106, 150, 181, 0.45);
    border-radius: 5px;
    font-size: 11.5px;
    letter-spacing: 0.5px;
}
.diplomacy-justify-status.ready {
    color: var(--gold);
    background: rgba(245, 211, 107, 0.14);
    border-color: var(--gold-dim);
}
.diplomacy-justify-line {
    line-height: 1.4;
}
.diplomacy-justify-line b {
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}
.diplomacy-justify-sub {
    margin-top: 2px;
    font-size: 10.5px;
    color: var(--ink-dim);
    letter-spacing: 0.4px;
}
.diplomacy-justify-bar {
    margin-top: 6px;
    height: 4px;
    background: rgba(0, 0, 0, 0.40);
    border-radius: 2px;
    overflow: hidden;
}
.diplomacy-justify-bar > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #6a96b5, #9fc7e6);
    transition: width 0.25s ease;
}
.diplomacy-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}
.diplomacy-action-btn {
    background: linear-gradient(180deg, #2c3a48, #1f2a35);
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    padding: 10px 12px;
    border-radius: 4px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition:
        border-color 0.15s ease,
        background 0.15s ease,
        transform 0.08s ease;
}
.diplomacy-action-btn:hover:not(:disabled) {
    border-color: var(--gold);
    background: linear-gradient(180deg, #354556, #25313c);
}
.diplomacy-action-btn:active:not(:disabled) { transform: translateY(1px); }
.diplomacy-action-btn:disabled {
    color: var(--ink-dim);
    border-color: rgba(245, 211, 107, 0.18);
    background: rgba(0, 0, 0, 0.20);
    cursor: not-allowed;
}
.diplomacy-action-btn.declare:not(:disabled) {
    color: #ffb8b8;
    border-color: #b04848;
    background: linear-gradient(180deg, #4a2424, #2f1818);
}
.diplomacy-action-btn.declare:hover:not(:disabled) {
    border-color: #d96868;
    background: linear-gradient(180deg, #5d2c2c, #3a1d1d);
    box-shadow: 0 0 18px rgba(216, 80, 80, 0.3);
}

/* White Peace — calm parchment-white tint to contrast with the red
   Declare War button. Only visible while at war (toggled by JS). */
.diplomacy-action-btn.peace:not(:disabled) {
    color: #f0e8d6;
    border-color: rgba(220, 215, 195, 0.6);
    background: linear-gradient(180deg, #5a5a55, #3d3d39);
}
.diplomacy-action-btn.peace:hover:not(:disabled) {
    border-color: rgba(245, 240, 215, 0.9);
    background: linear-gradient(180deg, #6c6c66, #4a4a45);
    box-shadow: 0 0 18px rgba(220, 215, 195, 0.25);
}
/* Active when the OTHER side has sent us a peace offer — green tint
   so the "this is an action you can take RIGHT NOW" cue is obvious. */
.diplomacy-action-btn.peace.peace-incoming:not(:disabled) {
    color: #cfead2;
    border-color: rgba(110, 180, 120, 0.85);
    background: linear-gradient(180deg, #2f5a36, #1f3e26);
    box-shadow: 0 0 18px rgba(110, 200, 120, 0.32);
}
.diplomacy-action-btn.peace.peace-incoming:hover:not(:disabled) {
    background: linear-gradient(180deg, #3d6f48, #28522f);
    border-color: rgba(140, 220, 150, 1);
}

/* Non-Aggression Pact — defensive blue-tint to set it apart from the
   white peace (parchment) and declare war (red). Same "incoming offer
   = green" cue as the peace button. Same "active = highlight" cue
   when a NAP is signed (cancel button). */
.diplomacy-action-btn.nap:not(:disabled) {
    color: #d6e3f0;
    border-color: rgba(120, 170, 220, 0.6);
    background: linear-gradient(180deg, #2c3f55, #1a2838);
}
.diplomacy-action-btn.nap:hover:not(:disabled) {
    border-color: rgba(160, 200, 240, 0.95);
    background: linear-gradient(180deg, #38516e, #233448);
    box-shadow: 0 0 18px rgba(120, 180, 230, 0.28);
}
.diplomacy-action-btn.nap.nap-incoming:not(:disabled) {
    color: #cfead2;
    border-color: rgba(110, 180, 120, 0.85);
    background: linear-gradient(180deg, #2f5a36, #1f3e26);
    box-shadow: 0 0 18px rgba(110, 200, 120, 0.32);
}
.diplomacy-action-btn.nap.nap-incoming:hover:not(:disabled) {
    background: linear-gradient(180deg, #3d6f48, #28522f);
    border-color: rgba(140, 220, 150, 1);
}
.diplomacy-action-btn.nap.nap-cancel:not(:disabled) {
    color: #f0d6d6;
    border-color: rgba(190, 100, 100, 0.7);
    background: linear-gradient(180deg, #4a2828, #2e1a1a);
}
.diplomacy-action-btn.nap.nap-cancel:hover:not(:disabled) {
    background: linear-gradient(180deg, #5a3030, #3a2020);
    border-color: rgba(220, 130, 130, 0.95);
}

/* Diplomacy box — shows the viewed country's wars + active
   justifications. Sits below the action buttons, hidden when the
   country has neither. Each row = status icon, then flag, then
   country name. */
.diplomacy-relations {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--gold-dim);
}
.diplomacy-relations-title {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.6px;
    text-transform: uppercase;
    font-size: 11px;
    margin-bottom: 8px;
}
.diplomacy-relations-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.diplomacy-relations-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    background: rgba(0, 0, 0, 0.22);
    border: 1px solid var(--line-soft);
    border-radius: 3px;
}
.diplomacy-relations-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    object-fit: contain;
    /* PNG ships with white background; we strip it at load time but
       keep this rule as a fallback so the icon doesn't blend into
       the panel if the processed-data-url isn't ready yet on the
       very first paint. */
    image-rendering: auto;
}
/* Inline flag list: every country involved in this status (war or
   justification) gets a flag side-by-side. Wraps to a second line if
   a country is at war with many others. */
.diplomacy-relations-flags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    min-width: 0;
}
.diplomacy-relations-flag {
    width: 28px;
    height: 19px;
    object-fit: cover;
    border: 1px solid #000;
    border-radius: 2px;
    background: #333;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ---------- Industry panel — infrastructure tool ---------- */
.left-panel-body .infra-blurb {
    font-size: 11.5px;
    line-height: 1.4;
    margin: 0 0 14px;
    color: var(--ink-dim);
}

/* Big clickable infrastructure icon. Acts as the "enter build mode"
   toggle. While active it pulses with a gold glow and the body class
   `infra-build-mode` flips the map cursor to a crosshair. */
.infra-tool-button {
    display: block;
    width: 110px;
    height: 110px;
    margin: 0 auto;
    padding: 0;
    background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
    border: 2px solid var(--gold);
    border-radius: 12px;
    cursor: pointer;
    overflow: hidden;
    box-shadow:
        0 4px 14px rgba(0,0,0,0.55),
        0 0 0 1px rgba(0,0,0,0.4) inset,
        0 0 18px rgba(245, 211, 107, 0.18);
    transition:
        transform 0.08s ease,
        background 0.15s ease,
        border-color 0.15s ease,
        box-shadow 0.18s ease;
}
.infra-tool-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.5));
    transition: transform 0.15s ease;
}
.infra-tool-button:hover {
    background: linear-gradient(180deg, #3d556b, var(--bg-panel-2));
    border-color: #ffe27d;
    box-shadow:
        0 8px 20px rgba(0,0,0,0.6),
        0 0 0 1px rgba(0,0,0,0.4) inset,
        0 0 26px rgba(245, 211, 107, 0.45);
}
.infra-tool-button:hover img { transform: scale(1.05); }
.infra-tool-button:active { transform: translateY(1px) scale(0.97); }
.infra-tool-button.active {
    border-color: #ffe27d;
    background: linear-gradient(180deg, #46607a, var(--bg-panel-2));
    box-shadow:
        0 0 0 2px var(--gold) inset,
        0 0 24px rgba(245, 211, 107, 0.65),
        0 4px 14px rgba(0,0,0,0.55);
    animation: infra-tool-pulse 1.4s ease-in-out infinite;
}
@keyframes infra-tool-pulse {
    0%, 100% { box-shadow:
        0 0 0 2px var(--gold) inset,
        0 0 22px rgba(245, 211, 107, 0.55),
        0 4px 14px rgba(0,0,0,0.55); }
    50%      { box-shadow:
        0 0 0 2px var(--gold) inset,
        0 0 32px rgba(245, 211, 107, 0.85),
        0 4px 14px rgba(0,0,0,0.55); }
}

.infra-build-hint {
    margin-top: 14px;
    padding: 8px 10px;
    text-align: center;
    font-size: 11.5px;
    color: var(--gold);
    border: 1px dashed var(--gold-dim);
    border-radius: 4px;
    background: rgba(245, 211, 107, 0.06);
}
.infra-build-hint.hidden { display: none; }

/* While in build mode, hovering states shows the pickaxe / target cursor
   so the player knows clicks will upgrade rather than open a panel.
   Port build mode uses the same cursor; the port view-mode overlay (blue
   tint over coastal player states) is what telegraphs which states are
   actually eligible. */
body.infra-build-mode .state,
body.science-build-mode .state,
body.port-build-mode .state {
    cursor: cell;
}

.research-points-card {
    padding: 12px;
    border: 1px solid var(--gold-dim);
    border-radius: 6px;
    background:
        linear-gradient(180deg, rgba(245, 211, 107, 0.08), rgba(245, 211, 107, 0.02)),
        rgba(11, 18, 26, 0.45);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.24) inset;
}
.research-points-label {
    color: var(--ink-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.2px;
}
.research-points-value {
    margin-top: 4px;
    color: var(--gold);
    font: bold 28px Georgia, serif;
    text-shadow: 0 2px 0 #000;
}
.research-points-rate {
    margin-top: 2px;
    color: #7ec97e;
    font-size: 12px;
    font-weight: bold;
}

/* ---------- Selected army tray ---------- */
.selected-army-panel {
    position: absolute;
    left: 104px;
    top: 14px;
    width: min(345px, calc(100vw - 118px));
    z-index: 24;
    background:
        linear-gradient(180deg, rgba(33, 49, 64, 0.985), rgba(15, 23, 32, 0.985)),
        radial-gradient(circle at 20% 0%, rgba(245, 211, 107, 0.14), transparent 34%);
    border: 1px solid var(--gold-dim);
    border-radius: 6px;
    box-shadow:
        0 12px 28px rgba(0, 0, 0, 0.42),
        0 0 0 1px rgba(255, 238, 160, 0.05) inset;
    overflow: hidden;
    pointer-events: auto;
    animation: command-panel-in 0.16s ease-out;
}
@media (max-width: 560px) {
    .selected-army-panel {
        left: 14px;
        top: 104px;
        width: min(345px, calc(100vw - 28px));
    }
}
@keyframes command-panel-in {
    from { opacity: 0; transform: translateY(-6px) scale(0.985); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.selected-army-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 10px 9px 12px;
    border-bottom: 1px solid rgba(245, 211, 107, 0.28);
}
.selected-army-title {
    font-family: Georgia, serif;
    color: var(--gold);
    font-weight: 800;
    font-size: 16px;
    letter-spacing: 1.1px;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #000;
}
.selected-army-summary {
    margin-top: 2px;
    color: var(--ink-dim);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}
.selected-army-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    max-height: min(430px, calc(100vh - 170px));
    overflow: auto;
}
.selected-command-dashboard {
    padding: 8px;
    background:
        linear-gradient(180deg, rgba(245, 211, 107, 0.08), rgba(245, 211, 107, 0.02)),
        rgba(0, 0, 0, 0.20);
    border: 1px solid rgba(245, 211, 107, 0.20);
    border-radius: 5px;
}
.selected-readiness {
    display: grid;
    gap: 6px;
}
.selected-readiness-copy {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-variant-numeric: tabular-nums;
}
.selected-readiness-copy span {
    color: var(--ink-dim);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 1.3px;
    text-transform: uppercase;
}
.selected-readiness-copy b {
    color: var(--gold);
    font-family: Georgia, serif;
    font-size: 15px;
    text-shadow: 0 1px 0 #000;
}
.selected-readiness-bar {
    height: 8px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.36);
    border: 1px solid rgba(245, 211, 107, 0.20);
    border-radius: 999px;
}
.selected-readiness-bar i {
    display: block;
    height: 100%;
    background:
        linear-gradient(90deg, #6fbe68, var(--gold)),
        repeating-linear-gradient(90deg, transparent 0 8px, rgba(255,255,255,0.14) 8px 10px);
    border-radius: inherit;
    box-shadow: 0 0 12px rgba(245, 211, 107, 0.35);
}
.selected-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-top: 8px;
}
.selected-stat {
    min-width: 0;
    padding: 5px 4px;
    text-align: center;
    background: rgba(12, 20, 28, 0.58);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    font-variant-numeric: tabular-nums;
}
.selected-stat span {
    display: block;
    color: var(--ink-dim);
    font-size: 8.5px;
    text-transform: uppercase;
}
.selected-stat b {
    display: block;
    margin-top: 2px;
    overflow: hidden;
    color: var(--ink);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.selected-mix {
    display: flex;
    gap: 2px;
    height: 6px;
    margin-top: 8px;
    overflow: hidden;
    background: rgba(0,0,0,0.30);
    border-radius: 999px;
}
.selected-mix-segment {
    min-width: 0;
    border-radius: 999px;
}
.selected-mix-infantry { background: #7f9a57; }
.selected-mix-artillery { background: #b58a46; }
.selected-mix-lightTank { background: #8d8f98; }
.selected-command-hint {
    margin-top: 7px;
    color: var(--ink-dim);
    font-size: 10.5px;
    line-height: 1.25;
}
.selected-army-row {
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto 30px;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 6px;
    background: linear-gradient(180deg, #27384a, #1d2b39);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
    transition: border-color 0.12s ease, transform 0.08s ease, background 0.12s ease;
    cursor: pointer;
}
.selected-army-row:hover {
    border-color: var(--gold-dim);
    background: linear-gradient(180deg, #304457, #21313f);
}
.selected-army-row.inactive {
    opacity: 0.58;
    background: linear-gradient(180deg, #202c38, #17222d);
    border-color: rgba(255, 255, 255, 0.06);
}
.selected-army-row.inactive:hover {
    opacity: 0.82;
    border-color: rgba(245, 211, 107, 0.42);
}
.selected-army-row.inactive .selected-army-icon {
    filter: grayscale(0.6);
}
.selected-army-row.inactive .selected-army-count {
    color: var(--ink-dim);
    border-color: rgba(255, 255, 255, 0.08);
}
.selected-army-row:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: -2px;
}
.selected-army-icon {
    width: 34px;
    height: 34px;
    padding: 3px;
    border: 1px solid var(--gold-dim);
    border-radius: 50%;
    background: radial-gradient(circle, #2b3d50 0%, #131d27 100%);
}
.selected-army-copy {
    min-width: 0;
}
.selected-army-unit {
    color: var(--ink);
    font-family: Georgia, serif;
    font-weight: 800;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.selected-army-meta {
    margin-top: 2px;
    color: var(--ink-dim);
    font-size: 10.5px;
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.selected-army-count {
    min-width: 28px;
    padding: 3px 7px;
    color: var(--gold);
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(245, 211, 107, 0.22);
    border-radius: 4px;
    font-family: Georgia, serif;
    font-size: 14px;
    font-weight: 900;
    font-variant-numeric: tabular-nums;
    text-align: center;
    text-shadow: 0 1px 0 #000;
}
.selected-trash {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    color: #ff8a7f;
    background: rgba(92, 22, 22, 0.82);
    border: 1px solid rgba(255, 115, 100, 0.78);
    border-radius: 4px;
    cursor: pointer;
}
.selected-trash:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.selected-trash:hover {
    color: #ffd0cc;
    background: rgba(136, 34, 30, 0.92);
    border-color: #ff8a7f;
}
.selected-trash:active {
    transform: translateY(1px);
}
.trash-icon {
    position: relative;
    display: block;
    width: 12px;
    height: 13px;
    border: 2px solid currentColor;
    border-top: 0;
    border-radius: 1px;
}
.trash-icon::before,
.trash-icon::after {
    content: "";
    position: absolute;
    left: 50%;
    background: currentColor;
    transform: translateX(-50%);
}
.trash-icon::before {
    top: -5px;
    width: 16px;
    height: 2px;
    border-radius: 2px;
}
.trash-icon::after {
    top: -8px;
    width: 7px;
    height: 2px;
    border-radius: 2px 2px 0 0;
}

/* Action cluster on the army-info header — holds the split-half button
   and the trash button side by side. Gap keeps them visually distinct
   so the player doesn't accidentally hit destroy when reaching for split. */
.selected-army-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Split-half button: matches the trash button's footprint (30×30 grid,
   1px border, rounded corners) but uses a neutral gold tone instead of
   the destructive red. The icon itself is the PNG asset, sized inside
   the .split-icon span. */
.selected-split-btn {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: rgba(40, 50, 60, 0.82);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    cursor: pointer;
}
.selected-split-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.selected-split-btn:hover {
    background: rgba(60, 70, 80, 0.92);
    border-color: var(--gold);
}
.selected-split-btn:active {
    transform: translateY(1px);
}
.split-icon {
    display: block;
    width: 18px;
    height: 18px;
    background-image: url('../assets/icons/split_division_button.png');
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
}

/* ---------- Frontline orders ---------- */
.frontline-order {
    pointer-events: none;
}
.frontline-hit-path {
    fill: none;
    stroke: transparent;
    stroke-width: 28;
    stroke-linecap: round;
    stroke-linejoin: round;
    vector-effect: non-scaling-stroke;
    pointer-events: stroke;
    cursor: help;
}
.frontline-count-label-wrap {
    --frontline-label-base-size: 10px;
    --frontline-label-zoom-scale: 1;
    --frontline-label-stroke-base: 0.95px;
    --frontline-label-halo-base: 2.8px;
    --frontline-label-shadow-base: 3.8px;
    --frontline-label-track: 0.12px;
    pointer-events: none;
}
#stage.show-state-borders .frontline-count-label-wrap,
body.deep-zoomed .frontline-count-label-wrap {
    display: none;
}
.frontline-count-curve {
    fill: none;
    stroke: none;
    pointer-events: none;
}
.frontline-count-label-shadow,
.frontline-count-label-halo,
.frontline-count-label {
    font-family: Georgia, "Times New Roman", serif;
    font-size: calc(var(--frontline-label-base-size) * var(--frontline-label-zoom-scale));
    font-weight: 900;
    text-anchor: middle;
    dominant-baseline: middle;
    font-variant-numeric: tabular-nums;
    letter-spacing: calc(var(--frontline-label-track) * var(--frontline-label-zoom-scale));
    stroke-linejoin: round;
    pointer-events: none;
}
.frontline-count-label-shadow {
    fill: rgba(0,0,0,0.58);
    stroke: rgba(0,0,0,0.72);
    stroke-width: calc(var(--frontline-label-shadow-base) * var(--frontline-label-zoom-scale));
    paint-order: stroke;
    filter:
        drop-shadow(0 2px 1px rgba(0,0,0,0.46))
        drop-shadow(0 5px 4px rgba(0,0,0,0.30));
}
.frontline-count-label-halo {
    fill: none;
    stroke: rgba(0,0,0,0.88);
    stroke-width: calc(var(--frontline-label-halo-base) * var(--frontline-label-zoom-scale));
}
.frontline-count-label {
    fill: #f8f6ef;
    stroke: rgba(0, 0, 0, 0.94);
    stroke-width: calc(var(--frontline-label-stroke-base) * var(--frontline-label-zoom-scale));
    paint-order: stroke;
    filter: drop-shadow(0 1px 0 rgba(0,0,0,0.72));
}
.frontline-count-label-curve .frontline-count-label-shadow,
.frontline-count-label-curve .frontline-count-label-halo,
.frontline-count-label-curve .frontline-count-label {
    dominant-baseline: central;
}
.frontline-tooltip {
    position: fixed;
    z-index: 130;
    min-width: 210px;
    padding: 9px 10px;
    background: var(--tt-bg);
    border: 1px solid var(--gold);
    border-radius: 4px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.65);
    color: var(--ink);
    pointer-events: none;
    font-size: 12px;
}
.frontline-tt-title {
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 800;
    color: var(--gold);
    margin-bottom: 6px;
}
.frontline-tt-row {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin: 3px 0 7px;
}
.frontline-tt-row span { color: var(--ink-dim); }
.frontline-tt-units {
    display: grid;
    gap: 4px;
    border-top: 1px solid rgba(245, 211, 107, 0.22);
    padding-top: 7px;
}
.frontline-tt-unit {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) auto;
    align-items: center;
    gap: 6px;
}
.frontline-tt-unit img {
    width: 18px;
    height: 18px;
}

/* ---------- Frontline popup ---------- */
#frontline-modal {
    position: fixed;
    inset: 0;
    z-index: 90;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(8, 13, 18, 0.34);
}
.frontline-panel {
    width: min(430px, 94vw);
    background: linear-gradient(180deg, var(--bg-panel) 0%, #182532 100%);
    border: 2px solid var(--gold-dim);
    border-radius: 6px;
    box-shadow: 0 14px 34px rgba(0,0,0,0.72);
    color: var(--ink);
    position: relative;
    overflow: hidden;
}
#frontline-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: transparent;
    color: var(--ink-dim);
    border: none;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
#frontline-close:hover { color: var(--gold); }
.frontline-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px 13px;
    border-bottom: 1px solid var(--gold-dim);
    background: rgba(0,0,0,0.15);
}
.frontline-flag {
    width: 52px;
    height: 34px;
    object-fit: cover;
    border: 1px solid #000;
    border-radius: 2px;
    background: #333;
    box-shadow: 0 2px 6px rgba(0,0,0,0.45);
    flex-shrink: 0;
}
.frontline-header h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 17px;
    color: var(--gold);
    letter-spacing: 1.4px;
}
.frontline-header p {
    margin: 3px 0 0;
    color: var(--ink-dim);
    font-size: 12px;
}
.frontline-unit-rows {
    display: flex;
    flex-direction: column;
    gap: 7px;
    padding: 14px 16px 8px;
}
.frontline-unit-row {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) 94px;
    align-items: center;
    gap: 10px;
    padding: 8px 9px;
    background: linear-gradient(180deg, var(--bg-panel-2), #243443);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
}
.frontline-unit-icon {
    width: 38px;
    height: 38px;
    padding: 3px;
    background: radial-gradient(circle, #2a3a4c 0%, #1a242e 100%);
    border: 1px solid var(--gold-dim);
    border-radius: 50%;
}
.frontline-unit-copy {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.frontline-unit-copy b {
    font-family: Georgia, serif;
    font-size: 13px;
    color: var(--ink);
}
.frontline-unit-copy span {
    font-size: 11px;
    color: var(--ink-dim);
}
.frontline-count-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 22px;
    width: 94px;
    height: 32px;
}
.frontline-unit-input {
    width: 100%;
    height: 32px;
    background: #15212c;
    border: 1px solid var(--gold-dim);
    border-right: 0;
    border-radius: 4px 0 0 4px;
    color: var(--gold);
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
}
.frontline-unit-input::-webkit-outer-spin-button,
.frontline-unit-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.frontline-unit-input[type="number"] { appearance: textfield; }
.frontline-unit-input:disabled {
    color: #777;
    border-color: #3b4650;
    background: #202a34;
}
.frontline-stepper {
    display: grid;
    grid-template-rows: 1fr 1fr;
}
.frontline-arrow {
    position: relative;
    width: 22px;
    min-width: 22px;
    padding: 0;
    background: linear-gradient(180deg, #263747 0%, #16222d 100%);
    border: 1px solid var(--gold-dim);
    cursor: pointer;
}
.frontline-arrow-up { border-radius: 0 4px 0 0; }
.frontline-arrow-down {
    border-top: 0;
    border-radius: 0 0 4px 0;
}
.frontline-arrow::before {
    content: "";
    position: absolute;
    left: 50%;
    top: 50%;
    width: 0;
    height: 0;
    transform: translate(-50%, -50%);
}
.frontline-arrow-up::before {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-bottom: 6px solid var(--gold);
}
.frontline-arrow-down::before {
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 6px solid var(--gold);
}
.frontline-arrow:hover:not([disabled]) { background: #304355; }
.frontline-arrow:active:not([disabled]) { background: #101923; }
.frontline-arrow[disabled] {
    border-color: #3b4650;
    cursor: not-allowed;
    opacity: 0.55;
}
.frontline-summary {
    margin: 4px 16px 12px;
    padding: 8px 10px;
    min-height: 34px;
    background: rgba(0,0,0,0.22);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    color: var(--ink-dim);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}
.frontline-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--line-soft);
}
.frontline-btn {
    border-radius: 4px;
    padding: 8px 14px;
    font-weight: 800;
    font-size: 12px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    cursor: pointer;
}
.frontline-btn.secondary {
    background: #2a3948;
    color: var(--ink);
    border: 1px solid var(--line-soft);
}
.frontline-btn.secondary:hover { border-color: var(--gold-dim); }
.frontline-btn.primary {
    background: var(--gold);
    color: #1a1a1a;
    border: 1px solid var(--gold-dim);
}
.frontline-btn.primary:hover:not([disabled]) { background: #ffe27d; }
.frontline-btn.primary[disabled] {
    background: #555;
    color: #999;
    border-color: #444;
    cursor: not-allowed;
}

/* ---------- Tooltip ---------- */
#tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 100;
    background: var(--tt-bg);
    border: 1px solid var(--tt-border);
    border-radius: 4px;
    padding: 8px 12px;
    min-width: 180px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.6);
    font-size: 12px;
    color: var(--ink);
}
#tooltip.hidden { display: none; }
.tt-header {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--gold-dim);
    padding-bottom: 5px;
    margin-bottom: 6px;
}
.tt-flag {
    width: 18px; height: 12px;
    background: #555;
    border: 1px solid #000;
    display: inline-block;
}
.tt-name {
    font-family: Georgia, serif;
    font-weight: bold;
    color: var(--gold);
    font-size: 13px;
}
.tt-row { padding: 1px 0; }
.tt-label { color: var(--ink-dim); }

/* Floating infrastructure-cost label. Pinned to the centroid of the
   hovered state via JS-set left/top. translate(-50%,-50%) makes those
   coords the visual CENTER. Only visible while industry build mode is
   on (tooltip.js manages the .hidden class). */
#infra-cost-overlay,
.infra-construction-badge {
    position: absolute;
    transform: translate(-50%, -50%);
    pointer-events: none;
    z-index: 50;
    background: rgba(20, 28, 38, 0.94);
    border: 2px solid var(--gold);
    border-radius: 6px;
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.6),
        0 0 16px rgba(245, 211, 107, 0.45);
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 800;
    font-size: 18px;
    color: var(--gold);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-shadow: 0 1px 2px rgba(0,0,0,0.85);
}
#infra-cost-overlay.hidden,
.infra-construction-badge.hidden { display: none; }
.infra-cost-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6));
}

/* Affordability colors flip the text + glow without restyling the
   gold-coin icon (the gold icon stays gold no matter what). */
#infra-cost-overlay.affordable {
    color: var(--gold);
}
#infra-cost-overlay.broke {
    color: var(--danger);
    border-color: var(--danger);
    box-shadow:
        0 4px 12px rgba(0,0,0,0.6),
        0 0 16px rgba(200, 85, 61, 0.55);
}
#infra-cost-overlay.maxed {
    color: var(--gold);
    border-color: var(--gold);
}
#infra-cost-overlay.disabled {
    color: var(--ink-dim);
    border-color: var(--ink-dim);
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}
/* Construction-in-progress: gold has already been spent, so we hide the
   coin icon and show a countdown ("Building 87d") in a steel-blue tone
   so it doesn't read as a cost the player still has to pay.
   .infra-construction-badge is the persistent always-on variant; it lives
   in #infra-construction-layer and is always in "building" appearance. */
#infra-cost-overlay.building,
.infra-construction-badge {
    color: #9fc7e6;
    border-color: #6a96b5;
    box-shadow:
        0 4px 12px rgba(0,0,0,0.6),
        0 0 14px rgba(106, 150, 181, 0.45);
}
#infra-cost-overlay.building .infra-cost-icon { display: none; }
/* Container layer: pointer-events:none so it never blocks state hovers. */
#infra-construction-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 49;
}

/* ---------- Side panel ---------- */
#side-panel {
    position: absolute;
    right: 0; top: 0; bottom: 0;
    width: 340px;
    background: linear-gradient(180deg, var(--bg-panel) 0%, #1a2632 100%);
    border-left: 2px solid var(--gold-dim);
    color: var(--ink);
    padding: 18px 18px 24px;
    overflow-y: auto;
    z-index: 25;
    box-shadow: -4px 0 16px rgba(0,0,0,0.5);
    transform: translateX(0);
    transition: transform 0.25s ease;
}
/* Override the global .hidden so the side panel can SLIDE out instead of pop. */
#side-panel.hidden {
    display: block !important;
    transform: translateX(360px);
    pointer-events: none;
}

#side-close {
    position: absolute;
    top: 8px; right: 10px;
    background: transparent;
    color: var(--ink-dim);
    border: none;
    font-size: 22px;
    cursor: pointer;
}
#side-close:hover { color: var(--gold); }

#side-header {
    display: flex;
    gap: 12px;
    align-items: center;
    border-bottom: 1px solid var(--gold-dim);
    padding-bottom: 10px;
    margin-bottom: 10px;
}
.side-flag-box {
    width: 38px; height: 26px;
    border: 1px solid #000;
    background: #555;
    flex-shrink: 0;
}
#side-state-name {
    margin: 0;
    font-family: Georgia, serif;
    color: var(--gold);
    font-size: 18px;
    letter-spacing: 1px;
}
#side-country {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--ink-dim);
    font-style: italic;
}

.side-section {
    border-top: 1px solid var(--line-soft);
    padding: 10px 0;
}
.side-section:first-of-type { border-top: none; }
.side-section h3 {
    margin: 0 0 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--gold-dim);
    font-weight: bold;
}
.kv {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 13px;
}
.kv span { color: var(--ink-dim); }
.kv b { color: var(--ink); font-weight: 500; }

.chip-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.chip-list li {
    background: var(--bg-panel-2);
    border: 1px solid var(--line-soft);
    border-radius: 3px;
    padding: 3px 8px;
    font-size: 11px;
    color: var(--ink);
}
.chip-list li.clickable { cursor: pointer; }
.chip-list li.clickable:hover {
    border-color: var(--gold);
    color: var(--gold);
}

.placeholder p.muted {
    font-size: 11px;
    color: var(--ink-dim);
    font-style: italic;
    margin: 0;
}

/* ---------- Minimap ---------- */
#minimap-wrap {
    position: absolute;
    left: 14px; bottom: 14px;
    width: 220px;
    background: var(--bg-panel);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    padding: 4px 4px 6px;
    z-index: 20;
    box-shadow: 0 4px 12px rgba(0,0,0,0.6);
}
.minimap-title {
    font-size: 10px;
    letter-spacing: 3px;
    color: var(--gold-dim);
    text-align: center;
    margin-bottom: 2px;
    font-weight: bold;
}
.minimap-stack {
    position: relative;
    line-height: 0;
}
#minimap {
    display: block;
    width: 100%;
    height: auto;
    cursor: pointer;
    background: var(--water);
}
#minimap-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Side-panel-shift adjustment for top of stage */
.with-panel #minimap-wrap { /* leave minimap where it is for now */ }

/* ---------- Country selection screen ---------- */
/* Full-screen modal shown at startup. Map renders behind so selecting a
   country can highlight it visually before the game begins. */
#country-select {
    position: fixed;
    inset: 0;
    background: rgba(10, 16, 22, 0.88);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

/* Loading screen — covers the page during initial state-group merging /
   geometry / map-render work, and again after country-select while the
   gameState + AI + divisions wire up. Z-index above country-select so
   the post-select pass can re-show it on top of the picker overlay. */
#loading-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, #0c1318 0%, #142028 100%);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
#loading-screen.hidden {
    display: none;
}
.ls-panel {
    width: min(420px, 90vw);
    background: linear-gradient(180deg, var(--bg-panel) 0%, #1a2632 100%);
    border: 2px solid var(--gold-dim);
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.7);
    padding: 32px 28px 26px;
    text-align: center;
}
.ls-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(245, 211, 107, 0.18);
    border-top-color: var(--gold);
    border-radius: 50%;
    margin: 0 auto 18px;
    animation: ls-spin 1s linear infinite;
}
@keyframes ls-spin {
    to { transform: rotate(360deg); }
}
.ls-panel h2 {
    margin: 0 0 10px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 18px;
    color: var(--gold);
    letter-spacing: 3px;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #000;
}
.ls-status {
    font-size: 12px;
    color: var(--ink-dim);
    font-style: italic;
    min-height: 1.2em;
}
.cs-panel {
    width: min(1100px, 96vw);
    max-height: 92vh;
    background: linear-gradient(180deg, var(--bg-panel) 0%, #1a2632 100%);
    border: 2px solid var(--gold-dim);
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.7);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.cs-header {
    text-align: center;
    padding: 18px 20px 12px;
    border-bottom: 1px solid var(--gold-dim);
}
.cs-header h2 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 22px;
    color: var(--gold);
    letter-spacing: 4px;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #000;
}
.cs-subtitle {
    margin: 6px 0 0;
    font-size: 12px;
    color: var(--ink-dim);
    font-style: italic;
}
.cs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 8px;
    padding: 14px 18px;
    overflow-y: auto;
    flex: 1;
}
.cs-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel-2);
    border: 1px solid var(--line-soft);
    border-radius: 4px;
    padding: 10px 12px;
    cursor: pointer;
    transition: border-color 0.12s ease, transform 0.12s ease, background 0.12s ease;
    user-select: none;
}
.cs-card:hover {
    border-color: var(--gold-dim);
    transform: translateY(-2px);
    background: #364b62;
}
.cs-card.selected {
    border-color: var(--gold);
    background: #3d5670;
    box-shadow: 0 0 0 1px var(--gold), 0 4px 12px rgba(245, 211, 107, 0.18);
}
.cs-card-flag {
    width: 100%;
    height: 70px;
    margin-bottom: 10px;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(0,0,0,0.18), rgba(0,0,0,0.45)),
        var(--bg-deep);
    border: 1px solid #0d141b;
    box-shadow: inset 0 0 0 1px rgba(245,211,107,0.08);
}
.cs-card-flag img {
    max-width: 92%;
    max-height: 92%;
    width: auto;
    height: auto;
    object-fit: contain;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,0.55));
}
.cs-card.selected .cs-card-flag {
    box-shadow: inset 0 0 0 1px var(--gold);
}
.cs-card-name {
    font-family: Georgia, serif;
    font-size: 13px;
    color: var(--ink);
    font-weight: 700;
    line-height: 1.15;
    margin-bottom: 4px;
}
.cs-card-stats {
    font-size: 11px;
    color: var(--ink-dim);
    line-height: 1.4;
}
.cs-card-stats b { color: var(--ink); font-weight: 500; }
.cs-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid var(--line-soft);
    background: rgba(0,0,0,0.18);
}
.cs-selected-info {
    color: var(--ink-dim);
    font-size: 13px;
    font-style: italic;
}
.cs-selected-info b { color: var(--gold); font-style: normal; font-weight: 600; }
.cs-confirm {
    padding: 8px 22px;
    background: var(--gold);
    border: 1px solid var(--gold-dim);
    color: #1a1a1a;
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.15s ease;
}
.cs-confirm:hover:not([disabled]) { background: #ffe27d; }
.cs-confirm[disabled] {
    background: #5a5a5a;
    color: #999;
    cursor: not-allowed;
    border-color: #444;
}

/* ---------- Naval transport modal ---------- */
/* Triggered when the player clicks a coastal state with divisions selected
   from a ported source. Backdrop dims the rest of the UI; popup centers
   the cost summary. Same parchment-on-charcoal palette as the rest of the
   right-side panels. */
.naval-transport-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 12, 16, 0.55);
    z-index: 60;
}
.naval-transport-backdrop.hidden { display: none; }

.naval-transport-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 380px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    background: linear-gradient(180deg, var(--bg-panel) 0%, #1a2632 100%);
    border: 2px solid var(--gold);
    border-radius: 8px;
    box-shadow:
        0 14px 38px rgba(0, 0, 0, 0.65),
        0 0 24px rgba(245, 211, 107, 0.25);
    color: var(--ink);
    z-index: 61;
    display: flex;
    flex-direction: column;
}
.naval-transport-popup.hidden { display: none; }

.naval-transport-header {
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--gold-dim);
}
.naval-transport-header h2 {
    margin: 0;
    font-family: 'Libre Baskerville', Georgia, serif;
    font-size: 18px;
    color: var(--gold);
    letter-spacing: 0.5px;
}

.naval-transport-body {
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Red banner shown at the top of the popup when the plan is displayable
   (source has port, target is coastal) but not eligible (peace with
   target owner, can't afford gold/manpower). Gives visible feedback
   instead of silently failing the click. */
.naval-blocker {
    padding: 8px 12px;
    background: rgba(200, 90, 80, 0.18);
    border: 1px solid rgba(200, 90, 80, 0.55);
    border-radius: 4px;
    color: #e8a299;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

.naval-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.naval-target {
    display: flex;
    flex-direction: column;
}
.naval-target-label {
    font-size: 11px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.naval-target-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--ink);
}
.naval-badge {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid;
}
.naval-badge-friendly {
    background: rgba(110, 180, 120, 0.18);
    color: #9bd29f;
    border-color: rgba(110, 180, 120, 0.55);
}
.naval-badge-hostile {
    background: rgba(200, 90, 80, 0.18);
    color: #e8a299;
    border-color: rgba(200, 90, 80, 0.55);
}

.naval-section {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.naval-section-title {
    font-size: 11px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.naval-sources {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    padding: 8px 10px;
}
.naval-source-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
}
.naval-source-name { color: var(--ink); }
.naval-source-count { color: var(--gold); font-weight: 700; }

.naval-cost-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 6px 10px;
    border-bottom: 1px dashed rgba(245, 211, 107, 0.18);
    font-size: 13px;
}
.naval-cost-row:last-child { border-bottom: none; }
.naval-cost-label {
    color: var(--ink-dim);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.5px;
}
.naval-cost-value { color: var(--gold); font-weight: 700; }
.naval-cost-have {
    color: var(--ink-dim);
    font-weight: 400;
    font-size: 11px;
    margin-left: 6px;
}
.naval-cost-row.unaffordable .naval-cost-value { color: #e8a299; }
.naval-cost-row.naval-total {
    border-top: 1px solid var(--gold-dim);
    margin-top: 4px;
    padding-top: 8px;
}

.naval-transport-footer {
    padding: 12px 18px 16px;
    border-top: 1px solid var(--gold-dim);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.naval-transport-btn {
    padding: 8px 16px;
    border-radius: 4px;
    border: 1px solid;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.6px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.naval-transport-cancel {
    background: transparent;
    border-color: var(--gold-dim);
    color: var(--ink);
}
.naval-transport-cancel:hover {
    border-color: var(--gold);
    color: var(--gold);
}
.naval-transport-execute {
    background: var(--gold);
    border-color: var(--gold);
    color: #1a1a1a;
}
.naval-transport-execute:hover:not([disabled]) {
    background: #ffe27d;
    border-color: #ffe27d;
}
.naval-transport-execute[disabled] {
    background: #5a5a5a;
    border-color: #444;
    color: #999;
    cursor: not-allowed;
}

/* ---------- Send-gold modal ---------- */
/* Sits inside the same .naval-transport-popup shell so it inherits the
   full modal styling. These rules only style the send-gold-specific
   bits: amount input, quick-pick buttons, and the small blocker banner
   that appears when the typed amount is invalid. */
.send-gold-input {
    width: 100%;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    color: var(--gold);
    font-family: 'Libre Baskerville', Georgia, serif;
    font-size: 16px;
    font-weight: 700;
    text-align: right;
    /* Strip browser-default number-spinner buttons — the quick-pick
       buttons below cover the same use case more clearly. */
    appearance: textfield;
    -moz-appearance: textfield;
}
.send-gold-input::-webkit-outer-spin-button,
.send-gold-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
.send-gold-input:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 2px rgba(245, 211, 107, 0.25);
}
.send-gold-quick-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}
.send-gold-quick {
    flex: 1 1 auto;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid var(--gold-dim);
    border-radius: 4px;
    color: var(--ink);
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.send-gold-quick:hover:not([disabled]) {
    background: rgba(245, 211, 107, 0.12);
    border-color: var(--gold);
    color: var(--gold);
}
.send-gold-quick[disabled] {
    background: rgba(0, 0, 0, 0.1);
    color: #5a5a5a;
    border-color: #3a3a3a;
    cursor: not-allowed;
}
.send-gold-effect {
    display: flex;
    flex-direction: column;
}
.send-gold-blocker {
    padding: 6px 10px;
    margin-bottom: 8px;
    background: rgba(200, 90, 80, 0.18);
    border: 1px solid rgba(200, 90, 80, 0.55);
    border-radius: 4px;
    color: #e8a299;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
}

/* The Send Gold button shares the .diplomacy-action-btn class with
   Justify/Declare; tint it green to telegraph the friendly nature of
   the action so it visually contrasts with the war buttons. */
.diplomacy-action-btn.send-gold {
    background: linear-gradient(180deg, #2f5236, #1f3a26);
    border-color: rgba(110, 180, 120, 0.6);
    color: #cfead2;
}
.diplomacy-action-btn.send-gold:hover:not([disabled]) {
    background: linear-gradient(180deg, #3d6b48, #28492f);
    border-color: rgba(140, 210, 150, 0.85);
    color: #e6f5e7;
}
.diplomacy-action-btn.send-gold[disabled] {
    background: #3a3a3a;
    border-color: #2a2a2a;
    color: #6a6a6a;
}

/* At-war state for Send Gold: keep the green tint visible but knock
   opacity down so the button reads "this is the action you'd normally
   take, but it's blocked while you're at war." pointer-events: none
   makes the unclickable state explicit beyond the [disabled] attribute. */
.diplomacy-action-btn.send-gold.at-war {
    opacity: 0.35;
    pointer-events: none;
    cursor: not-allowed;
}

/* Diplomacy response modal — popup confirming the AI's verdict on a
   player-sent peace or NAP request. Two flags frame the title (other
   country top-left, player top-right) so the player can read at a
   glance who responded and which way. Same parchment-blue palette as
   the naval-transport popup for visual consistency. Slide-in scale
   animation on open; backdrop fade. */
.diplomacy-response-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 12, 16, 0.55);
    z-index: 80;
    animation: drBackdropIn 0.18s ease;
}
.diplomacy-response-backdrop.hidden { display: none; }

.diplomacy-response-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 420px;
    max-width: calc(100vw - 32px);
    background: linear-gradient(180deg, var(--bg-panel) 0%, #1a2632 100%);
    border: 2px solid var(--gold);
    border-radius: 10px;
    box-shadow:
        0 18px 46px rgba(0, 0, 0, 0.72),
        0 0 32px rgba(245, 211, 107, 0.28);
    color: var(--ink);
    z-index: 81;
    padding: 56px 22px 18px;     /* room for the flags pinned to the top */
    text-align: center;
    animation: drModalIn 0.22s ease;
}
.diplomacy-response-modal.hidden { display: none; }

.dr-flags {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    pointer-events: none;
}
.dr-flag {
    width: 56px;
    height: 36px;
    border: 1px solid #000;
    background: #555 center/cover no-repeat;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.dr-body { margin-top: 6px; }
.dr-title {
    margin: 0 0 8px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 20px;
    color: var(--gold);
    letter-spacing: 1px;
}
.dr-title.accepted { color: #b8e0bc; }
.dr-title.rejected { color: #f0c0c0; }
.dr-subtitle {
    margin: 0;
    font-size: 13px;
    color: var(--ink-dim);
    line-height: 1.4;
}

.dr-close {
    margin-top: 16px;
    background: linear-gradient(180deg, #2c3a48, #1f2a35);
    border: 1px solid var(--gold-dim);
    color: var(--gold);
    padding: 8px 28px;
    border-radius: 4px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}
.dr-close:hover {
    border-color: var(--gold);
    background: linear-gradient(180deg, #354556, #25313c);
}

@keyframes drBackdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes drModalIn {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.92); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

/* Mini history feed — center-right strip of recent world events.
   No background, no panel chrome; just floating text + flags so the
   map underneath stays readable. Each entry slides in from the right
   and fades as the column fills. Newest entry sits at the top. */
.history-feed {
    position: absolute;
    top: 50%;
    right: 14px;
    transform: translateY(-50%);
    width: 240px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    z-index: 18;
    pointer-events: none;        /* events can pass through the empty gaps */
    text-align: right;
}
.history-entry {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    color: #e3dcc4;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 12px;
    line-height: 1.3;
    text-shadow:
        0 1px 2px rgba(0, 0, 0, 0.85),
        0 0 4px rgba(0, 0, 0, 0.55);
    animation: historyEntryIn 0.35s ease;
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: auto;
}
.history-entry .he-text {
    flex: 1 1 auto;
    min-width: 0;
}
.history-entry .he-text b { color: #f5d36b; }    /* gold tone for country names */
.history-entry .he-flag {
    flex: 0 0 auto;
    width: 22px;
    height: 14px;
    border: 1px solid #000;
    background: #555 center/cover no-repeat;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}
.history-entry.fading {
    opacity: 0;
    transform: translateX(18px);
}
/* Older entries dim progressively so the eye is drawn to the freshest. */
.history-entry:nth-child(n+4) { opacity: 0.78; }
.history-entry:nth-child(n+6) { opacity: 0.55; }
.history-entry:nth-child(n+8) { opacity: 0.32; }
@keyframes historyEntryIn {
    from { opacity: 0; transform: translateX(28px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   Research tree — 4 horizontal paths listed vertically.

   .research-tree            container, stacks paths top-to-bottom
   .research-path            one row: name + horizontal tech sequence
   .research-path-name       left-side label per path
   .research-path-techs      flex row of tech buttons + arrows
   .research-tech            individual tech button (1 of 5 per path)
     .researched               completed — gold border, no hover
     .affordable               prereq met + RP available — clickable
     .locked                   prereq met but not enough RP — greyed
     .gated                    prereq not met — faded heavy
   .research-tech-arrow      between-tech "→" connector
   ============================================================ */
.research-tree {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.research-path {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.18);
    border: 1px solid rgba(245, 211, 107, 0.18);
    border-radius: 5px;
}
.research-path-name {
    color: var(--ink-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    font-weight: bold;
}
.research-path-techs {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    flex-wrap: nowrap;
}
.research-tech {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 4px;
    background: rgba(40, 40, 50, 0.55);
    border: 1px solid rgba(245, 211, 107, 0.25);
    border-radius: 4px;
    color: var(--ink);
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, transform 0.08s;
}
.research-tech:hover:not(:disabled) {
    transform: translateY(-1px);
}
.research-tech:disabled {
    cursor: not-allowed;
}
.research-tech-name {
    font-size: 10px;
    line-height: 1.15;
    margin-bottom: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.research-tech-cost {
    font-size: 11px;
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: var(--ink-dim);
}
.research-tech-arrow {
    color: rgba(245, 211, 107, 0.35);
    font-size: 12px;
    flex: 0 0 auto;
}
/* State variants. */
.research-tech.researched {
    background: rgba(140, 110, 50, 0.55);
    border-color: rgba(245, 211, 107, 0.85);
    color: #f5d36b;
}
.research-tech.researched .research-tech-cost {
    color: #f5d36b;
}
.research-tech.researched .research-tech-cost::before {
    content: '\2713 ';      /* checkmark */
}
.research-tech.affordable {
    background: rgba(60, 110, 60, 0.55);
    border-color: rgba(110, 208, 137, 0.75);
}
.research-tech.affordable .research-tech-cost {
    color: #6ed089;
}
.research-tech.affordable:hover {
    background: rgba(80, 140, 80, 0.65);
}
.research-tech.locked {
    background: rgba(40, 40, 50, 0.45);
    border-color: rgba(245, 211, 107, 0.18);
    opacity: 0.75;
}
.research-tech.gated {
    background: rgba(30, 30, 38, 0.45);
    border-color: rgba(120, 120, 130, 0.18);
    opacity: 0.4;
}

/* ============================================================
   Game-over modal — fires on player extinction (you-lost) or
   1 Jan 1940 deadline (final leaderboard). Pauses the tick loop
   while open. Big and centered; the player has to read it.
   ============================================================ */
.game-over-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 4, 0.78);
    backdrop-filter: blur(4px);
    z-index: 9000;
}
.game-over-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(620px, 92vw);
    max-height: 90vh;
    overflow-y: auto;
    background: linear-gradient(180deg, #2a2118 0%, #1a140e 100%);
    border: 2px solid #f5d36b;
    border-radius: 9px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(245, 211, 107, 0.18) inset;
    color: var(--ink);
    z-index: 9100;
    padding: 28px 32px 22px;
    font-family: inherit;
}
.game-over-header {
    text-align: center;
    margin-bottom: 18px;
}
.game-over-title {
    margin: 0 0 6px;
    font-size: 32px;
    letter-spacing: 1.5px;
    color: #f5d36b;
    font-family: 'Georgia', serif;
}
.game-over-title.lost {
    color: #d96868;
}
.game-over-title.victory {
    color: #6ed089;
}
.game-over-subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--ink-dim);
    letter-spacing: 0.5px;
}
.game-over-leaderboard {
    margin: 0 0 18px;
    border: 1px solid rgba(245, 211, 107, 0.28);
    border-radius: 5px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.22);
}
.game-over-row {
    display: grid;
    grid-template-columns: 36px 26px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    border-bottom: 1px solid rgba(245, 211, 107, 0.10);
    font-size: 13px;
}
.game-over-row:last-child { border-bottom: none; }
.game-over-row.player {
    background: rgba(110, 208, 137, 0.10);
    border-left: 3px solid #6ed089;
}
.game-over-row.first {
    background: rgba(245, 211, 107, 0.10);
}
.game-over-row.first .game-over-rank {
    color: #f5d36b;
}
.game-over-rank {
    font-weight: bold;
    color: var(--ink-dim);
    font-variant-numeric: tabular-nums;
}
.game-over-flag {
    width: 24px;
    height: 16px;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border: 1px solid rgba(0, 0, 0, 0.35);
    border-radius: 2px;
}
.game-over-name {
    font-weight: 600;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.game-over-states {
    font-weight: bold;
    font-variant-numeric: tabular-nums;
    color: #f5d36b;
}
.game-over-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
}
.game-over-btn {
    padding: 9px 20px;
    background: rgba(40, 30, 20, 0.85);
    border: 1px solid rgba(245, 211, 107, 0.38);
    border-radius: 5px;
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.12s;
}
.game-over-btn:hover {
    background: rgba(60, 45, 30, 0.95);
}
.game-over-btn.primary {
    background: rgba(110, 80, 30, 0.85);
    border-color: #f5d36b;
    color: #f5d36b;
    font-weight: bold;
}
.game-over-btn.primary:hover {
    background: rgba(140, 100, 40, 0.95);
}

/* ============================================================
   Main menu — full-screen pre-game overlay with Play / Settings.
   ============================================================ */
.main-menu-backdrop {
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, rgba(8, 6, 4, 0.92) 0%, rgba(20, 16, 10, 0.96) 100%);
    backdrop-filter: blur(2px);
    z-index: 9000;
}
.main-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, 92vw);
    text-align: center;
    color: var(--ink);
    z-index: 9100;
    padding: 36px 44px;
    background: linear-gradient(180deg, #2a2118 0%, #1a140e 100%);
    border: 2px solid #f5d36b;
    border-radius: 9px;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(245, 211, 107, 0.18) inset;
}
.main-menu-title {
    margin: 0 0 6px;
    font-family: 'Georgia', serif;
    font-size: 44px;
    letter-spacing: 3px;
    color: #f5d36b;
    text-transform: uppercase;
}
.main-menu-subtitle {
    margin: 0 0 28px;
    font-size: 14px;
    letter-spacing: 4px;
    color: var(--ink-dim);
    text-transform: uppercase;
}
.main-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: stretch;
}
.main-menu-btn {
    padding: 12px 24px;
    background: rgba(40, 30, 20, 0.85);
    border: 1px solid rgba(245, 211, 107, 0.38);
    border-radius: 5px;
    color: var(--ink);
    font-family: inherit;
    font-size: 14px;
    letter-spacing: 1px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.main-menu-btn:hover {
    background: rgba(60, 45, 30, 0.95);
    border-color: rgba(245, 211, 107, 0.65);
}
.main-menu-btn.primary {
    background: rgba(110, 80, 30, 0.85);
    border-color: #f5d36b;
    color: #f5d36b;
    font-weight: bold;
}
.main-menu-btn.primary:hover {
    background: rgba(140, 100, 40, 0.95);
}
/* Disabled state — used by the Multiplayer button on the mode picker.
   Apply both `:disabled` (for native <button disabled>) and `.disabled`
   so the same look works on non-button hosts if we ever reuse it. */
.main-menu-btn:disabled,
.main-menu-btn.disabled {
    background: rgba(20, 15, 10, 0.5);
    border-color: rgba(245, 211, 107, 0.15);
    color: rgba(255, 240, 200, 0.32);
    cursor: not-allowed;
}
.main-menu-btn:disabled:hover,
.main-menu-btn.disabled:hover {
    background: rgba(20, 15, 10, 0.5);
    border-color: rgba(245, 211, 107, 0.15);
}
.main-menu-btn-tag {
    display: block;
    margin-top: 4px;
    font-size: 10px;
    letter-spacing: 1.4px;
    color: rgba(245, 211, 107, 0.45);
    text-transform: uppercase;
}

/* ============================================================
   Main menu — unique title-screen look (scoped to #main-menu so
   the mode picker keeps the simpler shared style).
   ============================================================ */
#main-menu-backdrop {
    background:
        radial-gradient(ellipse at center, rgba(40, 28, 18, 0.78) 0%, rgba(8, 6, 4, 0.98) 70%),
        repeating-linear-gradient(135deg,
            rgba(245, 211, 107, 0.018) 0px,
            rgba(245, 211, 107, 0.018) 1px,
            transparent 1px,
            transparent 4px);
}
#main-menu {
    width: min(640px, 92vw);
    padding: 0;
    background:
        radial-gradient(ellipse at top, rgba(245, 211, 107, 0.07), transparent 65%),
        linear-gradient(180deg, #2a2118 0%, #16110b 100%);
    border: 2px solid #f5d36b;
    border-radius: 4px;
    box-shadow:
        0 30px 90px rgba(0, 0, 0, 0.75),
        0 0 60px rgba(245, 211, 107, 0.10),
        0 0 0 1px rgba(245, 211, 107, 0.20) inset,
        0 0 0 6px rgba(20, 14, 8, 0.95) inset,
        0 0 0 7px rgba(245, 211, 107, 0.45) inset;
    animation: main-menu-glow 4.5s ease-in-out infinite;
    overflow: hidden;
}
#main-menu::before,
#main-menu::after {
    content: "";
    position: absolute;
    width: 36px;
    height: 36px;
    border: 2px solid rgba(245, 211, 107, 0.6);
    pointer-events: none;
}
#main-menu::before {
    top: 14px;
    left: 14px;
    border-right: none;
    border-bottom: none;
}
#main-menu::after {
    bottom: 14px;
    right: 14px;
    border-left: none;
    border-top: none;
}
@keyframes main-menu-glow {
    0%, 100% {
        box-shadow:
            0 30px 90px rgba(0, 0, 0, 0.75),
            0 0 60px rgba(245, 211, 107, 0.10),
            0 0 0 1px rgba(245, 211, 107, 0.20) inset,
            0 0 0 6px rgba(20, 14, 8, 0.95) inset,
            0 0 0 7px rgba(245, 211, 107, 0.45) inset;
    }
    50% {
        box-shadow:
            0 30px 90px rgba(0, 0, 0, 0.75),
            0 0 110px rgba(245, 211, 107, 0.20),
            0 0 0 1px rgba(245, 211, 107, 0.32) inset,
            0 0 0 6px rgba(20, 14, 8, 0.95) inset,
            0 0 0 7px rgba(245, 211, 107, 0.65) inset;
    }
}

#main-menu .main-menu-emblem {
    margin: 36px auto 18px;
    width: 92px;
    height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
}
#main-menu .main-menu-emblem-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 10px rgba(245, 211, 107, 0.45));
}
#main-menu .emblem-ring {
    fill: none;
    stroke: rgba(245, 211, 107, 0.85);
    stroke-width: 1.4;
}
#main-menu .emblem-ring.inner {
    stroke: rgba(245, 211, 107, 0.45);
    stroke-dasharray: 2 3;
}
#main-menu .emblem-fill {
    fill: rgba(245, 211, 107, 0.85);
    stroke: rgba(245, 211, 107, 0.95);
    stroke-width: 0.6;
    stroke-linejoin: round;
}
#main-menu .emblem-stroke {
    fill: none;
    stroke: rgba(245, 211, 107, 0.85);
    stroke-width: 1.6;
    stroke-linecap: round;
}

#main-menu .main-menu-title {
    margin: 0 0 4px;
    font-family: 'Georgia', serif;
    font-weight: 700;
    font-size: 56px;
    letter-spacing: 9px;
    color: #f5d36b;
    text-transform: uppercase;
    line-height: 1.05;
    text-shadow:
        0 0 24px rgba(245, 211, 107, 0.55),
        0 0 50px rgba(245, 211, 107, 0.25),
        0 2px 0 rgba(0, 0, 0, 0.85);
}

#main-menu .main-menu-flourish {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin: 14px auto 4px;
    width: min(420px, 80%);
}
#main-menu .flourish-rule {
    flex: 1;
    height: 1px;
    background: linear-gradient(90deg,
        transparent,
        rgba(245, 211, 107, 0.7) 30%,
        rgba(245, 211, 107, 0.7) 70%,
        transparent);
}
#main-menu .flourish-diamond {
    color: rgba(245, 211, 107, 0.85);
    font-size: 12px;
    transform: translateY(-1px);
    text-shadow: 0 0 8px rgba(245, 211, 107, 0.6);
}

#main-menu .main-menu-subtitle {
    margin: 0 0 32px;
    font-family: 'Georgia', serif;
    font-style: italic;
    font-size: 15px;
    letter-spacing: 8px;
    color: rgba(245, 211, 107, 0.65);
    text-transform: uppercase;
}

#main-menu .main-menu-buttons {
    margin: 0 auto;
    max-width: 320px;
    padding: 0 56px;
    gap: 12px;
}

#main-menu .main-menu-btn {
    padding: 13px 24px;
    background: linear-gradient(180deg, rgba(40, 30, 20, 0.85), rgba(28, 22, 14, 0.85));
    border-radius: 2px;
    font-family: 'Georgia', serif;
    font-size: 14px;
    letter-spacing: 5px;
    text-transform: uppercase;
    transition: background 0.18s, border-color 0.18s, color 0.18s, box-shadow 0.18s;
}
#main-menu .main-menu-btn:hover {
    background: linear-gradient(180deg, rgba(60, 45, 30, 0.95), rgba(48, 36, 22, 0.95));
    border-color: #f5d36b;
    color: #f5d36b;
    box-shadow: 0 0 22px rgba(245, 211, 107, 0.22);
}
#main-menu .main-menu-btn.primary {
    background: linear-gradient(180deg, rgba(150, 105, 40, 0.9), rgba(110, 80, 30, 0.9));
}
#main-menu .main-menu-btn.primary:hover {
    background: linear-gradient(180deg, rgba(180, 130, 55, 0.95), rgba(140, 100, 40, 0.95));
    box-shadow: 0 0 32px rgba(245, 211, 107, 0.38);
}

#main-menu .main-menu-footer {
    margin: 30px 0 28px;
    font-family: 'Georgia', serif;
    font-style: italic;
    font-size: 11px;
    letter-spacing: 4px;
    color: rgba(245, 211, 107, 0.45);
    text-transform: uppercase;
}

/* ============================================================
   Pause menu — Esc-toggled overlay during gameplay.
   ============================================================ */
.pause-menu-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 4, 0.72);
    backdrop-filter: blur(3px);
    z-index: 9000;
}
.pause-menu {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(360px, 88vw);
    text-align: center;
    color: var(--ink);
    z-index: 9100;
    padding: 28px 32px;
    background: linear-gradient(180deg, #2a2118 0%, #1a140e 100%);
    border: 2px solid #f5d36b;
    border-radius: 9px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    gap: 9px;
}
.pause-menu-title {
    margin: 0 0 12px;
    font-family: 'Georgia', serif;
    font-size: 24px;
    letter-spacing: 2px;
    color: #f5d36b;
    text-transform: uppercase;
}
.pause-menu-btn {
    padding: 10px 18px;
    background: rgba(40, 30, 20, 0.85);
    border: 1px solid rgba(245, 211, 107, 0.32);
    border-radius: 5px;
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    letter-spacing: 0.6px;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.pause-menu-btn:hover {
    background: rgba(60, 45, 30, 0.95);
    border-color: rgba(245, 211, 107, 0.6);
}
.pause-menu-btn.primary {
    background: rgba(110, 80, 30, 0.85);
    border-color: #f5d36b;
    color: #f5d36b;
    font-weight: bold;
}
.pause-menu-btn.primary:hover {
    background: rgba(140, 100, 40, 0.95);
}

/* ============================================================
   Settings dialog — opens over the main menu or pause menu.
   z-index above the menus so it stacks correctly.
   ============================================================ */
.settings-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 6, 4, 0.72);
    backdrop-filter: blur(3px);
    z-index: 9200;
}
.settings-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(420px, 92vw);
    color: var(--ink);
    z-index: 9300;
    padding: 22px 26px;
    background: linear-gradient(180deg, #2a2118 0%, #1a140e 100%);
    border: 2px solid #f5d36b;
    border-radius: 9px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.settings-title {
    margin: 0 0 14px;
    font-family: 'Georgia', serif;
    font-size: 18px;
    letter-spacing: 2px;
    color: #f5d36b;
    text-transform: uppercase;
}
.settings-row {
    display: grid;
    grid-template-columns: 110px 1fr 36px;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    font-size: 13px;
}
.settings-label {
    color: var(--ink-dim);
}
.settings-row input[type="range"] {
    width: 100%;
    accent-color: #f5d36b;
}
.settings-value {
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: #f5d36b;
}
.settings-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 14px;
}
.settings-btn {
    padding: 8px 16px;
    background: rgba(40, 30, 20, 0.85);
    border: 1px solid rgba(245, 211, 107, 0.38);
    border-radius: 5px;
    color: var(--ink);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
}
.settings-btn:hover {
    background: rgba(60, 45, 30, 0.95);
}

/* ============================================================
   Tips overlay — center-right onboarding box, right-click to
   dismiss. Sits over the map; pointer events captured so left-
   clicks don't punch through to the canvas underneath.
   ============================================================ */
.tips-box {
    position: fixed;
    top: 50%;
    right: 18px;
    transform: translateY(-50%);
    width: 280px;
    max-width: 30vw;
    padding: 14px 16px 12px;
    background: linear-gradient(180deg, rgba(42, 33, 24, 0.96), rgba(26, 20, 14, 0.96));
    border: 1px solid rgba(245, 211, 107, 0.45);
    border-radius: 6px;
    color: var(--ink);
    font-size: 12px;
    z-index: 130;
    box-shadow:
        0 12px 30px rgba(0, 0, 0, 0.55),
        0 0 0 1px rgba(245, 211, 107, 0.12) inset;
    pointer-events: auto;
    animation: tips-fade-in 0.4s ease-out;
}
@keyframes tips-fade-in {
    from { opacity: 0; transform: translate(8px, -50%); }
    to   { opacity: 1; transform: translate(0,    -50%); }
}
.tips-title {
    margin: 0 0 10px;
    font-family: 'Georgia', serif;
    font-size: 13px;
    letter-spacing: 3px;
    color: #f5d36b;
    text-transform: uppercase;
    text-align: center;
}
.tips-list {
    margin: 0;
    padding: 0 0 0 18px;
    list-style: disc;
    line-height: 1.5;
    color: rgba(232, 222, 200, 0.92);
}
.tips-list li {
    margin-bottom: 7px;
}
.tips-list li:last-child {
    margin-bottom: 0;
}
.tips-list b {
    color: #f5d36b;
}
.tips-list kbd {
    display: inline-block;
    min-width: 16px;
    padding: 0 5px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid rgba(245, 211, 107, 0.4);
    border-radius: 3px;
    font-family: 'Consolas', monospace;
    font-size: 10px;
    color: #f5d36b;
    text-align: center;
    line-height: 16px;
}
.tips-footer {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid rgba(245, 211, 107, 0.18);
    font-size: 10px;
    text-align: center;
    color: rgba(245, 211, 107, 0.55);
    letter-spacing: 0.6px;
    font-style: italic;
}

/* Utility */
.hidden { display: none !important; }

/* ============================================================
   Research refresh - icon-first cards with visible bonuses.
   Kept at the end so it cleanly overrides the older compact tree rules.
   ============================================================ */
#research-panel.left-panel {
    width: 430px;
}
.research-path {
    position: relative;
    gap: 10px;
    padding: 10px;
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.035), rgba(0, 0, 0, 0.08)),
        rgba(0, 0, 0, 0.20);
    border-color: rgba(245, 211, 107, 0.20);
    border-radius: 6px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}
.research-path-header {
    display: flex;
    align-items: center;
    gap: 9px;
}
.research-path-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    padding: 4px;
    background: rgba(5, 8, 12, 0.50);
    border: 1px solid rgba(245, 211, 107, 0.30);
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.30);
}
.research-path-name {
    color: var(--gold);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 13px;
    line-height: 1;
    letter-spacing: 1.3px;
    text-shadow: 0 1px 0 #000;
}
.research-path-detail {
    margin-top: 3px;
    color: var(--ink-dim);
    font-size: 10px;
    letter-spacing: 0.4px;
}
.research-path-techs {
    position: relative;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: stretch;
    gap: 6px;
}
.research-path-techs::before {
    content: '';
    position: absolute;
    left: 8%;
    right: 8%;
    top: 32px;
    height: 2px;
    background: linear-gradient(90deg,
        rgba(245, 211, 107, 0.10),
        rgba(245, 211, 107, 0.45),
        rgba(245, 211, 107, 0.10));
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.55);
    pointer-events: none;
}
.research-tech {
    position: relative;
    z-index: 1;
    min-height: 106px;
    padding: 7px 4px 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background:
        radial-gradient(circle at 50% 14%, rgba(245, 211, 107, 0.10), transparent 42%),
        linear-gradient(180deg, rgba(45, 64, 84, 0.78), rgba(22, 31, 41, 0.86));
    border-color: rgba(245, 211, 107, 0.26);
    border-radius: 6px;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.05),
        0 2px 5px rgba(0, 0, 0, 0.22);
    transition: background 0.12s, border-color 0.12s, filter 0.12s, transform 0.08s;
}
.research-tech:hover:not(:disabled) {
    filter: brightness(1.08);
}
.research-tech-tier {
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 1px 3px;
    color: rgba(245, 211, 107, 0.78);
    background: rgba(0, 0, 0, 0.36);
    border: 1px solid rgba(245, 211, 107, 0.20);
    border-radius: 3px;
    font-size: 8px;
    font-weight: bold;
    line-height: 1.1;
}
.research-tech-icon-wrap {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
    background: radial-gradient(circle, rgba(245, 211, 107, 0.12), rgba(0, 0, 0, 0.34));
    border: 1px solid rgba(245, 211, 107, 0.28);
    border-radius: 50%;
}
.research-tech-icon {
    width: 24px;
    height: 24px;
    object-fit: contain;
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.75));
}
.research-tech-bonus {
    min-height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #f5d36b;
    font-size: 9.5px;
    line-height: 1.08;
    font-weight: bold;
    text-align: center;
    text-transform: uppercase;
    text-shadow: 0 1px 0 #000;
}
.research-tech-name {
    width: 100%;
    min-height: 21px;
    margin-bottom: 0;
    color: var(--ink);
    font-size: 9.5px;
    line-height: 1.1;
    text-align: center;
    white-space: normal;
    overflow: hidden;
    text-overflow: clip;
}
.research-tech-cost {
    margin-top: auto;
    padding: 2px 5px;
    color: var(--ink-dim);
    background: rgba(0, 0, 0, 0.24);
    border-radius: 3px;
    font-size: 9.5px;
    white-space: nowrap;
}
.research-tech.researched {
    background:
        radial-gradient(circle at 50% 14%, rgba(245, 211, 107, 0.22), transparent 45%),
        linear-gradient(180deg, rgba(135, 106, 46, 0.72), rgba(63, 48, 24, 0.84));
    border-color: rgba(245, 211, 107, 0.90);
    box-shadow:
        inset 0 0 0 1px rgba(255, 238, 160, 0.18),
        0 0 10px rgba(245, 211, 107, 0.16);
}
.research-tech.affordable {
    background:
        radial-gradient(circle at 50% 14%, rgba(110, 208, 137, 0.22), transparent 45%),
        linear-gradient(180deg, rgba(49, 92, 63, 0.82), rgba(25, 51, 34, 0.90));
    border-color: rgba(110, 208, 137, 0.82);
}
.research-tech.affordable .research-tech-icon-wrap {
    border-color: rgba(110, 208, 137, 0.70);
}
.research-tech.locked {
    background: linear-gradient(180deg, rgba(38, 48, 60, 0.62), rgba(20, 27, 36, 0.76));
    border-color: rgba(245, 211, 107, 0.16);
    opacity: 0.72;
}
.research-tech.gated {
    background: linear-gradient(180deg, rgba(28, 34, 42, 0.52), rgba(14, 18, 24, 0.76));
    border-color: rgba(120, 120, 130, 0.16);
    opacity: 0.42;
}
