:root {
  color-scheme: dark;
  --bg: #0c0d10;
  --panel: #15171c;
  --panel-2: #1c1f25;
  --ink: #f6f2e8;
  --muted: #a6a8af;
  --line: rgba(255,255,255,.12);
  --yellow: #ffd635;
  --red: #ff3d5a;
  --telegram: #229ed9;
  --rarity: #6f7378;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); scroll-behavior: smooth; }
body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 16% 8%, rgba(255,214,53,.12), transparent 28rem),
    radial-gradient(circle at 92% 30%, rgba(255,61,90,.10), transparent 30rem),
    var(--bg);
}

button, a { font: inherit; }
button { color: inherit; }
.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .18;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
}
#confettiCanvas { position: fixed; inset: 0; z-index: 100; pointer-events: none; }

.app-shell { width: min(100%, 1240px); margin: 0 auto; padding: 24px 20px 44px; position: relative; z-index: 1; }
.hero { padding: 36px 0 30px; text-align: center; }
.live-pill {
  display: inline-flex; align-items: center; gap: 9px; padding: 8px 13px; border: 1px solid var(--line); border-radius: 999px;
  color: #d4d6dc; background: rgba(21,23,28,.8); font-size: 11px; font-weight: 900; letter-spacing: .12em;
}
.live-pill span { width: 8px; height: 8px; border-radius: 50%; background: #4be37f; box-shadow: 0 0 14px #4be37f; animation: pulse 1.5s infinite; }
@keyframes pulse { 50% { opacity: .35; transform: scale(.8); } }
.hero h1 { margin: 18px 0 0; font-size: clamp(42px, 8vw, 96px); line-height: .86; letter-spacing: -.075em; font-weight: 1000; text-transform: uppercase; }
.hero h1 mark { display: inline-block; margin-top: 12px; padding: .05em .13em .1em; color: #111; background: var(--yellow); transform: rotate(-1deg); }
.hero > p { max-width: 760px; margin: 22px auto 0; color: var(--muted); font-size: clamp(16px, 2vw, 20px); line-height: 1.5; }
.hero-stats { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.hero-stats span { padding: 8px 12px; border-radius: 10px; background: rgba(255,255,255,.06); border: 1px solid var(--line); color: #d6d7dc; font-size: 12px; font-weight: 800; }

.machine { display: grid; grid-template-columns: minmax(0, 1.06fr) minmax(370px, .94fr); align-items: start; gap: 22px; padding: 20px; border: 1px solid var(--line); border-radius: 30px; background: rgba(21,23,28,.92); box-shadow: 0 30px 100px rgba(0,0,0,.45); }
.card-column, .control-column { min-width: 0; }
.card-wrap { position: relative; width: 100%; aspect-ratio: 1 / 1; overflow: hidden; border: 6px solid var(--rarity); border-radius: 23px; background: #252830; box-shadow: 0 20px 48px rgba(0,0,0,.38); transition: border-color .4s, box-shadow .4s, transform .4s; }
.card-wrap img { display: block; width: 100%; height: 100%; max-width: 100%; object-fit: cover; object-position: center; }
.card-wrap.rarity-common { --rarity: #6f7378; }
.card-wrap.rarity-rare { --rarity: #168cff; box-shadow: 0 20px 58px rgba(22,140,255,.22); }
.card-wrap.rarity-epic { --rarity: #a84cff; box-shadow: 0 20px 65px rgba(168,76,255,.28); }
.card-wrap.rarity-legendary { --rarity: #ffb300; box-shadow: 0 20px 70px rgba(255,179,0,.34); }
.card-wrap.rarity-mythic { --rarity: #ff3d5a; box-shadow: 0 20px 80px rgba(255,61,90,.42); }
.card-wrap.rarity-divine { --rarity: #00d7b5; animation: divineGlow 2.4s linear infinite; }
@keyframes divineGlow { 50% { box-shadow: 0 0 25px #00d7b5, 0 0 70px rgba(168,76,255,.45); } }

.generation-overlay { position: absolute; inset: 0; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 13px; padding: 30px; text-align: center; background: rgba(8,9,12,.84); backdrop-filter: blur(14px); }
.generation-overlay[hidden] { display: none; }
.generation-overlay strong { font-size: clamp(23px, 4vw, 39px); letter-spacing: -.03em; }
.generation-overlay span { max-width: 430px; color: #c6c7cc; line-height: 1.5; }
.spinner { width: 62px; height: 62px; border: 7px solid rgba(255,255,255,.15); border-top-color: var(--yellow); border-radius: 50%; animation: spin .8s linear infinite; }
.scanline { position: absolute; left: 0; right: 0; height: 3px; top: 0; background: var(--yellow); box-shadow: 0 0 20px var(--yellow); animation: scan 2.3s ease-in-out infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scan { 50% { top: calc(100% - 3px); } }
.rarity-flash { position: absolute; inset: 0; z-index: 5; pointer-events: none; opacity: 0; }
.rarity-flash.is-active { animation: flash 1.1s ease-out; }
.rarity-flash.rarity-rare { background: #168cff; }
.rarity-flash.rarity-epic { background: #a84cff; }
.rarity-flash.rarity-legendary { background: #ffb300; }
.rarity-flash.rarity-mythic { background: #ff3d5a; }
.rarity-flash.rarity-divine { background: linear-gradient(135deg,#ff3d5a,#ffd635,#00d7b5,#168cff,#a84cff); }
@keyframes flash { 0% { opacity: .9; } 100% { opacity: 0; } }

.control-column { display: flex; flex-direction: column; padding: 10px 6px 4px; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card-number { color: #8e9199; font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.rarity-badge { display: inline-flex; padding: 8px 11px; border-radius: 9px; border: 1px solid currentColor; background: rgba(255,255,255,.05); font-size: 12px; font-weight: 950; letter-spacing: .08em; }
.rarity-common { color: #a7abb0; }
.rarity-rare { color: #43a5ff; }
.rarity-epic { color: #c077ff; }
.rarity-legendary { color: #ffc33d; }
.rarity-mythic { color: #ff657b; }
.rarity-divine { color: #46efd4; }
.category-line { margin: 31px 0 8px; color: var(--yellow); font-size: 12px; font-weight: 950; letter-spacing: .12em; }
.control-column h2 { margin: 0; font-size: clamp(39px, 5vw, 67px); line-height: .92; letter-spacing: -.06em; }
.result-subtitle { margin: 17px 0 0; min-height: 70px; color: #c0c2c8; font-size: clamp(17px, 2vw, 22px); line-height: 1.42; }

.button { min-height: 52px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 16px; border: 0; border-radius: 13px; text-decoration: none; font-weight: 900; cursor: pointer; transition: transform .15s, filter .15s, opacity .15s; }
.button:hover:not(:disabled):not(.is-disabled) { transform: translateY(-2px); filter: brightness(1.05); }
.button:active:not(:disabled):not(.is-disabled) { transform: translateY(0); }
.button.is-disabled, .button:disabled { opacity: .38; pointer-events: none; }
.button-generate { width: 100%; min-height: 83px; margin-top: 25px; justify-content: flex-start; color: #101114; background: var(--yellow); box-shadow: 0 12px 33px rgba(255,214,53,.20); text-align: left; }
.button-generate .button-icon { display: grid; place-items: center; width: 48px; height: 48px; flex: 0 0 auto; border-radius: 50%; color: var(--yellow); background: #121318; font-size: 24px; }
.button-generate span:last-child { display: flex; flex-direction: column; gap: 3px; }
.button-generate b { font-size: 16px; letter-spacing: .02em; }
.button-generate small { font-size: 11px; font-weight: 750; opacity: .65; }
.share-grid { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; margin-top: 9px; }
.button-telegram { color: white; background: var(--telegram); }
.button-secondary { color: #e4e5e8; background: #272a31; border: 1px solid var(--line); }

.collection-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: auto; padding-top: 25px; }
.collection-summary > div { padding: 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.035); }
.collection-summary span { display: block; color: #858891; font-size: 10px; font-weight: 900; letter-spacing: .12em; }
.collection-summary strong { display: block; margin-top: 5px; font-size: 13px; }
.button-collection { grid-column: 1 / -1; color: var(--ink); border: 1px dashed rgba(255,214,53,.5); background: rgba(255,214,53,.07); }
.cost-note { margin: 14px 0 0; color: #7f828b; font-size: 11px; line-height: 1.45; }

.rarity-legend { margin-top: 24px; padding: 24px; border: 1px solid var(--line); border-radius: 23px; background: rgba(21,23,28,.72); }
.rarity-legend h3 { margin: 0 0 15px; font-size: 18px; letter-spacing: .07em; }
.rarity-list { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.rarity-list > span { display: flex; flex-direction: column; gap: 4px; padding: 13px 10px; border: 1px solid currentColor; border-radius: 11px; background: rgba(255,255,255,.025); text-align: center; }
.rarity-list b { font-size: 11px; }
.rarity-list small { color: #8f929a; font-size: 11px; }
.rarity-legend > p { margin: 15px 0 0; color: #8f929a; font-size: 13px; }
footer { padding: 26px 0 0; color: #757881; font-size: 12px; text-align: center; }

.collection-dialog { width: min(1060px, calc(100vw - 24px)); max-height: 88vh; padding: 0; overflow: auto; color: var(--ink); border: 1px solid var(--line); border-radius: 24px; background: #15171c; box-shadow: 0 40px 120px rgba(0,0,0,.7); }
.collection-dialog::backdrop { background: rgba(0,0,0,.76); backdrop-filter: blur(7px); }
.dialog-head { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 20px; padding: 22px; border-bottom: 1px solid var(--line); background: rgba(21,23,28,.95); backdrop-filter: blur(16px); }
.dialog-head span { color: var(--yellow); font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.dialog-head h2 { margin: 5px 0 0; font-size: clamp(25px, 4vw, 42px); letter-spacing: -.04em; }
.close-button { width: 45px; height: 45px; flex: 0 0 auto; border: 1px solid var(--line); border-radius: 50%; color: white; background: #272a31; font-size: 30px; cursor: pointer; }
.achievement-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; padding: 20px; border-bottom: 1px solid var(--line); }
.achievement { display: flex; align-items: center; gap: 9px; min-height: 70px; padding: 10px; border: 1px solid var(--line); border-radius: 12px; opacity: .45; }
.achievement.is-unlocked { opacity: 1; border-color: rgba(255,214,53,.5); background: rgba(255,214,53,.06); }
.achievement > span { font-size: 23px; }
.achievement b, .achievement small { display: block; }
.achievement b { font-size: 12px; }
.achievement small { margin-top: 3px; color: #858891; font-size: 9px; line-height: 1.3; }
.collection-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; padding: 20px; }
.collection-card { overflow: hidden; color: white; border: 2px solid currentColor; border-radius: 14px; background: #20232a; text-decoration: none; transition: transform .15s; }
.collection-card:hover { transform: translateY(-3px); }
.collection-card img { display: block; width: 100%; height: auto; aspect-ratio: 1 / 1; object-fit: cover; }
.collection-card div { padding: 10px; }
.collection-card span, .collection-card b, .collection-card small { display: block; }
.collection-card span { font-size: 9px; font-weight: 900; }
.collection-card b { margin-top: 5px; color: white; font-size: 12px; line-height: 1.25; }
.collection-card small { margin-top: 5px; color: #8f929a; font-size: 10px; }
.empty-state { grid-column: 1 / -1; padding: 60px 20px; color: #8f929a; text-align: center; }
.dialog-actions { padding: 0 20px 22px; text-align: center; }
.text-button { padding: 8px; border: 0; color: #8f929a; background: none; text-decoration: underline; cursor: pointer; }
.toast { position: fixed; z-index: 150; left: 50%; bottom: 24px; max-width: calc(100vw - 30px); padding: 13px 17px; border: 1px solid rgba(255,255,255,.14); border-radius: 12px; color: white; background: rgba(15,16,20,.95); box-shadow: 0 16px 45px rgba(0,0,0,.4); font-weight: 800; opacity: 0; transform: translate(-50%, 20px); transition: .2s; pointer-events: none; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .machine { grid-template-columns: 1fr; }
  .control-column { padding: 6px 4px; }
  .result-subtitle { min-height: 0; }
  .collection-summary { margin-top: 0; }
  .rarity-list { grid-template-columns: repeat(3, 1fr); }
  .achievement-list { grid-template-columns: repeat(2, 1fr); }
  .collection-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 620px) {
  .app-shell { padding: 12px 10px 30px; }
  .hero { padding-top: 25px; }
  .live-pill { font-size: 9px; }
  .machine { padding: 9px; border-radius: 21px; }
  .card-wrap { border-width: 4px; border-radius: 17px; }
  .result-head { margin-top: 8px; }
  .category-line { margin-top: 21px; }
  .share-grid { grid-template-columns: 1fr; }
  .collection-summary { grid-template-columns: 1fr; }
  .button-collection { grid-column: auto; }
  .rarity-legend { padding: 15px; }
  .rarity-list { grid-template-columns: repeat(2, 1fr); }
  .achievement-list { grid-template-columns: 1fr; padding: 12px; }
  .collection-grid { grid-template-columns: repeat(2, 1fr); padding: 12px; gap: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
