:root {
  --bg: rgba(11, 34, 48, 0.94);
  --card: #123247;
  --line: #1F4A62;
  --text: #F4F1EA;
  --text2: #A9C1CC;
  --accent: #FF8A1E;
  --accent-ink: #1B1208;
  --accent2: #5ED3D0;
  --warn: #FF6B5E;
  --font: ui-rounded, "SF Pro Rounded", -apple-system, system-ui, "Segoe UI", sans-serif;
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}

html, body {
  position: fixed;
  inset: 0;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #000;
  color: var(--text);
  font-family: var(--font);
}

* {
  box-sizing: border-box;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-drag: none;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---------- licznik (prawy górny róg) ---------- */
.counter {
  position: fixed;
  top: calc(var(--st) + 14px);
  right: calc(var(--sr) + 16px);
  height: 40px;
  padding: 0 16px 0 12px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.55;
  font-weight: 700;
  font-size: 20px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}
.counter svg { width: 22px; height: 22px; fill: currentColor; }
.counter.pop { animation: pop 0.32s ease-out; }
@keyframes pop {
  0% { transform: scale(1); opacity: 0.55; }
  35% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(1); opacity: 0.55; }
}
body.menu-open .counter { opacity: 0; }

/* ---------- kłódka (lewy dolny róg) ---------- */
.lock {
  position: fixed;
  left: calc(var(--sl) + 16px);
  bottom: calc(var(--sb) + 16px);
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  z-index: 5;
}
.lock-face {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.18);
  opacity: 0.45;
  transition: opacity 0.2s;
}
.lock .ico {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  grid-area: 1 / 1;
}
.lock .ico rect { fill: #fff; stroke: none; }
.lock .opened { display: none; }
.lock.open .closed, .lock.ready .closed { display: none; }
.lock.open .opened, .lock.ready .opened { display: block; }
.lock.open .lock-face, .lock.holding .lock-face { opacity: 1; }
.lock .ring {
  position: absolute;
  width: 76px;
  height: 76px;
  left: -6px;
  top: -6px;
  transform: rotate(-90deg);
  pointer-events: none;
  opacity: 0;
}
.lock.holding .ring { opacity: 1; }
.lock .ring circle {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
}
body.menu-open .lock { display: none; }

.hint {
  position: fixed;
  left: calc(var(--sl) + 92px);
  bottom: calc(var(--sb) + 28px);
  padding: 10px 16px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 16px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none;
}
.hint.show { opacity: 1; }

.panel {
  position: fixed;
  left: calc(var(--sl) + 92px);
  bottom: calc(var(--sb) + 20px);
  z-index: 5;
}
.panel.fade .menu-btn { opacity: 0.5; transition: opacity 5s linear; }
.menu-btn {
  min-width: 96px;
  height: 56px;
  padding: 0 24px;
  border-radius: 28px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 20px;
  font-weight: 700;
}

body.locked .counter { pointer-events: none; }

/* ---------- menu ---------- */
.menu {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 10;
}
.menu-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: calc(var(--st) + 20px) calc(var(--sr) + 20px) calc(var(--sb) + 20px) calc(var(--sl) + 20px);
  display: flex;
  justify-content: center;
}
.menu-scroll * { touch-action: pan-y; }
.menu-card {
  width: 100%;
  max-width: 880px;
  margin: auto 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.menu-head h1 {
  margin: 0;
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.menu-head .sub, .sub { margin: 4px 0 0; color: var(--text2); font-size: 17px; font-weight: 600; }

.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.level {
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 24px;
  padding: 14px;
  display: grid;
  grid-template-columns: 72px 1fr;
  grid-template-rows: auto auto;
  column-gap: 14px;
  align-items: center;
  text-align: left;
}
.level.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.level .thumb { grid-row: 1 / 3; width: 72px; height: 72px; border-radius: 18px; }
.thumb-pond {
  background:
    radial-gradient(ellipse 18px 8px at 38% 40%, #FF8A1E 98%, transparent),
    radial-gradient(ellipse 12px 6px at 62% 66%, #19C8F0 98%, transparent),
    radial-gradient(circle at 50% 50%, #0D3D52, #082B3D);
}
.thumb-board {
  background:
    radial-gradient(ellipse 16px 9px at 50% 50%, #F5F2EA 98%, transparent),
    repeating-linear-gradient(0deg, #A06B3A 0 22px, #80532B 22px 24px);
}
.level-name { font-size: 22px; font-weight: 700; }
.level-desc { color: var(--text2); font-size: 15px; font-weight: 600; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
}
.row .label { font-size: 17px; font-weight: 600; }
.skins-row { grid-column: 1 / -1; flex-wrap: wrap; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  min-width: 56px;
  height: 48px;
  padding: 0 16px;
  border-radius: 24px;
  background: var(--card);
  border: 2px solid var(--line);
  font-size: 17px;
  font-weight: 700;
}
.pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.pill.round { width: 56px; padding: 0; font-size: 26px; }
.pressed { transform: scale(0.96); filter: brightness(1.15); }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper .value { min-width: 36px; text-align: center; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }

.switch {
  width: 64px;
  height: 36px;
  border-radius: 18px;
  background: var(--line);
  position: relative;
  flex: none;
}
.switch .knob {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--text);
  transition: transform 0.15s;
}
.switch.on { background: var(--accent2); }
.switch.on .knob { transform: translateX(28px); }

.swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 78px;
  padding: 8px 2px;
  border-radius: 18px;
  border: 2px solid transparent;
}
.swatch.on { border-color: var(--accent); background: rgba(255, 138, 30, 0.12); }
.swatch .dot { width: 44px; height: 44px; border-radius: 50%; margin: 4px; }
.swatch .dot.mix {
  background: conic-gradient(#7A7F89 0 20%, #F5F2EA 0 40%, #9C663C 0 60%, #1E1E23 0 80%, #E6FF2E 0);
  box-shadow: 0 0 0 4px #A9C1CC;
}
.swatch .cap { font-size: 15px; font-weight: 700; }
.swatch .warn { display: none; font-size: 11px; color: var(--warn); font-weight: 700; }
.swatch.weak { opacity: 0.45; }
.swatch.weak .warn { display: block; }

.menu[data-level="pond"] .only-board { display: none; }
.menu[data-level="board"] .only-pond { display: none; }

.start {
  height: 64px;
  border-radius: 32px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 24px;
  font-weight: 800;
  margin-top: 4px;
}
.note { margin: 0; color: var(--text2); font-size: 15px; font-weight: 600; text-align: center; }
.foot { margin: 0; color: var(--text2); font-size: 15px; text-align: center; opacity: 0.8; }
.link {
  color: var(--accent2);
  font-size: 17px;
  font-weight: 700;
  min-height: 48px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.help {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  padding: 20px;
}
.help-card {
  width: 100%;
  max-width: 640px;
  max-height: 100%;
  overflow-y: auto;
  touch-action: pan-y;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 24px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.help-card * { touch-action: pan-y; }
.help-card h2 { margin: 0; font-size: 22px; }
.help-card p { margin: 0; font-size: 17px; line-height: 1.45; }
.help-card ol { margin: 0; padding-left: 24px; display: flex; flex-direction: column; gap: 10px; font-size: 17px; line-height: 1.45; }

button:focus-visible { outline: 3px solid var(--accent2); outline-offset: 3px; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .levels { grid-template-columns: 1fr; }
  .menu-head h1 { font-size: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .counter.pop { animation: none; }
}
