@font-face {
  font-family: "Fraunces";
  src: url("fonts/Fraunces-Variable.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("fonts/Nunito-Variable.ttf") format("truetype");
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  --felt: #164a2c;
  --felt-dark: #0c2a1a;
  --felt-mid: #1c5634;
  --wood: #6b3e1f;
  --wood-dark: #3a2110;
  --cream: #f3e6c4;
  --cream-dim: #d4c49a;
  --gold: #e0b456;
  --gold-dim: #b8892e;
  --ink: #14110c;
  --stick: #efd27a;
  --stick-edge: #c9a24a;
  --head: #c43c2c;
  --head-dark: #8b1e16;
  --danger: #e07060;
  --line: rgba(243, 230, 196, 0.32);
  --line-strong: rgba(243, 230, 196, 0.55);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --font-ui: "Nunito", system-ui, sans-serif;
  --font-display: "Fraunces", Georgia, serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: var(--felt-dark);
  color: var(--cream);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body {
  min-height: 100dvh;
  overflow: hidden;
}
button, input {
  font-family: inherit;
  color: inherit;
}
button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
[hidden] { display: none !important; }
.felt {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(60, 140, 80, 0.35), transparent 55%),
    radial-gradient(ellipse at 50% 120%, rgba(0, 0, 0, 0.45), transparent 50%),
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(0, 0, 0, 0.04) 2px,
      rgba(0, 0, 0, 0.04) 3px
    ),
    repeating-linear-gradient(
      90deg,
      transparent,
      transparent 3px,
      rgba(255, 255, 255, 0.015) 3px,
      rgba(255, 255, 255, 0.015) 4px
    ),
    var(--felt);
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding:
    calc(var(--safe-top) + 6px)
    calc(var(--safe-right) + 10px)
    calc(var(--safe-bottom) + 10px)
    calc(var(--safe-left) + 10px);
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 2px 0 6px;
}
.top-actions { display: flex; gap: 2px; }
.icon-btn {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--cream);
  display: grid;
  place-items: center;
}
.icon-btn:disabled {
  opacity: 0.35;
}
.icon-btn.is-on {
  background: rgba(224, 180, 86, 0.2);
  color: var(--gold);
  box-shadow: inset 0 0 0 1px rgba(224, 180, 86, 0.45);
}
.title-block { text-align: center; min-width: 0; }
.app-title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: clamp(1.05rem, 4.4vw, 1.45rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--cream);
}
.app-sub {
  margin: 1px 0 0;
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cream-dim);
  opacity: 0.85;
}

.target-row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin: 2px 0 8px;
}
.target-btn, .pill {
  border: 0;
  background: rgba(0, 0, 0, 0.22);
  color: var(--cream-dim);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 700;
  font-size: 0.86rem;
  letter-spacing: 0.04em;
  box-shadow: inset 0 0 0 1px rgba(243, 230, 196, 0.12);
}
.target-btn.is-active,
.pill.is-active {
  background: linear-gradient(180deg, #efd48a, #c9993a);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.25) inset, 0 2px 8px rgba(0, 0, 0, 0.25);
}

.board {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 14px 1fr;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 18%),
    rgba(8, 28, 16, 0.35);
  border-radius: 18px;
  box-shadow:
    inset 0 0 0 1px rgba(243, 230, 196, 0.14),
    inset 0 0 40px rgba(0, 0, 0, 0.25),
    0 8px 28px rgba(0, 0, 0, 0.28);
  overflow: hidden;
  position: relative;
}
.gutter {
  display: flex;
  justify-content: center;
  padding: 12px 0 16px;
}
.gutter-line {
  width: 2px;
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(180deg, transparent, var(--line-strong) 8%, var(--line-strong) 92%, transparent);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2);
}
.team {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 8px 8px 10px;
}
.team-name {
  border: 0;
  background: transparent;
  font-family: var(--font-display);
  font-weight: 650;
  font-size: clamp(1rem, 4.6vw, 1.45rem);
  letter-spacing: -0.02em;
  padding: 6px 4px 4px;
  text-align: center;
  color: var(--cream);
  border-bottom: 1px solid var(--line);
  margin-bottom: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.team-name::after {
  content: " ✎";
  font-size: 0.7em;
  opacity: 0.45;
  font-family: var(--font-ui);
}

.sticks-hit {
  flex: 1;
  min-height: 0;
  border: 0;
  background: transparent;
  padding: 2px 0 4px;
  display: flex;
  width: 100%;
}
.sticks {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.sticks.to-15 {
  justify-content: center;
  align-items: center;
}
.sticks.to-30 {
  display: grid;
  grid-template-columns: 1fr 8px 1fr;
  align-items: stretch;
  gap: 0;
}
.half {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.half-label {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--cream-dim);
  text-align: center;
  margin-bottom: 2px;
  font-weight: 800;
  opacity: 0.8;
}
.split {
  width: 1px;
  margin: 16px 0 4px;
  background: var(--line);
  justify-self: center;
}
.squares {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  align-items: center;
  min-height: 0;
  gap: 4px;
}
.square {
  width: min(100%, 118px);
  aspect-ratio: 1;
  max-height: 32%;
}
.square svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}
.fosforo-wood {
  stroke: var(--stick);
  stroke-width: 9;
  stroke-linecap: round;
  fill: none;
  filter: drop-shadow(0 1px 0 rgba(80, 50, 10, 0.55));
}
.fosforo-ghost {
  stroke: rgba(243, 230, 196, 0.14);
  stroke-width: 7;
  stroke-linecap: round;
  fill: none;
}
.fosforo-head {
  fill: var(--head);
  stroke: var(--head-dark);
  stroke-width: 0.8;
}
.fosforo-wood.draw-in {
  stroke-dasharray: 120;
  stroke-dashoffset: 120;
  animation: draw-stick 0.32s ease forwards;
}
.fosforo-head.draw-in {
  opacity: 0;
  animation: pop-head 0.2s ease 0.22s forwards;
}
@keyframes draw-stick {
  to { stroke-dashoffset: 0; }
}
@keyframes pop-head {
  from { opacity: 0; transform: scale(0.4); }
  to { opacity: 1; transform: scale(1); }
}

.score-line {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  padding: 2px 0 6px;
}
.score {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 7vw, 2.35rem);
  line-height: 1;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}
.score-of {
  font-size: 0.85rem;
  color: var(--cream-dim);
  opacity: 0.75;
}

.quick {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.quick button,
.quick-extra button {
  border: 0;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(243, 230, 196, 0.16), rgba(243, 230, 196, 0.07));
  box-shadow: inset 0 0 0 1px rgba(243, 230, 196, 0.2);
  color: var(--cream);
  padding: 7px 4px 5px;
  font-weight: 800;
  font-size: 1.05rem;
  line-height: 1.1;
  min-height: 44px;
}
.quick button span {
  display: block;
  font-weight: 650;
  font-size: 0.58rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--cream-dim);
  margin-top: 2px;
}
.quick button:active,
.quick-extra button:active,
.icon-btn:active,
.target-btn:active {
  transform: scale(0.97);
  background: rgba(0, 0, 0, 0.28);
}
.quick-extra {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 5px;
  margin-top: 5px;
}
.falta-btn {
  font-size: 0.82rem !important;
  font-weight: 800 !important;
  letter-spacing: 0.02em;
  color: var(--gold) !important;
}
.minus-btn {
  min-width: 52px;
  font-size: 1.2rem !important;
  color: var(--danger) !important;
}
.app.hide-falta .falta-btn { display: none; }
.app.hide-falta .quick-extra { grid-template-columns: 1fr; }
.app.hide-falta .minus-btn { width: 100%; }

.hint {
  margin: 8px 8px 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--cream-dim);
  line-height: 1.35;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(4, 14, 8, 0.62);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 16px) 18px calc(var(--safe-bottom) + 16px);
  backdrop-filter: blur(6px);
}
.sheet-overlay {
  align-items: flex-end;
  padding: 0;
  background: rgba(4, 14, 8, 0.5);
}
.sheet {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  background: linear-gradient(180deg, #1d4e32, #143322);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.4);
  padding: 10px 20px calc(var(--safe-bottom) + 20px);
  color: var(--cream);
  max-height: min(86dvh, 720px);
  overflow: auto;
}
.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 4px;
  background: rgba(243, 230, 196, 0.28);
  margin: 6px auto 12px;
}
.sheet h2 {
  font-family: var(--font-display);
  font-weight: 650;
  margin: 0 0 14px;
  font-size: 1.45rem;
  text-align: center;
}
.setting {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-weight: 700;
}
.setting-pills { display: flex; gap: 6px; }
.toggle { cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 0 0 1px rgba(243, 230, 196, 0.18);
  position: relative;
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cream-dim);
  transition: transform 0.2s ease, background 0.2s ease;
}
.toggle input:checked + .switch {
  background: linear-gradient(180deg, #efd48a, #c9993a);
}
.toggle input:checked + .switch::after {
  transform: translateX(20px);
  background: var(--ink);
}
.sheet-link {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--cream);
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.sheet-link.danger { color: var(--danger); }
.sheet-close { width: 100%; margin-top: 14px; }
.btn-primary, .btn-ghost {
  border: 0;
  border-radius: 12px;
  padding: 12px 16px;
  font-weight: 800;
  font-size: 1rem;
}
.btn-primary {
  background: linear-gradient(180deg, #efd48a, #c9993a);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.28) inset, 0 3px 10px rgba(0, 0, 0, 0.25);
}
.btn-ghost {
  background: rgba(0, 0, 0, 0.22);
  color: var(--cream);
  box-shadow: inset 0 0 0 1px rgba(243, 230, 196, 0.18);
}

.win-card {
  position: relative;
  overflow: hidden;
  width: min(100%, 420px);
  background: linear-gradient(180deg, #245c38, #143322);
  border-radius: 22px;
  padding: 28px 22px 22px;
  text-align: center;
  box-shadow: 0 0 0 1px rgba(224, 180, 86, 0.35), 0 20px 50px rgba(0, 0, 0, 0.45);
}
.win-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.72rem;
  font-weight: 800;
  color: var(--gold);
}
.win-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.8rem, 7vw, 2.6rem);
  margin: 8px 0 6px;
  line-height: 1.1;
}
.win-score {
  margin: 0 0 20px;
  font-size: 1.1rem;
  color: var(--cream-dim);
}
.win-actions { display: flex; flex-direction: column; gap: 8px; }
.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 12px;
  border-radius: 1px;
  animation: confetti-fall 1.6s ease-in forwards;
}
@keyframes confetti-fall {
  to { transform: translateY(460px) rotate(280deg); opacity: 0.2; }
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  min-height: 80px;
}
.history-list li {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.history-list .h-date {
  display: block;
  font-size: 0.75rem;
  color: var(--cream-dim);
  text-transform: capitalize;
}
.history-list .h-line {
  font-weight: 800;
  margin-top: 2px;
}
.history-empty {
  text-align: center;
  color: var(--cream-dim);
  padding: 24px 8px;
}
.install-steps {
  margin: 0 0 12px;
  padding-left: 1.2em;
  line-height: 1.5;
}
.install-steps li { margin: 0 0 10px; }
.install-note {
  color: var(--cream-dim);
  font-size: 0.92rem;
  line-height: 1.45;
}
#nameForm input {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 14px 14px;
  font-size: 1.15rem;
  font-weight: 700;
  background: rgba(0, 0, 0, 0.28);
  color: var(--cream);
  box-shadow: inset 0 0 0 1px rgba(243, 230, 196, 0.22);
  outline: none;
}
#nameForm input:focus {
  box-shadow: inset 0 0 0 2px var(--gold);
}
.name-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 18px);
  transform: translateX(-50%);
  z-index: 40;
  background: rgba(10, 22, 14, 0.94);
  color: var(--cream);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 0 0 1px rgba(243, 230, 196, 0.2), 0 8px 24px rgba(0, 0, 0, 0.35);
  max-width: calc(100% - 32px);
  text-align: center;
}

@media (min-width: 520px) {
  .quick { grid-template-columns: repeat(4, 1fr); }
  .square { width: min(100%, 140px); }
}
@media (max-height: 700px) {
  .quick button { min-height: 40px; padding: 5px 3px 4px; font-size: 0.98rem; }
  .app-sub { display: none; }
  .score { font-size: 1.55rem; }
}
@media (orientation: landscape) and (max-height: 500px) {
  .app { padding-top: calc(var(--safe-top) + 2px); }
  .target-row { display: none; }
  .hint { display: none; }
  .square { max-height: 40%; }
}

@media (prefers-reduced-motion: reduce) {
  .fosforo-wood.draw-in,
  .fosforo-head.draw-in,
  .confetti i {
    animation: none;
  }
  .fosforo-wood.draw-in { stroke-dashoffset: 0; }
  .fosforo-head.draw-in { opacity: 1; }
  .icon-btn:active, .quick button:active { transform: none; }
}
