:root {
  --felt-deep: #06241c;
  --felt-mid: #0a3d2e;
  --felt-light: #125c45;
  --gold: #e6b422;
  --gold-soft: #f0d78c;
  --ivory: #f7f1e3;
  --ink: #10241c;
  --muted: rgba(247, 241, 227, 0.62);
  --danger: #ff6b5b;
  --ok: #3dd68c;
  --sheet: #0f2f25;
  --line: rgba(247, 241, 227, 0.12);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font: "Manrope", system-ui, sans-serif;
  --display: "Bebas Neue", "Arial Narrow", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: var(--font);
  color: var(--ivory);
  background: var(--felt-deep);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.felt {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 120% 80% at 50% -10%, rgba(230, 180, 34, 0.18), transparent 55%),
    radial-gradient(ellipse 90% 60% at 80% 100%, rgba(18, 92, 69, 0.55), transparent 50%),
    linear-gradient(165deg, var(--felt-mid), var(--felt-deep) 55%, #041a14);
}

.felt::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.app {
  width: min(100%, 480px);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b));
}

.screen {
  animation: rise 0.45s ease both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Brand / setup */
.brand {
  text-align: center;
  padding: 28px 8px 22px;
}

.brand__eyebrow {
  font-size: 0.75rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 8px;
}

.brand__title {
  font-family: var(--display);
  font-size: clamp(4.2rem, 18vw, 5.6rem);
  line-height: 0.9;
  letter-spacing: 0.04em;
  color: var(--ivory);
}

.brand__title span {
  color: var(--gold);
}

.brand__sub {
  margin-top: 14px;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--muted);
  max-width: 280px;
  margin-inline: auto;
}

.install-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(8, 36, 28, 0.78);
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  box-shadow: var(--shadow);
}

.install-card.hidden {
  display: none !important;
}

.install-card__icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: color-mix(in srgb, var(--gold) 18%, transparent);
  color: var(--gold);
  flex-shrink: 0;
}

.install-card__text {
  min-width: 0;
  flex: 1;
  display: grid;
  gap: 2px;
}

.install-card__text strong {
  font-size: 0.95rem;
}

.install-card__text span {
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.3;
}

.install-card .btn {
  width: auto;
  margin-top: 0;
  min-width: 72px;
  min-height: 42px;
  padding: 0 14px;
}

.install-steps {
  margin: 8px 0 16px;
  padding-left: 18px;
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.install-steps li strong {
  color: var(--ivory);
}

.modal__actions--single {
  grid-template-columns: 1fr;
}

.modal__actions--single .btn {
  margin-bottom: 8px;
}

.panel {
  background: rgba(8, 36, 28, 0.72);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  padding: 20px 16px 18px;
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.panel__title {
  font-size: 1.05rem;
  font-weight: 700;
}

.panel__title--gap {
  margin-top: 6px;
}

.panel__hint {
  margin: 4px 0 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 8px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--line);
}

.mode-toggle__btn {
  min-height: 46px;
  border-radius: 12px;
  font-weight: 700;
  color: var(--muted);
  transition: background 0.2s, color 0.2s, transform 0.15s;
}

.mode-toggle__btn.is-active {
  background: linear-gradient(180deg, #f0c84a, #d4a017);
  color: #1a1405;
  box-shadow: 0 8px 18px rgba(212, 160, 23, 0.28);
}

.mode-toggle__btn:active {
  transform: scale(0.98);
}

.team-setup {
  margin-bottom: 8px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.team-setup__label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--team, var(--gold));
}

.team-setup .player-row {
  margin-bottom: 8px;
}

.team-setup .player-row:last-child {
  margin-bottom: 0;
}

.player-inputs {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.player-row {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 8px;
  align-items: center;
}

.player-seat {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  background: color-mix(in srgb, var(--seat, var(--gold)) 22%, transparent);
  color: var(--seat, var(--gold));
  border: 1px solid color-mix(in srgb, var(--seat, var(--gold)) 45%, transparent);
}

.player-row input {
  width: 100%;
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  padding: 0 14px;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

.player-row input:focus {
  border-color: color-mix(in srgb, var(--gold) 60%, transparent);
  background: rgba(255, 255, 255, 0.07);
}

.player-row input::placeholder {
  color: rgba(247, 241, 227, 0.35);
}

.btn-remove {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  color: var(--muted);
  border: 1px solid transparent;
}

.btn-remove:active {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 0.15s ease, opacity 0.15s ease, background 0.2s;
  width: 100%;
  margin-top: 10px;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: linear-gradient(180deg, #1f8a66, #147553);
  color: #fff;
  box-shadow: 0 10px 24px rgba(20, 117, 83, 0.35);
}

.btn--gold {
  background: linear-gradient(180deg, #f0c84a, #d4a017);
  color: #1a1405;
  font-weight: 800;
  width: auto;
  min-width: 110px;
  margin-top: 0;
  flex-shrink: 0;
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  color: var(--ivory);
}

.btn--lg {
  min-height: 56px;
  font-size: 1.05rem;
}

.btn--block {
  width: 100%;
}

.link-resume {
  display: block;
  width: 100%;
  margin-top: 18px;
  text-align: center;
  color: var(--gold-soft);
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* Game */
.game-top {
  display: grid;
  grid-template-columns: 64px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.game-top__label {
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

.game-top__value {
  font-family: var(--display);
  font-size: 2rem;
  line-height: 1;
  color: var(--gold);
}

.game-top__brand {
  font-family: var(--display);
  font-size: 1.9rem;
  letter-spacing: 0.06em;
  text-align: center;
}

.game-top__brand span {
  color: var(--gold);
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 1.15rem;
  justify-self: end;
}

.turn-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(230, 180, 34, 0.18), rgba(230, 180, 34, 0.05)),
    rgba(8, 36, 28, 0.8);
  border: 1px solid color-mix(in srgb, var(--gold) 35%, transparent);
  box-shadow: 0 0 0 1px rgba(230, 180, 34, 0.08), var(--shadow);
  margin-bottom: 16px;
  animation: pulse-glow 2.8s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%,
  100% {
    box-shadow: 0 0 0 1px rgba(230, 180, 34, 0.08), 0 12px 30px rgba(0, 0, 0, 0.35);
  }
  50% {
    box-shadow: 0 0 0 1px rgba(230, 180, 34, 0.22), 0 12px 36px rgba(230, 180, 34, 0.12);
  }
}

.turn-card__label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-soft);
  margin-bottom: 4px;
}

.turn-card__name {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.scoreboard {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.teams {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.teams:empty {
  display: none;
}

.team-card {
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(8, 36, 28, 0.8);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}

.team-card.is-leader {
  border-color: color-mix(in srgb, var(--ok) 55%, transparent);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--ok) 10%, transparent), transparent 50%),
    rgba(8, 36, 28, 0.8);
}

.team-card__top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.team-card__badge {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 800;
  color: var(--team);
}

.team-card__names {
  margin-top: 4px;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.team-card__score {
  text-align: right;
}

.team-card__total {
  font-family: var(--display);
  font-size: 2.2rem;
  line-height: 1;
}

.team-card__unit {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.team-card__members {
  display: grid;
  gap: 6px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.team-card__member {
  display: flex;
  justify-content: space-between;
  font-size: 0.88rem;
  color: var(--muted);
  width: 100%;
}

.team-card__member--btn {
  padding: 8px 6px;
  border-radius: 10px;
  text-align: left;
  border: 1px solid transparent;
}

.team-card__member--btn:active {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}

.team-card__member strong {
  color: var(--ivory);
  font-variant-numeric: tabular-nums;
}

.player-card--btn {
  width: 100%;
  text-align: left;
  color: inherit;
}

.player-card--btn:active {
  transform: scale(0.99);
}

.player-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px 14px 14px 12px;
  border-radius: var(--radius);
  background: rgba(8, 36, 28, 0.75);
  border: 1px solid var(--line);
  position: relative;
  overflow: hidden;
  transition: border-color 0.25s, transform 0.2s;
}

.player-card.is-dealer {
  border-color: color-mix(in srgb, var(--gold) 55%, transparent);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--gold) 12%, transparent), transparent 42%),
    rgba(8, 36, 28, 0.75);
}

.player-card.is-leader:not(.is-dealer)::before {
  content: "Lider";
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ok);
  font-weight: 700;
}

.player-card__rank {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 800;
  background: color-mix(in srgb, var(--seat) 20%, transparent);
  color: var(--seat);
  border: 1px solid color-mix(in srgb, var(--seat) 40%, transparent);
}

.player-card__meta {
  min-width: 0;
}

.player-card__name {
  font-weight: 800;
  font-size: 1.05rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-card__last {
  margin-top: 2px;
  font-size: 0.8rem;
  color: var(--muted);
}

.player-card__score {
  text-align: right;
  padding-right: 2px;
}

.player-card__total {
  font-family: var(--display);
  font-size: 2.1rem;
  line-height: 1;
  letter-spacing: 0.02em;
}

.player-card__unit {
  display: block;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 2px;
}

.actions {
  position: sticky;
  bottom: calc(8px + var(--safe-b));
  display: grid;
  gap: 8px;
  padding-top: 4px;
}

.actions .btn {
  margin-top: 0;
}

.actions__row {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 8px;
}

.btn--danger {
  background: linear-gradient(180deg, #ff7d6d, #e24b3b);
  color: #fff;
  box-shadow: 0 10px 24px rgba(226, 75, 59, 0.32);
  font-weight: 800;
}

.penalty-section-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin: 14px 0 8px;
}

.penalty-players {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.penalty-player {
  min-height: 52px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-weight: 700;
  padding: 8px 10px;
  text-align: center;
}

.penalty-player.is-selected {
  border-color: color-mix(in srgb, var(--seat, var(--gold)) 70%, transparent);
  background: color-mix(in srgb, var(--seat, var(--gold)) 18%, transparent);
  color: var(--ivory);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--seat, var(--gold)) 35%, transparent);
}

.penalty-player__team {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--seat, var(--gold));
  margin-bottom: 2px;
}

.penalty-presets {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.chip {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  font-weight: 800;
  font-size: 0.9rem;
}

.chip.is-selected {
  background: linear-gradient(180deg, #ff7d6d, #e24b3b);
  border-color: transparent;
  color: #fff;
}

.penalty-custom {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}

.penalty-custom label {
  font-weight: 600;
  color: var(--muted);
}

.penalty-custom input {
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
  font-size: 1.15rem;
  font-weight: 700;
  outline: none;
  width: 100%;
  padding: 0 10px;
}

.penalty-custom input:focus {
  border-color: var(--danger);
}

.tap-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: -6px 0 10px;
  text-align: center;
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  padding-bottom: max(12px, var(--safe-b));
  animation: fade 0.2s ease;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal__sheet {
  width: min(100%, 480px);
  background: linear-gradient(180deg, #143d31, var(--sheet));
  border: 1px solid var(--line);
  border-radius: 24px 24px 20px 20px;
  padding: 10px 16px 16px;
  box-shadow: var(--shadow);
  animation: sheet-up 0.28s cubic-bezier(0.22, 1, 0.36, 1);
  max-height: min(88dvh, 720px);
  overflow: auto;
}

.modal__sheet--tall {
  min-height: 50dvh;
}

@keyframes sheet-up {
  from {
    transform: translateY(24px);
    opacity: 0.6;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

.modal__handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.2);
  margin: 4px auto 14px;
}

.modal__title {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.modal__hint {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.round-form {
  display: grid;
  gap: 12px;
}

.round-row {
  display: grid;
  grid-template-columns: 1fr 110px;
  gap: 10px;
  align-items: center;
}

.round-row--name {
  grid-template-columns: 88px 1fr;
}

.round-row label {
  font-weight: 600;
}

.round-row input {
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  outline: none;
  width: 100%;
  padding: 0 10px;
}

.round-row--name input {
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
}

.round-row input:focus {
  border-color: var(--gold);
}

.modal__actions {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 10px;
  margin-top: 16px;
}

.modal__actions .btn {
  margin-top: 0;
}

.menu-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
}

.menu-item {
  width: 100%;
  text-align: left;
  min-height: 52px;
  padding: 0 16px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  font-weight: 650;
}

.menu-item--danger {
  color: var(--danger);
}

.history {
  display: grid;
  gap: 10px;
  margin: 12px 0 16px;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 8px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.15);
}

.history-item__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.85rem;
  color: var(--muted);
}

.history-item__head strong {
  color: var(--gold-soft);
  font-size: 0.95rem;
}

.history-item__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.history-item__edit,
.history-item__delete {
  width: 100%;
  min-height: 40px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 0.88rem;
}

.history-item__edit {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--ivory);
}

.history-item__edit:active {
  background: rgba(255, 255, 255, 0.1);
}

.history-item__delete {
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  color: var(--danger);
}

.history-item__delete:active {
  background: color-mix(in srgb, var(--danger) 22%, transparent);
}

.history-scores {
  display: grid;
  gap: 6px;
}

.history-scores div {
  display: flex;
  justify-content: space-between;
  font-size: 0.92rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 60;
  background: #102820;
  border: 1px solid color-mix(in srgb, var(--gold) 40%, transparent);
  color: var(--ivory);
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 650;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  white-space: nowrap;
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translate(-50%, 8px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%);
  }
}

@media (min-width: 480px) {
  .app {
    padding-top: calc(28px + var(--safe-t));
  }
}

@media (prefers-reduced-motion: reduce) {
  .screen,
  .modal,
  .modal__sheet,
  .turn-card,
  .toast {
    animation: none !important;
  }
}
