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

:root,
[data-scheme="dark"] {
  --bg: #101116;
  --bg-panel: #1a1b22;
  --bg-stage: #1c1e28;
  --bg-chip: #22242f;
  --border: #35384a;
  --border-soft: #252732;
  --border-panel: #2e3140;
  --copper: #d4926a;
  --copper-soft: #e8b896;
  --copper-deep: #8f5a3e;
  --text: #f2eee8;
  --muted: #9a958c;
  --ground: #2a2c36;
  --safe: #6bcf8e;
  --overlay: rgba(16, 17, 22, 0.86);
  --shadow: rgba(0, 0, 0, 0.45);
  --btn-secondary: #2a2d3a;
  --btn-secondary-border: #3a3e52;
  --radius: 16px;
  --toggle-off: #35384a;
  --toggle-knob: #f2eee8;
  color-scheme: dark;
}

[data-scheme="light"] {
  --bg: #f6f0e6;
  --bg-panel: #ffffff;
  --bg-stage: #fff8ee;
  --bg-chip: #efe6d8;
  --border: #d4c4b0;
  --border-soft: #e2d4c2;
  --border-panel: #e0d2bf;
  --copper: #c4784a;
  --copper-soft: #d4926a;
  --copper-deep: #8f5a3e;
  --text: #2a241c;
  --muted: #6e6458;
  --ground: #e8dcc8;
  --safe: #2f9e5c;
  --overlay: rgba(246, 240, 230, 0.9);
  --shadow: rgba(80, 50, 20, 0.18);
  --btn-secondary: #efe6d8;
  --btn-secondary-border: #d4c4b0;
  --toggle-off: #cfc2b0;
  --toggle-knob: #ffffff;
  color-scheme: light;
}

html, body {
  height: 100%; width: 100%;
  height: 100svh; height: 100dvh; width: 100dvw;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden; touch-action: manipulation;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
  transition: background 0.25s ease, color 0.25s ease;
  overscroll-behavior: none;
  position: fixed; inset: 0;
}

#app {
  display: flex; flex-direction: column;
  height: 100%; height: 100svh; height: 100dvh;
  height: var(--app-height, 100dvh);
  max-height: 100%; max-height: 100svh; max-height: 100dvh;
  max-height: var(--app-height, 100dvh);
  width: 100%; width: 100dvw; max-width: 100%;
  margin: 0 auto;
  overflow: hidden;
  position: relative;
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
}

.hud {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px 6px; flex-shrink: 0; flex-wrap: wrap;
  z-index: 2;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1rem; color: var(--copper-soft); }
.brand-logo { display: block; filter: drop-shadow(0 0 4px rgba(212, 146, 106, 0.4)); }
.hud-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-size: 0.72rem; font-weight: 600; padding: 4px 8px; border-radius: 999px;
  background: var(--bg-chip); border: 1px solid var(--border); color: var(--muted);
}
.scores { display: flex; align-items: center; gap: 10px; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
.score-block { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.score-label { font-size: 0.65rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
#score { color: var(--copper); }
#highscore { color: var(--safe); }
#candy-count { color: #ff6b8a; display: inline-flex; align-items: baseline; gap: 3px; }
.candy-emoji { font-size: 0.95em; }
#candy-num { color: #ff6b8a; }
.candy-block .score-label { color: #ff8aa3; }
.btn-icon {
  appearance: none; border: 1px solid var(--border); background: var(--bg-chip); color: var(--text);
  border-radius: 10px; width: 44px; height: 44px; font-size: 1.1rem; cursor: pointer; touch-action: manipulation;
}

#stage {
  position: relative; flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 50% 80%, var(--bg-stage) 0%, var(--bg) 70%);
  border-radius: var(--radius); margin: 0 8px; overflow: hidden; border: 1px solid var(--border-soft);
  touch-action: manipulation;
  width: auto;
}
#stage.shake { animation: shake 0.35s ease; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}
#game {
  display: block; width: 100%; height: 100%;
  max-height: min(70dvh, 520px);
  object-fit: contain; touch-action: manipulation; cursor: pointer;
}

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 12px; background: var(--overlay); backdrop-filter: blur(6px); z-index: 20; overflow-y: auto;
  -webkit-overflow-scrolling: touch; pointer-events: auto;
}
.overlay.hidden { display: none !important; pointer-events: none; }
#menu, #pause { z-index: 20; }
#btn-start, #btn-resume { position: relative; z-index: 21; pointer-events: auto; }
.panel {
  width: min(100%, 420px); background: var(--bg-panel); border: 1px solid var(--border-panel);
  border-radius: 20px; padding: 18px 16px 20px; text-align: center;
  box-shadow: 0 16px 40px var(--shadow);
}

.mascot-stack {
  position: relative; width: 96px; height: 96px; margin: 0 auto 8px;
  filter: drop-shadow(0 6px 12px rgba(212, 146, 106, 0.28));
}
.mascot-stack.small { width: 72px; height: 72px; }
.mascot-stack img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.mascot-stack .ms-rotor { animation: spin-slow 4s linear infinite; }
.mascot-stack .ms-face, .mascot-stack .ms-eyes { transform: none; }
@keyframes spin-slow { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

h1, h2 { font-size: 1.4rem; margin-bottom: 4px; color: var(--text); }
.hint { color: var(--muted); font-size: 0.92rem; line-height: 1.35; margin-bottom: 12px; }
.section-label {
  text-align: left; font-size: 0.72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--muted); margin: 0 0 6px 2px;
}
.versions, .themes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.themes { grid-template-columns: 1fr 1fr 1fr; }
.themes.has-halloween { grid-template-columns: 1fr 1fr; }
.ver-btn, .theme-btn {
  appearance: none; border: 2px solid var(--border); background: var(--bg-chip); color: var(--text);
  border-radius: 14px; padding: 12px 8px; font-size: 0.92rem; font-weight: 700;
  cursor: pointer; min-height: 48px; touch-action: manipulation;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}
.ver-btn:active, .theme-btn:active { transform: scale(0.97); }
.ver-btn.active, .theme-btn.active {
  border-color: var(--copper); background: rgba(212, 146, 106, 0.18);
  color: var(--copper-soft); box-shadow: 0 0 0 1px rgba(212, 146, 106, 0.35);
}
.ver-btn[data-ver="v3"]:not(.active) { opacity: 0.75; }

.toggles { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.toggle {
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 10px 12px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--bg-chip); cursor: pointer; min-height: 48px; touch-action: manipulation;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.toggle-ui {
  flex-shrink: 0; width: 44px; height: 26px; border-radius: 999px;
  background: var(--toggle-off); position: relative; transition: background 0.2s;
}
.toggle-ui::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--toggle-knob);
  box-shadow: 0 1px 3px rgba(0,0,0,0.25); transition: transform 0.2s;
}
.toggle input:checked + .toggle-ui { background: var(--copper); }
.toggle input:checked + .toggle-ui::after { transform: translateX(18px); }
.toggle-text { font-size: 0.92rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.toggle-text small { display: block; font-weight: 600; font-size: 0.72rem; color: var(--muted); }

.speed-wrap { margin-bottom: 16px; }
#speed-slider, #speed-slider-pause {
  width: 100%; accent-color: var(--copper); height: 36px; cursor: pointer; touch-action: manipulation;
}
.speed-labels { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); margin-top: 2px; }

.btn-primary, .btn-secondary {
  appearance: none; border: none; border-radius: 14px; font-weight: 800; font-size: 1.05rem;
  cursor: pointer; touch-action: manipulation; min-height: 52px; padding: 12px 22px;
  transition: transform 0.1s, filter 0.15s;
}
.btn-primary:active, .btn-secondary:active { transform: scale(0.97); }
.btn-primary {
  width: 100%; background: linear-gradient(180deg, var(--copper-soft), var(--copper));
  color: #1a120e; box-shadow: 0 6px 0 var(--copper-deep);
}
.btn-primary:active { box-shadow: 0 2px 0 var(--copper-deep); transform: translateY(3px) scale(0.99); }
.btn-secondary { width: 100%; background: var(--btn-secondary); color: var(--text); border: 2px solid var(--btn-secondary-border); }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.fx {
  position: absolute; left: 50%; top: 28%; transform: translateX(-50%);
  pointer-events: none; z-index: 4; font-size: 1.4rem; font-weight: 800;
  color: var(--copper-soft); text-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  opacity: 0; transition: opacity 0.15s, transform 0.35s;
}
.fx.show { opacity: 1; transform: translateX(-50%) translateY(-12px); }
.fx.collect { color: #ff6b8a; }

.controls-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 14px 12px; color: var(--muted); font-size: 0.85rem; flex-shrink: 0;
}
.tip { color: var(--copper-soft); }
.mobile-only { display: none; }
.desktop-only { display: inline; }
@media (hover: none), (pointer: coarse) {
  .mobile-only { display: inline; }
  .desktop-only { display: none; }
}
@media (max-width: 480px) {
  .brand span { font-size: 0.88rem; }
  .hud-meta { display: none; }
  .themes { gap: 6px; }
  .theme-btn, .ver-btn { font-size: 0.85rem; padding: 10px 6px; min-height: 46px; }
  .mascot-stack { width: 80px; height: 80px; }
  h1, h2 { font-size: 1.25rem; }
  .toggle { padding: 8px 10px; }
}
/* Telefon landscape = pełny ekran gry; hint obrócenia WYŁĄCZONY */
@media (orientation: landscape) {
  html, body, #app {
    overflow: hidden !important;
    height: 100% !important;
    height: 100svh !important;
    height: 100dvh !important;
    height: var(--app-height, 100dvh) !important;
    max-height: var(--app-height, 100dvh) !important;
    position: fixed;
    inset: 0;
    width: 100%;
    width: 100dvw;
  }
  #app { max-width: none; }
  #stage {
    margin: 0;
    border-radius: 0;
    border: none;
    flex: 1;
    min-height: 0;
    width: 100%;
  }
  #game {
    max-height: none;
    width: 100%;
    height: 100%;
  }
  .hud {
    padding: 4px max(10px, env(safe-area-inset-right, 0px)) 2px max(10px, env(safe-area-inset-left, 0px));
    flex-shrink: 0;
  }
  .hud-meta { display: none; }
  .brand span { font-size: 0.85rem; }
  .controls-hint {
    padding: 2px max(10px, env(safe-area-inset-right, 0px)) max(4px, env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
    font-size: 0.75rem;
  }
  .mascot-stack { width: 56px; height: 56px; }
  .panel {
    padding: 10px 12px;
    max-height: min(88dvh, calc(var(--app-height, 100dvh) - 16px), 520px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .overlay { z-index: 30; pointer-events: auto; }
  h1, h2 { font-size: 1.1rem; }
  .hint { margin-bottom: 8px; font-size: 0.85rem; }
  .themes, .versions, .toggles { margin-bottom: 8px; }
  .btn-primary, .btn-secondary { min-height: 44px; }
  .toggle { min-height: 40px; padding: 6px 10px; }
  .score-label { font-size: 0.58rem; }
  .scores { font-size: 0.95rem; gap: 8px; }
  .btn-icon { width: 40px; height: 40px; }
  /* t355u: w landscape hint NIGDY nie blokuje Startu */
  .rotate-hint,
  .rotate-hint:not([hidden]) {
    display: none !important;
    visibility: hidden !important;
    pointer-events: none !important;
    opacity: 0 !important;
  }
}

@media (orientation: landscape) and (max-height: 420px) {
  .controls-hint { display: none; }
  .hud { padding-top: 2px; padding-bottom: 0; }
  .brand-logo { width: 22px; height: 22px; }
}

/* Portrait na telefonie: gra playable + delikatny hint obrócenia */
@media (orientation: portrait) and (max-width: 900px) {
  #game {
    max-height: min(62dvh, 520px);
  }
}

.rotate-hint {
  position: fixed; inset: 0; z-index: 8; /* poniżej menu (z-index 20+) — nie zasłania Startu */
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0 16px max(18px, env(safe-area-inset-bottom, 0px));
  pointer-events: none !important;
  background: linear-gradient(to top, rgba(16,17,22,0.45), transparent 40%);
}
.rotate-hint[hidden],
.rotate-hint.is-landscape-hidden {
  display: none !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
.rotate-hint-card {
  pointer-events: none !important;
  background: rgba(26, 27, 34, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 16px;
  padding: 12px 16px;
  text-align: center;
  box-shadow: 0 10px 28px var(--shadow);
  max-width: 280px;
}
.rotate-emoji { font-size: 1.6rem; display: inline-block; margin-bottom: 4px; }
.rotate-hint-card p { margin: 0; font-size: 0.95rem; }
.rotate-sub { color: var(--muted); font-size: 0.8rem !important; margin-top: 2px !important; }

/* t355u: portrait-only hint; landscape = natychmiast ukryty (CSS + JS) */
@media (orientation: landscape) {
  .rotate-hint { display: none !important; pointer-events: none !important; }
}
@media (orientation: portrait) {
  .rotate-hint:not([hidden]) { display: flex; }
}

.vibrate-strength-wrap { margin-bottom: 10px; }
.vib-strengths { grid-template-columns: 1fr 1fr; }
.vibrate-strength-wrap[hidden] { display: none; }
