/* Lo de Pocho — anotador de truco.
   Concepto: la mesa de un bodegón de noche. Marrón café, luz de lámpara ámbar,
   rojo del grito de "¡Truco!" y el azul del dorso de las cartas.
   Prioridad absoluta: celular en vertical, una mano, pulgar. */

:root {
  color-scheme: dark;

  /* Madera y cuero */
  --ink-950: #120b08;
  --ink-900: #1a110c;
  --ink-850: #21160f;
  --ink-800: #2b1b11;

  /* Papel y texto */
  --cream: #f4e7cf;
  --cream-dim: #c9ba9c;
  --line: rgba(244, 231, 207, 0.13);
  --line-strong: rgba(244, 231, 207, 0.26);

  /* Equipos: oro (lámpara) y azul (dorso de las cartas) */
  --lamp: #f6b84a;
  --lamp-hi: #ffd584;
  --lamp-deep: #d28a1c;
  --blue: #86a8ee;
  --blue-hi: #b8cffb;
  --blue-deep: #4468c0;

  /* Marca: el rojo del grito */
  --truco: #c92a20;
  --truco-hi: #e24234;
  --truco-deep: #8f180f;

  --font-display: "Alfa Slab One", "Rockwell Extra Bold", Rockwell, "Roboto Slab", "Arial Black", Georgia, serif;
  --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --page-max: 880px;
  --gutter: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--ink-950);
  background-image:
    radial-gradient(90% 38% at 50% 0%, rgba(246, 184, 74, 0.1), transparent 72%),
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.012) 0 1px, transparent 1px 9px),
    linear-gradient(180deg, var(--ink-900), var(--ink-950));
  color: var(--cream);
  font: 16px/1.45 var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 1.3em;
  height: 1.3em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: none;
}

.emblem {
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  fill: currentColor;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -64px;
  z-index: 20;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--cream);
  color: var(--ink-950);
  font-weight: 700;
}

.skip:focus {
  top: calc(env(safe-area-inset-top, 0px) + 12px);
}

:focus-visible {
  outline: 3px solid var(--cream);
  outline-offset: 2px;
}

#board:focus {
  outline: none;
}

/* ---------- Cabecera con el logo ---------- */

.hero {
  position: relative;
  isolation: isolate;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  aspect-ratio: 900 / 390;
  min-height: 150px;
  max-height: 40svh;
  overflow: hidden;
  border-radius: 0 0 28px 28px;
  background: var(--ink-800);
  box-shadow: 0 22px 40px -22px #000;
}

.hero__art {
  position: absolute;
  inset: 0;
  display: block;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}

.hero__art img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 12%;
}

.hero__shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(18, 11, 8, 0.6) 0%, rgba(18, 11, 8, 0) 26%, rgba(18, 11, 8, 0) 42%, rgba(18, 11, 8, 0.94) 100%),
    linear-gradient(90deg, rgba(18, 11, 8, 0.6), rgba(18, 11, 8, 0) 58%);
}

.hero__bar {
  position: absolute;
  top: calc(env(safe-area-inset-top, 0px) + 10px);
  right: 12px;
  z-index: 2;
  display: flex;
  gap: 8px;
}

.hero__title {
  position: absolute;
  left: var(--gutter);
  bottom: 14px;
  z-index: 2;
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--lamp);
  font: 800 0.68rem/1 var(--font-ui);
  letter-spacing: 0.2em;
  text-transform: uppercase;
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.8);
}

.brand {
  margin: 0;
  color: var(--cream);
  font: 400 clamp(2rem, 9.4vw, 2.7rem) / 0.95 var(--font-display);
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.5), 0 10px 26px rgba(0, 0, 0, 0.7);
  text-wrap: balance;
}

/* ---------- Estructura de la página ---------- */

.page {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 12px var(--gutter) 0;
}

.series {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.28);
}

.series p {
  margin: 0;
}

.series__side {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.series__side--b {
  justify-content: flex-end;
}

.series__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 700;
}

.series__n {
  font: 400 1.35rem/1 var(--font-display);
  font-variant-numeric: tabular-nums;
}

.series__side--a {
  color: var(--lamp);
}

.series__side--b {
  color: var(--blue);
}

.series__mid {
  color: var(--cream-dim);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-align: center;
}

/* ---------- Marcador ---------- */

.board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
}

.team {
  --accent: var(--lamp);
  --accent-hi: var(--lamp-hi);
  --accent-deep: var(--lamp-deep);
  --accent-soft: rgba(246, 184, 74, 0.15);
  --glow: rgba(246, 184, 74, 0.34);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 12px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background:
    radial-gradient(120% 60% at 50% 0%, var(--accent-soft), transparent 62%),
    linear-gradient(170deg, var(--ink-800), var(--ink-900) 72%);
  box-shadow: inset 0 1px 0 rgba(255, 244, 220, 0.07), 0 24px 36px -26px #000;
  transition: border-color 0.25s, box-shadow 0.25s, opacity 0.25s;
}

.team--b {
  --accent: var(--blue);
  --accent-hi: var(--blue-hi);
  --accent-deep: var(--blue-deep);
  --accent-soft: rgba(134, 168, 238, 0.15);
  --glow: rgba(134, 168, 238, 0.34);
}

.team.is-winner {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent), 0 0 38px var(--glow), 0 24px 36px -26px #000;
}

.team.is-loser {
  opacity: 0.58;
}

.team__head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 2.3em;
  color: var(--accent);
}

.team__name {
  margin: 0;
  min-width: 0;
  font: 800 0.76rem/1.15 var(--font-ui);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.team__score {
  margin: 0;
  text-align: center;
  font: 400 clamp(4rem, 22vw, 6.4rem) / 0.95 var(--font-display);
  font-variant-numeric: tabular-nums;
  color: var(--cream);
  text-shadow: 0 0 34px var(--glow), 0 3px 0 rgba(0, 0, 0, 0.4);
  user-select: none;
  -webkit-user-select: none;
}

.team__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  color: var(--cream-dim);
  font-size: 0.8rem;
  font-weight: 600;
}

.chip {
  padding: 3px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  color: var(--cream-dim);
  font: 800 0.68rem/1.5 var(--font-ui);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.team[data-phase="buenas"] .chip {
  border-color: transparent;
  background: var(--accent);
  color: var(--ink-950);
}

/* ---------- Fósforos ---------- */

.tally {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 6px 6px 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.22);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.45);
}

.tally__sec + .tally__sec {
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.tally__head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin: 0 2px 2px;
  color: var(--cream-dim);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.tally__count {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.tally__row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.tally__group {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.stick__slot {
  fill: rgba(244, 231, 207, 0.045);
  stroke: rgba(244, 231, 207, 0.13);
  stroke-width: 0.6;
}

.stick__shadow {
  fill: rgba(0, 0, 0, 0.5);
}

.stick__shine {
  fill: rgba(255, 255, 255, 0.4);
}

.stick__gloss {
  fill: rgba(255, 255, 255, 0.55);
}

.stick--fresh {
  transform-box: fill-box;
  transform-origin: center;
  animation: strike 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.25);
}

@keyframes strike {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(1.08);
  }
}

/* ---------- Botones ---------- */

.btn {
  text-decoration: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 18px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(244, 231, 207, 0.07);
  color: var(--cream);
  font: 700 1rem/1 var(--font-ui);
  cursor: pointer;
  transition: background 0.15s, transform 0.08s, box-shadow 0.15s;
}

.btn:hover {
  background: rgba(244, 231, 207, 0.14);
}

.btn:active {
  transform: translateY(1px) scale(0.985);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  transform: none;
}

.btn--glass {
  width: 46px;
  min-height: 46px;
  padding: 0;
  border-color: var(--line-strong);
  border-radius: 14px;
  background: rgba(18, 11, 8, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.btn--cream {
  border-color: transparent;
  background: linear-gradient(180deg, #fff6e0, var(--cream));
  color: var(--ink-950);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

.btn--cream:hover {
  background: #fff8e8;
}

.btn--truco {
  border-color: transparent;
  background: linear-gradient(180deg, var(--truco-hi), var(--truco) 55%, var(--truco-deep));
  color: #fff3e6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), inset 0 -3px 0 rgba(0, 0, 0, 0.22), 0 10px 20px -10px #000;
}

.btn--truco:hover {
  background: linear-gradient(180deg, #f0503f, var(--truco-hi) 55%, var(--truco));
}

.team__controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.btn--add {
  grid-column: 1 / -1;
  min-height: 68px;
  padding: 0;
  border-color: transparent;
  background: linear-gradient(180deg, var(--accent-hi), var(--accent) 52%, var(--accent-deep));
  color: var(--ink-950);
  font: 400 2.2rem/1 var(--font-display);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55), inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 12px 20px -10px #000;
}

.btn--add:hover {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent) 52%, var(--accent-deep));
  filter: brightness(1.07);
}

.btn--add:active {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), inset 0 -2px 0 rgba(0, 0, 0, 0.2), 0 6px 12px -8px #000;
}

.btn--step {
  min-height: 48px;
  padding: 0;
  color: var(--accent);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- Ganador ---------- */

.winner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px 14px;
  padding: 14px 16px;
  border: 1px solid rgba(255, 190, 170, 0.35);
  border-radius: 20px;
  background: linear-gradient(170deg, var(--truco-hi), var(--truco) 50%, var(--truco-deep));
  color: #fff3e6;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25), 0 20px 34px -22px #000;
}

.winner__text {
  min-width: 0;
}

.winner__title {
  margin: 0;
  font: 400 1.3rem/1.1 var(--font-display);
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.winner > .btn {
  grid-column: 1 / -1;
}

.winner__pocho {
  position: relative;
  width: 76px;
  height: 94px;
  margin-top: -30px;
  animation: pocho-in 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}

.winner__pocho img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border: 3px solid var(--lamp);
  border-radius: 50% 50% 46% 46% / 56% 56% 44% 44%;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  transform-origin: 50% 90%;
  animation: pocho-laugh 0.55s ease-in-out 0.5s infinite alternate;
}

.winner__bubble {
  position: absolute;
  z-index: 1;
  left: 62%;
  top: -12px;
  padding: 6px 9px;
  border-radius: 12px 12px 12px 2px;
  background: #fff6e0;
  color: var(--truco-deep);
  font: 400 0.8rem/1 var(--font-display);
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  animation: pocho-pop 0.55s ease-in-out 0.5s infinite alternate;
}

.winner__mock {
  margin: 6px 0 0;
  font-weight: 800;
  color: var(--lamp-hi);
  overflow-wrap: anywhere;
}

@keyframes pocho-in {
  from { transform: translateY(24px) scale(0.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@keyframes pocho-laugh {
  from { transform: rotate(-7deg) scale(1); }
  to { transform: rotate(7deg) scale(1.06); }
}

@keyframes pocho-pop {
  from { transform: scale(0.92) rotate(-3deg); }
  to { transform: scale(1.08) rotate(3deg); }
}

@media (prefers-reduced-motion: reduce) {
  .winner__pocho,
  .winner__pocho img,
  .winner__bubble {
    animation: none;
  }
}

.winner__detail {
  margin: 4px 0 0;
  font-weight: 700;
  opacity: 0.9;
}

/* ---------- Pie y barra de acciones ---------- */

.footer {
  width: 100%;
  max-width: var(--page-max);
  margin: auto auto 0;
  padding: 18px var(--gutter) 4px;
  text-align: center;
}

.footer p {
  margin: 0;
  color: var(--cream-dim);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}

.footer strong {
  color: var(--cream);
  font-weight: 800;
}

.toolbar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1.25fr;
  gap: 10px;
  width: 100%;
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 14px var(--gutter) calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, var(--ink-950) 62%, rgba(18, 11, 8, 0));
}

/* ---------- Diálogos ---------- */

dialog {
  width: min(92vw, 440px);
  max-height: 88dvh;
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 26px;
  background: linear-gradient(170deg, var(--ink-800), var(--ink-900) 70%);
  color: var(--cream);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6);
}

dialog::backdrop {
  background: rgba(8, 4, 2, 0.74);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

dialog h2 {
  margin: 0 0 16px;
  font: 400 1.45rem/1.15 var(--font-display);
}

.dialog--art {
  width: min(94vw, 560px);
  padding: 10px;
}

.dialog--art img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 18px;
}

.dialog--art .dialog__actions {
  margin-top: 10px;
}

.dialog--art .btn {
  width: 100%;
}

.confirm__msg {
  margin: 0 0 4px;
  font-size: 1.08rem;
  font-weight: 600;
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.field label,
.field legend,
.field__title {
  margin: 0;
  padding: 0;
  color: var(--cream-dim);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.field input[type="text"] {
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.35);
  color: var(--cream);
  font: 600 1.05rem var(--font-ui);
}

.field input[type="text"]:focus-visible {
  outline-color: var(--lamp);
}

.field--check {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

.field--check input {
  width: 24px;
  height: 24px;
  accent-color: var(--lamp);
}

.field--check label {
  color: var(--cream);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.field--stack .btn {
  justify-content: flex-start;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 60px;
  padding: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  color: var(--cream);
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: none;
  cursor: pointer;
}

.segmented small {
  color: var(--cream-dim);
  font-size: 0.74rem;
  font-weight: 600;
}

.segmented input:checked + label {
  border-color: transparent;
  background: linear-gradient(180deg, var(--lamp-hi), var(--lamp));
  color: var(--ink-950);
}

.segmented input:checked + label small {
  color: #5a3a0c;
}

.segmented input:focus-visible + label {
  outline: 3px solid var(--cream);
  outline-offset: 2px;
}

/* ---------- Historial ---------- */

.history {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history__item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.24);
}

.history__when,
.history__mode {
  color: var(--cream-dim);
  font-size: 0.78rem;
  font-weight: 600;
}

.history__mode {
  grid-row: 1;
  grid-column: 2;
  text-align: right;
}

.history__line {
  grid-column: 1 / -1;
  margin: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.history__side.is-winner {
  color: var(--lamp);
  font-weight: 800;
}

.muted {
  color: var(--cream-dim);
}

/* ---------- Adaptaciones ---------- */

@media (max-width: 359px) {
  :root {
    --gutter: 12px;
  }

  .team {
    padding-inline: 8px;
  }

  .btn--add {
    font-size: 1.9rem;
  }

  .series__mid {
    display: none;
  }

  .series {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .toolbar {
    grid-template-columns: 1fr 1.4fr;
    gap: 8px;
  }

  .toolbar .btn {
    padding-inline: 10px;
    font-size: 0.94rem;
  }

  .toolbar .icon {
    display: none;
  }
}

@media (min-width: 640px) {
  :root {
    --gutter: 24px;
  }

  .hero {
    border-radius: 0 0 36px 36px;
  }

  .team {
    padding: 18px 16px 16px;
  }

  .board {
    gap: 18px;
  }

  .tally__row {
    grid-template-columns: repeat(3, 72px);
    justify-content: space-evenly;
  }

  .toolbar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-height: 520px) and (orientation: landscape) {
  .hero {
    max-height: 34svh;
    min-height: 110px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
