:root {
  --bg: #1b2430;
  --panel: rgba(28, 24, 18, 0.94);
  --panel-border: #8a6a3a;
  --gold: #e3b341;
  --text: #f3e9d2;
  --muted: #b9a888;
  --ok: #6fcf6f;
  --bad: #e06666;
  font-family: "Alegreya Sans", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
#game { position: fixed; inset: 0; display: block; cursor: default; touch-action: none; }
#game.grabbing { cursor: grabbing; }
#game.pointer { cursor: pointer; }
#game.cross { cursor: crosshair; }

button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  background: linear-gradient(#5a4a30, #3a2e1c); border: 1px solid var(--panel-border);
  border-radius: 6px; padding: 6px 12px; color: var(--text); font-weight: 600;
}
.btn:hover { filter: brightness(1.15); }
.btn.gold { background: linear-gradient(#e3b341, #a87a1c); color: #2a1e08; border-color: #f0d080; }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }

/* HUD */
#hud {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 14px; gap: 16px;
  background: linear-gradient(rgba(20,16,10,.95), rgba(20,16,10,.75)); border-bottom: 2px solid var(--panel-border);
  user-select: none;
}
.hud-left { display: flex; flex-direction: column; line-height: 1.1; }
.city-name { font-weight: 700; font-size: 16px; cursor: text; }
.era { font-size: 12px; color: var(--gold); }
.hud-res { display: flex; gap: 18px; font-weight: 700; font-size: 15px; }
.res { display: flex; align-items: center; gap: 6px; background: rgba(0,0,0,.35); padding: 4px 10px; border-radius: 14px; }
.res.bad { color: var(--bad); }
.res.great { color: var(--ok); }
.ico { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }
.ico.coin { background: radial-gradient(circle at 35% 35%, #ffe08a, #c58a0b); }
.ico.supply { background: linear-gradient(#b6895b, #6e4a24); border-radius: 3px; }
.ico.pop { background: radial-gradient(circle at 50% 30%, #f6d6b8, #b06f45); }
.ico.happy { background: radial-gradient(circle at 50% 40%, #ffe766, #d4a200); }
.hud-right { display: flex; gap: 8px; }

/* Toolbar */
#toolbar {
  position: fixed; left: 0; right: 0; bottom: 0; height: 64px; display: flex; align-items: stretch; gap: 4px;
  padding: 4px 10px; background: linear-gradient(rgba(20,16,10,.8), rgba(20,16,10,.97));
  border-top: 2px solid var(--panel-border); user-select: none;
}
.tool {
  display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 78px;
  background: transparent; border: 1px solid transparent; border-radius: 8px; font-size: 11px; gap: 2px; color: var(--muted);
}
.tool span { font-size: 22px; line-height: 1; }
.tool:hover { background: rgba(255,255,255,.06); color: var(--text); }
.tool.active { background: rgba(227,179,65,.18); border-color: var(--gold); color: var(--gold); }
.spacer { flex: 1; }

/* Paneles */
.panel {
  position: fixed; bottom: 72px; left: 10px; width: 420px; max-height: calc(100% - 150px);
  background: var(--panel); border: 2px solid var(--panel-border); border-radius: 10px;
  display: flex; flex-direction: column; box-shadow: 0 8px 30px rgba(0,0,0,.5);
}
.panel.hidden { display: none; }
#infoPanel { left: auto; right: 10px; width: 340px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid #4a3a22; }
.panel-head h3 { margin: 0; font-size: 16px; }
.close { background: none; border: none; font-size: 22px; color: var(--muted); padding: 0 6px; }
.close:hover { color: var(--text); }
.panel-body { overflow-y: auto; padding: 10px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: rgba(255,255,255,.05); border: 1px solid transparent; border-radius: 6px; padding: 4px 10px; font-size: 12px; color: var(--muted); }
.tabs button.active { border-color: var(--gold); color: var(--gold); background: rgba(227,179,65,.12); }

.bitem {
  display: grid; grid-template-columns: 56px 1fr auto; gap: 10px; align-items: center; padding: 8px; border-radius: 8px;
  border: 1px solid transparent; cursor: pointer;
}
.bitem:hover { background: rgba(255,255,255,.05); border-color: #4a3a22; }
.bitem.active { border-color: var(--gold); background: rgba(227,179,65,.12); }
.bitem.locked { opacity: .5; }
.bitem canvas { width: 56px; height: 56px; }
.bitem .name { font-weight: 700; }
.bitem .meta { font-size: 11px; color: var(--muted); }
.bitem .cost { font-size: 12px; text-align: right; line-height: 1.3; }
.cost .no { color: var(--bad); }

.info-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; border-bottom: 1px dashed #3a2e1c; }
.info-row b { color: var(--gold); }
.info-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.info-actions .btn { font-size: 12px; padding: 5px 9px; }
.warn { color: var(--bad); font-size: 12px; margin-top: 6px; }
.progress { height: 8px; background: #2a2218; border-radius: 4px; overflow: hidden; margin: 6px 0; }
.progress i { display: block; height: 100%; background: linear-gradient(90deg, #8ac36a, #4e9a3a); }

.ico.fp { background: none; width: auto; height: auto; color: #8ad0ff; font-size: 14px; }
.res.fp { color: #8ad0ff; }
.res.fp small { font-size: 10px; color: var(--muted); font-weight: 400; }

/* Investigación */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 20; }
.overlay.hidden { display: none; }
.tech-modal {
  width: min(1100px, calc(100% - 24px)); height: min(680px, calc(100% - 90px));
  background: var(--panel); border: 2px solid var(--panel-border); border-radius: 12px;
  display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.6);
}
.tech-fp { display: flex; align-items: center; gap: 10px; font-size: 15px; color: #8ad0ff; }
.tech-fp b { font-size: 18px; }
.tech-scroll { flex: 1; overflow: auto; position: relative; background: radial-gradient(ellipse at 30% 20%, rgba(255,255,255,.04), transparent 60%); }
#techLines { position: absolute; top: 0; left: 0; pointer-events: none; }
#techNodes { position: relative; }
.tech-foot { padding: 8px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid #4a3a22; }
.era-label { position: absolute; top: 8px; font-size: 12px; letter-spacing: 1px; text-transform: uppercase; color: var(--gold); opacity: .8; }
.tech {
  position: absolute; width: 190px; min-height: 96px; padding: 8px 10px; border-radius: 10px;
  background: #2a2218; border: 2px solid #4a3a22; font-size: 12px; display: flex; flex-direction: column; gap: 4px;
}
.tech .tname { font-weight: 700; font-size: 13px; }
.tech .tdesc { color: var(--muted); font-size: 11px; }
.tech .tbar { height: 8px; background: #1a140c; border-radius: 4px; overflow: hidden; }
.tech .tbar i { display: block; height: 100%; background: linear-gradient(90deg, #5ab0ff, #2a70c0); }
.tech .trow { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.tech .btn { font-size: 11px; padding: 3px 7px; }
.tech.locked { opacity: .5; }
.tech.available { border-color: #5ab0ff; }
.tech.funded { border-color: var(--gold); box-shadow: 0 0 12px rgba(227,179,65,.35); }
.tech.done { border-color: #4e9a3a; background: #22301c; }
.tech.done .tname::after { content: ' ✓'; color: var(--ok); }
.tech .no { color: var(--bad); }

.btn.hidden { display: none; }
.btn.tiny { font-size: 11px; padding: 2px 7px; }

/* Militar en panel info */
.slots { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.slot { display: flex; align-items: center; gap: 8px; font-size: 12px; background: rgba(0,0,0,.25); padding: 5px 8px; border-radius: 6px; }
.slot > span:first-child { flex: 1; }
.slot.empty { justify-content: space-between; }
.hpbar { display: inline-block; width: 70px; height: 7px; background: #1a140c; border-radius: 4px; overflow: hidden; }
.hpbar i { display: block; height: 100%; }
.hpnum { font-size: 11px; color: var(--muted); min-width: 34px; text-align: right; }

/* Mapa */
.map-modal, .battle-modal {
  width: min(1200px, calc(100% - 24px)); height: min(720px, calc(100% - 90px));
  background: var(--panel); border: 2px solid var(--panel-border); border-radius: 12px;
  display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0,0,0,.6); position: relative;
}
.map-body, .battle-body { flex: 1; display: flex; min-height: 0; }
.map-canvas { flex: 1; min-width: 0; background: radial-gradient(ellipse at 40% 40%, #3a5a7a, #1e3a52 70%); position: relative; }
.map-canvas svg { width: 100%; height: 100%; display: block; }
.map-side, .battle-side { width: 320px; border-left: 1px solid #4a3a22; padding: 10px; overflow-y: auto; font-size: 13px; }
.prov { cursor: pointer; }
.prov circle.body { stroke-width: 3; }
.prov.locked circle.body { fill: #3a3a3a; stroke: #555; }
.prov.available circle.body { fill: #6a5a2a; stroke: var(--gold); }
.prov.conquered circle.body { fill: #2e5a2e; stroke: #6fcf6f; }
.prov.selected circle.body { stroke: #fff; }
.prov text { fill: #f3e9d2; font-size: 13px; font-weight: 700; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: rgba(0,0,0,.7); stroke-width: 3px; }
.prov text.sub { font-size: 10px; font-weight: 400; }
.map-edge { stroke: rgba(255,255,255,.25); stroke-width: 3; stroke-dasharray: 6 5; }
.map-edge.open { stroke: #e3b341; stroke-dasharray: none; }
.sector { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; background: rgba(0,0,0,.25); margin: 4px 0; }
.sector.done { opacity: .6; }
.sector .st { font-size: 16px; }
.army-icons { display: flex; flex-wrap: wrap; gap: 3px; font-size: 14px; }
.army-icons span { background: rgba(255,255,255,.08); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.unit-pick { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 6px; border: 1px solid transparent; cursor: pointer; margin: 3px 0; font-size: 12px; }
.unit-pick:hover { background: rgba(255,255,255,.05); }
.unit-pick.sel { border-color: var(--gold); background: rgba(227,179,65,.12); }
.unit-pick.dis { opacity: .4; cursor: not-allowed; }
.unit-pick > span:first-child { flex: 1; }

/* Batalla */
#battleCanvas { flex: 1; min-width: 0; display: block; background: #2a3a2a; cursor: pointer; }
.turn-strip { display: flex; gap: 3px; flex-wrap: wrap; margin: 6px 0 10px; }
.turn-strip span { width: 26px; height: 26px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; border: 2px solid transparent; background: #334; }
.turn-strip span.p { background: #2a4a7a; }
.turn-strip span.e { background: #7a2a2a; }
.turn-strip span.cur { border-color: #ffe066; box-shadow: 0 0 8px #ffe066; }
.turn-strip span.dead { opacity: .25; }
.unit-card { background: rgba(0,0,0,.3); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.unit-card h4 { margin: 0 0 4px; font-size: 14px; }
.unit-card.enemy { border-left: 3px solid #e06666; }
.unit-card.player { border-left: 3px solid #5ab0ff; }
.battle-log { font-size: 11px; color: var(--muted); max-height: 160px; overflow-y: auto; margin-top: 8px; border-top: 1px dashed #4a3a22; padding-top: 6px; }
.battle-log div { padding: 1px 0; }
.battle-result {
  position: absolute; inset: 0; background: rgba(0,0,0,.72); display: flex; align-items: center; justify-content: center; border-radius: 12px;
}
.battle-result.hidden { display: none; }
.result-card { background: var(--panel); border: 2px solid var(--panel-border); border-radius: 12px; padding: 24px 32px; text-align: center; min-width: 300px; }
.result-card h2 { margin: 0 0 10px; font-size: 28px; }
.result-card h2.win { color: var(--ok); } .result-card h2.lose { color: var(--bad); }
.result-card p { margin: 6px 0; color: var(--muted); }

@media (max-width: 760px) {
  .map-body, .battle-body { flex-direction: column; }
  .map-side, .battle-side { width: 100%; border-left: none; border-top: 1px solid #4a3a22; flex: 1 1 auto; min-height: 0; }
  .map-canvas { flex: 0 0 42%; }
  #battleCanvas { flex: 0 0 38%; }
  .map-modal, .battle-modal { width: calc(100% - 12px); height: calc(100% - 140px); }
}

#toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,.85);
  border: 1px solid var(--panel-border); padding: 8px 16px; border-radius: 8px; font-weight: 600; opacity: 0;
  transition: opacity .2s; pointer-events: none; max-width: 80vw; text-align: center;
}
#toast.show { opacity: 1; }
#toast.err { border-color: var(--bad); color: #ffb3b3; }
#hint {
  position: fixed; top: 62px; left: 50%; transform: translateX(-50%); font-size: 12px; color: var(--muted);
  background: rgba(0,0,0,.5); padding: 4px 10px; border-radius: 6px; pointer-events: none; max-width: 90vw; text-align: center;
}
#hint:empty { display: none; }

@media (max-width: 760px) {
  #hud { height: auto; flex-wrap: wrap; padding: 6px 8px; gap: 6px; }
  .hud-left { flex: 1; }
  .city-name { font-size: 14px; }
  .hud-right { order: 2; }
  .hud-res { order: 3; width: 100%; justify-content: space-between; gap: 4px; font-size: 12px; flex-wrap: wrap; }
  .res.fp small { display: none; }
  .res { padding: 3px 6px; gap: 4px; }
  .ico { width: 12px; height: 12px; }
  .hud-right .btn { padding: 4px 8px; font-size: 11px; }
  #hint { top: auto; bottom: 70px; font-size: 11px; }
  .tool { min-width: 52px; font-size: 10px; }
  .tool span { font-size: 18px; }
  .panel { width: calc(100% - 20px); max-height: 55vh; }
  #infoPanel { width: calc(100% - 20px); }
  .tech-modal { width: calc(100% - 12px); height: calc(100% - 140px); }
  .tech-modal .panel-head { flex-wrap: wrap; gap: 6px; }
  .tech-modal h3 { font-size: 14px; }
  .tech-fp { font-size: 13px; gap: 6px; }
  .tech-fp .btn { font-size: 11px; padding: 3px 6px; }
  .tech-foot { font-size: 11px; }
}

/* =====================================================================
   Tema: madera, latón y pergamino
   ===================================================================== */
:root {
  --wood-1: #4a3520; --wood-2: #33241499; --wood-dark: #21170c;
  --brass: #c9a24a; --brass-light: #f0d68a; --brass-dark: #7a5a1a;
  --parch-1: #f3e4bf; --parch-2: #dcc48e; --ink: #3a2a12;
  --title: "Cinzel", Georgia, serif;
}
.wood, #hud, #toolbar, .panel, .tech-modal, .map-modal, .battle-modal, .result-card {
  background-color: #2c1f12;
  background-image:
    repeating-linear-gradient(92deg, rgba(255,255,255,.025) 0 2px, transparent 2px 9px),
    repeating-linear-gradient(88deg, rgba(0,0,0,.08) 0 1px, transparent 1px 23px),
    linear-gradient(#3e2c19, #261a0e);
}

/* HUD */
#hud { height: 60px; border-bottom: 3px solid var(--brass-dark); box-shadow: 0 2px 0 var(--brass) inset, 0 -1px 0 rgba(0,0,0,.6) inset, 0 4px 14px rgba(0,0,0,.45); }
#hud::after { content: ''; position: absolute; left: 0; right: 0; bottom: -6px; height: 3px; background: linear-gradient(90deg, transparent, var(--brass), transparent); opacity: .7; }
.city-name { font-family: var(--title); font-size: 17px; letter-spacing: .5px; color: var(--brass-light); text-shadow: 0 1px 0 #000; }
.era { font-family: var(--title); font-size: 11px; letter-spacing: 1.5px; text-transform: uppercase; color: #d8c8a0; }
.hud-res { gap: 10px; }
.res {
  background: linear-gradient(#1a120a, #2a1e12); border: 1px solid #5a4226; border-radius: 16px;
  box-shadow: inset 0 2px 4px rgba(0,0,0,.6), 0 1px 0 rgba(255,255,255,.06);
  padding: 4px 12px 4px 5px; font-size: 15px; font-weight: 700; letter-spacing: .3px;
}
.res .i { width: 22px; height: 22px; flex: none; filter: drop-shadow(0 1px 1px rgba(0,0,0,.6)); }
.res.up { animation: resUp .7s ease-out; }
.res.down { animation: resDown .7s ease-out; }
@keyframes resUp { 0% { color: #9cff9c; transform: scale(1.12); box-shadow: inset 0 2px 4px rgba(0,0,0,.6), 0 0 12px rgba(120,255,120,.55); } 100% { transform: scale(1); } }
@keyframes resDown { 0% { color: #ff9c9c; transform: scale(.94); } 100% { transform: scale(1); } }
.res.fp { color: #9fd8ff; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; gap: 6px; font-family: var(--title); font-weight: 700; font-size: 13px; letter-spacing: .3px;
  color: #f3e4bf; padding: 7px 14px; border-radius: 7px; border: 1px solid #1a1008;
  background: linear-gradient(#6a4c2c, #4a3219 55%, #3a2612);
  box-shadow: inset 0 1px 0 rgba(255,230,180,.35), inset 0 -2px 0 rgba(0,0,0,.35), 0 2px 3px rgba(0,0,0,.5);
  text-shadow: 0 1px 0 rgba(0,0,0,.7);
}
.btn:hover:not(:disabled) { filter: brightness(1.15); }
.btn:active:not(:disabled) { transform: translateY(1px); box-shadow: inset 0 1px 3px rgba(0,0,0,.6); }
.btn.gold {
  color: #2a1a04; text-shadow: 0 1px 0 rgba(255,240,200,.6); border-color: #5a3a08;
  background: linear-gradient(#ffe9a0, #e3b341 45%, #b07c18);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7), inset 0 -2px 0 rgba(90,58,8,.45), 0 2px 3px rgba(0,0,0,.5);
}
.btn.gold.ready { animation: glowGold 1.6s ease-in-out infinite; }
@keyframes glowGold { 50% { box-shadow: inset 0 1px 0 rgba(255,255,255,.7), 0 0 14px rgba(255,210,90,.9); } }
.btn .bi { width: 17px; height: 17px; flex: none; }
.btn.tiny { font-size: 11px; padding: 3px 8px; font-family: inherit; }

/* Barra inferior */
#toolbar { height: 70px; border-top: 3px solid var(--brass-dark); box-shadow: 0 2px 0 var(--brass) inset, 0 -4px 14px rgba(0,0,0,.45); padding: 5px 10px; gap: 6px; }
.tool { font-family: var(--title); font-size: 10.5px; letter-spacing: .4px; color: #cdbb94; min-width: 80px; border-radius: 10px; gap: 3px; }
.tool span { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #5a4228, #2a1c0e); border: 1px solid #6a4e2a;
  box-shadow: inset 0 1px 0 rgba(255,230,180,.2), 0 2px 3px rgba(0,0,0,.5); }
.tool .i { width: 20px; height: 20px; }
.tool:hover { background: rgba(255,220,150,.06); color: var(--brass-light); }
.tool.active { background: rgba(201,162,74,.14); border-color: transparent; color: var(--brass-light); }
.tool.active span { background: radial-gradient(circle at 40% 35%, #ffe9a0, #c9a24a 60%, #8a6a1a); color: #2a1a04; border-color: #f0d68a; box-shadow: 0 0 10px rgba(240,200,100,.6); }

/* Paneles y modales */
.panel, .tech-modal, .map-modal, .battle-modal {
  border: 3px solid #1a1008; border-radius: 12px;
  box-shadow: 0 0 0 2px var(--brass-dark), 0 0 0 3px var(--brass), 0 12px 40px rgba(0,0,0,.6), inset 0 0 30px rgba(0,0,0,.35);
}
.panel-head {
  background: linear-gradient(var(--parch-1), var(--parch-2)); color: var(--ink);
  border-bottom: 2px solid var(--brass-dark); border-radius: 9px 9px 0 0; padding: 9px 12px;
  box-shadow: inset 0 -6px 12px rgba(120,80,20,.18);
}
.panel-head h3 { font-family: var(--title); font-size: 17px; letter-spacing: .5px; color: var(--ink); }
.panel-head .meta, .panel-head #battleRound { color: #6a4a1a !important; font-family: var(--title); }
.close { color: #6a4a1a; font-size: 24px; line-height: 1; }
.close:hover { color: #2a1a04; }
.tabs button { font-family: var(--title); font-size: 11.5px; color: #6a4a1a; background: rgba(255,255,255,.35); border: 1px solid rgba(120,80,20,.35); }
.tabs button.active { color: #2a1a04; background: linear-gradient(#ffe9a0, #e3b341); border-color: #8a6a1a; }
.tech-fp { color: #1f5a8a; }
.tech-fp .btn { font-size: 11px; }
.info-row b { color: var(--brass-light); }
.info-row { border-bottom-color: rgba(201,162,74,.2); }

/* Panel construir */
.panel#buildPanel { width: 470px; }
.bitem { grid-template-columns: 76px 1fr auto; padding: 8px 10px; margin-bottom: 4px; background: rgba(0,0,0,.18); border: 1px solid rgba(201,162,74,.15); border-radius: 10px; }
.bitem:hover { background: rgba(255,220,150,.07); border-color: rgba(201,162,74,.5); }
.bitem.active { border-color: var(--brass-light); background: rgba(201,162,74,.16); box-shadow: 0 0 10px rgba(240,200,100,.25); }
.bitem canvas { width: 76px; height: 76px; background: radial-gradient(ellipse at 50% 65%, rgba(140,170,90,.35), transparent 70%); border-radius: 8px; }
.bitem .name { font-family: var(--title); font-size: 14px; color: var(--brass-light); }
.bitem .cost { font-weight: 700; }

/* Superposiciones */
.overlay { background: radial-gradient(ellipse at center, rgba(0,0,0,.45), rgba(0,0,0,.75)); backdrop-filter: blur(2px); }
.result-card { border: 3px solid #1a1008; box-shadow: 0 0 0 2px var(--brass-dark), 0 0 0 3px var(--brass), 0 12px 40px rgba(0,0,0,.6); }
.result-card h2 { font-family: var(--title); letter-spacing: 1px; }
#toast { font-family: var(--title); letter-spacing: .3px; background: linear-gradient(var(--parch-1), var(--parch-2)); color: var(--ink); border: 2px solid var(--brass-dark); box-shadow: 0 6px 20px rgba(0,0,0,.5); top: 76px; }
#toast.err { background: linear-gradient(#ffe0d8, #e8b0a0); color: #5a1408; border-color: #8a2a1a; }
#hint { top: 72px; background: rgba(20,14,8,.7); border: 1px solid rgba(201,162,74,.35); color: #e0d0a8; }
h4 { font-family: var(--title); color: var(--brass-light); letter-spacing: .4px; }

@media (max-width: 760px) {
  #hud { height: auto; }
  .res { padding: 3px 8px 3px 3px; font-size: 12px; }
  .res .i { width: 17px; height: 17px; }
  .btn { font-size: 11px; padding: 5px 8px; }
  .btn .bi { width: 14px; height: 14px; }
  #toolbar { height: 64px; }
  .tool { min-width: 54px; font-size: 9px; }
  .tool span { width: 30px; height: 30px; }
  .tool .i { width: 17px; height: 17px; }
  .panel#buildPanel { width: calc(100% - 20px); }
  .bitem { grid-template-columns: 60px 1fr auto; }
  .bitem canvas { width: 60px; height: 60px; }
  #hint { top: auto; bottom: 74px; }
}

.tech .free { color: #8ad0ff; font-size: 11px; }

/* El aviso (toast) y la pista comparten sitio: mientras se ve el aviso, la pista se oculta */
#hint { transition: opacity .2s; }
body.toasting #hint { opacity: 0; }
#toast { z-index: 30; }

/* Mapa de provincias (pergamino) */
.map-canvas { background: #c9cdb0; }
.parchment-map text { font-family: var(--title); text-anchor: middle; pointer-events: none; }
.parchment-map .pname { font-size: 13px; font-weight: 700; fill: #3a2a12; }
.parchment-map .pera { font-size: 10px; fill: #5a3e22; font-weight: 600; paint-order: stroke; stroke: rgba(243,228,191,.85); stroke-width: 3px; }
.parchment-map .cartouche { font-size: 15px; font-weight: 700; fill: #3a2a12; letter-spacing: 1px; }
.parchment-map .compass { font-size: 12px; font-weight: 700; fill: #5a3e22; }
.parchment-map .region { cursor: pointer; transition: fill .2s; }
.parchment-map .region:hover { fill: rgba(255,230,150,.28); }
.parchment-map .region.sel { fill: rgba(255,220,120,.32); }
.parchment-map .route { fill: none; stroke: #6a4a2a; stroke-width: 2.4; stroke-dasharray: 1 7; stroke-linecap: round; opacity: .8; }
.parchment-map .route.open { stroke: #8a2a1a; stroke-dasharray: 10 5; stroke-width: 2.6; opacity: .9; }
.prov { cursor: pointer; }
.prov .shield { stroke: #2a1a08; stroke-width: 2; transition: filter .15s; }
.prov:hover .shield { filter: brightness(1.2) drop-shadow(0 0 6px rgba(255,220,120,.8)); }
.prov.available .shield { animation: shieldPulse 1.8s ease-in-out infinite; }
@keyframes shieldPulse { 50% { filter: drop-shadow(0 0 7px rgba(255,190,80,.9)); } }
.prov .sel-ring { fill: none; stroke: #f0c040; stroke-width: 3; stroke-dasharray: 8 6; animation: selSpin 6s linear infinite; transform-origin: 0 0; }
@keyframes selSpin { to { transform: rotate(360deg); } }

/* Investigación: lienzo arrastrable y flechas */
.tech-viewport { flex: 1; position: relative; min-height: 0; display: flex; }
.tech-viewport .tech-scroll { flex: 1; cursor: grab; user-select: none; }
.tech-viewport .tech-scroll.dragging { cursor: grabbing; }
.tech-viewport .tech-scroll.dragging .tech { pointer-events: none; }
.tech .btn { cursor: pointer; }
.tech-arrow {
  position: absolute; z-index: 5; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; padding: 0;
  color: #2a1a04; border: 2px solid #5a3a08;
  background: radial-gradient(circle at 40% 35%, #ffe9a0, #e3b341 60%, #a87418);
  box-shadow: 0 3px 10px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.6);
  transition: opacity .2s, transform .15s;
}
.tech-arrow svg { width: 22px; height: 22px; }
.tech-arrow:hover { transform: scale(1.1); }
.tech-arrow:active { transform: scale(.95); }
.tech-arrow.left { left: 10px; top: 50%; margin-top: -21px; }
.tech-arrow.right { right: 22px; top: 50%; margin-top: -21px; }
.tech-arrow.up { top: 8px; left: 50%; margin-left: -21px; }
.tech-arrow.down { bottom: 20px; left: 50%; margin-left: -21px; }
.tech-arrow.off { opacity: 0; pointer-events: none; }
.tech-arrow:not(.off) { opacity: .85; }
.tech-arrow:not(.off):hover { opacity: 1; }

/* Botones de zoom */
#zoomCtl { position: fixed; right: 14px; bottom: 86px; display: flex; flex-direction: column; gap: 6px; z-index: 6; }
#zoomCtl button {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; padding: 0; color: #f0d68a;
  border: 2px solid #1a1008; background: radial-gradient(circle at 40% 35%, #6a4c2c, #2a1c0e);
  box-shadow: 0 0 0 1px var(--brass-dark), 0 3px 8px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,230,180,.25);
}
#zoomCtl button:hover { filter: brightness(1.2); }
#zoomCtl button:active { transform: scale(.94); }
#zoomCtl svg { width: 20px; height: 20px; }
@media (max-width: 760px) { #zoomCtl { bottom: 78px; right: 10px; } #zoomCtl button { width: 36px; height: 36px; } }
body:has(.panel#infoPanel:not(.hidden)) #zoomCtl { right: 364px; }
@media (max-width: 760px) { body:has(.panel#infoPanel:not(.hidden)) #zoomCtl { display: none; } }

/* Diálogo propio */
#dialog { z-index: 60; }
.dlg {
  width: min(420px, calc(100% - 32px)); border-radius: 12px; border: 3px solid #1a1008; overflow: hidden;
  background-color: #2c1f12;
  background-image: repeating-linear-gradient(92deg, rgba(255,255,255,.025) 0 2px, transparent 2px 9px), linear-gradient(#3e2c19, #261a0e);
  box-shadow: 0 0 0 2px var(--brass-dark), 0 0 0 3px var(--brass), 0 16px 50px rgba(0,0,0,.7);
  animation: dlgIn .18s ease-out;
}
@keyframes dlgIn { from { transform: translateY(10px) scale(.96); opacity: 0; } }
.dlg-body { padding: 16px 18px 6px; font-size: 15px; line-height: 1.45; }
.dlg-body p { margin: 0; }
.dlg-input { width: 100%; margin-top: 10px; padding: 8px 10px; font: inherit; font-size: 15px; color: var(--ink);
  background: linear-gradient(var(--parch-1), var(--parch-2)); border: 2px solid var(--brass-dark); border-radius: 6px; outline: none; }
.dlg-input:focus { box-shadow: 0 0 0 2px var(--brass); }
.dlg-input.hidden { display: none; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px 16px; }
.btn.danger { background: linear-gradient(#e07060, #a8342a 50%, #7a2018); color: #fff3e8; border-color: #3a0a04; text-shadow: 0 1px 0 rgba(0,0,0,.6); }

/* Barra de deshacer */
#undoBar {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 25;
  display: flex; align-items: center; gap: 12px; padding: 8px 10px 10px 14px; border-radius: 10px; overflow: hidden;
  background: linear-gradient(var(--parch-1), var(--parch-2)); color: var(--ink); font-family: var(--title); font-size: 13px;
  border: 2px solid var(--brass-dark); box-shadow: 0 6px 20px rgba(0,0,0,.5); animation: dlgIn .18s ease-out;
}
#undoBar.hidden { display: none; }
#undoBar small { opacity: .7; font-family: "Alegreya Sans", sans-serif; }
#undoTimer { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--brass-dark); width: 100%; transform-origin: left; }
@media (max-width: 760px) { #undoBar { bottom: 76px; } #undoBar small { display: none; } }

/* Teclas en los botones */
.tool { position: relative; }
.tool kbd { position: absolute; top: 3px; right: 10px; font: 700 9px/1 "Alegreya Sans", sans-serif; color: #cdbb94; background: rgba(0,0,0,.45); border: 1px solid #6a4e2a; border-radius: 3px; padding: 1px 3px; }
.tool.active kbd { color: #2a1a04; background: #f0d68a; }
@media (hover: none), (max-width: 760px) { .tool kbd { display: none; } }

/* Ayuda */
#helpOverlay { z-index: 55; }
.help-dlg { width: min(760px, calc(100% - 24px)); }
.help-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 6px 22px; padding: 14px 18px 18px; max-height: 70vh; overflow: auto; }
.help-body h4 { margin: 4px 0 8px; font-size: 14px; }
.help-body dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; font-size: 13px; }
.help-body dt { color: var(--brass-light); font-weight: 700; white-space: nowrap; }
.help-body dd { margin: 0; color: #e0d0a8; }
kbd { display: inline-block; min-width: 18px; text-align: center; font: 700 11px/1.4 "Alegreya Sans", sans-serif; color: #2a1a04; background: linear-gradient(#fff3d0, #e0c890); border: 1px solid #8a6a1a; border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; margin: 0 1px; }

/* Chip de colocación (móvil) */
#placingChip { position: fixed; left: 50%; top: 128px; transform: translateX(-50%); z-index: 22; display: flex; border-radius: 22px; overflow: hidden;
  border: 2px solid var(--brass-dark); box-shadow: 0 4px 14px rgba(0,0,0,.5); background: linear-gradient(var(--parch-1), var(--parch-2)); }
#placingChip.hidden { display: none; }
#placingChip button { border: none; background: none; color: var(--ink); font-family: var(--title); font-weight: 700; padding: 8px 14px; display: flex; align-items: center; gap: 8px; }
#placingChip small { font-family: "Alegreya Sans", sans-serif; font-weight: 500; opacity: .7; }
#placingCancel { border-left: 1px solid rgba(90,62,34,.4) !important; font-size: 20px !important; padding: 4px 14px !important; }

/* Barra inferior desplazable en pantallas estrechas */
@media (max-width: 760px) {
  #toolbar { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  #toolbar::-webkit-scrollbar { display: none; }
  #toolbar .tool { flex: none; }
  #toolbar .spacer { flex: none; width: 10px; }
}

/* Pantalla de entrada */
#authScreen { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 50% 40%, rgba(40,60,30,.55), rgba(10,8,4,.92)), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='64' height='32'%3E%3Cpath d='M0 16L32 0L64 16L32 32Z' fill='none' stroke='%23ffffff10'/%3E%3C/svg%3E"), #1c2a18; }
#authScreen.hidden { display: none; }
.auth-card { width: min(380px, 100%); padding: 24px 24px 20px; border-radius: 14px; border: 3px solid #1a1008;
  background-color: #2c1f12; background-image: repeating-linear-gradient(92deg, rgba(255,255,255,.025) 0 2px, transparent 2px 9px), linear-gradient(#3e2c19, #261a0e);
  box-shadow: 0 0 0 2px var(--brass-dark), 0 0 0 3px var(--brass), 0 20px 60px rgba(0,0,0,.7); }
.auth-title { font-family: var(--title); font-size: 28px; text-align: center; color: var(--brass-light); letter-spacing: 1px; text-shadow: 0 2px 0 #000; }
.auth-sub { text-align: center; color: #cdbb94; font-size: 14px; margin: 4px 0 18px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; }
.auth-tabs button { font-family: var(--title); font-weight: 700; padding: 8px; border-radius: 8px; border: 1px solid rgba(201,162,74,.35); background: rgba(0,0,0,.25); color: #cdbb94; }
.auth-tabs button.active { background: linear-gradient(#ffe9a0, #e3b341); color: #2a1a04; border-color: #8a6a1a; }
#authForm { display: flex; flex-direction: column; gap: 10px; }
#authForm label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #e0d0a8; }
#authForm label.hidden { display: none; }
#authForm input { font: inherit; font-size: 16px; padding: 9px 11px; border-radius: 7px; color: var(--ink); border: 2px solid var(--brass-dark);
  background: linear-gradient(var(--parch-1), var(--parch-2)); outline: none; }
#authForm input:focus { box-shadow: 0 0 0 2px var(--brass); }
.auth-note { font-size: 12px; color: #9fd8ff; min-height: 0; }
.auth-error { font-size: 13px; color: #ff9c8c; min-height: 18px; }
.auth-submit { justify-content: center; font-size: 15px; padding: 10px; }

/* Vecinos */
#neighborsOverlay { z-index: 50; }
.neighbors-dlg { width: min(640px, calc(100% - 24px)); }
.neighbors-body { padding: 12px 16px 16px; max-height: 70vh; overflow: auto; }
.neighbors-help { margin: 0 0 10px; font-size: 13px; color: #cdbb94; }
.nrow { display: grid; grid-template-columns: 36px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; background: rgba(0,0,0,.2); border: 1px solid rgba(201,162,74,.15); margin-bottom: 5px; }
.nrow.me { border-color: var(--brass); background: rgba(201,162,74,.12); }
.nrank { font-family: var(--title); font-weight: 700; font-size: 16px; color: var(--brass-light); text-align: center; }
.nname { font-weight: 700; } .ncity { font-size: 12px; color: #cdbb94; }
.npts { font-family: var(--title); font-weight: 700; color: #e0d0a8; white-space: nowrap; }
.nstatus { font-size: 11px; color: #9fd8ff; }
.nrow .btn { font-size: 12px; padding: 5px 10px; }

/* Visita */
#visitBar { position: fixed; top: 70px; left: 50%; transform: translateX(-50%); z-index: 24; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; justify-content: center;
  padding: 8px 10px 8px 16px; border-radius: 12px; background: linear-gradient(var(--parch-1), var(--parch-2)); color: var(--ink); border: 2px solid var(--brass-dark); box-shadow: 0 6px 20px rgba(0,0,0,.5); max-width: calc(100% - 20px); }
#visitBar.hidden { display: none; }
#visitBar b { font-family: var(--title); }
#visitInfo { font-size: 13px; }
body.visiting #toolbar, body.visiting #hint, body.visiting .hud-right, body.visiting #undoBar { display: none !important; }
@media (max-width: 760px) { #visitBar { top: auto; bottom: 14px; } }

/* Gremio */
#guildOverlay { z-index: 50; }
.g-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.g-level { font-family: var(--title); font-weight: 700; color: var(--brass-light); font-size: 16px; }
.g-bonus { font-size: 13px; color: #9fd8ff; }
.g-tabs { margin-bottom: 10px; }
.g-pane { min-height: 200px; }
.g-row .nrank { font-size: 12px; }
.g-form { margin-top: 14px; padding-top: 10px; border-top: 1px dashed rgba(201,162,74,.3); }
.g-form h4 { margin: 0 0 8px; }
.g-form-row, .g-chat-form { display: flex; gap: 8px; flex-wrap: wrap; }
.g-form input, .g-chat-form input { flex: 1; min-width: 90px; font: inherit; font-size: 15px; padding: 7px 10px; border-radius: 6px; color: var(--ink); border: 2px solid var(--brass-dark); background: linear-gradient(var(--parch-1), var(--parch-2)); outline: none; }
.g-form input.g-tag { flex: 0 0 90px; text-transform: uppercase; }
.g-chat { height: 300px; max-height: 45vh; overflow-y: auto; padding: 8px 10px; margin-bottom: 8px; border-radius: 8px; background: rgba(0,0,0,.28); border: 1px solid rgba(201,162,74,.2); }
.g-msg { font-size: 14px; padding: 3px 0; line-height: 1.35; word-wrap: break-word; }
.g-msg b { color: var(--brass-light); }
.g-time { font-size: 11px; color: #9a8a6a; margin-right: 6px; }
.g-treasury { display: flex; gap: 24px; font-family: var(--title); font-weight: 700; font-size: 20px; color: var(--brass-light); }
.g-upgrade { margin-top: 12px; font-size: 13px; }
.g-leave { margin-top: 10px; }

/* Mercado */
#marketOverlay { z-index: 50; }
.m-row { grid-template-columns: 1fr auto auto auto auto; }
.m-give, .m-want { display: flex; flex-direction: column; align-items: center; min-width: 74px; }
.m-give b, .m-want b { font-family: var(--title); font-size: 15px; color: var(--brass-light); }
.m-give small, .m-want small { font-size: 10px; color: #9a8a6a; }
.m-arrow { color: #9a8a6a; font-size: 18px; }
.m-btn { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.m-btn small { font-size: 10px; color: #e3a060; }
.m-form { display: flex; flex-direction: column; gap: 10px; }
.m-field { display: flex; flex-direction: column; gap: 4px; }
.m-field label { font-size: 13px; color: #e0d0a8; }
.m-field input { font: inherit; font-size: 15px; padding: 7px 10px; border-radius: 6px; color: var(--ink); border: 2px solid var(--brass-dark); background: linear-gradient(var(--parch-1), var(--parch-2)); outline: none; }
.m-check { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.m-form .btn { align-self: flex-start; }
@media (max-width: 600px) {
  .m-row { grid-template-columns: 1fr auto auto auto; }
  .m-row .m-who { grid-column: 1 / -1; }
}

/* Ficha flotante al pasar el ratón por un edificio */
.tip { position: fixed; z-index: 15; pointer-events: none; min-width: 190px; max-width: 260px; border-radius: 8px; overflow: hidden;
  background: #2c1f12; border: 2px solid #1a1008; box-shadow: 0 0 0 1px var(--brass-dark), 0 8px 22px rgba(0,0,0,.55); font-size: 13px; }
.tip.hidden { display: none; }
.tip-title { font-family: var(--title); font-weight: 700; font-size: 14px; padding: 6px 10px; color: var(--ink); background: linear-gradient(var(--parch-1), var(--parch-2)); border-bottom: 1px solid var(--brass-dark); }
.tip-sec { padding: 5px 10px; border-top: 1px solid rgba(201,162,74,.18); }
.tip-sec:first-of-type { border-top: none; }
.tip-label { font-size: 11px; color: #b9a888; text-transform: uppercase; letter-spacing: .5px; }
.tip-val { font-family: var(--title); font-weight: 700; font-size: 16px; color: #8fe08f; }
.tip-val.wait { color: #f3e9d2; }
.tip-val.warn { color: #ff9c8c; font-size: 13px; }
.tip-sub { color: #e0d0a8; }
.tip-bar { height: 6px; margin-top: 4px; background: #1a140c; border-radius: 3px; overflow: hidden; }
.tip-bar i { display: block; height: 100%; background: linear-gradient(90deg, #8ac36a, #4e9a3a); }
