/* Mancala web: MISMO estilo que la app Android (cartoon): colores vivos, bordes gruesos, sombras duras tipo pegatina y
   rebotes con muelle. En modo oscuro se invierten fondo y texto y se mantienen los colores vivos.
   Paleta = CartoonUi.kt (Android) y palette() de js/board.js: si cambias un color, cámbialo en los tres sitios. */
:root {
  --paper: #FFF4DC; --card: #FFFFFF; --ink: #2B1B17; --muted: #7A675C;
  --on-bright: #2B1B17; --orange: #FF8A3D; --yellow: #FFCB47; --teal: #2EC4B6; --pink: #FF6B9A; --good: #4CD964; --bad: #FF4D4D;
  --line: var(--ink); --alert: var(--bad);
  --bounce: cubic-bezier(.34, 1.8, .5, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #1D1533; --card: #2E2350; --ink: #FFF4DC; --muted: #B9ABDD; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink); }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }

/* cada pantalla entra con un rebote (se aplica sólo al CAMBIAR de pantalla: ver render()) */
@keyframes pop { 0% { transform: scale(.94); opacity: 0; } 60% { opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
#app.enter { animation: pop .55s var(--bounce); transform-origin: 50% 20%; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.05); } }
@keyframes beat { from { transform: scale(.8); } to { transform: scale(1.3); } }
@keyframes bump { 0% { transform: scale(1.45); } 100% { transform: scale(1); } }

.topbar { position: sticky; top: 0; z-index: 2; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--paper); }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.title-end { font-weight: 700; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
.content { max-width: 720px; margin: 0 auto; padding: 8px 18px 24px; display: flex; flex-direction: column; gap: 10px; }
.onboarding { min-height: 90vh; justify-content: center; }
.brand { font-size: 44px; margin: 0; font-weight: 900; color: var(--orange); }
h2 { font-size: 18px; font-weight: 900; margin: 18px 0 4px; }
p { margin: 0; }
.muted { color: var(--muted); } .small { font-size: 13px; } .strong { font-weight: 800; } .center { text-align: center; }
.mono { font-family: ui-monospace, Consolas, monospace; word-break: break-all; }
.headline { font-size: 32px; font-weight: 900; margin: 24px 0 8px; animation: bump .6s var(--bounce); transform-origin: left center; }
.headline.won { color: var(--good); } .headline.lost { color: var(--bad); } .headline.draw { color: var(--yellow); }

/* ---------------------------------------------------------------- pegatinas: botones y tarjetas */
.btn { font: inherit; font-weight: 800; color: var(--on-bright); background: var(--orange); border: 3px solid var(--ink); border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink); margin-bottom: 4px; padding: 10px 16px; cursor: pointer; min-height: 46px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center;
  transition: transform .35s var(--bounce), box-shadow .15s; }
.btn:active:not(:disabled) { transform: translateY(3px) scale(.93); box-shadow: 0 1px 0 var(--ink); transition-duration: .08s; }
.btn.secondary { background: var(--yellow); }
.btn.outline { background: var(--card); color: var(--ink); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.link { background: none; color: var(--ink); border: none; box-shadow: none; text-decoration: underline; padding: 6px 8px; min-height: 36px; margin: 0; font-weight: 700; }
.btn.wide { width: 100%; }
.btn.big { font-size: 18px; font-weight: 900; }
.btn:focus-visible, .panel.clickable:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--good); outline-offset: 3px; }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; flex-wrap: wrap; } .row > * { flex: 1 1 0; min-width: 0; }
.segmented { display: flex; gap: 8px; } .segmented > .btn { flex: 1; }
.line { display: flex; align-items: center; gap: 10px; } .grow { flex: 1; min-width: 0; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; }

input[type=text], input[type=search], input[type=email], input[type=password], select {
  font: inherit; width: 100%; padding: 10px 14px; border: 3px solid var(--ink); border-radius: 16px; background: var(--card); color: var(--ink); min-height: 46px; }
.toggle input { width: 24px; height: 24px; accent-color: var(--good); }

.panel { border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink); margin-bottom: 4px; padding: 14px; background: var(--card);
  display: flex; flex-direction: column; gap: 6px; }
.panel.match { flex-direction: row; align-items: center; }
.panel.clickable { cursor: pointer; transition: transform .3s var(--bounce); } .panel.clickable:active { transform: scale(.97); }
.panel.mine { background: color-mix(in srgb, var(--good) 38%, var(--card)); border-width: 4px; }
.panel.invite, .panel.request { background: color-mix(in srgb, var(--yellow) 45%, var(--card)); }
.end { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.notice { border: 2px solid var(--ink); border-radius: 14px; box-shadow: 0 3px 0 var(--ink); padding: 10px; font-size: 14px; font-weight: 700;
  background: color-mix(in srgb, var(--yellow) 55%, var(--card)); }
.offline-banner { background: var(--bad); color: #fff; padding: 8px 16px; font-size: 14px; margin: 0; font-weight: 700; }
.alert { color: var(--ink); font-weight: 900; display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--bad); display: inline-block; animation: beat .55s ease-in-out infinite alternate; }
.badge { flex: none; display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 5px;
  background: var(--bad); color: #fff; border: 2px solid var(--ink); border-radius: 11px; font-size: 12px; font-weight: 900; line-height: 1; }
.countdown.urgent, .turn-clock .urgent { color: var(--bad); }
.tiles { display: flex; gap: 10px; } .tiles > * { flex: 1; } .tile strong { font-size: 28px; font-weight: 900; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; display: table; } .table th, .table td { padding: 6px 4px; text-align: end; border-bottom: 2px solid color-mix(in srgb, var(--ink) 25%, transparent); }
.table th:first-child, .table td:first-child { text-align: start; }

/* ---------------------------------------------------------------- partida: cartel de turno, marcador y tablero */
/* Altura FIJA: «¡TU TURNO!», «Turno de <nombre>» (con o sin reloj) y «Partida terminada» miden lo mismo, así el marcador y el tablero de debajo no saltan al cambiar el turno. */
.turn-banner { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border: 4px solid var(--ink); border-radius: 22px; box-shadow: 0 5px 0 var(--ink);
  min-height: 64px; margin-bottom: 5px; background: var(--yellow); color: var(--on-bright); }
.turn-banner.anim { animation: bump .5s var(--bounce); }
.turn-banner strong { flex: 1; min-width: 0; font-size: 22px; font-weight: 900; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.turn-banner.mine { background: var(--good); }
.turn-banner.mine:not(.anim) { animation: pulse .6s ease-in-out infinite alternate; }
.turn-banner.over { background: var(--bad); color: #fff; }
.turn-banner.side0 { background: var(--teal); } .turn-banner.side1 { background: var(--pink); }
.turn-banner .turn-clock { font-size: 20px; line-height: 1.2; font-weight: 900; background: rgb(255 255 255 / .55); border: 2px solid var(--ink); border-radius: 12px; padding: 0 10px; }
.turn-banner .turn-clock.urgent { background: var(--bad); color: #fff; }
.scores { display: flex; gap: 12px; margin: 6px 0; }
.score-card { flex: 1; text-align: center; display: flex; flex-direction: column; padding: 8px 10px; background: var(--card); color: var(--ink);
  border: 2px solid var(--ink); border-radius: 20px; box-shadow: 0 2px 0 var(--ink); opacity: .78; transform: scale(.96); transition: transform .45s var(--bounce), opacity .3s; }
.score-card strong { font-size: 34px; font-weight: 900; line-height: 1.1; }
.score-card.active { opacity: 1; transform: scale(1.06); border-width: 4px; box-shadow: 0 5px 0 var(--ink); background: var(--yellow); color: var(--on-bright); }
.score-card.active.me, .score-card.active.side0 { background: var(--good); } .score-card.active.side0 { background: var(--teal); } .score-card.active.side1 { background: var(--pink); }
.score-card strong.pop { animation: bump .5s var(--bounce); }
.board-canvas { display: block; width: 100%; height: 360px; touch-action: manipulation; user-select: none; -webkit-tap-highlight-color: transparent; }

/* ---------------------------------------------------------------- diálogos y avisos */
.modal { position: fixed; inset: 0; background: rgb(0 0 0 / .5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.dialog { max-width: 420px; width: 100%; animation: bump .5s var(--bounce); }
.dialog .install-icon { width: 72px; height: 72px; border-radius: 18px; border: 3px solid var(--ink); align-self: center; }
.install-banner { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 4px 0 var(--ink);
  margin-bottom: 4px; background: color-mix(in srgb, var(--yellow) 45%, var(--card)); animation: bump .5s var(--bounce); }
.install-banner-icon { width: 44px; height: 44px; border-radius: 12px; border: 2px solid var(--ink); flex: none; }
.install-banner .btn { min-height: 40px; padding: 6px 14px; }
.install-banner-close { flex: none; width: 32px; height: 32px; border: none; background: none; color: var(--ink); font-size: 24px; line-height: 1; cursor: pointer; border-radius: 50%; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 12; background: var(--ink); color: var(--paper); font-weight: 800;
  padding: 10px 18px; border-radius: 999px; animation: bump .4s var(--bounce); max-width: 90vw; text-align: center; }
.cookie-bar { position: fixed; inset: auto 0 0 0; z-index: 9; border-top: 3px solid var(--ink); background: var(--card); padding: 12px 16px;
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.cookie-bar p { flex: 1 1 280px; font-size: 14px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 2px solid var(--muted); }
/* ---------------------------------------------------------------- anuncios (footer) */
#ad-footer { position: fixed; inset: auto 0 0 0; z-index: 5; min-height: 60px; max-height: 110px; overflow: hidden;
  background: var(--paper); border-top: 3px solid var(--ink); display: flex; justify-content: center; align-items: center; }
#ad-footer[hidden] { display: none; }
#ad-footer ins { width: 100%; max-width: 728px; min-height: 50px; }
body.with-ad-footer .content { padding-bottom: 130px; }
body.with-ad-footer .cookie-bar { bottom: 110px; }
#google-button { min-height: 44px; display: flex; justify-content: center; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
body:has(.cookie-bar) .content { padding-bottom: 160px; }
@media (prefers-reduced-motion: reduce) {
  #app.enter, .headline, .turn-banner, .turn-banner.anim, .turn-banner.mine:not(.anim), .dialog, .toast, .dot, .score-card strong.pop { animation: none; }
  .btn, .panel.clickable, .score-card { transition: none; }
}
