/* ===== База: без выделения, казуальный тёплый стиль ===== */
:root {
  --bg-deep: #1a1208;
  --bg-warm: #2a1c0e;
  --wood: #5c3d1e;
  --wood-light: #8b5a2b;
  --cream: #f6e7c8;
  --cream-dim: #e8d4a8;
  --gold: #f0c14b;
  --gold-bright: #ffe08a;
  --gold-dark: #b8860b;
  --copper: #c87533;
  --win: #3ecf6e;
  --lose: #e85d5d;
  --foil: #c5c9ce;
  --foil-dark: #8a9199;
  --text: #2a1a0a;
  --text-inv: #fff8e7;
  --shadow: rgba(20, 10, 0, 0.45);
  --radius: 16px;
  --font: "Nunito", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", system-ui, sans-serif;
  --display: "Russo One", "Nunito", "Segoe UI Emoji", system-ui, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg-deep);
  font-family: var(--font);
  color: var(--text-inv);
  touch-action: manipulation;
}

.no-select, .no-select * {
  user-select: none !important;
  -webkit-user-select: none !important;
}

.app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 0%, #3d2814 0%, transparent 55%),
    linear-gradient(180deg, #2a1c0e 0%, #1a1208 100%);
  box-shadow: 0 0 0 1px rgba(240, 193, 75, 0.12);
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 12px 16px calc(16px + var(--safe-b));
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
}

.screen.active {
  display: flex;
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.hidden { display: none !important; }

/* ===== Кнопки ===== */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 800;
  font-size: 1rem;
  border-radius: 14px;
  padding: 12px 18px;
  transition: transform 0.12s ease, filter 0.12s ease, box-shadow 0.12s;
  touch-action: manipulation;
}

.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.btn-gold {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold) 45%, var(--gold-dark));
  color: #3a2408;
  box-shadow: 0 4px 0 #8a6500, 0 8px 20px var(--shadow);
}

.btn-wood {
  background: linear-gradient(180deg, #a06a36, var(--wood-light) 40%, var(--wood));
  color: var(--cream);
  box-shadow: 0 4px 0 #3a2410, 0 6px 16px var(--shadow);
}

.btn-danger {
  background: linear-gradient(180deg, #f08080, #c04040);
  color: white;
  margin-top: 12px;
  width: 100%;
}

.btn-lg {
  font-size: 1.25rem;
  padding: 16px 22px;
  width: 100%;
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  background: rgba(255, 248, 231, 0.12);
  color: var(--cream);
  font-size: 1.3rem;
  border-radius: 12px;
}

.btn-sm {
  font-size: 0.9rem;
  padding: 10px 14px;
}

/* ===== Баланс ===== */
.balance-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
  border: 2px solid var(--gold);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 800;
  color: var(--gold-bright);
  box-shadow: inset 0 0 12px rgba(240, 193, 75, 0.15);
}

.balance-chip.compact {
  padding: 6px 10px;
  font-size: 0.95rem;
}

.coin { font-size: 1.1em; }

/* ===== Загрузка ===== */
.screen-loading {
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

.loading-logo {
  font-size: 4rem;
  animation: bob 1.4s ease-in-out infinite;
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.brand {
  font-family: var(--display);
  color: var(--gold-bright);
  text-shadow: 0 2px 0 #8a6500, 0 8px 24px rgba(0, 0, 0, 0.5);
  margin: 0;
  letter-spacing: 0.02em;
}

.hero-brand {
  font-size: clamp(1.8rem, 7vw, 2.4rem);
  line-height: 1.15;
}

.loading-bar {
  width: min(260px, 70vw);
  height: 10px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.loading-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-dark), var(--gold-bright));
  transition: width 0.25s ease;
}

.muted { color: var(--cream-dim); opacity: 0.85; font-size: 0.9rem; }

/* ===== Меню ===== */
.menu-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 80%, rgba(240, 193, 75, 0.12), transparent 40%),
    radial-gradient(circle at 80% 20%, rgba(200, 117, 51, 0.15), transparent 35%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M0 0h60v60H0z' fill='none'/%3E%3Cpath d='M30 2v4M30 54v4M2 30h4M54 30h4' stroke='%23f0c14b' stroke-opacity='0.08' stroke-width='1'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

.menu-header, .menu-nav, .goal-hint {
  position: relative;
  z-index: 1;
}

.menu-header {
  text-align: center;
  padding: 28px 8px 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--cream-dim);
  font-weight: 700;
}

.menu-nav {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: auto;
  margin-bottom: auto;
  padding: 0 8px;
}

.goal-hint {
  text-align: center;
  margin: 8px 0 4px;
  color: var(--cream-dim);
  font-size: 0.9rem;
}

.goal-hint strong { color: var(--gold-bright); }

/* ===== Topbar ===== */
.topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.topbar h2 {
  margin: 0;
  font-size: 1.15rem;
  text-align: center;
  color: var(--gold-bright);
  font-family: var(--display);
}

.spacer { width: 44px; }

.play-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.play-title > span:first-child {
  font-weight: 900;
  color: var(--gold-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.play-title .muted {
  font-size: 0.72rem;
  text-align: center;
  line-height: 1.2;
}

/* ===== Магазин лотереек ===== */
.ticket-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
}

.ticket-card {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 248, 231, 0.1), rgba(0, 0, 0, 0.25));
  border: 2px solid rgba(240, 193, 75, 0.35);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s;
}

.ticket-card:active { transform: scale(0.98); }
.ticket-card.locked { opacity: 0.55; }

.ticket-icon {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.2);
}

.ticket-info h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  color: var(--cream);
}

.ticket-info p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--cream-dim);
  line-height: 1.3;
}

.ticket-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-weight: 800;
  font-size: 0.85rem;
}

.ticket-price { color: var(--gold-bright); }
.ticket-jackpot { color: var(--win); font-size: 0.75rem; }
.ticket-chance { color: var(--cream-dim); font-size: 0.7rem; font-weight: 700; }

/* ===== Игра / стирание ===== */
.play-stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-height: 0;
}

.scratch-wrap {
  position: relative;
  width: min(360px, 92vw, calc((100dvh - 14rem) * 0.75));
  max-height: calc(100dvh - 14rem);
  aspect-ratio: 3 / 4;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 0 0 3px var(--gold-dark),
    0 0 0 6px var(--gold),
    0 16px 40px var(--shadow);
  touch-action: none;
  cursor: crosshair;
  background: #1a1208;
  transition: box-shadow 0.35s ease;
}

.scratch-wrap.revealed-win {
  box-shadow:
    0 0 0 3px #1a6b38,
    0 0 0 7px var(--win),
    0 16px 40px rgba(62, 207, 110, 0.35);
  cursor: default;
}

.scratch-wrap.revealed-lose {
  box-shadow:
    0 0 0 3px #6b1a1a,
    0 0 0 7px var(--lose),
    0 16px 40px rgba(232, 93, 93, 0.3);
  cursor: default;
}

/* Баннер «посмотри результат» поверх карточки */
.reveal-banner {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 12px;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(12, 8, 4, 0.88);
  border: 2px solid var(--gold);
  text-align: center;
  animation: bannerIn 0.35s ease;
  pointer-events: auto;
}

.reveal-banner.win { border-color: var(--win); }
.reveal-banner.lose { border-color: var(--lose); }

.reveal-banner #reveal-banner-emoji {
  font-size: 1.6rem;
  line-height: 1;
}

.reveal-banner #reveal-banner-text {
  font-size: 0.88rem;
  font-weight: 800;
  color: var(--cream);
  line-height: 1.35;
}

@keyframes bannerIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.scratch-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

#scratch-foil {
  z-index: 2;
}

.hud-row {
  width: min(360px, 92vw);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.progress-block {
  flex: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--cream-dim);
}

.progress-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--copper), var(--gold-bright));
  transition: width 0.1s linear;
}

.trash-info {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
  color: var(--cream-dim);
}

.play-actions {
  width: min(360px, 92vw, calc((100dvh - 14rem) * 0.75));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.play-actions #btn-buy-again {
  grid-column: 1 / -1;
}

.menu-row {
  display: flex;
  gap: 8px;
}

.flex-1 { flex: 1; min-width: 0; }

.streak-hint {
  text-align: center;
  margin: 4px 0 0;
  color: var(--cream-dim);
  font-size: 0.9rem;
}

.streak-hint strong { color: var(--gold-bright); }

.center-hint {
  text-align: center;
  margin: 0 0 12px;
}

.collection-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 10px;
  padding-bottom: 8px;
}

.collection-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(240, 193, 75, 0.3);
  border-radius: 12px;
}

.collection-emoji { font-size: 1.8rem; }
.collection-count { font-weight: 800; color: var(--gold-bright); font-size: 0.85rem; }

.missions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  padding-bottom: 8px;
}

.mission-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(240, 193, 75, 0.3);
}

.mission-card.claimed { opacity: 0.55; }

.mission-card h3 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  color: var(--cream);
}

.mission-card p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--cream-dim);
}

.section-label {
  margin: 8px 0 4px;
  color: var(--gold-bright);
  font-size: 1rem;
}

.pity-line {
  min-height: 1.2em;
  color: var(--win) !important;
  font-weight: 700;
}

/* ===== Результат ===== */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(10, 6, 2, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.result-card {
  width: min(340px, 100%);
  background: linear-gradient(180deg, #3d2814, #24180c);
  border: 3px solid var(--gold);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  animation: popIn 0.35s cubic-bezier(0.2, 1.2, 0.4, 1);
}

@keyframes popIn {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.result-card.win { border-color: var(--win); }
.result-card.lose { border-color: var(--lose); }

.result-emoji { font-size: 3rem; margin-bottom: 8px; }
.result-card h2 { margin: 0 0 8px; color: var(--gold-bright); font-family: var(--display); }
#result-amount {
  font-size: 1.8rem;
  font-weight: 900;
  margin: 0 0 8px;
  color: var(--win);
}
.result-card.lose #result-amount { color: var(--lose); }
.result-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

/* ===== Улучшения ===== */
.upgrades-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.upgrade-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(255, 248, 231, 0.08), rgba(0, 0, 0, 0.3));
  border: 2px solid rgba(240, 193, 75, 0.3);
}

.upgrade-icon {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  background: rgba(240, 193, 75, 0.15);
}

.upgrade-body h3 {
  margin: 0 0 4px;
  color: var(--cream);
}

.upgrade-body p {
  margin: 0 0 10px;
  font-size: 0.8rem;
  color: var(--cream-dim);
  line-height: 1.35;
}

.upgrade-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.upgrade-level {
  font-weight: 800;
  color: var(--gold-bright);
  font-size: 0.9rem;
}

/* ===== Сюжет ===== */
#screen-story {
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 30%, #3d2814, transparent 60%),
    var(--bg-deep);
}

.story-panel {
  background: linear-gradient(180deg, #3a2614, #22160c);
  border: 3px solid var(--gold-dark);
  border-radius: 20px;
  padding: 24px 18px;
  text-align: center;
  max-width: 400px;
  width: 100%;
  margin: 0 auto;
  box-shadow: 0 16px 40px var(--shadow);
}

.story-art {
  font-size: 4rem;
  margin-bottom: 12px;
  animation: bob 2s ease-in-out infinite;
}

.story-text {
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--cream);
  min-height: 4.5em;
  margin: 0 0 18px;
}

.story-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.story-dots {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}

.story-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
}

.story-dots span.on {
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}

/* ===== Настройки ===== */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 8px 4px;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 14px;
  border: 1px solid rgba(240, 193, 75, 0.25);
  font-weight: 700;
}

.setting-row select,
.setting-row input[type="checkbox"] {
  font-size: 1rem;
  accent-color: var(--gold);
}

.setting-row select {
  background: var(--wood);
  color: var(--cream);
  border: 2px solid var(--gold-dark);
  border-radius: 8px;
  padding: 6px 10px;
  font-family: var(--font);
  font-weight: 700;
}

/* ===== Адаптив ===== */
@media (min-height: 780px) {
  .menu-header { padding-top: 48px; }
}

@media (max-width: 360px) {
  .ticket-card { grid-template-columns: 52px 1fr; }
  .ticket-meta { grid-column: 2; flex-direction: row; justify-content: flex-start; }
}

/* ----- ПК / широкий экран ----- */
@media (min-width: 768px) {
  html, body {
    overflow: auto;
  }

  body {
    background:
      radial-gradient(ellipse at 20% 30%, rgba(240, 193, 75, 0.08), transparent 40%),
      radial-gradient(ellipse at 80% 70%, rgba(200, 117, 51, 0.1), transparent 45%),
      linear-gradient(180deg, #120c06 0%, #1a1208 50%, #0e0a05 100%);
  }

  .app {
    max-width: 920px;
    height: min(100vh, 920px);
    margin: 0 auto;
    border-left: 1px solid rgba(240, 193, 75, 0.15);
    border-right: 1px solid rgba(240, 193, 75, 0.15);
    box-shadow: 0 0 80px rgba(0, 0, 0, 0.55);
  }

  .screen {
    padding: 20px 28px 24px;
  }

  .menu-nav {
    max-width: 420px;
    margin-left: auto;
    margin-right: auto;
  }

  .hero-brand {
    font-size: 2.6rem;
  }

  .ticket-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    align-content: start;
  }

  .ticket-card {
    min-height: 88px;
  }

  .ticket-card:hover {
    border-color: var(--gold);
    transform: translateY(-2px);
  }

  .upgrades-list {
    display: grid;
    grid-template-columns: 1fr;
    max-width: 560px;
    margin: 0 auto;
    width: 100%;
  }

  .play-stage {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 20px 28px;
    padding-top: 8px;
  }

  .scratch-wrap {
    width: min(420px, 46vw);
    flex-shrink: 0;
  }

  .hud-row,
  .play-actions {
    width: min(420px, 46vw);
  }

  /* боковая колонка контролов на очень широких */
  .play-side {
    display: contents;
  }

  .btn:hover:not(:disabled) {
    filter: brightness(1.06);
  }

  .btn-icon:hover {
    background: rgba(255, 248, 231, 0.2);
  }

  .settings-list {
    max-width: 480px;
    margin: 0 auto;
    width: 100%;
  }

  .story-panel {
    max-width: 480px;
  }

  .result-card {
    max-width: 380px;
  }
}

@media (min-width: 1100px) {
  .app {
    max-width: 980px;
  }

  .scratch-wrap {
    width: 440px;
  }

  .hud-row,
  .play-actions {
    width: 440px;
  }

  #screen-play.active {
    /* карточка по центру, контролы под ней — читаемо на мониторе */
  }

  .play-stage {
    max-width: 480px;
    margin: 0 auto;
    flex-direction: column;
    align-items: center;
  }
}

@media (min-width: 768px) and (min-height: 800px) {
  .scratch-wrap {
    width: min(460px, 42vw, calc((100dvh - 12rem) * 0.75));
  }
}

/* ----- 125% DPI / низкие окна (Win scale) ----- */
@media (max-height: 900px) {
  .screen {
    padding: 8px 12px calc(10px + var(--safe-b));
  }

  .menu-header {
    padding: 10px 4px 6px;
    gap: 6px;
  }

  .hero-brand {
    font-size: clamp(1.35rem, 4.5vh, 2rem);
  }

  .menu-nav {
    gap: 8px;
  }

  .btn-lg {
    padding: 12px 16px;
    font-size: 1.1rem;
  }

  .btn {
    padding: 10px 14px;
  }

  .scratch-wrap {
    width: min(340px, 90vw, calc((100dvh - 12.5rem) * 0.72));
  }

  .hud-row,
  .play-actions {
    width: min(340px, 90vw, calc((100dvh - 12.5rem) * 0.72));
  }

  .reveal-banner {
    padding: 8px 10px;
    gap: 6px;
  }

  .reveal-banner #reveal-banner-text {
    font-size: 0.8rem;
  }

  .topbar h2 {
    font-size: 1rem;
  }

  .goal-hint,
  .streak-hint {
    font-size: 0.8rem;
    margin: 2px 0;
  }
}

@media (max-height: 720px) {
  .eyebrow { display: none; }
  .loading-logo { font-size: 2.5rem; }
  .scratch-wrap {
    width: min(300px, 88vw, calc((100dvh - 11rem) * 0.7));
  }
  .menu-nav .btn-wood:not(.btn-sm) {
    padding: 8px 12px;
    font-size: 0.95rem;
  }
}
