html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--sky);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
}

#stage {
  position: absolute;
  inset: 0;
}
#stage canvas {
  display: block;
}

#loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 800 2rem var(--font-display);
  color: #fff;
  background: linear-gradient(180deg, var(--sky), var(--sky-light));
  z-index: 50;
}

/* --- etykiety nad piłkami --- */
#labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.ball-label {
  position: absolute;
  transform: translate(-50%, -100%);
  padding: 0.12em 0.6em;
  border-radius: 999px;
  font: 800 0.8rem var(--font-display);
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  transition: opacity 0.2s;
}
.ball-label.current {
  font-size: 0.95rem;
  animation: bob 1s ease-in-out infinite;
}
@keyframes bob {
  50% {
    transform: translate(-50%, calc(-100% - 5px));
  }
}

/* --- HUD --- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
#hud > * {
  position: absolute;
}
#hud button {
  pointer-events: auto;
}
.hud-hole {
  left: max(12px, env(safe-area-inset-left));
  top: 12px;
  background: #fff;
  border-radius: 16px;
  padding: 0.45rem 0.9rem 0.5rem;
  box-shadow: var(--shadow);
  line-height: 1.1;
}
.hud-hole small {
  display: block;
  color: var(--ink-soft);
  font-size: 0.75rem;
}
.hud-hole b {
  font: 800 1.25rem var(--font-display);
}
.hud-hole .par {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--sun);
  font-size: 0.75rem;
  vertical-align: 0.15rem;
}

.hud-score {
  right: max(12px, env(safe-area-inset-right));
  top: 12px;
  background: #fff;
  border-radius: 16px;
  padding: 0.4rem 0.6rem;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  min-width: 150px;
}
.hud-score table {
  border-collapse: collapse;
  width: 100%;
}
.hud-score td {
  padding: 0.12rem 0.25rem;
  white-space: nowrap;
}
.hud-score td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}
.hud-score td.warn {
  color: var(--coral-deep);
}
.hud-score td.warn small {
  font-size: 0.7em;
  opacity: 0.7;
}
.hud-score tr.current {
  background: #fff7cc;
}
.hud-score tr.done td {
  color: var(--ink-soft);
}
.dot {
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  border-radius: 50%;
  vertical-align: -0.05em;
  margin-right: 0.3em;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

.hud-turn {
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  padding: 0.45rem 1.2rem;
  border-radius: 999px;
  color: #fff;
  font: 800 1.2rem var(--font-display);
  box-shadow: 0 5px 0 rgba(0, 0, 0, 0.2);
  white-space: nowrap;
  transition: background 0.3s;
}
.hud-turn .cap {
  font-size: 0.8rem;
  opacity: 0.9;
  margin-left: 0.4rem;
  padding: 0.1rem 0.5rem;
  background: rgba(255, 255, 255, 0.25);
  border-radius: 999px;
}
.hud-turn:empty {
  display: none;
}

.hud-info {
  left: 50%;
  top: 64px;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-weight: 800;
  box-shadow: var(--shadow);
}

.hud-item {
  left: max(12px, env(safe-area-inset-left));
  bottom: 14px;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: #fff;
  border-radius: 18px;
  padding: 0.5rem 0.9rem 0.5rem 0.6rem;
  box-shadow: var(--shadow);
  pointer-events: auto;
  cursor: pointer;
  max-width: min(360px, 45vw);
}
.hud-item .icon {
  font-size: 2rem;
  width: 2.6rem;
  height: 2.6rem;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(135deg, #ffe680, #ff9ec4);
}
.hud-item b {
  font: 800 1.05rem var(--font-display);
  display: block;
}
.hud-item small {
  color: var(--ink-soft);
  font-size: 0.78rem;
  line-height: 1.25;
  display: block;
}
.hud-item.ready {
  animation: glow 1.2s ease-in-out infinite;
}
@keyframes glow {
  50% {
    box-shadow: 0 6px 0 rgba(15, 43, 70, 0.18), 0 0 0 5px rgba(255, 210, 63, 0.75);
  }
}

.hud-bottom {
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: min(520px, 90vw);
}
.hud-hint {
  background: rgba(15, 43, 70, 0.72);
  color: #fff;
  border-radius: 999px;
  padding: 0.35rem 1rem;
  font-size: 0.9rem;
  text-align: center;
}
.hud-hint:empty {
  display: none;
}
.hud-power {
  position: relative;
  width: 100%;
  height: 28px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.hud-power-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, var(--grass), var(--sun) 55%, var(--coral));
  transition: width 0.12s;
}
.hud-power-fill.weak {
  background: #94a3b8;
}
.hud-power-live {
  position: absolute;
  left: 0;
  bottom: 0;
  height: 5px;
  width: 0;
  background: var(--sea);
  opacity: 0.7;
}
.hud-power-thr {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  margin-left: -1px;
  background: var(--ink);
  opacity: 0.55;
}
.hud-power span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font: 800 0.95rem var(--font-display);
}

.hud-buttons {
  right: max(12px, env(safe-area-inset-right));
  bottom: 14px;
  display: flex;
  gap: 0.5rem;
}

/* --- komunikaty --- */
#toasts {
  position: absolute;
  left: 0;
  right: 0;
  top: 28%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  pointer-events: none;
}
.toast {
  font: 800 clamp(1.6rem, 5vw, 3rem) var(--font-display);
  color: #fff;
  text-shadow: 0 4px 0 rgba(15, 43, 70, 0.35), 0 0 18px rgba(15, 43, 70, 0.25);
  animation: pop 2.2s ease forwards;
  text-align: center;
  padding: 0 1rem;
}
.toast.small {
  font-size: clamp(1.1rem, 3.2vw, 1.7rem);
}
.toast.gold {
  color: var(--sun);
}
.toast.red {
  color: #ffd0d0;
}
@keyframes pop {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  12% {
    transform: scale(1.12);
    opacity: 1;
  }
  20% {
    transform: scale(1);
  }
  80% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(-20px);
  }
}

/* --- ekrany / menu --- */
#screens {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  pointer-events: auto;
  background: rgba(14, 116, 175, 0.18);
  overflow-y: auto;
}
.screen.clear {
  background: none;
}
.panel {
  background: #fff;
  border-radius: 28px;
  box-shadow: 0 10px 0 rgba(15, 43, 70, 0.2);
  padding: 1.4rem 1.6rem 1.6rem;
  width: min(560px, 100%);
  max-height: calc(100% - 1rem);
  overflow-y: auto;
  margin: auto;
}
.panel.wide {
  width: min(860px, 100%);
}
.panel h2 {
  font-size: 2rem;
  color: var(--sea-deep);
  margin-bottom: 0.8rem;
}
.panel p {
  color: var(--ink-soft);
  line-height: 1.45;
}

.logo {
  text-align: center;
  margin-bottom: 1.2rem;
}
.logo h1 {
  font-size: clamp(2.6rem, 9vw, 4.4rem);
  color: var(--coral);
  text-shadow: 0 5px 0 var(--coral-deep);
  letter-spacing: 0.01em;
  transform: rotate(-3deg);
}
.logo h1 span {
  color: var(--sky-deep);
  text-shadow: 0 5px 0 var(--sea-deep);
}
.logo p {
  margin: 0.7rem 0 0;
  font-weight: 800;
  color: var(--ink-soft);
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}
.mi {
  appearance: none;
  border: 3px solid transparent;
  width: 100%;
  border-radius: 18px;
  background: #f1f7fb;
  color: var(--ink);
  font: 800 1.15rem var(--font-display);
  padding: 0.65rem 1rem;
  text-align: left;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, border-color 0.15s;
}
.mi:hover {
  background: #e3f2fb;
}
.mi.focus {
  border-color: var(--sky-deep);
  background: #e0f4ff;
  transform: scale(1.02);
}
.mi.primary {
  background: var(--coral);
  color: #fff;
  box-shadow: 0 5px 0 var(--coral-deep);
  justify-content: center;
  font-size: 1.35rem;
}
.mi.primary.focus {
  border-color: var(--sun);
}
.mi .val {
  font-size: 1rem;
  color: var(--sea);
  white-space: nowrap;
}
.mi.primary .val {
  color: #fff;
}
.mi.disabled {
  opacity: 0.5;
}
.mi input {
  font: inherit;
  border: 0;
  background: transparent;
  color: inherit;
  width: 9em;
  outline: none;
  border-bottom: 2px dashed #b9d7ea;
}
.mi .swatch {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  flex: none;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
}
.mi .left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.screen.top {
  align-items: flex-start;
}
.screen.top .panel {
  margin: max(1rem, 4vh) auto auto;
}
.count-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.count-chips .chip {
  display: inline-grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  box-shadow: inset 0 0 0 2px #cfe3f0;
  font: 800 1rem var(--font-display);
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
}
.count-chips .chip:hover {
  transform: scale(1.12);
  background: #fff7cc;
}
.count-chips .chip.on {
  background: var(--sky-deep);
  color: #fff;
  box-shadow: 0 3px 0 var(--sea-deep);
}

.nav-hint {
  margin-top: 1rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.caps-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}
.cap-badge {
  display: inline-grid;
  place-items: center;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  color: #fff;
  font: 800 1rem var(--font-display);
}
.state-ok {
  color: var(--grass-deep);
}
.state-bad {
  color: var(--coral-deep);
}

/* tabela wyników */
.scores {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  margin: 0.4rem 0 1rem;
}
.scores th,
.scores td {
  padding: 0.35rem 0.4rem;
  text-align: center;
  border-bottom: 2px solid #eef4f8;
}
.scores th:first-child,
.scores td:first-child {
  text-align: left;
}
.scores td.total {
  font: 800 1.15rem var(--font-display);
}
.scores tr.lead td {
  background: #fff7cc;
}
.scores .under {
  color: var(--grass-deep);
  font-weight: 800;
}
.scores .over {
  color: var(--coral-deep);
}
.scores .cur {
  background: #e0f4ff;
}

.podium {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.6rem;
  margin: 1rem 0 1.4rem;
}
.podium > div {
  width: 30%;
  max-width: 150px;
  text-align: center;
  font-weight: 800;
}
.podium .block {
  border-radius: 14px 14px 0 0;
  color: #fff;
  font: 800 2rem var(--font-display);
  display: grid;
  place-items: center;
}
.podium .p1 .block {
  height: 120px;
  background: var(--sun);
  color: var(--ink);
}
.podium .p2 .block {
  height: 86px;
  background: #cbd5e1;
  color: var(--ink);
}
.podium .p3 .block {
  height: 64px;
  background: #f0a35c;
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 0.6rem 1rem;
  margin: 0.6rem 0 1rem;
}
.help-grid .it {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.9rem;
}
.help-grid .it .ic {
  font-size: 1.6rem;
  line-height: 1;
}
.help-grid .it b {
  display: block;
}
.tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.05rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.3rem;
  vertical-align: 0.1rem;
}
.tag.atk {
  background: #ffe0e0;
  color: var(--coral-deep);
}
.tag.help {
  background: #dcfce7;
  color: var(--grass-deep);
}

.hole-card {
  text-align: center;
  pointer-events: none;
}
.hole-card .num {
  font: 800 1.1rem var(--font-display);
  color: #fff;
  background: var(--coral);
  display: inline-block;
  padding: 0.2rem 1rem;
  border-radius: 999px;
  box-shadow: 0 4px 0 var(--coral-deep);
}
.hole-card h2 {
  font-size: clamp(2.6rem, 9vw, 4.6rem);
  color: #fff;
  text-shadow: 0 5px 0 rgba(15, 43, 70, 0.35);
  margin: 0.5rem 0 0.2rem;
}
.hole-card p {
  font: 800 1.2rem var(--font-body);
  color: #fff;
  text-shadow: 0 2px 0 rgba(15, 43, 70, 0.35);
  margin: 0;
}
.hole-card .par {
  margin-top: 0.6rem;
  display: inline-block;
  background: var(--sun);
  color: var(--ink);
  font: 800 1rem var(--font-display);
  padding: 0.15rem 0.9rem;
  border-radius: 999px;
}

.target-panel {
  margin: auto auto 64px;
  width: auto;
  max-width: min(760px, 100%);
  padding: 0.8rem 1rem 0.9rem;
}
.target-panel h2 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}
.menu.row {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
}
.menu.row .mi {
  width: auto;
  font-size: 1rem;
  padding: 0.5rem 0.9rem;
}
.target-panel .nav-hint {
  margin-top: 0.5rem;
}
.target-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 0.6rem;
}

@media (max-width: 640px) {
  .hud-score {
    font-size: 0.75rem;
    min-width: 0;
  }
  .hud-turn {
    top: auto;
    bottom: 96px;
    font-size: 1rem;
  }
  .hud-hole b {
    font-size: 1rem;
  }
  .hud-item {
    bottom: 64px;
  }
  .hud-item small {
    display: none;
  }
  .hud-bottom {
    bottom: 10px;
  }
  .hud-hint {
    font-size: 0.78rem;
  }
  .hud-buttons {
    top: 78px;
    bottom: auto;
    left: max(12px, env(safe-area-inset-left));
    right: auto;
    flex-direction: column;
    align-items: flex-start;
  }
  .panel {
    padding: 1.1rem 1rem 1.2rem;
  }
}
