:root {
  --papel: #f6f3ec;
  --hoja: #fffdf8;
  --tinta: #1f1d2b;
  --tenue: #6d6a7c;
  --linea: #e3ddd0;
  --acento: #4b5bd6;
  --acento-suave: #e6e8fb;
  --bien: #2f8f5b;
  --mal: #c0453a;
  --aviso: #b7791f;
  --radio: 14px;
  --top: env(safe-area-inset-top, 0px);
  --bottom: env(safe-area-inset-bottom, 0px);
  --left: env(safe-area-inset-left, 0px);
  --right: env(safe-area-inset-right, 0px);
  --bar-h: 44px;
  --tab-h: 52px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif;
  color: var(--tinta);
  background: var(--papel);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--papel);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: calc(var(--bar-h) + var(--top));
  padding: var(--top) calc(16px + var(--right)) 0 calc(16px + var(--left));
  background: rgba(246, 243, 236, 0.92);
  border-bottom: 1px solid var(--linea);
}

.bar-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.bar-end { display: flex; align-items: center; gap: 10px; }
.bar-version { font-size: 12px; color: var(--tenue); font-variant-numeric: tabular-nums; }
.tinta { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-size: 15px; font-variant-numeric: tabular-nums; }
.tinta svg { width: 16px; height: 16px; color: var(--acento); }

.view {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0 calc(12px + var(--right)) 0 calc(12px + var(--left));
}

.screen { height: 100%; }
.screen.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 0 24px; user-select: text; -webkit-user-select: text; }

#screen-jugar { display: flex; flex-direction: column; gap: 8px; padding: 8px 0; }

.hud { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; }
.hud-estado { margin: 0; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; flex: 1 1 auto; min-width: 0; line-height: 1.25; }
.hud-acciones { display: flex; gap: 6px; flex: 0 0 auto; }

.chip-btn {
  min-height: 44px;
  min-width: 44px;
  padding: 0 11px;
  border: 1px solid var(--linea);
  border-radius: 999px;
  background: var(--hoja);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.chip-btn.primary { background: var(--tinta); color: var(--hoja); border-color: var(--tinta); }
.chip-btn:disabled { opacity: 0.45; cursor: default; }
.demo-btn { background: var(--mal); color: #fff; border-color: var(--mal); }

.campo-wrap {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: var(--radio);
  overflow: hidden;
  background: #efe9dc;
  border: 1px solid var(--linea);
  position: relative;
}
.campo-wrap canvas, .pad-wrap canvas { display: block; width: 100%; height: 100%; }
.campo-wrap .destello-capa { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.leyenda-btn {
  position: absolute;
  left: 6px;
  top: 6px;
  z-index: 4;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 1px solid var(--linea);
  background: rgba(255, 253, 248, 0.92);
  color: var(--tinta);
  cursor: pointer;
}
.leyenda-btn svg { width: 24px; height: 24px; }
.campo-wrap.lento { box-shadow: inset 0 0 0 2px rgba(75, 91, 214, 0.35); }

#pad-wrap {
  position: absolute;
  left: 0;
  right: 0;
  top: 25%;
  height: 54%;
  border-top: 1px dashed rgba(75, 91, 214, 0.35);
  border-bottom: 1px dashed rgba(75, 91, 214, 0.35);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
#pad-wrap canvas { touch-action: none; }
#pad-wrap.tuto-foco { position: absolute; box-shadow: inset 0 0 0 3px var(--acento); border-radius: 0; }
.zona-cabeza {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 6px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  pointer-events: none;
}
.zona-cabeza .pad-hint { position: static; flex: 1 1 auto; min-width: 0; padding: 3px 8px; border-radius: 8px; background: rgba(255, 253, 248, 0.9); color: #6f6a5f; }
.cola { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-radius: 999px; background: rgba(255, 253, 248, 0.9); border: 1px solid var(--linea); }
.cola-tit { font-size: 11px; font-weight: 600; color: var(--tenue); margin-right: 2px; }
.cola-item { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; color: var(--acento); background: var(--acento-suave); }
.cola-item svg { width: 15px; height: 15px; }

.torres {
  position: absolute;
  left: 0;
  right: 0;
  top: 79%;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  gap: 4px;
  padding: 0 18% 0 4px;
  pointer-events: none;
  z-index: 2;
}
#torres:has(.tuto-foco) { z-index: 51; }
#torres.tuto-foco { position: absolute; border-radius: 0; box-shadow: inset 0 0 0 3px var(--acento); }
.torre { position: relative; display: flex; pointer-events: auto; }
.torre-btn {
  --marco: var(--linea);
  position: relative;
  width: 62px;
  border: 1.5px solid var(--marco);
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.94);
  padding: 2px 3px 3px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  color: var(--tinta);
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(31, 29, 43, 0.14);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.torre-btn[aria-pressed="true"] { --marco: var(--acento); box-shadow: 0 0 0 2px rgba(75, 91, 214, 0.22), 0 1px 3px rgba(31, 29, 43, 0.14); }
.torre.maximo .torre-btn { --marco: #b8862b; }
.torre-btn:active { transform: translateY(1px); }
.torre-btn svg { width: 40px; height: 40px; display: block; pointer-events: none; }
.torre-nombre { font-size: 10.5px; font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; white-space: nowrap; color: #5d584e; pointer-events: none; }
.torre-btn[aria-pressed="true"] .torre-nombre { color: var(--acento); }
.torre-nivel { position: absolute; left: 3px; top: 3px; min-width: 20px; padding: 1px 4px; border-radius: 999px; background: var(--tinta); color: #fff; font-size: 10px; font-weight: 800; line-height: 1.3; text-align: center; pointer-events: none; z-index: 1; }
.torre[data-nivel="0"] .torre-nivel { background: #8d877a; }
.mejora-btn {
  align-self: stretch;
  height: 20px;
  margin-top: 1px;
  border-radius: 999px;
  background: var(--acento);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  line-height: 1;
}
.mejora-btn .mas { font-size: 14px; font-weight: 800; }
.mejora-btn small { font-size: 11.5px; font-weight: 700; }
.mejora-btn.progreso { background: linear-gradient(to right, #aeb6f0 var(--p), #e6e8fb var(--p)); color: var(--tinta); font-variant-numeric: tabular-nums; }
.mejora-btn.espera { background: #e7e2d6; color: #8d877a; }
.mejora-btn.maximo { background: #f4e7c8; color: #8a6420; }
.mejora-btn.maximo .mas { font-size: 11.5px; letter-spacing: 0.02em; }
.torre-aviso {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 6px);
  transform: translateX(-50%);
  white-space: nowrap;
  background: var(--acento);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 5;
  animation: aviso 1.6s ease-out forwards;
}
.torre:first-child .torre-aviso { left: 0; transform: none; }
.torre:last-child .torre-aviso { left: auto; right: 0; transform: none; }
@keyframes aviso { 0% { opacity: 0; } 12% { opacity: 1; } 75% { opacity: 1; } 100% { opacity: 0; } }

.pad-wrap {
  flex: 1 1 auto;
  min-height: 200px;
  position: relative;
  background: var(--hoja);
  border: 1px solid var(--linea);
  border-radius: var(--radio);
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}
.pad-wrap canvas { touch-action: none; }
.pad-hint {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 8px;
  margin: 0;
  font-size: 13px;
  color: var(--tenue);
  pointer-events: none;
  line-height: 1.3;
}

.lectura { display: flex; flex-wrap: wrap; gap: 4px 6px; flex: 0 0 58px; height: 58px; overflow: hidden; align-content: flex-start; font-size: 13px; font-variant-numeric: tabular-nums; }
.dato { padding: 3px 8px; border-radius: 999px; background: var(--hoja); border: 1px solid var(--linea); white-space: nowrap; }
.dato b { font-weight: 700; }
.dato.bien { color: var(--bien); border-color: #bfe3cf; }
.dato.mal { color: var(--mal); border-color: #f0c7c2; }
.dato.dano { background: var(--tinta); color: var(--hoja); border-color: var(--tinta); }
.lectura.puntos { font-size: 11.5px; gap: 3px 4px; }
.lectura.puntos .dato { padding: 2px 6px; }

.tabbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--bottom));
  padding: 0 var(--right) var(--bottom) var(--left);
  border-top: 1px solid var(--linea);
  background: rgba(246, 243, 236, 0.96);
}
.tabbar button {
  border: 0;
  background: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
  color: var(--tenue);
  min-height: 44px;
  cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; }
.tabbar button.activo { color: var(--acento); }

.card { background: var(--hoja); border: 1px solid var(--linea); border-radius: var(--radio); padding: 14px; margin: 0 0 12px; }
.card h2 { margin: 0 0 6px; font-size: 17px; letter-spacing: -0.01em; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card p { margin: 4px 0; font-size: 14px; line-height: 1.4; }
.tenue { color: var(--tenue); }
.fila { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.nivel { font-weight: 700; color: var(--acento); font-variant-numeric: tabular-nums; }
.medidor { height: 6px; border-radius: 999px; background: var(--linea); overflow: hidden; margin: 6px 0; }
.medidor span { display: block; height: 100%; background: var(--acento); border-radius: inherit; }
.curva { width: 100%; height: 96px; display: block; margin-top: 6px; }
.curva .eje { stroke: var(--linea); stroke-width: 1; }
.curva .traza { fill: none; stroke: var(--acento); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.curva .punto { fill: var(--acento); }
.curva text { font-size: 10px; fill: var(--tenue); font-family: inherit; }

.lista { list-style: none; margin: 8px 0 0; padding: 0; }
.lista li { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-top: 1px solid var(--linea); font-size: 14px; line-height: 1.35; }
.lista li:first-child { border-top: 0; }
.marca { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; border: 1.5px solid var(--linea); color: var(--tenue); }
.marca.hecho { background: var(--bien); border-color: var(--bien); color: #fff; }

.btn {
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--linea);
  background: var(--hoja);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--tinta); color: var(--hoja); border-color: var(--tinta); }
.btn.peligro { color: var(--mal); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.ancho { width: 100%; margin-top: 8px; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; display: grid; place-items: center; cursor: pointer; flex: 0 0 auto; }
.icon-btn svg { width: 22px; height: 22px; }

.proyecto { padding: 10px 12px; border: 1px solid var(--linea); border-radius: 10px; background: #faf8f2; font-size: 14px; line-height: 1.35; }
.proyecto p { margin: 0; }
.proyecto-fase { font-weight: 600; }
.proyecto-barra { height: 4px; margin: 8px 0; border-radius: 999px; background: var(--linea); overflow: hidden; }
.proyecto-barra span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--acento), #8a6ee0); }
.proyecto-objetivo { color: var(--tenue); }
.proyecto.estado-2 .proyecto-fase { color: var(--aviso); }
.proyecto.estado-4 .proyecto-fase { color: var(--bien); }

.tuto { position: absolute; inset: 0; pointer-events: none; }
.tuto-velo { position: absolute; inset: 0; z-index: 50; background: rgba(31, 29, 43, 0.45); pointer-events: auto; }
.tuto.interactivo .tuto-velo { background: rgba(31, 29, 43, 0.3); }
.tuto-card {
  position: absolute;
  left: calc(12px + var(--left));
  right: calc(12px + var(--right));
  max-width: 520px;
  margin: 0 auto;
  background: var(--hoja);
  border-radius: 16px;
  padding: 14px 16px 12px;
  box-shadow: 0 16px 48px rgba(31, 29, 43, 0.25);
  pointer-events: auto;
  z-index: 52;
}
.tuto-card.abajo { bottom: calc(12px + var(--bottom)); }
.tuto-card.arriba { top: calc(12px + var(--top)); }
.tuto-card h2 { margin: 2px 0 6px; font-size: 18px; letter-spacing: -0.01em; }
.tuto-card p { margin: 0; font-size: 15px; line-height: 1.4; }
.tuto-paso { font-size: 12px !important; color: var(--tenue); font-weight: 600; }
.tuto-acciones { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.tuto-foco { position: relative; z-index: 51; box-shadow: 0 0 0 3px var(--acento), 0 0 0 9999px rgba(0, 0, 0, 0); border-radius: 12px; }

.leyenda { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: calc(12px + var(--top)) calc(12px + var(--right)) calc(12px + var(--bottom)) calc(12px + var(--left)); }
.leyenda[hidden] { display: none; }
.leyenda-velo { position: absolute; inset: 0; background: rgba(31, 29, 43, 0.45); }
.leyenda-card { position: relative; width: 100%; max-width: 440px; max-height: 100%; overflow: hidden; background: var(--hoja); border-radius: 16px; padding: 14px 16px 12px; box-shadow: 0 16px 48px rgba(31, 29, 43, 0.25); }
.leyenda-card h2 { margin: 0 0 2px; font-size: 19px; letter-spacing: -0.01em; }
.leyenda-card > p { margin: 0 0 8px; font-size: 13px; line-height: 1.35; }
.leyenda-card h3 { margin: 8px 0 6px; font-size: 14px; }
.leyenda-anillos { display: flex; align-items: center; gap: 14px; }
.leyenda-diana { flex: 0 0 104px; width: 104px; height: 104px; }
.leyenda-num circle { fill: var(--tinta); }
.leyenda-num text { fill: #fff; font-size: 7.5px; font-weight: 800; text-anchor: middle; font-family: -apple-system, system-ui, sans-serif; }
.leyenda-dims { margin: 0; padding: 0; list-style: none; display: grid; gap: 3px; font-size: 14px; font-weight: 700; }
.leyenda-dims li { display: flex; align-items: baseline; gap: 6px; }
.leyenda-dims .n { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 999px; background: var(--tinta); color: #fff; font-size: 11px; font-weight: 800; flex: 0 0 auto; align-self: center; }
.leyenda-dims small { color: var(--tenue); font-weight: 500; font-size: 12px; }
.leyenda-barra { height: 16px; border-radius: 6px; border: 1px solid #c8c0b2; background: linear-gradient(to right, #1b1b1f, #d2452a 33.3%, #f2b33d 66.6%, #ffffff); }
.leyenda-extremos { display: flex; justify-content: space-between; font-size: 11px; color: var(--tenue); margin: 2px 0 6px; }
.leyenda-niveles { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 6px 10px; }
.leyenda-niveles li { display: flex; align-items: center; gap: 8px; min-width: 0; }
.leyenda-niveles .muestra { flex: 0 0 26px; width: 26px; height: 26px; border-radius: 999px; border: 1.5px solid #c8c0b2; }
.leyenda-niveles .muestra.brilla { box-shadow: 0 0 10px 3px rgba(242, 179, 61, 0.7); }
.leyenda-niveles b { display: block; font-size: 14px; }
.leyenda-niveles small { display: block; font-size: 11px; color: var(--tenue); white-space: nowrap; }
.leyenda-pie { margin: 8px 0 0; font-size: 13px; font-weight: 600; }
.lectura .dato.nivel-0 { border-color: #1b1b1f; }
.lectura .dato.nivel-1 { border-color: #d2452a; }
.lectura .dato.nivel-2 { border-color: #f2b33d; }
.lectura .dato.nivel-3 { border-color: #f2b33d; box-shadow: 0 0 6px rgba(242, 179, 61, 0.55); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--bottom) + 14px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  background: var(--tinta);
  color: var(--hoja);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.35;
  z-index: 60;
  margin: 0;
  box-shadow: 0 8px 24px rgba(31, 29, 43, 0.2);
}

@media (max-height: 680px) and (max-width: 699px) {
  #screen-jugar { gap: 6px; padding: 6px 0; }
  .lectura { flex-basis: 30px; height: 30px; }
  .lectura.puntos { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .lectura.puntos::-webkit-scrollbar { display: none; }
  .hud { min-height: 44px; }
}
@media (min-width: 700px) {
  .view { max-width: 900px; padding: 0 calc(16px + var(--right)) 0 calc(16px + var(--left)); }
  #screen-jugar { gap: 10px; padding: 12px 0; }
  .hud-estado { font-size: 16px; }
  .zona-cabeza .pad-hint { font-size: 15px; }
  .cola-item { width: 28px; height: 28px; }
  .cola-item svg { width: 18px; height: 18px; }
  .cola-tit { font-size: 13px; }
  .torres { gap: 10px; }
  .torre-btn { width: 84px; padding: 3px 4px 4px; border-radius: 16px; gap: 2px; }
  .torre-btn svg { width: 56px; height: 56px; }
  .torre-nombre { font-size: 13px; }
  .torre-nivel { font-size: 12px; min-width: 24px; }
  .mejora-btn { height: 26px; }
  .mejora-btn .mas { font-size: 17px; }
  .mejora-btn small { font-size: 14px; }
  .mejora-btn.maximo .mas { font-size: 13px; }
}
@media (min-width: 900px) and (orientation: landscape) {
  .view { max-width: 1400px; }
  #screen-jugar {
    display: grid;
    grid-template-columns: minmax(300px, 340px) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "hud campo" "lectura campo";
    gap: 12px 16px;
  }
  .hud { grid-area: hud; flex-wrap: wrap; }
  .campo-wrap { grid-area: campo; min-height: 0; }
  .lectura { grid-area: lectura; height: auto; align-self: start; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

