:root {
  --bg: #2E3440;
  --bg-top: #283140;
  --bg-elev: #3B4252;
  --bg-elev-2: #3b4752;
  --bg-elev-3: #394252;
  --header-bg: rgba(46, 52, 64, 0.85);
  --border: #4C566A;
  --text: #D8DEE9;
  --text-weak: #BFC7D5;
  --heading: #ECEFF4;
  --primary: #5E81AC;
  --primary-strong: #81A1C1;
  --success: #4CAF50;
  --warn: #FF9800;
  --danger: #E53935;
  --radius: 10px;
  --shadow: 0 6px 18px rgba(0,0,0,0.25);
}

/* Light theme overrides */
[data-theme="light"] {
  --bg: #f3f7fc;
  --bg-top: #e9eef5;
  --bg-elev: #ffffff;
  --bg-elev-2: #f4f7fb;
  --bg-elev-3: #ffffff;
  --header-bg: rgba(255, 255, 255, 0.85);
  --border: #d6deea;
  --text: #1f2937;
  --text-weak: #4b5563;
  --heading: #0f172a;
  --primary: #a3c0ff;
  --primary-strong: #90adff;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 6px 18px rgba(0,0,0,0.12);
}

/* Sepia (warm) theme */
[data-theme="sepia"] {
  --bg: #2b2320;
  --bg-top: #241d1a;
  --bg-elev: #3a2f2a;
  --bg-elev-2: #453832;
  --bg-elev-3: #3a2f2a;
  --header-bg: rgba(43, 35, 32, 0.85);
  --border: #5c4a3f;
  --text: #f0e6d8;
  --text-weak: #d3c4b0;
  --heading: #faf3e8;
  --primary: #b07d4f;
  --primary-strong: #c99a6b;
  --success: #7cb342;
  --warn: #ffb300;
  --danger: #e57373;
  --shadow: 0 6px 18px rgba(0,0,0,0.3);
}

/* Midnight (deep blue) theme */
[data-theme="midnight"] {
  --bg: #0f1420;
  --bg-top: #0b0f18;
  --bg-elev: #1a2233;
  --bg-elev-2: #202a3d;
  --bg-elev-3: #1a2233;
  --header-bg: rgba(15, 20, 32, 0.85);
  --border: #2e3a52;
  --text: #d6e0f0;
  --text-weak: #a8b6cc;
  --heading: #eef3fb;
  --primary: #4a6fa5;
  --primary-strong: #6b8fc4;
  --success: #4caf50;
  --warn: #ff9800;
  --danger: #e53935;
  --shadow: 0 6px 18px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }

body {
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg));
  color: var(--text);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 20px 40px;
}

/* Header / Toolbar */
.app-header {
  position: sticky;
  top: 0;
  z-index: 2;
  backdrop-filter: blur(8px);
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px 20px;
}
.title { font-size: 1.25rem; font-weight: 700; color: var(--heading); letter-spacing: 0.2px; }
.title-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  vertical-align: middle;
}
.app-logo {
  height: 32px;
  width: 32px;
  object-fit: contain;
  border-radius: 4px;
}
.actions { display: flex; gap: 8px; align-items: center; }

/* Buttons */
button {
  padding: 8px 14px;
  font-size: 0.95rem;
  cursor: pointer;
  color: var(--heading);
  background-color: var(--primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  transition: transform 0.06s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 2px 0 rgba(0,0,0,0.25);
}
button:hover { background-color: var(--primary-strong); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--primary-strong); outline-offset: 2px; }
button:disabled { background-color: var(--bg-elev-2); color: var(--text-weak); border-color: var(--border); cursor: not-allowed; opacity: 0.65; filter: grayscale(100%); box-shadow: none; }

/* Score + Stats */
#score { font-size: 1.2rem; margin: 18px 0 10px; color: var(--heading); text-align: center; }

.panel { background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-3)); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
[data-theme="light"] .panel { background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev)); }

#progress-section { padding: 14px; }

/* Progress */
#progress-container {
  width: 100%;
  height: 34px;
  border: 1px solid #333a44;
  background: linear-gradient(180deg, #2e3542, var(--bg-elev-2));
  border-radius: 999px;
  overflow: hidden;
  position: relative;
  margin: 6px auto 12px auto;
}
[data-theme="light"] #progress-container { border: 1px solid var(--border); background: linear-gradient(180deg, #f0f4fa, var(--bg-elev-2)); }

#progress-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #43a047, #4CAF50 35%, #66bb6a);
  background-size: 200% 100%;
  animation: shift 3s linear infinite;
  clip-path: inset(0 100% 0 0);
  transition: clip-path 1s linear;
  position: relative;
  will-change: clip-path;
}
#progress-bar.premium-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.15) 0 8px, rgba(255,255,255,0.05) 8px 16px);
  opacity: 0.5;
  background-size: 200% 100%;
  animation: premiumStripes 1.5s linear infinite;
  pointer-events: none;
  z-index: 1;
}
#progress-bar.premium-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0, rgba(255,255,255,0.45) 12%, rgba(255,255,255,0) 24%);
  background-size: 220% 100%;
  background-position: -100% 0;
  filter: blur(1px);
  animation: sheenSlide 2.2s linear infinite;
  pointer-events: none;
  z-index: 1;
}
@keyframes shift { from { background-position: 0% 0; } to { background-position: 200% 0; } }
/* Premium effects keyframes */
@keyframes premiumStripes { from { background-position: 0% 0; } to { background-position: 200% 0; } }
@keyframes sheenSlide { from { background-position: -100% 0; } to { background-position: 100% 0; } }

#progress-label { display: none; }

/* Cross-fade overlay used when changing smoothness (transitionDuration) */
.progress-layer {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  width: 0; /* width will be set dynamically in JS */
  border-radius: 999px;
  pointer-events: none;
  opacity: 0; /* default hidden; JS will set to 1 then fade to 0 */
  transition: opacity 0.3s ease; /* duration overridden in JS */
  will-change: opacity, width;
  animation: shift 3s linear infinite;
  z-index: 2; /* stays above the fill but below the label (label has z-index:3) */
}
.progress-layer.premium-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg, rgba(255,255,255,0.15) 0 8px, rgba(255,255,255,0.05) 8px 16px);
  opacity: 0.5;
  background-size: 200% 100%;
  animation: premiumStripes 1.5s linear infinite;
  pointer-events: none;
  z-index: 1;
}
.progress-layer.premium-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0) 0, rgba(255,255,255,0.45) 12%, rgba(255,255,255,0) 24%);
  background-size: 220% 100%;
  background-position: -100% 0;
  filter: blur(1px);
  animation: sheenSlide 2.2s linear infinite;
  pointer-events: none;
  z-index: 1;
}

/* Stats grid */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 8px; }
.stat { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,0.03); }
[data-theme="light"] .stat { background: rgba(0,0,0,0.02); }
.stat .label { color: var(--text-weak); font-size: 0.8rem; }
.stat .value { display: block; font-weight: 700; color: var(--heading); margin-top: 4px; }

/* Shop */
#shop { margin-top: 18px; padding: 14px; }
#shop h2 { margin: 0 0 10px; color: var(--heading); font-size: 1.1rem; }
.item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px dashed rgba(255,255,255,0.08); }
[data-theme="light"] .item { border-bottom-color: rgba(0,0,0,0.08); }
.item:last-child { border-bottom: none; }
.item .info .name { font-weight: 700; color: var(--heading); }
.item .info .desc { color: var(--text-weak); font-size: 0.9rem; margin-top: 2px; }

/* Shop tabs */
.shop-tabs { display: flex; gap: 6px; margin: 0 0 10px; border-bottom: 1px solid var(--border); }
.shop-tab-btn { appearance: none; background: transparent; border: none; border-bottom: 2px solid transparent; color: var(--text-weak); font: inherit; font-weight: 700; padding: 8px 12px; margin-bottom: -1px; cursor: pointer; border-radius: 8px 8px 0 0; }
.shop-tab-btn:hover { color: var(--heading); background: rgba(255,255,255,0.04); }
[data-theme="light"] .shop-tab-btn:hover { background: rgba(0,0,0,0.04); }
.shop-tab-btn[aria-selected="true"] { color: var(--heading); border-bottom-color: var(--accent, #4CAF50); }
.shop-tab-btn:focus-visible { outline: 2px solid var(--accent, #4CAF50); outline-offset: 2px; }
.shop-tab-panel.hidden { display: none; }

/* Appearance styles grid */
#appearance-section { margin-top: 16px; }
#appearance-section h3 { margin: 8px 0 6px; font-size: 1rem; color: var(--heading); }
.appearance-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
@media (min-width: 700px) { .appearance-grid { grid-template-columns: repeat(5, minmax(0,1fr)); } }
.style-card { padding: 8px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,0.03); display: flex; flex-direction: column; gap: 8px; align-items: stretch; justify-content: flex-start; min-height: 92px; }
[data-theme="light"] .style-card { background: rgba(0,0,0,0.02); }
.style-name { font-size: 0.85rem; color: var(--heading); font-weight: 700; }
.style-preview { height: 14px; border-radius: 999px; border: 1px solid var(--border); overflow: hidden; }
.style-meta { font-size: 0.8rem; color: var(--text-weak); }
.style-actions button { width: 100%; }

/* Appearance section visibility control */
#appearance-section.hidden { display: none; }

/* Achievements */
#achievements { margin-top: 18px; padding: 14px; }
#achievements h2 { margin: 0 0 10px; color: var(--heading); font-size: 1.1rem; }
.ach-summary { color: var(--text-weak); margin-bottom: 8px; font-size: 0.92rem; }
.achievements-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
@media (min-width: 700px) { .achievements-grid { grid-template-columns: repeat(3, minmax(0,1fr)); } }
.ach-card { padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,0.03); display: flex; gap: 10px; align-items: center; min-height: 72px; }
[data-theme="light"] .ach-card { background: rgba(0,0,0,0.02); }
.ach-card.completed { border-color: var(--success); background: rgba(76,175,80,0.08); }
.ach-icon { font-size: 1.4rem; }
.ach-content { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.ach-name { font-weight: 700; color: var(--heading); font-size: 0.95rem; }
.ach-desc { color: var(--text-weak); font-size: 0.85rem; }
.ach-reward { color: var(--success); font-weight: 700; font-size: 0.85rem; }

/* Prestige */
#prestige { margin-top: 16px; padding: 14px; }
#prestige h2 { margin: 0 0 10px; color: var(--heading); font-size: 1.1rem; }
#prestige .item { border-bottom: none; }
.prestige-summary { margin-top: 6px; opacity: 0.9; }

/* Footer */
.app-footer { max-width: 1000px; margin: 0 auto; padding: 10px 20px 30px; color: var(--text-weak); display: flex; align-items: center; justify-content: space-between; font-size: 0.9rem; }
.autosave-note { opacity: 0.7; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%) translateY(16px); background: rgba(30, 136, 229, 0.95); color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.25s ease, transform 0.25s ease; z-index: 5; min-width: 220px; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: rgba(229, 57, 53, 0.95); }
#toast.success { background: rgba(67, 160, 71, 0.95); }

/* Bonus layer (clickable temporary boosts) */
#bonus-layer {
  position: fixed;
  inset: 0;
  pointer-events: none; /* enable clicks only on children */
  z-index: 4; /* above UI, below toast (5) */
}
.bonus {
  position: absolute;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.95rem;
  color: #111;
  box-shadow: var(--shadow);
  user-select: none;
  cursor: pointer;
  pointer-events: auto; /* re-enable for children */
  transform: translate(-50%, -50%) scale(0.9);
  transition: transform 0.12s ease, opacity 0.2s ease;
  opacity: 0.95;
}
.bonus:hover {
  transform: translate(-50%, -50%) scale(1.1);
}
.bonus:focus-visible { outline: 2px solid var(--primary-strong); outline-offset: 2px; }
.bonus:active { transform: translate(-50%, -50%) scale(0.98); }
.bonus.fade-out { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
.bonus.speed { background: radial-gradient(circle at 30% 30%, #ffe082, #f6b93b); border: 1px solid #e2a82c; }
.bonus.points { background: radial-gradient(circle at 30% 30%, #a5d6a7, #66bb6a); border: 1px solid #4caf50; }
.bonus.mystery { background: radial-gradient(circle at 30% 30%, #b39ddb, #7e57c2); border: 1px solid #6c49ab; }

/* Animacja kliknięcia - burst effect */
.bonus.burst {
  animation: bonusBurst 0.4s ease-out forwards;
}

@keyframes bonusBurst {
  0% {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.8);
    opacity: 0.6;
  }
  100% {
    transform: translate(-50%, -50%) scale(2.5);
    opacity: 0;
  }
}

/* Efekt cząsteczek przy kliknięciu */
.bonus-particle {
position: absolute;
width: 6px;
height: 6px;
border-radius: 50%;
pointer-events: none;
animation: particleFly 0.6s ease-out forwards;
}
.bonus-particle.speed {
  background: #f6b93b;
  box-shadow: 0 0 4px #f6b93b;
}
.bonus-particle.points {
  background: #66bb6a;
  box-shadow: 0 0 4px #66bb6a;
}
.bonus-particle.positive {
  background: #ffd54f;
  box-shadow: 0 0 6px #ffd54f;
}
.bonus-particle.negative {
  background: #ef5350;
  box-shadow: 0 0 4px #ef5350;
}

@keyframes particleFly {
0% {
transform: translate(-50%, -50%) scale(1);
opacity: 1;
}
100% {
transform: translate(calc(-50% + var(--particle-x, 0px)), calc(-50% + var(--particle-y, 0px))) scale(0);
opacity: 0;
}
}

/* Respect light theme contrast */
[data-theme="light"] .bonus { color: #0a0a0a; }

/* Responsive */
@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  button { padding: 8px 12px; }
  .app-header-inner { flex-direction: row; align-items: center; gap: 10px; padding: 10px 14px; }
  .title { flex: 1 1 auto; font-size: 1.05rem; text-align: left; min-width: 0; }
  .actions { flex: 0 0 auto; flex-wrap: nowrap; justify-content: flex-end; gap: 6px; }
  .actions button { padding: 6px 10px; font-size: 0.85rem; }
  .achievements-grid { grid-template-columns: 1fr; }
  .ach-card { flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; }
  .ach-content { min-width: 0; }
}
@media (max-width: 400px) {
  .title { font-size: 0.95rem; }
}

/* Tabs / Bonus info helpers */
.panel.hidden { display: none !important; }

/* Modal (for Bonus info) */
.hidden { display: none !important; }
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 15; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(1px); }
.modal-dialog {
  position: relative;
  width: min(92vw, 860px);
  max-height: 85vh;
  overflow: auto;
  background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev-3));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  color: var(--text);
}
[data-theme="light"] .modal-dialog { background: linear-gradient(180deg, var(--bg-elev), var(--bg-elev)); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.modal-body { margin-top: 10px; color: var(--text); }
.modal-body p { margin: 8px 0; }
.modal-body ul { margin: 8px 0 8px 18px; }
.modal-body ul ul { margin: 6px 0 6px 18px; }
.modal-title { margin: 0; color: var(--heading); font-size: 1.1rem; }
.modal-close { padding: 6px 10px; background: var(--bg-elev-2); color: var(--heading); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
.modal-close:hover { background: var(--primary-strong); color: #fff; }
body.modal-open { overflow: hidden; }

/* Animacje dla panelu modal (Bonusy) */
.modal .modal-dialog { will-change: transform, opacity; }
.modal .modal-backdrop { will-change: opacity; }

/* Wejście */
.modal:not(.hidden):not(.closing) .modal-backdrop { animation: modalBackdropIn 200ms ease-out both; }
.modal:not(.hidden):not(.closing) .modal-dialog { animation: modalDialogIn 220ms cubic-bezier(0.2,0.8,0.2,1) both; }

/* Wyjście */
.modal.closing .modal-backdrop { animation: modalBackdropOut 180ms ease-in both; }
.modal.closing .modal-dialog { animation: modalDialogOut 180ms cubic-bezier(0.2,0.8,0.2,1) both; }

@keyframes modalBackdropIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalBackdropOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes modalDialogIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes modalDialogOut { from { opacity: 1; transform: translateY(0) scale(1); } to { opacity: 0; transform: translateY(8px) scale(0.98); } }

@media (prefers-reduced-motion: reduce) {
  .modal .modal-backdrop, .modal .modal-dialog { animation: none !important; transition: none !important; }
}

/* Positive/negative bonus activation feedback */
.bonus.burst-positive { animation: bonusBurstPositive 0.5s ease-out forwards; }
.bonus.burst-negative { animation: bonusBurstNegative 0.4s ease-in forwards; }

@keyframes bonusBurstPositive {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; box-shadow: 0 0 0 0 rgba(102,187,106,0.7); }
  50% { transform: translate(-50%, -50%) scale(2); opacity: 0.8; box-shadow: 0 0 0 18px rgba(102,187,106,0.25); }
  100% { transform: translate(-50%, -50%) scale(2.8); opacity: 0; box-shadow: 0 0 0 32px rgba(102,187,106,0); }
}
@keyframes bonusBurstNegative {
  0% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  60% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.7; filter: grayscale(0.6); }
  100% { transform: translate(-50%, -50%) scale(0.2); opacity: 0; filter: grayscale(1); }
}

/* Floating result text at click position */
.bonus-float-text {
  position: absolute;
  transform: translate(-50%, -50%);
  font-weight: 800;
  font-size: 0.95rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 5;
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  animation: floatUpFade 1.1s ease-out forwards;
}
.bonus-float-text.positive { color: #7ee787; }
.bonus-float-text.negative { color: #ff6b6b; }

@keyframes floatUpFade {
  0% { opacity: 0; transform: translate(-50%, -50%) translateY(0) scale(0.8); }
  15% { opacity: 1; transform: translate(-50%, -50%) translateY(-6px) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -50%) translateY(-48px) scale(1); }
}

/* Mystery positive toast */
#toast.mystery-positive { background: linear-gradient(90deg, rgba(67,160,71,0.95), rgba(246,185,59,0.95)); }

/* Progress bar reaction when a toast fires */
#progress-container.toast-positive { box-shadow: 0 0 0 2px rgba(102,187,106,0.55), 0 0 14px rgba(102,187,106,0.5); animation: toastBarPulse 0.5s ease-out; }
#progress-container.toast-positive #progress-bar { filter: saturate(1.5) brightness(1.12); }
#progress-container.toast-positive::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(126,231,135,0) 0, rgba(126,231,135,0.5) 50%, rgba(126,231,135,0) 100%);
  background-size: 220% 100%;
  animation: toastShimmer 0.9s linear infinite;
  pointer-events: none;
  z-index: 2;
}
#progress-container.toast-negative { box-shadow: 0 0 0 2px rgba(239,83,80,0.55), 0 0 14px rgba(239,83,80,0.5); animation: toastBarShake 0.4s ease-in-out; }
#progress-container.toast-negative #progress-bar { filter: hue-rotate(-55deg) saturate(1.4); }

@keyframes toastShimmer {
  0% { background-position: 120% 0; }
  100% { background-position: -120% 0; }
}
@keyframes toastBarPulse {
  0% { transform: scale(1); }
  35% { transform: scale(1.02); }
  100% { transform: scale(1); }
}
@keyframes toastBarShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* Progress bar glow while a positive boost is active */
#progress-container.boost-glow-speed { animation: glowPulseSpeed 1.6s ease-in-out infinite; }
#progress-container.boost-glow-points { animation: glowPulsePoints 1.6s ease-in-out infinite; }

@keyframes glowPulseSpeed {
  0%, 100% { box-shadow: 0 0 4px rgba(246,185,59,0.35); }
  50% { box-shadow: 0 0 16px rgba(246,185,59,0.75); }
}
@keyframes glowPulsePoints {
  0%, 100% { box-shadow: 0 0 4px rgba(102,187,106,0.35); }
  50% { box-shadow: 0 0 16px rgba(102,187,106,0.75); }
}

/* Affected stat highlight */
.stat.boost-active { border-color: var(--success); background: rgba(76,175,80,0.10); }
.stat .value.boost-flash { animation: statFlash 0.9s ease-out; }

@keyframes statFlash {
  0% { color: var(--success); transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* Active boost chips */
.boost-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.boost-chips:empty { display: none; }
.boost-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--heading);
  border: 1px solid var(--success);
  background: rgba(76,175,80,0.12);
}
.boost-chip.negative { border-color: var(--danger); background: rgba(229,57,53,0.12); }
.boost-chip-time { color: var(--text-weak); font-variant-numeric: tabular-nums; }

/* Screen-edge flash on positive activation */
#positive-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 6;
  opacity: 0;
  background: radial-gradient(ellipse at center, rgba(76,175,80,0) 55%, rgba(76,175,80,0.35) 100%);
}
#positive-flash.show { animation: positiveFlash 0.45s ease-out; }

@keyframes positiveFlash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

/* Score counter pulse */
#score-value.score-pulse { display: inline-block; animation: scorePulse 0.5s ease-out; }

@keyframes scorePulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.35); color: var(--success); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .bonus-float-text, #positive-flash.show, .stat .value.boost-flash, #score-value.score-pulse,
  .bonus.burst-positive, .bonus.burst-negative,
  #progress-container.toast-positive, #progress-container.toast-positive::before,
  #progress-container.toast-negative,
  #progress-container.boost-glow-speed, #progress-container.boost-glow-points { animation: none !important; }
  .bonus.burst-positive, .bonus.burst-negative { opacity: 0 !important; }
  #progress-container.boost-glow-speed { box-shadow: 0 0 10px rgba(246,185,59,0.55); }
  #progress-container.boost-glow-points { box-shadow: 0 0 10px rgba(102,187,106,0.55); }
}

/* Dostępność: obszary dotykowe i ograniczenie ruchu */
button, .modal-close { min-height: 44px; }
.actions button { min-width: 44px; }
.bonus::before { content: ''; position: absolute; inset: -10px; border-radius: inherit; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  #progress-bar { transition: none !important; }
}

/* Ustawienie użytkownika: ograniczenie animacji (niezależne od preferencji systemu) */
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}
html.reduce-motion #progress-bar { transition: none !important; }

/* Ustawienia (modal) */
.settings-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 0 0 14px; }
.settings-group legend { padding: 0 6px; color: var(--heading); font-weight: 700; font-size: 0.95rem; }
.theme-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
@media (min-width: 480px) { .theme-grid { grid-template-columns: repeat(4, minmax(0,1fr)); } }
.theme-option { width: 100%; min-height: 44px; }
.theme-option.selected { background-color: var(--primary-strong); color: #fff; border-color: var(--primary-strong); }
.settings-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; min-height: 44px; color: var(--text); }
.settings-toggle input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary-strong); cursor: pointer; }
.settings-hint { color: var(--text-weak); font-size: 0.85rem; margin: 6px 0 0; }

/* Podsumowanie powrotu (postęp offline) */
.modal[hidden] { display: none; }
.offline-summary-list { display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; margin: 0; }
.offline-summary-list dt { color: var(--text-weak); }
.offline-summary-list dd { margin: 0; font-weight: 700; text-align: right; }
@media (max-width: 480px) {
  .offline-summary-list { grid-template-columns: 1fr; gap: 2px; }
  .offline-summary-list dd { text-align: left; margin-bottom: 8px; }
}

/* Cienka tacka nawigacji (sekcje gry) */
body { padding-bottom: 72px; }

main .panel { scroll-margin-top: var(--anchor-offset, 96px); }

.game-nav {
  position: fixed;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  max-width: calc(100vw - 16px);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--header-bg);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}

.game-nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 4px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text-weak);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  box-shadow: none;
}
.game-nav-btn:hover { background: var(--primary); color: var(--heading); }
.game-nav-btn:active { transform: translateY(1px); }
.game-nav-btn:focus-visible { outline: 2px solid var(--primary-strong); outline-offset: 2px; }
.game-nav-btn[aria-current="true"] { background: var(--bg-elev); border-color: var(--primary-strong); color: var(--heading); box-shadow: inset 0 0 0 1px var(--primary-strong); }
.game-nav-icon { font-size: 1.05rem; line-height: 1; }

@media (max-width: 560px) {
  .game-nav { left: 8px; right: 8px; bottom: 10px; transform: none; max-width: none; justify-content: space-between; }
  .game-nav-btn { flex: 1; padding: 4px 8px; }
  .game-nav-label { display: none; }
}

/* Menu nagłówka: jeden przycisk zamiast wielu */
.actions { position: relative; }

#menu-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  min-height: 44px;
  padding: 8px 16px;
}
.menu-toggle-icon { font-size: 1.1rem; line-height: 1; }
#menu-toggle[aria-expanded="true"] { background-color: var(--primary-strong); }

.header-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: max-content;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 28px));
  max-height: min(70vh, 460px);
  overflow-y: auto;
  padding: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  animation: menu-pop 0.14s ease-out;
}
.header-menu[hidden] { display: none; }
@keyframes menu-pop {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}
html.reduce-motion .header-menu { animation: none; }

.header-menu button {
  width: 100%;
  justify-content: flex-start;
  text-align: left;
  min-height: 44px;
  padding: 10px 12px;
  background: transparent;
  border-color: transparent;
  border-radius: 8px;
  box-shadow: none;
}
.header-menu button:hover { background-color: var(--primary); }
.header-menu button[aria-pressed="true"] { box-shadow: inset 0 0 0 1px var(--primary-strong); }
