:root {
  --accent: #C45C56;
  --ink: #1E1E1E;
  --hud: #161616;
  --hud-2: #222;
  --line: #3a3a3a;
  --paper: #f4efe4;
  --gold: #f3e2a4;
  --muted: #b7b7b7;
  --nav-h: 56px;
  --nav-text: #f5f5f5;
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  color: #f2f2f2;
  background: var(--hud);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr) auto auto;
  background: #101010;
  color: #f2f2f2;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
code { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 0.92em; }

/* Age-of-Empires bar stays in the DOM for the partida clock, but it is not the visible header. */
.topbar { display: none; }

.nav {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 1.25rem;
  z-index: 50;
  background: linear-gradient(to bottom, rgba(0,0,0,.55), transparent);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  pointer-events: none;
}
.nav-brand { display: flex; align-items: center; pointer-events: auto; text-decoration: none; }
.nav-logo { height: 22px; width: auto; display: block; }
@media (min-width: 1100px) {
  .nav { padding: 0 2rem; }
}
.resources { display: flex; gap: 14px; flex: 1; align-items: center; }
.resource {
  display: flex; align-items: center; gap: 6px;
  min-width: 0;
}
.resource .label, .resource .unit { display: none; }
.resource .num {
  font-size: 18px; font-weight: 750; color: var(--gold);
  font-variant-numeric: tabular-nums; line-height: 1;
  text-shadow: 0 1px 0 #000;
}
.clock-block { text-align: center; min-width: 140px; }
.clock {
  font-size: 22px; font-weight: 750; color: #fff;
  font-variant-numeric: tabular-nums; letter-spacing: 0.06em; line-height: 1;
}
.clock-sub { font-size: 10px; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; }
body.is-closed .clock { color: #ffb4b4; }
.places { display: flex; gap: 4px; }
.places button {
  background: #514C47; color: #F7F4EF; border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 650;
}
.places button.is-on { background: #C45C56; color: #fff; border-radius: 999px; }

.stage { position: relative; min-height: 0; min-width: 0; }
.map {
  position: absolute; inset: 0;
  overflow: hidden;
  touch-action: none;
  background: #141414;
  --pass: 0;
}
#gmap {
  position: absolute; inset: 0; z-index: 0;
  pointer-events: auto;
  background: #141414;
}
.map.pass-on #gmap { pointer-events: none; }
.gmap-error {
  position: absolute; z-index: 5; left: 12px; bottom: 12px;
  margin: 0; max-width: min(420px, calc(100% - 24px));
  background: rgba(16,16,16,.9); color: #fff;
  border: 1px solid #666; padding: 8px 10px;
  font-size: 14px; font-weight: 700;
  pointer-events: none;
}
.gmap-error[hidden] { display: none; }
.world { position: absolute; inset: 0; z-index: 1; transform-origin: 0 0; }
.map:not(.pass-on) .world { clip-path: inset(0 0 40px 0); pointer-events: none; }
.floor { position: absolute; inset: 0; }
.floor.planta, .floor.obra {
  background-color: #6d7a48;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  opacity: var(--pass);
}
.floor.planta { background-image: url("map/sat-planta.png"); }
.floor.obra { background-image: url("map/sat-obra.png"); }
.scenery { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; opacity: calc(1 - var(--pass)); }
#sweep {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: fill; pointer-events: none;
  opacity: var(--pass);
  transition: opacity 160ms linear;
}
#buildings, #pins { position: absolute; inset: 0; pointer-events: none; }
.building, .pin { pointer-events: auto; }
.map:not(.pass-on) #buildings,
.map:not(.pass-on) #pins,
.map:not(.pass-on) .building,
.map:not(.pass-on) .pin {
  visibility: hidden;
  pointer-events: none;
}

.building {
  position: absolute;
  transform: translate(-50%, -100%);
  border: 0; background: transparent;
  display: grid; justify-items: center; gap: 1px;
  padding: 0;
  z-index: 4;
}
.building .stem {
  width: 2px; height: 10px; background: var(--ink);
}
.building .mark {
  min-width: 18px; height: 18px; padding: 0 4px;
  display: grid; place-items: center;
  background: #f7f4ea; color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 2px 2px 2px 0;
  font-size: 10px; font-weight: 800;
  box-shadow: 0 1px 0 rgba(0,0,0,.35);
}
.building .pin-name {
  background: rgba(20,20,20,.82); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1.2;
  padding: 0 4px; white-space: nowrap;
}
.building.is-selected .mark { background: var(--accent); color: #fff; border-color: #fff; }

.pin {
  position: absolute;
  transform: translate(-50%, -50%);
  border: 0; background: transparent;
  display: grid; justify-items: center; gap: 1px;
  padding: 0;
  z-index: 5;
}
.pin .mark {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  background: #1c1c1c; color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  font-size: 8px; font-weight: 800;
  box-shadow: 0 1px 2px rgba(0,0,0,.45);
}
.pin.machine .mark { border-radius: 2px; background: var(--accent); }
.pin.is-selected .mark { outline: 2px solid var(--gold); outline-offset: 2px; }
.pin .pin-name {
  background: rgba(20,20,20,.78); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 1.2;
  padding: 0 3px; max-width: 88px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.map.pass-on .pin .pin-name,
.map.pass-on .building .pin-name { background: rgba(0,0,0,.72); }

.overlay-ui { position: absolute; z-index: 4; pointer-events: none; }
.sweep-badge {
  top: 10px; left: 12px;
  background: rgba(16,16,16,.82); color: #fff;
  padding: 4px 8px; font-size: 12px; font-weight: 700;
}
.zoom-hint {
  top: 10px; right: 320px;
  background: rgba(16,16,16,.72); color: var(--gold);
  padding: 4px 8px; font-size: 12px;
}

.dock {
  position: absolute; top: calc(var(--nav-h) + 8px); right: 8px; z-index: 6;
  width: min(300px, calc(100% - 16px));
  max-height: calc(100% - 16px);
  overflow: auto;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.dock > .panel { pointer-events: none; }
.panel.has-selection { pointer-events: auto; }
#card:not(.has-selection), #card[hidden] { display: none; }
.panel.has-selection { position: relative; padding-top: 30px; }
.card-close {
  position: absolute; top: 6px; right: 6px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  padding: 0;
  background: #1c1c1c; color: #fff;
  border: 1px solid #6a6a6a;
  font-size: 21px; line-height: 1;
}
.card-close:hover, .card-close:focus-visible { border-color: var(--gold); color: var(--gold); }
.panel {
  background: rgba(18,18,18,.92);
  border: 1px solid #4a4a4a;
  padding: 10px;
  color: #f3f3f3;
}
.panel h2, .ficha-kicker {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 6px;
}
.empty-title { font-weight: 800; margin-bottom: 4px; }
.ficha-name { font-size: 20px; letter-spacing: -0.02em; line-height: 1.1; color: #fff; }
.ficha-task { margin: 4px 0 8px; color: #ddd; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; }
.stat { background: #111; border: 1px solid #3a3a3a; padding: 6px; }
.stat b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; color: var(--gold); }
.stat span { font-size: 10px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.note { font-size: 11px; color: var(--muted); margin-top: 8px; }
.orders { margin: 6px 0 0; padding-left: 16px; }
.orders li { margin: 2px 0; }
.crew { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.crew button, .linkish {
  text-align: left; background: #111; color: #fff;
  border: 1px solid #4a4a4a; padding: 6px 8px;
}
.crew button:hover, .linkish:hover { border-color: var(--gold); }
.crew small { display: block; color: var(--muted); }
.log { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.log li { font-size: 12px; border-left: 3px solid var(--accent); padding-left: 6px; }
.log time { display: block; font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

.hud {
  display: grid;
  grid-template-columns: 248px minmax(180px, 280px) minmax(0, 1fr);
  gap: 10px;
  align-items: stretch;
  padding: 8px 10px;
  background: linear-gradient(#1a1a1a, #101010);
  border-top: 1px solid #3a3a3a;
  min-height: 168px;
}
.minimap {
  background: #0c0c0c;
  border: 1px solid #5a5a5a;
  box-shadow: inset 0 0 0 1px #000;
  padding: 4px;
}
.mini-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 4px; }
.minimap-label {
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  font-weight: 800; color: var(--gold);
}
.zoom { display: flex; gap: 3px; }
.zoom button {
  background: #1c1c1c; color: #fff; border: 1px solid #666;
  min-width: 28px; height: 22px; padding: 0 6px; font-weight: 800; font-size: 12px;
}
#mini-canvas { width: 100%; height: 124px; display: block; cursor: crosshair; background: #8ea36a; }

.scoreboard {
  border: 1px solid #3a3a3a;
  background: #121212;
  padding: 6px 8px;
  overflow: auto;
}
.scoreboard h2 {
  font-size: 11px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); margin-bottom: 4px;
}
.score-head, .partial li {
  display: grid; grid-template-columns: 16px 1fr 36px 28px; gap: 4px; align-items: center;
  font-size: 12px;
}
.score-head { color: var(--muted); font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 2px; }
.partial { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.partial .bar { display: none; }
.partial .pts, .partial .evs { font-variant-numeric: tabular-nums; text-align: right; }
.partial .pts { color: var(--gold); font-weight: 800; }

.replay { display: flex; flex-direction: column; justify-content: center; gap: 6px; min-width: 0; }
.transport, .match-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.transport button, .match-actions button, .ceremony footer button {
  background: #1c1c1c; color: #fff; border: 1px solid #6a6a6a; padding: 6px 8px; font-weight: 750; font-size: 13px;
}
.transport button.is-on { background: var(--gold); color: #1a1a1a; border-color: var(--gold); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
.transport-state { font-size: 12px; color: var(--muted); }
body.mode-fast #btn-fast { animation: pulse 1.4s ease-in-out infinite; }
body.mode-pause:not(.is-closed) #btn-fast { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px rgba(210, 34, 42, 0.45); } }
@media (prefers-reduced-motion: reduce) { #btn-fast { animation: none !important; } }
.scrub-head { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: #ddd; }
.scrub-head label { font-weight: 750; }
#gap-note { color: var(--muted); text-align: right; }
.tickrow { position: relative; height: 12px; margin: 0 6px; }
.tickrow button {
  position: absolute; top: 2px; width: 8px; height: 8px;
  transform: translateX(-50%);
  background: var(--accent); border: 0; padding: 0;
}
.tickrow button:disabled { opacity: 1; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

.toast {
  position: fixed; bottom: 188px; left: 50%; transform: translateX(-50%);
  background: #111; color: #fff; border: 1px solid #666; padding: 8px 12px;
  font-size: 14px; z-index: 15; pointer-events: none;
}
.toast:empty { display: none; }

.modal {
  position: fixed; inset: 0; z-index: 30;
  background: rgba(0,0,0,.62);
  display: grid; place-items: center; padding: 20px;
}
.modal[hidden] { display: none; }
.ceremony {
  width: min(860px, 100%);
  max-height: min(86dvh, 720px);
  overflow: auto;
  background: #161616;
  color: #f3f3f3;
  border: 1px solid #666;
}
.ceremony > header { background: var(--accent); color: #fff; padding: 14px 16px; }
.brand-kicker { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 700; }
.ceremony > header h2 { font-size: 26px; }
.ceremony > header p:last-child { margin-top: 4px; font-size: 14px; }
.rank-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; padding: 14px 16px; }
.rank-cols h3 { font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; margin: 0 0 8px; color: var(--gold); }
.rank-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.rank-row .pos { font-weight: 800; color: var(--accent); }
.rank-row .who { font-weight: 750; }
.rank-row .meta { font-size: 12px; color: var(--muted); }
.rank-row .bar { height: 6px; background: #333; margin-top: 3px; }
.rank-row .bar > i { display: block; height: 100%; background: var(--accent); }
.rank-row .pts { font-variant-numeric: tabular-nums; font-weight: 800; color: var(--gold); }
.ceremony footer { display: flex; justify-content: flex-end; gap: 8px; padding: 0 16px 14px; }
.disclaimer {
  margin: 0; padding: 4px 12px 6px;
  font-size: 11px; color: #8d8d8d; background: #101010;
}

@media (max-width: 980px) {
  .topbar, .hud, .dock .log-panel { display: none; }
  body { grid-template-rows: minmax(0, 1fr) auto; }
  .disclaimer {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
    background: rgba(16,16,16,.55); color: #d9d3cb;
  }
  .zoom-hint { right: 12px; top: auto; bottom: 36px; }
  .dock {
    width: min(300px, calc(100% - 16px));
    max-height: min(52dvh, calc(100% - 16px));
  }
  .rank-cols { grid-template-columns: 1fr; }
  #mini-canvas { height: 100px; }
}

.pin.machine.fleet {
  transform: translate(-16px, -50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  z-index: 6;
}
.pin.machine.fleet .mark {
  width: 30px; height: 30px; border-radius: 50%;
  background: #fff; border: 2px solid #2456c5; color: #2456c5;
  box-shadow: 0 1px 3px rgba(0,0,0,.45);
}
.pin.machine.fleet .pin-name {
  background: #fff; color: #1a1a1a;
  border: 1px solid #d0d0d0; border-radius: 3px;
  font-size: 12px; font-weight: 700;
  padding: 2px 6px; max-width: 190px;
  box-shadow: 0 1px 2px rgba(0,0,0,.35);
}
.pos-card {
  background: #fff; color: #1a1a1a;
  border-radius: 4px; padding: 8px 10px; margin: 8px 0;
}
.pos-card .ficha-kicker { color: #666; margin-bottom: 0; }
.pos-time, .pos-speed { font-weight: 750; margin: 0 0 6px; }

.fleetbar {
  position: absolute;
  top: calc(var(--nav-h) + 10px); left: 10px; right: 10px;
  z-index: 7;
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px;
  max-height: min(46dvh, 260px);
  overflow: auto;
  margin: 0;
  padding: 14px 16px;
  background: rgba(28, 26, 24, 0.62);
  color: #F3EFE8;
  border: 1px solid rgba(243, 239, 232, 0.14);
  border-radius: 18px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}
.fleet-stats { display: flex; gap: 20px; align-items: baseline; }
.fleet-stat { display: flex; flex-direction: column; gap: 3px; min-width: 76px; }
.fleet-stat strong {
  font-size: 26px; line-height: 1; font-weight: 500; color: #FFFFFF;
  font-variant-numeric: tabular-nums; letter-spacing: -0.03em;
}
.fleet-stat span { font-size: 13px; line-height: 1.2; color: #E4DCD2; max-width: 160px; }
.fleet-filters { display: flex; flex-wrap: wrap; gap: 6px; }
.fleet-filters button {
  background: rgba(243, 239, 232, 0.1); color: #F3EFE8;
  border: 0; border-radius: 999px;
  padding: 8px 14px; font-size: 14px; font-weight: 500;
  transition: background 180ms ease, color 180ms ease;
}
.fleet-filters button:hover { background: rgba(243, 239, 232, 0.18); }
.fleet-filters button.is-on { background: #C45C56; color: #fff; }
#fleet-search {
  background: rgba(255, 255, 255, 0.08); color: #F7F4EF;
  border: 1px solid rgba(243, 239, 232, 0.16); border-radius: 999px;
  padding: 8px 14px; min-width: 180px; font-size: 15px;
}
#fleet-search::placeholder { color: #C9C0B6; }
#fleet-search:focus { outline: 2px solid rgba(196, 92, 86, 0.55); border-color: transparent; }
.fleet-card {
  position: absolute; z-index: 6; left: 12px; bottom: 12px;
  width: min(320px, calc(100% - 24px));
  background: rgba(28, 26, 24, 0.72); color: #F3EFE8;
  border: 1px solid rgba(243, 239, 232, 0.14);
  border-radius: 18px; padding: 16px;
  pointer-events: auto;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  animation: fleet-in 200ms ease;
}
@keyframes fleet-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.fleet-card p { margin: 0 0 6px; font-size: 14px; line-height: 1.35; color: #E4DCD2; }
.fleet-card-name { font-size: 18px; font-weight: 500; letter-spacing: -0.02em; color: #FFFFFF; }
#fleet-card-close {
  float: right; background: #C45C56; color: #fff; border: 0; border-radius: 999px;
  padding: 7px 12px; font-size: 14px; font-weight: 500; margin-left: 8px;
}
@media (max-width: 720px) {
  .fleetbar { top: calc(var(--nav-h) + 8px); left: 8px; right: 8px; padding: 12px; gap: 10px; }
  .fleet-stat { min-width: 64px; }
  .fleet-stat strong { font-size: 22px; }
  .fleet-stat span { font-size: 13px; }
  #fleet-search { flex: 1; min-width: 0; font-size: 16px; }
  .fleet-card { bottom: 10px; left: 10px; right: 10px; width: auto; }
}

.fleet-panel {
  flex: 1 1 220px;
  min-width: 200px;
  max-width: 360px;
  margin: 0;
  padding: 0 4px;
}
.fleet-panel-line, .fleet-panel-km {
  margin: 0;
  font-size: 13px;
  line-height: 1.3;
  color: #F3EFE8;
}
.fleet-panel-km { color: #E4DCD2; margin-top: 4px; }
.fleet-status-list {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 92px;
  overflow: auto;
}
.fleet-status-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  line-height: 1.35;
  color: #E4DCD2;
}
.fleet-status-list li span:last-child { color: #FFFFFF; white-space: nowrap; }
