/* Acampada Sol — estética de pancarta de cartón sobre asfalto */

:root {
    --asfalto: #1d2023;
    --asfalto-2: #2a2e33;
    --carton: #d9b77e;
    --carton-oscuro: #b8924f;
    --rotulador: #1b1b1b;
    --verde: #2f9e44;
    --verde-oscuro: #20702f;
    --rojo: #d7263d;
    --amarillo: #f4c430;
    --texto: #f1ece2;
    --texto-suave: #b9b3a6;
    --marker: "Marker Felt", "Comic Sans MS", "Chalkboard SE", "Comic Neue", cursive;
    --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }
body {
    background:
        radial-gradient(circle at 20% 10%, rgba(255,255,255,0.04) 0 2px, transparent 3px) 0 0 / 23px 23px,
        radial-gradient(circle at 70% 60%, rgba(0,0,0,0.25) 0 2px, transparent 3px) 0 0 / 31px 31px,
        var(--asfalto);
    color: var(--texto);
    font-family: var(--sans);
    font-size: 15px;
    line-height: 1.45;
    min-height: 100vh;
}

h1, h2, h3 { font-family: var(--marker); letter-spacing: 0.5px; }

.carton {
    background:
        repeating-linear-gradient(90deg, rgba(0,0,0,0.035) 0 2px, transparent 2px 7px),
        var(--carton);
    color: var(--rotulador);
    border-radius: 6px;
    box-shadow: 0 4px 0 var(--carton-oscuro), 0 10px 30px rgba(0,0,0,0.45);
}

/* ---- Botones ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 2px solid var(--rotulador);
    border-radius: 8px;
    padding: 10px 16px;
    font: 700 15px/1.2 var(--sans);
    cursor: pointer;
    text-decoration: none;
    background: #fff8ea;
    color: var(--rotulador);
    transition: transform 0.08s, box-shadow 0.08s;
    box-shadow: 0 3px 0 var(--rotulador);
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--rotulador); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--lg { width: 100%; padding: 13px 18px; font-size: 16px; }
.btn--start { background: var(--verde); color: #fff; }
.btn--secondary { background: #fff8ea; }
.btn--warning { background: var(--rojo); color: #fff; }
.btn--kofi { background: #ff5e5b; color: #fff; }
.btn--icon {
    width: 42px; height: 42px; padding: 0; font-size: 20px;
    background: var(--carton); box-shadow: 0 3px 0 var(--carton-oscuro); border-color: var(--carton-oscuro);
}
.btn--opcion { width: 100%; text-align: left; justify-content: flex-start; font-weight: 600; }

/* ---- Inicio ---- */
#start-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
}
.start-content { width: 100%; max-width: 520px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.start-emoji { font-size: 46px; }
.start-content h1 {
    margin: 0;
    font-size: clamp(38px, 11vw, 60px);
    color: var(--carton);
    text-shadow: 3px 3px 0 var(--verde-oscuro);
    transform: rotate(-2deg);
}
.start-subtitle { margin: 0 0 6px; font-family: var(--marker); font-size: 20px; color: var(--amarillo); }
.start-intro { text-align: left; padding: 16px 18px; transform: rotate(0.6deg); }
.start-intro p { margin: 0 0 10px; }
.start-intro p:last-child { margin: 0; }
.landing-footer { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 8px; }
.landing-kofi, .back-to-menu {
    color: var(--texto-suave); background: none; border: none; font: inherit; cursor: pointer; text-decoration: underline;
}
.landing-kofi { color: #ff8c89; }
.start-note { margin: 0; font-size: 12px; color: var(--texto-suave); }

/* ---- Juego ---- */
#game-header {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 8px 12px;
    background: rgba(20,22,25,0.94);
    border-bottom: 3px solid var(--verde);
    backdrop-filter: blur(4px);
}
.header-centro { display: flex; flex-direction: column; align-items: center; min-width: 0; }
.hud-dia { font-family: var(--marker); font-size: 22px; color: var(--amarillo); line-height: 1; }
.hud-franja { font-size: 13px; color: var(--texto-suave); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62vw; }

.layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 12px;
    max-width: 1180px;
    margin: 0 auto;
}
@media (min-width: 900px) {
    .layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); align-items: start; }
    .col-plaza { position: sticky; top: 70px; }
}
.col-plaza, .col-acciones { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.escena-wrap {
    position: relative;
    height: clamp(190px, 38vw, 300px);
    border-radius: 10px;
    overflow: hidden;
    border: 3px solid var(--carton-oscuro);
    background: #8fd3ff;
}
#escena { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.canto {
    position: absolute; left: 8px; right: 8px; top: 8px;
    font-family: var(--marker); font-size: 14px; text-align: center;
    color: #fff; text-shadow: 0 1px 3px #000, 0 0 6px #000;
    pointer-events: none;
}
.canto--in { animation: canto 7s ease-in-out; }
@keyframes canto { 0% { opacity: 0; transform: translateY(-6px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }

.resumen { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.resumen-item {
    background: var(--asfalto-2); border-radius: 8px; padding: 6px 4px;
    display: flex; flex-direction: column; align-items: center; line-height: 1.15;
}
.resumen-item span { font-size: 18px; }
.resumen-item strong { font-size: 17px; }
.resumen-item small { font-size: 11px; color: var(--texto-suave); }

.insalubridad { background: var(--asfalto-2); border-radius: 8px; padding: 10px 12px; border: 2px solid transparent; }
.insalubridad.peligro { border-color: var(--rojo); animation: latido 1.2s infinite; }
@keyframes latido { 50% { box-shadow: 0 0 16px rgba(215,38,61,0.55); } }
.insal-cabecera { display: flex; justify-content: space-between; font-weight: 800; font-size: 13px; letter-spacing: 0.5px; }
.insal-cabecera strong { font-size: 20px; color: var(--amarillo); }
.insal-barra { height: 12px; border-radius: 6px; background: #111; margin: 6px 0; overflow: hidden; }
#insal-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--verde), var(--amarillo) 55%, var(--rojo)); transition: width 0.4s; }
.insalubridad small { color: var(--texto-suave); font-size: 11.5px; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--asfalto-2); border-radius: 8px; padding: 7px 10px; }
.stat-cab { display: flex; justify-content: space-between; gap: 6px; font-size: 13px; }
.stat-barra { height: 7px; background: #111; border-radius: 4px; margin-top: 5px; overflow: hidden; }
.stat-barra div { height: 100%; transition: width 0.4s; }
.stat--bien .stat-barra div { background: var(--verde); }
.stat--regular .stat-barra div { background: var(--amarillo); }
.stat--mal .stat-barra div { background: var(--rojo); }
.stat--mal strong { color: #ff7b8a; }

.panel-titulo { margin: 4px 0 0; font-size: 20px; color: var(--carton); }

.acciones { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 560px) { .acciones { grid-template-columns: 1fr 1fr; } }
.accion {
    display: flex; gap: 10px; align-items: flex-start; text-align: left;
    padding: 10px; border-radius: 8px; cursor: pointer;
    border: 2px solid var(--rotulador);
    background: repeating-linear-gradient(90deg, rgba(0,0,0,0.035) 0 2px, transparent 2px 7px), var(--carton);
    color: var(--rotulador);
    box-shadow: 0 3px 0 var(--carton-oscuro);
    font: inherit;
    transition: transform 0.08s;
}
.accion:hover:not(:disabled) { transform: translateY(-1px) rotate(-0.4deg); }
.accion:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--carton-oscuro); }
.accion:disabled { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }
.accion--repetida { background: #cdb48a; }
.accion-emoji { font-size: 26px; line-height: 1; }
.accion-cuerpo { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.accion-cuerpo strong { font-size: 14.5px; }
.accion-cuerpo small { font-size: 12.5px; line-height: 1.3; color: #3b3223; }
.accion-coste {
    align-self: flex-start; margin-top: 3px;
    font-size: 11.5px; font-weight: 800; background: var(--rotulador); color: var(--carton);
    padding: 1px 6px; border-radius: 4px;
}
.accion-efectos { margin-top: 3px; }
.accion-efectos .delta { font-size: 11px; }
.accion-hint { font-size: 11.5px; font-weight: 700; line-height: 1.3; color: #3b3223; }
.accion-hint::before { content: '→ '; }
.accion-hint--nueva { font-weight: 400; font-style: italic; opacity: 0.7; }
.accion-hint--nueva::before { content: '❔ '; }
.accion-motivo { font-size: 11.5px; font-weight: 700; color: #8b1020; }

.cronica {
    list-style: none; margin: 0; padding: 0 4px 0 0; display: flex; flex-direction: column; gap: 8px;
    max-height: 230px; overflow-y: auto;
}
.cronica li { background: var(--asfalto-2); border-left: 4px solid var(--verde); border-radius: 6px; padding: 8px 10px; }
.cronica li:first-child { border-left-color: var(--amarillo); }
.cronica-cab { font-size: 12px; font-weight: 800; color: var(--amarillo); }
.cronica p { margin: 3px 0 0; font-size: 13.5px; }

.deltas { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.delta { font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 10px; background: #111; }
.delta.bien { color: #7be08d; }
.delta.mal { color: #ff7b8a; }
.delta.neutro { color: var(--texto-suave); }
.modal .delta { background: rgba(0,0,0,0.75); }

/* ---- Modales ---- */
.modal {
    position: fixed; inset: 0; z-index: 100;
    display: none; align-items: center; justify-content: center;
    padding: 16px;
    background: rgba(0,0,0,0.72);
}
.modal.active { display: flex; }
.modal-content {
    width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto;
    padding: 20px 18px;
    animation: entra 0.18s ease-out;
}
@keyframes entra { from { transform: scale(0.94) rotate(-1deg); opacity: 0; } }
.modal-content h3 { margin: 0 0 10px; font-size: 24px; text-align: center; }
.evento-emoji { font-size: 50px; text-align: center; line-height: 1.1; }
.evento-opciones, .pause-botones, .fin-botones { display: flex; flex-direction: column; gap: 9px; margin-top: 12px; }
.evento-resultado p { font-style: italic; }
.evento-resultado .btn { width: 100%; margin-top: 12px; }

.concesion {
    position: relative; border: 3px double #8b1020; border-radius: 6px;
    padding: 12px; margin-bottom: 12px; background: rgba(255,255,255,0.35);
}
.concesion-sello {
    display: inline-block; transform: rotate(-4deg);
    border: 2px solid #8b1020; color: #8b1020; font-weight: 900; font-size: 12px;
    padding: 1px 6px; margin-bottom: 6px; letter-spacing: 1px;
}
.concesion strong { display: block; font-size: 16px; }
.concesion p { margin: 6px 0 0; font-size: 13.5px; }

.parte-deltas { display: flex; flex-direction: column; gap: 3px; }
.parte-fila { display: flex; justify-content: space-between; padding: 4px 2px; border-bottom: 1px dashed rgba(0,0,0,0.25); font-size: 14px; }
.parte-fila .bien { color: #1d6b2b; }
.parte-fila .mal { color: #a3122a; }
.parte-fila .neutro { color: #555; }
.parte-clima { font-weight: 700; margin: 12px 0; }
.parte-notas { margin-bottom: 10px; }
.parte-notas p { margin: 0 0 6px; padding: 6px 8px; font-size: 13.5px; border-left: 3px solid #8b1020; background: rgba(255,255,255,0.3); }
#parte-modal .btn { width: 100%; }

.fin-dias { text-align: center; margin: 12px 0 4px; }
.fin-dias span { display: block; font-weight: 800; font-size: 12px; letter-spacing: 1px; }
.fin-dias strong { font-family: var(--marker); font-size: 64px; line-height: 1; color: var(--verde-oscuro); }
.fin-rango { text-align: center; font-family: var(--marker); font-size: 19px; margin: 0 0 8px; }
.fin-stats { margin: 0; padding-left: 18px; font-size: 13.5px; }

.help-content details { border-bottom: 1px dashed rgba(0,0,0,0.3); padding: 6px 0; }
.help-content summary { font-weight: 800; cursor: pointer; }
.help-content p { margin: 6px 0; font-size: 14px; }
.help-content .btn { margin-top: 12px; }
.help-content ol { margin: 6px 0; padding-left: 20px; font-size: 14px; }
.help-content li { margin-bottom: 5px; }

.nickname-input {
    width: 100%; padding: 10px 12px; font-size: 16px;
    border: 2px solid var(--rotulador); border-radius: 8px; background: #fffdf6;
}
.nickname-error { color: #a3122a; font-weight: 700; font-size: 13px; }

.ranking-nick-info { text-align: center; font-size: 13px; margin: 0 0 8px; }
.ranking-list { display: flex; flex-direction: column; gap: 4px; }
.ranking-row {
    display: grid; grid-template-columns: 40px 1fr auto auto; gap: 8px; align-items: center;
    padding: 6px 8px; border-radius: 6px; background: rgba(255,255,255,0.4); font-size: 14px;
}
.ranking-row.is-me { outline: 2px solid var(--verde-oscuro); }
.ranking-row.is-top1 { background: #f4d35e; }
.ranking-row.is-top2 { background: #dcdcdc; }
.ranking-row.is-top3 { background: #e0a878; }
.ranking-rank { font-weight: 900; }
.ranking-nick { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ranking-score { font-weight: 800; }
.ranking-time { font-size: 12px; color: #444; }
.ranking-loading, .ranking-error, .ranking-empty { text-align: center; }

@media (max-width: 380px) {
    .stats { grid-template-columns: 1fr; }
    .resumen-item strong { font-size: 15px; }
}

/* Resultado flotante de la última acción: en móvil la crónica queda fuera de pantalla. */
.toast-accion {
    position: fixed; left: 50%; bottom: 16px; z-index: 90;
    width: min(92vw, 460px);
    transform: translate(-50%, 140%);
    background: rgba(17,19,21,0.96); border: 2px solid var(--verde); border-radius: 10px;
    padding: 8px 12px; font-size: 13.5px; font-weight: 700;
    transition: transform 0.25s ease-out;
    pointer-events: none;
}
.toast-accion.visible { transform: translate(-50%, 0); }
.toast-accion .deltas { margin-top: 4px; }

/* ---- Minijuego: defensa de la plaza ---- */
.defensa-content { max-width: 860px; padding: 12px 12px 14px; }
.defensa-cabecera { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.defensa-cabecera h3 { margin: 0; font-size: 20px; }
.defensa-marcador { font-weight: 800; font-size: 13px; background: rgba(0,0,0,0.12); padding: 3px 8px; border-radius: 10px; }
.defensa-escenario { position: relative; border: 2px solid var(--rotulador); border-radius: 6px; overflow: hidden; background: #a79d88; }
#defensa-canvas {
    display: block; margin: 0 auto; aspect-ratio: var(--ar, 1.6);
    width: min(100%, calc((100dvh - 190px) * var(--ar, 1.6)));
    touch-action: none; cursor: crosshair;
}
.defensa-panel {
    position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; padding: 16px; text-align: center; background: rgba(20,20,24,0.78); color: var(--texto);
}
.defensa-panel p { margin: 0; max-width: 560px; }
.defensa-lista { list-style: none; margin: 0; padding: 0; text-align: left; font-size: 14px; max-width: 560px; }
.defensa-lista li { margin: 4px 0; }
.defensa-lista li.defensa-jefe { margin-top: 8px; padding: 4px 8px; border-left: 3px solid #ff5a36; background: rgba(255,90,54,0.12); }
.defensa-titular { font-family: var(--marker); font-size: 34px; color: var(--amarillo); }
.defensa-armas { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.arma {
    position: relative; overflow: hidden; display: flex; flex-direction: column; align-items: center; gap: 1px;
    padding: 6px 4px; border: 2px solid var(--rotulador); border-radius: 8px; background: #fff8ea;
    color: var(--rotulador); font: 700 12px/1.15 var(--sans); cursor: pointer;
}
.arma.activa { background: var(--amarillo); box-shadow: inset 0 0 0 2px var(--rotulador); }
.arma-cd {
    position: absolute; left: 0; right: 0; bottom: 0; height: calc(var(--cd, 0) * 100%);
    background: rgba(0,0,0,0.28); pointer-events: none;
}
.arma-emoji { font-size: 24px; }
.arma kbd { font: 700 10px var(--sans); opacity: 0.6; }
@media (max-width: 520px) {
    .modal:has(.defensa-content) { padding: 6px; }
    .defensa-content { max-height: 100dvh; padding: 8px 8px 10px; }
    .defensa-cabecera h3 { font-size: 17px; }
    .arma-nombre { font-size: 10.5px; }
    .arma kbd { display: none; }
    .defensa-lista { font-size: 12.5px; }
    .defensa-panel { gap: 6px; padding: 10px; font-size: 13px; }
}
