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

html {
  color-scheme: light dark;
}

:root {
  --z-toast: 1000;
  --z-egg: 1300;
  --z-status-bar: 1400;
  --z-emoji: 2000;
  --z-topbar: 2100;
  --z-menu: 2110;
  --z-dmg: 2850;
  --z-riot-flash: 2990;
  --z-modal: 3000;
  --z-fullscreen: 4000;
  --z-boot: 4200;
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
    sans-serif;
  text-align: center;
  margin: 0;
  padding: max(14px, calc(env(safe-area-inset-top, 0px) + 10px)) 20px max(18px, env(safe-area-inset-bottom, 0px) + 14px);
  background-color: var(--tg-theme-bg-color, #f0f8ff);
  color: var(--tg-theme-text-color, #111827);
}

main#app-main:has(#app-status-bar:not([hidden])) {
  padding-top: 52px;
}

h1 {
  font-size: 2rem;
  margin-bottom: 10px;
}

.subtitle {
  font-size: 1.2rem;
  margin-bottom: 20px;
  max-width: 100%;
}

.subtitle--chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: stretch;
  gap: 8px 12px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  max-width: min(560px, calc(100vw - 24px));
  text-align: left;
}

.stat-chip {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px 8px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--tg-theme-hint-color, #cbd5e1);
  background: var(--tg-theme-secondary-bg-color, #f8fafc);
  font-size: 0.95rem;
  line-height: 1.35;
  min-width: min(160px, 42vw);
}

.stat-chip__label {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--tg-theme-hint-color, #64748b);
  flex: 0 0 100%;
}

.stat-chip__value {
  font-weight: 600;
  flex: 1 1 auto;
}

body.night .stat-chip {
  background: rgba(30, 30, 60, 0.55);
  border-color: rgba(255, 255, 255, 0.14);
}

body.night .stat-chip__label {
  color: #94a3b8;
}

.tap-night-hint {
  font-weight: 600;
  color: var(--tg-theme-link-color, #2563eb);
  white-space: nowrap;
}

.noscript {
  box-sizing: border-box;
  max-width: 28rem;
  margin: 12px auto;
  padding: 14px 16px;
  font:
    600 1rem/1.45 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
  text-align: center;
  border-radius: 10px;
  border: 1px solid #fecaca;
  color: #b91c1c;
  background: #fef2f2;
}

@media (prefers-color-scheme: dark) {
  .noscript {
    color: #fecaca;
    background: rgba(69, 10, 10, 0.92);
    border-color: rgba(248, 113, 113, 0.45);
  }
}

#game-area {
  margin-bottom: 30px;
  min-height: min(280px, clamp(160px, 32vh, 360px));
}

button.reset {
  padding: 8px 16px;
  font-size: 0.95rem;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid var(--tg-theme-hint-color, #9ca3af);
  background: var(--tg-theme-secondary-bg-color, #fff);
  color: var(--tg-theme-text-color, inherit);
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    filter 0.2s ease,
    opacity 0.2s ease;
}

button.reset:hover:not(:disabled) {
  filter: brightness(0.97);
}

button.reset:disabled {
  opacity: 0.72;
  filter: grayscale(0.18);
  cursor: not-allowed;
}

.sukh-tap {
  border: none;
  padding: 0;
  margin: 0;
  background: none;
  border-radius: 12px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  position: relative;
}

.sukh-tap:focus-visible {
  outline: 3px solid var(--tg-theme-link-color, #2563eb);
  outline-offset: 4px;
}

#sukh-img {
  display: block;
  width: min(300px, 80vw);
  height: auto;
  max-width: 100%;
  aspect-ratio: 320 / 356;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  pointer-events: none;
}

#sukh-img.tap-animation {
  animation: tap-tilt 0.15s ease;
}

@keyframes tap-tilt {
  0% {
    transform: rotate(0deg);
  }
  35% {
    transform: rotate(-5deg);
  }
  70% {
    transform: rotate(5deg);
  }
  100% {
    transform: rotate(0deg);
  }
}

button.upgrade {
  padding: 10px 20px;
  font-size: 1rem;
  cursor: pointer;
  background-color: var(--tg-theme-secondary-bg-color, #fff);
  color: var(--tg-theme-text-color, inherit);
  border: 2px solid var(--tg-theme-link-color, #1e90ff);
  border-radius: 8px;
  transition:
    background-color 0.2s ease,
    color 0.2s ease,
    border-color 0.2s ease,
    transform 0.18s ease,
    filter 0.18s ease,
    opacity 0.2s ease,
    box-shadow 0.2s ease;
}

button.upgrade:active:not(:disabled) {
  transform: scale(0.98);
}

button.upgrade:focus-visible,
button.reset:focus-visible {
  outline: 3px solid var(--tg-theme-link-color, #2563eb);
  outline-offset: 2px;
}

button.upgrade:hover:not(:disabled) {
  background-color: var(--tg-theme-link-color, #1e90ff);
  color: var(--tg-theme-button-text-color, #fff);
}

button.upgrade.final {
  background-color: var(--final-bg, #ffcccb);
  border-color: var(--final-border, #b91c1c);
  color: var(--final-text, #450a0a);
}

button.upgrade.final:hover:not(:disabled) {
  background-color: var(--final-bg-hover, #ff9e9a);
  border-color: var(--final-border-hover, #7f1d1d);
}

button.upgrade.final:focus-visible {
  outline: 3px solid var(--tg-theme-link-color, #2563eb);
  outline-offset: 2px;
}

@media (prefers-color-scheme: dark) {
  button.upgrade.final {
    --final-bg: #7f1d1d;
    --final-border: #fca5a5;
    --final-text: #fef2f2;
  }

  button.upgrade.final:hover:not(:disabled) {
    --final-bg-hover: #991b1b;
    --final-border-hover: #fecaca;
  }

  button.upgrade.final.btn--countdown:disabled {
    color: var(--final-text, #fef2f2);
    border-color: var(--final-border, #fca5a5);
    background-color: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #334155) 72%, var(--final-bg, #7f1d1d));
  }
}

button.upgrade:disabled,
button.upgrade.final:disabled {
  opacity: 0.72;
  filter: grayscale(0.22);
  cursor: not-allowed;
  background-color: var(--tg-theme-secondary-bg-color, #e5e7eb);
  color: var(--tg-theme-hint-color, #6b7280);
  border-color: var(--tg-theme-hint-color, #d1d5db);
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.06);
}

button.upgrade.final.btn--countdown:disabled {
  opacity: 1;
  filter: none;
  cursor: progress;
  border-style: dashed;
  border-width: 2px;
  border-color: var(--tg-theme-hint-color, #94a3b8);
  background-color: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #e2e8f0) 88%, var(--final-bg, #ffcccb));
  color: var(--tg-theme-text-color, #1e293b);
  font-variant-numeric: tabular-nums;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  max-width: min(92vw, 360px);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  opacity: 0;
  /* CS3: always-contrast popover; avoid tg bg/text pair that matches page outside Telegram */
  background: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #1e293b) 92%, #020617);
  color: #f8fafc;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 4px 18px rgba(0, 0, 0, 0.42);
  z-index: var(--z-toast);
}

.toast.toast--error {
  border: 2px solid #f87171;
  font-weight: 600;
  box-shadow:
    0 0 0 1px rgba(248, 113, 113, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.12) inset,
    0 4px 16px rgba(0, 0, 0, 0.35);
  color: #fef2f2;
  background: #7f1d1d;
}

@media (max-width: 480px) {
  #sukh-img {
    width: min(260px, 72vw);
  }

  .top-bar h1 {
    font-size: clamp(1.05rem, 4.2vw, 1.42rem);
  }

  .subtitle {
    font-size: 1rem;
  }

  .subtitle--chips .stat-chip {
    font-size: 0.88rem;
  }
}

@media (max-height: 700px) and (orientation: portrait) {
  #sukh-img {
    width: min(260px, 72vw);
  }

  .top-bar h1 {
    font-size: clamp(1.05rem, 4.2vw, 1.42rem);
  }

  .subtitle {
    font-size: 1rem;
  }

  .subtitle--chips .stat-chip {
    font-size: 0.88rem;
  }
}

/* --- v3 UI --- */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  position: relative;
  z-index: var(--z-topbar);
}

.top-bar h1 {
  margin: 0 44px;
  margin-bottom: 0;
  font-size: clamp(1.15rem, 4.6vw, 1.75rem);
  line-height: 1.2;
}

.tapalka-compact-h1 .top-bar h1 {
  font-size: clamp(1rem, 3.8vw, 1.35rem);
}

.api-status-wrap {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: min(52vw, 280px);
}

.api-status {
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.tg-link-btn {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--tg-theme-button-color, #2481cc) 55%, transparent);
  background: color-mix(in srgb, var(--tg-theme-button-color, #2481cc) 14%, var(--tg-theme-bg-color, #fff));
  color: var(--tg-theme-button-color, #2481cc);
  cursor: pointer;
  white-space: nowrap;
}

.tg-link-btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.api-status.api-offline,
.api-status.api-browser-local {
  color: #c2410c;
}

.api-status.api-online {
  color: #15803d;
}

.api-status:not(.api-offline):not(.api-browser-local):not(.api-online) {
  color: #15803d;
}

@media (max-width: 520px) {
  /* CS7–CS9: unified top-bar layout — no absolute chip/menu vs wrapped title overlap */
  .top-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto;
    align-items: center;
    column-gap: 10px;
    row-gap: 4px;
    padding-top: 0.35rem;
  }

  .api-status-wrap {
    grid-column: 1 / -1;
    grid-row: 1;
    position: static;
    transform: none;
    width: 100%;
    max-width: none;
    justify-content: center;
    text-align: center;
    margin: 0 0 2px;
  }

  .player-chip-wrap {
    grid-column: 1;
    grid-row: 2;
    position: static;
    transform: none;
    justify-self: start;
    align-self: center;
  }

  .menu-btn {
    grid-column: 2;
    grid-row: 2;
    position: static;
    align-self: center;
    justify-self: end;
  }

  .top-bar h1 {
    grid-column: 1 / -1;
    grid-row: 3;
    margin: 6px 8px 0;
  }
}

.menu-btn {
  position: absolute;
  right: 0;
  top: 0;
  font-size: 1.4rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
}

.menu-btn:focus-visible {
  border-radius: 4px;
}

.menu-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  margin: 0;
  width: min(360px, calc(100vw - 16px));
  max-width: 420px;
  z-index: var(--z-menu);
  padding: 10px;
  border-radius: 10px;
  background: var(--tg-theme-secondary-bg-color, #e5e7eb);
  text-align: left;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

.menu-item--danger {
  border: 1px solid rgba(185, 28, 28, 0.45);
  color: #b91c1c;
  background: rgba(254, 226, 226, 0.55);
}

body.night .menu-item--danger {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.38);
  border-color: rgba(248, 113, 113, 0.45);
}

.menu-item:focus-visible {
  border-radius: 6px;
}

.field-length {
  display: block;
  margin-top: 4px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--tg-theme-hint-color, #64748b);
  text-align: right;
}

body.night .field-length {
  color: #94a3b8;
}

.menu-hint {
  margin: 0;
  padding: 8px 4px;
  font-size: 0.9rem;
  color: var(--tg-theme-hint-color, #6b7280);
}

.avatar-upload-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}

.lb-toolbar {
  display: flex;
  justify-content: center;
  margin: 0 auto 12px;
  max-width: 520px;
}

.lb-loading {
  margin: 16px 0;
  font-size: 1rem;
  color: var(--tg-theme-hint-color, #64748b);
}

.lb-error-panel {
  margin: 16px 0;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--tg-theme-hint-color, #e2e8f0);
  background: var(--tg-theme-secondary-bg-color, #f8fafc);
}

.lb-error-text {
  margin: 0 0 12px;
  line-height: 1.45;
  font-size: 0.95rem;
}

.lb-error-panel .upgrade {
  width: 100%;
}

.avatar-upload-busy {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
  font-size: 0.85rem;
  color: var(--tg-theme-hint-color, #64748b);
}

.avatar-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--tg-theme-hint-color, #cbd5e1);
  border-top-color: var(--tg-theme-link-color, #2563eb);
  border-radius: 50%;
  animation: avatar-spin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes avatar-spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .avatar-spinner {
    animation: none;
    border-top-color: var(--tg-theme-link-color, #2563eb);
    opacity: 0.85;
  }

  .boot-skeleton__line {
    animation: none;
    opacity: 0.72;
  }
}

.boot-loading {
  position: fixed;
  inset: 0;
  z-index: var(--z-boot);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  margin: 0;
  background: color-mix(in srgb, var(--tg-theme-bg-color, #f8fafc) 93%, var(--tg-theme-text-color, #0f172a) 7%);
}

.boot-skeleton {
  width: min(260px, 72vw);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.boot-skeleton__line {
  height: 11px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, 0.22),
    rgba(148, 163, 184, 0.45),
    rgba(148, 163, 184, 0.22)
  );
  background-size: 200% 100%;
  animation: boot-shimmer 1.15s ease-in-out infinite;
}

.boot-skeleton__line--long {
  width: 100%;
}

.boot-skeleton__line--mid {
  width: 72%;
}

.boot-skeleton__line--short {
  width: 44%;
}

@keyframes boot-shimmer {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

.boot-loading-text {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--tg-theme-text-color, #1e293b);
  margin: 0;
}

.boot-loading .avatar-spinner {
  width: 28px;
  height: 28px;
  border-width: 3px;
}

.global-task-create {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px dashed var(--tg-theme-hint-color, #cbd5e1);
}

.global-task-create h4 {
  margin-top: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

.panel {
  max-width: 440px;
  margin: 16px auto;
  padding: 12px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #f8fafc) 92%, transparent);
  border: 1px solid color-mix(in srgb, var(--tg-theme-hint-color, #cbd5e1) 50%, transparent);
  backdrop-filter: blur(10px);
}

.panel > h3 {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 10px;
}

/* CX-C: разные акценты секций */
.panel--kind-stats {
  box-shadow: inset 4px 0 0 rgba(71, 85, 105, 0.85);
}

.panel--kind-achievements {
  box-shadow: inset 4px 0 0 rgba(202, 138, 4, 0.9);
}

.panel--kind-custom {
  box-shadow: inset 4px 0 0 rgba(124, 58, 237, 0.88);
}

.panel--kind-buff-shop {
  box-shadow: inset 4px 0 0 rgba(37, 99, 235, 0.9);
}

.panel--kind-work {
  box-shadow: inset 4px 0 0 rgba(13, 148, 136, 0.9);
}

.panel--kind-global {
  box-shadow: inset 4px 0 0 rgba(234, 88, 12, 0.88);
}

body.night .panel--kind-stats {
  box-shadow: inset 4px 0 0 rgba(148, 163, 184, 0.65);
}

body.night .panel--kind-achievements {
  box-shadow: inset 4px 0 0 rgba(250, 204, 21, 0.55);
}

body.night .panel--kind-custom {
  box-shadow: inset 4px 0 0 rgba(196, 181, 253, 0.55);
}

body.night .panel--kind-buff-shop {
  box-shadow: inset 4px 0 0 rgba(147, 197, 253, 0.55);
}

body.night .panel--kind-work {
  box-shadow: inset 4px 0 0 rgba(45, 212, 191, 0.5);
}

body.night .panel--kind-global {
  box-shadow: inset 4px 0 0 rgba(251, 146, 60, 0.55);
}

.stats-box {
  display: grid;
  gap: 6px;
  text-align: left;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stat-val {
  margin-left: auto;
  font-weight: 700;
}

.upgrades-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

.achievements-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.ach {
  opacity: 0.35;
  font-size: 1.4rem;
  filter: grayscale(1);
  border: none;
  background: transparent;
  padding: 2px 4px;
  margin: 0;
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
}

.ach:focus-visible {
  border-radius: 6px;
  opacity: 1;
}

.ach--ok {
  opacity: 1;
  filter: none;
}

.auto-badge {
  margin-left: 4px;
  font-size: 0.95rem;
  color: var(--tg-theme-hint-color, #6b7280);
}

.idle-bubble {
  position: relative;
  margin: 0 auto 8px;
  max-width: 200px;
  padding: 6px 10px;
  border-radius: 12px;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #111);
  font-size: 0.9rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.idle-bubble::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--tg-theme-bg-color, #fff);
}

body.night {
  background-color: #0a0a1e;
  background-image: linear-gradient(#0a0a1e, #1a1a3e);
  background-attachment: fixed;
  color: #ddd;
}

/* CX-P: soften stacked dark when Telegram UI is already dark */
body.night.tg-color-scheme-dark {
  background-color: #12121f;
  background-image: linear-gradient(#141422, #222236);
}

body.night.tg-color-scheme-dark .panel,
body.night.tg-color-scheme-dark .menu-panel {
  background: rgba(32, 32, 48, 0.94);
}

.app-status-bar {
  position: fixed;
  top: max(6px, env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-status-bar);
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
  gap: 5px;
  max-width: min(540px, 96vw);
  max-height: 48px;
  padding: 4px 10px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  pointer-events: none;
  -webkit-overflow-scrolling: touch;
}

.app-status-chip {
  flex: 0 0 auto;
  max-width: min(320px, 78vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-status-bar[hidden] {
  display: none !important;
}

.app-status-bar .buff-active-bar {
  margin: 0;
  text-align: center;
  animation: buff-bar-glow 2.6s ease-in-out infinite;
}

@keyframes buff-bar-glow {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.35);
  }
  50% {
    box-shadow: 0 0 0 7px rgba(96, 165, 250, 0);
  }
}

.stat-chip .tap-night-hint {
  margin-left: 4px;
  white-space: nowrap;
}

.night-bonus-banner {
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(30, 30, 60, 0.92);
  color: #f3f4f6;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.academic-leave-banner {
  padding: 4px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(120, 53, 15, 0.92);
  color: #fffbeb;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.wake-countdown-banner {
  padding: 4px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: 999px;
  background: rgba(30, 64, 120, 0.92);
  color: #eff6ff;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.sukh-night-cap {
  display: none;
  position: absolute;
  top: 5%;
  left: 50%;
  width: clamp(1.25rem, 11%, 2.125rem);
  height: clamp(0.65rem, 6%, 1.125rem);
  margin-left: calc(clamp(1.25rem, 11%, 2.125rem) / -2);
  background: linear-gradient(180deg, #5c4033 0%, #2c1810 100%);
  border-radius: 50% 50% 0 0 / 100% 100% 0 0;
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12);
}

body.night:not(.has-custom-avatar) .sukh-night-cap {
  display: block;
}

#app-main.riot-flash {
  position: relative;
}

#app-main.riot-flash::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: var(--z-riot-flash);
  pointer-events: none;
  background: rgba(255, 255, 255, 0.82);
  animation: riot-flash-fade 0.52s ease-out forwards;
}

@keyframes riot-flash-fade {
  0% {
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.riot-alert {
  border: 2px solid #dc2626;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.08);
  font-weight: 600;
}

.riot-hint {
  font-size: 0.95rem;
  color: var(--tg-theme-hint-color, #94a3b8);
}

.riot-outcome {
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--tg-theme-text-color, #334155);
  margin: 0 0 8px;
}

body.night .panel,
body.night .menu-panel {
  background: rgba(18, 18, 42, 0.96);
  color: #e5e5e5;
  border: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(8px);
}

body.night .idle-bubble {
  background: rgba(40, 40, 80, 0.95);
  color: #f3f4f6;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

body.night .idle-bubble::after {
  border-top-color: rgba(40, 40, 80, 0.95);
}

#game-area.shake-game {
  animation: screen-shake 0.4s linear 8;
}

@keyframes screen-shake {
  0% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(2px, -1px);
  }
  50% {
    transform: translate(-2px, 1px);
  }
  75% {
    transform: translate(1px, 2px);
  }
  100% {
    transform: translate(0, 0);
  }
}

.emoji-fly {
  position: fixed;
  pointer-events: none;
  font-size: clamp(1.35rem, 3.6vw, 2rem);
  z-index: var(--z-emoji);
  animation: emoji-fly-anim 1.5s ease-out forwards;
}

@keyframes emoji-fly-anim {
  0% {
    transform: translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(var(--dx), var(--dy)) scale(0.4);
    opacity: 0;
  }
}

#sukh-img.wink {
  animation: wink-sukh 0.6s ease;
}

@keyframes wink-sukh {
  0%,
  100% {
    transform: scaleY(1);
  }
  40% {
    transform: scaleY(0.12);
  }
  55% {
    transform: scaleY(1);
  }
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: var(--z-modal);
  animation: modal-backdrop-in 0.22s ease-out both;
}

.modal {
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #111);
  padding: 16px;
  border-radius: 12px;
  max-width: min(92vw, 360px);
  width: min(360px, 100%);
  max-height: min(90vh, 720px);
  margin: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: modal-pane-in 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes modal-backdrop-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-pane-in {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* CS21: captcha shells reuse .modal; extra rules live under .captcha-modal … */

.console-input {
  width: 100%;
  margin: 8px 0;
  padding: 8px;
  font-size: 1rem;
}

.captcha-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 12px;
}

.fullscreen-meme {
  position: fixed;
  inset: 0;
  z-index: var(--z-fullscreen);
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.fullscreen-meme img {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.fullscreen-meme-caption {
  position: absolute;
  bottom: 10%;
  left: 0;
  right: 0;
  text-align: center;
  color: #fff;
  font-size: clamp(1rem, 4vw, 1.5rem);
  font-weight: 800;
  text-shadow: 0 0 12px #000, 0 0 4px #000;
  padding: 0 12px;
}

.toast--rise {
  animation: toast-rise 0.35s ease;
}

@keyframes toast-rise {
  from {
    transform: translate(-50%, 20px);
    opacity: 0;
  }
  to {
    transform: translate(-50%, 0);
    opacity: 1;
  }
}

.btn-secondary {
  margin-top: 8px;
  padding: 8px 14px;
  font-size: 0.95rem;
  border-radius: 8px;
  border: 1px solid var(--tg-theme-hint-color, #cbd5e1);
  background: var(--tg-theme-secondary-bg-color, #f1f5f9);
  color: inherit;
  cursor: pointer;
}

/* CS37: shared 2px focus ring for menu chrome and compact buttons */
.menu-btn:focus-visible,
.menu-item:focus-visible,
.ach:focus-visible,
.btn-secondary:focus-visible {
  outline: 2px solid var(--tg-theme-link-color, #2563eb);
  outline-offset: 2px;
}

.riot-modal .riot-hint {
  margin-top: 8px;
}

.riot-modal .riot-outcome {
  margin-top: 8px;
}

.reset-confirm-modal .reset-warn {
  line-height: 1.45;
  margin: 0 0 12px;
}

.reset-confirm-modal .reset-warn--strong {
  font-weight: 600;
}

.reset-confirm-modal .reset-keyword-hint {
  font-size: 0.85rem;
  color: var(--tg-theme-hint-color, #64748b);
  margin: -4px 0 12px;
  line-height: 1.4;
}

.reset-confirm-modal #reset-keyword {
  width: min(100%, 280px);
  margin-top: 6px;
  padding: 8px 10px;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--tg-theme-hint-color, #cbd5e1);
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-text-color, #111);
}

.reset-confirm-modal .reset-actions {
  margin-top: 14px;
}

.main-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 12px 0 16px;
}

.main-tab {
  padding: 8px 16px;
  border-radius: 999px;
  border: 2px solid var(--tg-theme-link-color, #1e90ff);
  background: var(--tg-theme-secondary-bg-color, #fff);
  color: var(--tg-theme-text-color, inherit);
  cursor: pointer;
  font-size: 0.95rem;
  transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}

.main-tab:hover:not(.main-tab--active) {
  background: color-mix(in srgb, var(--tg-theme-link-color, #1e90ff) 12%, var(--tg-theme-secondary-bg-color, #fff));
}

.main-tab--active {
  background: var(--tg-theme-link-color, #1e90ff);
  color: #fff;
}

.tab-panel {
  text-align: center;
  -webkit-overflow-scrolling: touch;
}

.tab-heading {
  margin: 8px 0 12px;
}

.egg-counter {
  position: fixed;
  bottom: max(12px, env(safe-area-inset-bottom, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: var(--z-egg);
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--tg-theme-hint-color, #9ca3af);
  background: var(--tg-theme-bg-color, #fff);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  min-width: 3.5rem;
  min-height: 2.75rem;
  box-sizing: border-box;
}

body.night .egg-counter {
  background: rgba(30, 30, 60, 0.92);
  color: #e5e5e5;
  border-color: rgba(255, 255, 255, 0.15);
}

/* CX-H: lift egg FAB when Telegram MainButton is visible (~48px + inset) */
body.tg-main-button-visible .egg-counter {
  bottom: calc(max(12px, env(safe-area-inset-bottom, 0px)) + 52px);
}

.egg-modal .egg-list {
  text-align: left;
  max-height: 55vh;
  overflow-y: auto;
  margin: 12px 0;
  -webkit-overflow-scrolling: touch;
}

.egg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 10px;
  margin: 5px 0;
  border-radius: 12px;
  border: 1px solid transparent;
}

.egg-row:not(.egg-row--ok) {
  background: color-mix(in srgb, var(--tg-theme-secondary-bg-color, #f1f5f9) 88%, transparent);
  border-color: rgba(148, 163, 184, 0.4);
}

.egg-row--ok {
  background: color-mix(in srgb, #bbf7d0 42%, var(--tg-theme-secondary-bg-color, #f8fafc));
  border-color: rgba(21, 128, 61, 0.38);
}

body.night .egg-row:not(.egg-row--ok) {
  background: rgba(30, 30, 55, 0.55);
  border-color: rgba(148, 163, 184, 0.22);
}

body.night .egg-row--ok {
  background: rgba(20, 83, 45, 0.35);
  border-color: rgba(74, 222, 128, 0.35);
}

.egg-row--ok .egg-desc {
  font-style: italic;
}

.egg-ico {
  flex-shrink: 0;
  font-size: 1.25rem;
}

.btn-close-egg {
  padding: 8px 20px;
  border-radius: 8px;
  border: 1px solid var(--tg-theme-link-color, #2563eb);
  background: var(--tg-theme-secondary-bg-color, #fff);
  cursor: pointer;
}

.leaderboard-root {
  max-width: 520px;
  margin: 0 auto;
  text-align: left;
  max-height: min(70vh, 720px);
  overflow-y: auto;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.lb-block-title {
  margin: 16px 0 6px;
  font-size: 1.05rem;
}

.lb-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px;
}

.lb-list li {
  padding: 4px 0;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.1);
}

body.night .lb-list li {
  border-bottom-color: rgba(255, 255, 255, 0.12);
}

.lb-me {
  margin-top: 12px;
  font-size: 0.95rem;
  color: var(--tg-theme-hint-color, #6b7280);
}

.pixel-hint {
  margin: 0 0 10px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--tg-theme-hint-color, #64748b);
}

.pixel-palette-lead {
  margin-bottom: 6px;
  font-weight: 600;
  color: var(--tg-theme-text-color, #334155);
}

body.night .pixel-palette-lead {
  color: #e2e8f0;
}

.pixel-palette {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin: 12px 0;
}

.pixel-swatch {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  box-sizing: border-box;
}

.pixel-swatch--active {
  border-color: var(--tg-theme-link-color, #2563eb);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.35);
}

.pixel-cd {
  font-size: 0.95rem;
  margin: 8px 0;
}

.pixel-grid {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.pixel-canvas {
  display: block;
  border-radius: 8px;
  border: 2px solid var(--tg-theme-hint-color, #cbd5e1);
  cursor: crosshair;
  touch-action: manipulation;
}

.pixel-canvas.pixel-canvas--locked {
  cursor: not-allowed;
  filter: brightness(0.52) saturate(0.88);
}

body.night .pixel-canvas {
  border-color: color-mix(in srgb, var(--tg-theme-hint-color, #64748b) 70%, #1e293b);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.07);
}

.pixel-canvas-fallback {
  max-width: 320px;
  margin: 0 auto;
  padding: 16px;
  text-align: center;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--tg-theme-hint-color, #64748b);
  border: 2px dashed var(--tg-theme-hint-color, #cbd5e1);
  border-radius: 8px;
}

.player-chip-wrap {
  position: absolute;
  right: 48px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 44px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  pointer-events: none;
}

.player-chip-wrap .player-chip:not([hidden]) {
  pointer-events: auto;
}

.player-chip {
  position: static;
  max-width: min(36vw, 200px);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--tg-theme-hint-color, #cbd5e1);
  background: var(--tg-theme-secondary-bg-color, #f1f5f9);
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-chip-photo {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.player-chip-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-modal .profile-stats {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  text-align: left;
}

.profile-modal .profile-stats li {
  padding: 6px 0;
  border-bottom: 1px dashed rgba(0, 0, 0, 0.08);
}

.captcha-modal .captcha-foot {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--tg-theme-hint-color, #6b7280);
}

.captcha-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-width: 280px;
  margin: 12px auto;
}

.captcha-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 64px;
  padding: 4px;
  font-size: clamp(1.2rem, 5.2vw, 1.62rem);
  line-height: 1;
  border-radius: 8px;
  border: 2px solid var(--tg-theme-hint-color, #cbd5e1);
  background: var(--tg-theme-bg-color, #fff);
  cursor: pointer;
}

.captcha-cell--on {
  outline: 3px solid var(--tg-theme-link-color, #2563eb);
  background: rgba(37, 99, 235, 0.08);
}

.zach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin: 14px 0;
}

.zach-cell {
  width: 64px;
  height: 64px;
  font-size: 1.4rem;
  font-weight: 700;
  border-radius: 8px;
  border: 2px solid var(--tg-theme-hint-color, #cbd5e1);
  cursor: pointer;
  background: var(--tg-theme-secondary-bg-color, #e5e7eb);
}

.zach-cell--ok {
  border-color: #15803d;
  background: rgba(21, 128, 61, 0.12);
  animation: zach-ok-pop 0.38s ease;
}

@keyframes zach-ok-pop {
  0% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.07);
  }
  100% {
    transform: scale(1);
  }
}

.captcha-modal.captcha-modal--celebrate {
  animation: captcha-success-ring 0.48s ease-out both;
}

@keyframes captcha-success-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
  }
  100% {
    box-shadow: 0 0 0 16px rgba(34, 197, 94, 0);
  }
}

.sukh-tap--sticker-mode {
  animation: sukh-vibrate 0.12s linear infinite;
}

@keyframes sukh-vibrate {
  0%,
  100% {
    transform: translate(0, 0);
  }
  25% {
    transform: translate(-2px, 1px);
  }
  75% {
    transform: translate(2px, -1px);
  }
}

#panel-game.konami-invert-temp {
  filter: invert(1);
}

#panel-game.glitch-active {
  animation: glitch-jolt 0.28s infinite;
  filter: saturate(1.35) contrast(1.05);
}

@keyframes glitch-jolt {
  0%,
  100% {
    transform: translate(0, 0);
  }
  33% {
    transform: translate(-3px, 1px);
  }
  66% {
    transform: translate(3px, -1px);
  }
}

.riot-penance-modal .upgrade {
  width: 100%;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.btn-inline {
  font: inherit;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--tg-theme-hint-color, #9ca3af);
  background: var(--tg-theme-secondary-bg-color, #fff);
  color: var(--tg-theme-text-color, inherit);
  cursor: pointer;
}

.btn-inline:hover:not(:disabled) {
  filter: brightness(0.97);
}

.menu-avatar-block {
  width: 100%;
  padding: 6px 0 10px;
  margin-bottom: 2px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.1);
  text-align: left;
}

body.night .menu-avatar-block {
  border-bottom-color: rgba(255, 255, 255, 0.12);
}

#menu-avatar.menu-avatar-block {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
}

.buff-active-bar {
  max-width: 440px;
  margin: 0 auto 10px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  background: rgba(30, 64, 175, 0.18);
  border: 1px solid rgba(59, 130, 246, 0.5);
  color: inherit;
}

.stat-chip__value--glory {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.glory-hint {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.2rem;
  min-height: 1.2rem;
  padding: 0 4px;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  border-radius: 999px;
  border: 1px solid var(--tg-theme-hint-color, #94a3b8);
  color: var(--tg-theme-hint-color, #64748b);
  cursor: help;
  user-select: none;
  -webkit-user-select: none;
}

#glory {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.dmg-float {
  position: fixed;
  z-index: var(--z-dmg);
  pointer-events: none;
  font-weight: 800;
  font-size: 1.1rem;
  color: #ea580c;
  text-shadow: 0 0 2px #fff, 0 1px 2px rgba(0, 0, 0, 0.35);
  /* CS14: center on tap point (spawn uses clientX/clientY as top-left of label) */
  transform: translate(-50%, -50%);
  animation: dmg-rise 0.85s ease-out forwards;
}

.dmg-float--crit {
  font-size: 1.35rem;
  color: #dc2626;
  animation-duration: 1s;
}

@keyframes dmg-rise {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 48px)) scale(1.08);
  }
}

.upgrade--buff {
  border-left-width: 2px;
  box-shadow: inset 4px 0 0 0 #2563eb;
}

.upgrade--custom {
  border-left-width: 2px;
  box-shadow: inset 4px 0 0 0 #9333ea;
}

.factory-go .factory-modal h2 {
  letter-spacing: 0.04em;
  font-size: clamp(1.35rem, 4.5vw, 1.75rem);
  font-weight: 800;
  color: #b45309;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.35);
}

body.night .factory-go .factory-modal h2 {
  color: #fdba74;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.factory-modal .factory-img-wrap {
  margin: 12px 0;
}

.factory-modal .factory-img {
  border-radius: 8px;
}

.whac-modal {
  max-width: 340px;
}

.whac-hud {
  font-size: 0.95rem;
  margin: 10px 0;
}

.whac-actions {
  margin-top: 14px;
  text-align: center;
}

.whac-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 8px;
}

.whac-cell {
  aspect-ratio: 1;
  min-width: 0;
  min-height: 56px;
  font-size: 1.6rem;
  border-radius: 10px;
  border: 2px solid var(--tg-theme-hint-color, #cbd5e1);
  background: var(--tg-theme-secondary-bg-color, #f1f5f9);
  cursor: pointer;
}

.whac-cell:active {
  transform: scale(0.97);
}

/* CS34–CS36: respect reduced motion; soften riot/glitch/shake without breaking layout */
@media (prefers-reduced-motion: reduce) {
  #sukh-img.tap-animation,
  #sukh-img.wink {
    animation: none !important;
  }

  #app-main.riot-flash::after {
    animation-duration: 0.12s !important;
  }

  #game-area.shake-game {
    animation: none !important;
  }

  #panel-game.glitch-active {
    animation: none !important;
    filter: none !important;
  }

  #panel-game.konami-invert-temp {
    filter: none !important;
  }

  .sukh-tap--sticker-mode {
    animation: none !important;
  }

  .emoji-fly {
    animation-duration: 0.12s !important;
  }

  .dmg-float,
  .dmg-float--crit {
    animation-duration: 0.2s !important;
  }

  .toast--rise {
    animation-duration: 0.12s !important;
  }

  .whac-cell:active {
    transform: none;
  }

  .modal-backdrop {
    animation: none !important;
    opacity: 1 !important;
  }

  .modal-backdrop .modal {
    animation: none !important;
    opacity: 1 !important;
    transform: none !important;
  }

  .captcha-modal.captcha-modal--celebrate {
    animation: none !important;
  }

  .zach-cell--ok {
    animation: none !important;
  }

  .app-status-bar .buff-active-bar {
    animation: none !important;
  }
}

/* CS38: high-contrast mode */
@media (prefers-contrast: more) {
  .panel,
  .menu-panel,
  .egg-counter {
    border: 1px solid var(--tg-theme-text-color, #0f172a);
  }

  body.night .panel,
  body.night .menu-panel,
  body.night .egg-counter {
    border-color: rgba(248, 250, 252, 0.85);
  }

  .stat-chip {
    border-width: 2px;
  }

  .toast:not(.toast--error) {
    outline: 2px solid currentColor;
    outline-offset: 1px;
  }
}

/* CX-X: readable print */
@media print {
  body {
    background: #fff !important;
    color: #111 !important;
    padding: 12px !important;
  }

  .app-status-bar,
  .egg-counter,
  .boot-loading,
  .toast,
  .menu-btn,
  .menu-panel,
  .modal-backdrop,
  .fullscreen-meme {
    display: none !important;
  }

  .panel,
  .stat-chip {
    box-shadow: none !important;
    border: 1px solid #ccc !important;
    backdrop-filter: none !important;
  }

  #sukh-img {
    max-width: 220px !important;
  }
}
