:root { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0a0a12; font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif; }

/* This is a Telegram mini-app built for a phone screen. In a real phone (or the Telegram
   in-app webview) #app-frame simply fills the device. In a wide desktop browser tab it stays
   phone-shaped and centered, so the static farm background never stretches across a wide window. */
body { display: flex; align-items: center; justify-content: center; }
#app-frame { position: relative; width: 100%; max-width: 480px; height: 100%; max-height: 900px; overflow: hidden; background: #0a0a12; box-shadow: 0 0 60px rgba(0,0,0,.6); }

/* ---- static background, plus a thin layer of motion on top (no sprite art: CSS/SVG only) ---- */
#farm { position: absolute; inset: 0; overflow: hidden; background: #0a0a12; }
#farm-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }
#farm-fx { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

/* real windmill-blade sprite spinning on the hub */
#farm-fx .fx-blades { transform-box: fill-box; transform-origin: 50% 50%; animation: fxSpin 6s linear infinite; }
@keyframes fxSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* soft drifting clouds - three independent layers for a bit of parallax */
#farm-fx .fx-cloud { fill: #fff; opacity: .55; filter: blur(.35px); }
#farm-fx .fx-cloud-a { animation: fxDriftA 85s linear infinite; }
#farm-fx .fx-cloud-b { animation: fxDriftB 110s linear infinite; animation-delay: -30s; }
#farm-fx .fx-cloud-c { animation: fxDriftC 130s linear infinite; animation-delay: -70s; }
@keyframes fxDriftA { from { transform: translateX(-20px); } to { transform: translateX(120px); } }
@keyframes fxDriftB { from { transform: translateX(-20px); } to { transform: translateX(120px); } }
@keyframes fxDriftC { from { transform: translateX(-20px); } to { transform: translateX(120px); } }

/* small birds flapping across the sky */
#farm-fx .fx-bird { fill: none; stroke: #3a3228; stroke-width: .5; stroke-linecap: round; opacity: .8; transform-box: fill-box; transform-origin: 50% 50%; animation: fxFlap .42s ease-in-out infinite alternate; }
#farm-fx .fx-bird-fly { animation: fxFly linear infinite; }
#farm-fx .fx-bird-a { animation-duration: 13s; }
#farm-fx .fx-bird-b { animation-duration: 17s; animation-delay: -6s; }
@keyframes fxFly { from { transform: translateX(-15px); } to { transform: translateX(115px); } }
@keyframes fxFlap { from { transform: scaleY(1); } to { transform: scaleY(.35); } }

/* smoke curling up from the chimney */
#farm-fx .fx-smoke { animation: fxSmoke 7s ease-out infinite; opacity: 0; }
#farm-fx .fx-smoke circle { fill: #fff; }
@keyframes fxSmoke {
  0%   { transform: translate(0,0) scale(.45); opacity: 0; }
  12%  { opacity: .5; }
  60%  { opacity: .3; }
  100% { transform: translate(-3,-20) scale(2); opacity: 0; }
}

/* a lamp inside the house, glowing on and off now and then */
#farm-fx .fx-win { fill: #ffd37a; opacity: 0; filter: blur(.12px); animation: fxWin 13s ease-in-out infinite; }
@keyframes fxWin {
  0%, 55% { opacity: 0; }
  62%     { opacity: .6; }
  72%     { opacity: .4; }
  78%     { opacity: .62; }
  92%, 100% { opacity: 0; }
}

/* sunlight glinting on the pond ripples */
#farm-fx .fx-glint { fill: #fff; opacity: 0; }
#farm-fx .fx-glint-a { animation: fxGlint 3.6s ease-in-out infinite; }
#farm-fx .fx-glint-b { animation: fxGlint 4.4s ease-in-out infinite; animation-delay: -1.8s; }
#farm-fx .fx-glint-c { animation: fxGlint 3.1s ease-in-out infinite; animation-delay: -.9s; }
@keyframes fxGlint { 0%, 100% { opacity: 0; } 50% { opacity: .85; } }

/* the bitcoin medallion catching the light - a slow gold pulse plus a few twinkling sparkle stars */
#farm-fx .fx-coinglow { fill: #ffd24a; opacity: 0; filter: blur(.3px); animation: fxCoinGlow 2.6s ease-in-out infinite; }
@keyframes fxCoinGlow { 0%, 100% { opacity: 0; transform: scale(.7); } 50% { opacity: .5; transform: scale(1.15); } }
#farm-fx .fx-spark { fill: #fff8df; opacity: 0; transform-box: fill-box; transform-origin: 50% 50%; }
#farm-fx .fx-spark-a { animation: fxSpark 2.1s ease-in-out infinite; }
#farm-fx .fx-spark-b { animation: fxSpark 1.8s ease-in-out infinite; animation-delay: -.7s; }
#farm-fx .fx-spark-c { animation: fxSpark 2.4s ease-in-out infinite; animation-delay: -1.3s; }
@keyframes fxSpark {
  0%, 100% { opacity: 0; transform: scale(.2) rotate(0deg); }
  50%      { opacity: 1; transform: scale(1.15) rotate(45deg); }
}

#ui { position: absolute; inset: 0; z-index: 20; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
#hello { margin: 14px 16px 0; color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,.6); font-weight: 600; font-size: 15px; pointer-events: none; }
#buttons { display: flex; flex-direction: row; gap: 8px; padding: 16px 12px calc(14px + env(safe-area-inset-bottom, 0px)); pointer-events: auto; position: relative; }
#buttons::before { content: ''; position: absolute; inset: -50px 0 0; background: linear-gradient(to bottom, transparent, rgba(5,5,10,.28) 60%, rgba(5,5,10,.38)); z-index: -1; pointer-events: none; }
.btn {
  font-family: inherit; font-weight: 700; font-size: 13.5px; color: #fff3da; flex: 1; min-width: 0;
  padding: 13px 6px; border-radius: 12px; border: 2px solid rgba(92,66,40,.75);
  background: rgba(60, 42, 24, .32);
  -webkit-backdrop-filter: blur(5px) saturate(1.1); backdrop-filter: blur(5px) saturate(1.1);
  box-shadow: 0 4px 14px rgba(0,0,0,.22), inset 0 1px 0 rgba(255,255,255,.12);
  text-shadow: 0 1px 3px rgba(0,0,0,.85);
  letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 6px rgba(0,0,0,.2); }
.btn-main { flex: 1.15; font-size: 16px; background: rgba(184, 79, 23, .45); border-color: rgba(122,58,16,.85); box-shadow: 0 6px 18px rgba(184,79,23,.3), inset 0 1px 0 rgba(255,255,255,.18); }

/* ---- modal sheet ---- */
#modal-overlay { position: absolute; inset: 0; z-index: 50; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
#modal-overlay.hidden { display: none; }
#modal { width: 100%; max-width: 480px; max-height: 82vh; overflow-y: auto; background: #241a12; color: #fde9c8; border-radius: 18px 18px 0 0; padding: 18px 16px 24px; position: relative; border-top: 3px solid #8a6440; }
#modal-close { position: absolute; top: 10px; right: 12px; background: none; border: none; color: #fde9c8; font-size: 20px; cursor: pointer; }
#modal h2 { margin: 2px 0 12px; font-size: 18px; }
#modal h3 { margin: 16px 0 8px; font-size: 15px; color: #ffcf7a; }
.muted { opacity: .65; font-size: 13px; }
.div { border: none; border-top: 1px solid #3a2a1c; margin: 16px 0; }

/* ---- quick play ---- */
.quickplay { text-align: center; }
.sam-go-btn {
  display: block; width: 100%; padding: 15px; margin: 6px 0 10px; border: none; border-radius: 12px;
  background: linear-gradient(180deg, #e08a35, #b84f17); color: #fff; font-weight: 800; font-size: 16px;
  box-shadow: 0 6px 14px rgba(184,79,23,.35), inset 0 1px 0 rgba(255,255,255,.25); cursor: pointer;
}
.sam-go-btn:active { transform: translateY(2px); }
.sam-go-btn.alt { background: linear-gradient(180deg, #5fae57, #3c7a34); box-shadow: 0 6px 14px rgba(60,122,52,.35), inset 0 1px 0 rgba(255,255,255,.25); }
.sam-go-btn[disabled] { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }
.sam-b-link { display: block; margin: 10px auto 0; background: none; border: none; color: #ffcf7a; text-decoration: underline; cursor: pointer; font-size: 13px; }

/* ---- tournament panel ---- */
.prize { color: #ffcf7a; font-weight: 700; margin: 2px 0 10px; }
.countdown { font-size: 30px; font-weight: 800; text-align: center; letter-spacing: 1px; color: #fde9c8; background: #1a120c; border: 1px solid #5c4228; border-radius: 10px; padding: 10px 0; margin-bottom: 8px; }
.tasks { margin: 12px 0; }
.task { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #1a120c; border: 1px solid #3a2a1c; border-radius: 10px; padding: 9px 10px; margin-top: 6px; font-size: 13.5px; }
.task a { color: #9fd0ff; }
.task.done { border-color: #3c7a34; }
.task .task-done { padding: 6px 10px; font-size: 12px; border-radius: 7px; border: none; background: #3c7a34; color: #fff; font-weight: 700; cursor: pointer; white-space: nowrap; }
.ok-line { text-align: center; color: #9fe39a; font-weight: 700; margin: 8px 0; }
.mymatch { background: #1a120c; border: 1px solid #5c4228; border-radius: 10px; padding: 10px; margin: 8px 0; }
.mymatch .sam-go-btn { margin-top: 10px; }

/* ---- bracket ---- */
.bracket { display: flex; overflow-x: auto; gap: 16px; padding-bottom: 6px; }
.bracket-round { flex: 0 0 auto; min-width: 140px; }
.rlabel { font-size: 11px; text-transform: uppercase; color: #9c8a6c; margin-bottom: 6px; text-align: center; }
.bm { background: #1a120c; border: 1px solid #3a2a1c; border-radius: 8px; padding: 6px 8px; margin-bottom: 20px; font-size: 12.5px; }
.bm div { padding: 3px 0; }
.bm .win { color: #9fe39a; font-weight: 700; }

/* ---- Профиль (profile + referrals merged) ---- */
.ref-link { display: flex; gap: 8px; margin-bottom: 14px; }
.ref-link input { flex: 1; min-width: 0; padding: 10px; border-radius: 8px; border: 1px solid #5c4228; background: #1a120c; color: #fde9c8; font-size: 13px; }
.ref-link button { padding: 10px 14px; border-radius: 8px; border: none; background: #b84f17; color: #fff; font-weight: 700; }
.ref-stats { display: flex; gap: 10px; margin-bottom: 14px; }
.ref-stats .card { flex: 1; background: #332419; border-radius: 10px; padding: 10px; text-align: center; }
.ref-stats .card b { display: block; font-size: 20px; }
.ref-list, .ref-top { list-style: none; margin: 0 0 14px; padding: 0; font-size: 14px; }
.ref-list li, .ref-top li { display: flex; justify-content: space-between; padding: 7px 4px; border-bottom: 1px solid #3a2a1c; }
.ref-top li b { color: #ffcf7a; }

/* ---- Профиль v2 ---- */
#modal { background: linear-gradient(180deg, #2f2012 0%, #1c130b 100%); max-height: 90vh; padding: 0; border-top: 3px solid #e0a82a; box-shadow: 0 -10px 40px rgba(0,0,0,.6); }
#modal-close { z-index: 5; width: 32px; height: 32px; border-radius: 50%; background: rgba(0,0,0,.4); top: 12px; right: 12px; }
.kab { padding: 0 16px 28px; }
.kab-load { padding: 50px 16px; text-align: center; opacity: .8; }
.kab-spin { width: 34px; height: 34px; margin: 0 auto 12px; border-radius: 50%; border: 3px solid rgba(255,255,255,.2); border-top-color: #e0a82a; animation: kabSpin .8s linear infinite; }
@keyframes kabSpin { to { transform: rotate(360deg); } }
.kab-hero { display: flex; gap: 14px; align-items: center; margin: 0 -16px 14px; padding: 26px 16px 18px; background: radial-gradient(120% 120% at 20% 0%, rgba(255,190,80,.35), transparent 60%), linear-gradient(180deg, rgba(120,80,30,.55), transparent); }
.kab-ava { width: 76px; height: 76px; flex: 0 0 76px; border-radius: 50%; padding: 3px; background: conic-gradient(#ffe58a, #e0a82a, #b84f17, #ffe58a); box-shadow: 0 6px 20px rgba(224,168,42,.5); }
.kab-ava img, .kab-ava span { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: flex; align-items: center; justify-content: center; background: #5a3b1f; font-size: 32px; font-weight: 900; color: #ffe9b8; }
.kab-name { font-size: 21px; font-weight: 900; color: #fff3d6; line-height: 1.15; word-break: break-word; }
.kab-rank { margin-top: 4px; display: inline-block; padding: 3px 10px; border-radius: 99px; background: rgba(255,210,74,.18); border: 1px solid rgba(255,210,74,.5); color: #ffe08a; font-weight: 800; font-size: 13px; }
.kab-place { margin-top: 6px; font-size: 12.5px; opacity: .75; } .kab-place b { color: #ffd24a; }
.kab-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.kab-stats .st { padding: 10px 4px; border-radius: 14px; text-align: center; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); }
.kab-stats .st.gold { background: linear-gradient(180deg, rgba(255,210,74,.28), rgba(224,138,53,.15)); border-color: rgba(255,210,74,.6); }
.kab-stats b { display: block; font-size: 20px; font-weight: 900; color: #fff; } .kab-stats small { font-size: 10px; opacity: .65; letter-spacing: .3px; }
.kab-wr { margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: rgba(0,0,0,.25); }
.kab-wr-t { display: flex; justify-content: space-between; font-size: 12.5px; margin-bottom: 6px; } .kab-wr-t b { color: #9fe39a; }
.kab-bar { height: 9px; border-radius: 99px; background: rgba(0,0,0,.45); overflow: hidden; } .kab-bar span { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #5fae57, #b6e05a); }
.kab-sec { margin: 20px 2px 8px; font-size: 12px; letter-spacing: 2px; font-weight: 900; color: #ffcf7a; }
.kab-ref { padding: 14px; border-radius: 18px; background: linear-gradient(180deg, rgba(95,174,87,.2), rgba(60,122,52,.1)); border: 1px solid rgba(130,220,120,.35); }
.kab-ref p { margin: 0 0 12px; font-size: 13px; line-height: 1.45; opacity: .85; }
.kab-share { display: block; width: 100%; margin-top: 10px; padding: 13px; border: none; border-radius: 12px; font-weight: 800; font-size: 14.5px; color: #fff; background: linear-gradient(135deg, #e08a35, #b84f17); box-shadow: 0 6px 18px rgba(184,79,23,.45); cursor: pointer; }
.kab-share:active { transform: translateY(2px); }
.kab-by { margin-top: 10px; font-size: 12.5px; opacity: .8; text-align: center; }
.kab-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.kab-2 div { padding: 10px; border-radius: 12px; text-align: center; background: rgba(0,0,0,.28); } .kab-2 b { display: block; font-size: 22px; color: #ffd24a; } .kab-2 small { font-size: 11px; opacity: .7; }
.kab-tabs { display: flex; gap: 6px; margin: 18px 0 8px; padding: 4px; border-radius: 14px; background: rgba(0,0,0,.35); }
.kab-tabs button { flex: 1; padding: 10px 6px; border: none; border-radius: 10px; background: transparent; color: #e8d6b4; font-weight: 800; font-size: 13px; cursor: pointer; }
.kab-tabs button.on { background: linear-gradient(135deg, #e08a35, #b84f17); color: #fff; box-shadow: 0 3px 10px rgba(184,79,23,.4); }
.kab-list { list-style: none; margin: 0; padding: 0; }
.kab-list li { display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin-bottom: 6px; border-radius: 12px; background: rgba(255,255,255,.06); font-size: 14px; }
.kab-list li i { flex: 0 0 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-style: normal; font-weight: 900; background: #5a3b1f; color: #ffe9b8; }
.kab-list li i.rk { background: none; font-size: 16px; } .kab-list li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.kab-list li em { font-style: normal; font-size: 12px; opacity: .7; } .kab-list li em b { color: #ffd24a; font-size: 15px; opacity: 1; }
.kab-empty { padding: 22px 12px; text-align: center; opacity: .65; font-size: 13.5px; border-radius: 14px; background: rgba(0,0,0,.2); }


/* ===== shine: calm gold sheen on hero surfaces ===== */
@keyframes kabSheen { 0%, 60% { transform: translateX(-130%) skewX(-18deg); } 100% { transform: translateX(260%) skewX(-18deg); } }
@keyframes kabGlow { 0%, 100% { box-shadow: 0 0 0 0 rgba(255,200,90,0); } 50% { box-shadow: 0 0 20px 2px rgba(255,200,90,.3); } }
.kab-hero, .kab-share, .kab-ref { position: relative; overflow: hidden; }
.kab-hero::after, .kab-share::after, .kab-ref::after { content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 34%; pointer-events: none; background: linear-gradient(100deg, transparent, rgba(255,255,255,.22), transparent); transform: translateX(-130%) skewX(-18deg); animation: kabSheen 7s ease-in-out infinite; }
.kab-share::after { animation-duration: 4.6s; background: linear-gradient(100deg, transparent, rgba(255,244,200,.4), transparent); }
.kab-ava { animation: kabGlow 3.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .kab-hero::after, .kab-share::after, .kab-ref::after, .kab-ava { animation: none; } }

/* ---- v3: whole page locked (no drag), bigger / brighter / more transparent buttons, nickname in the clouds ---- */
html, body { overscroll-behavior: none; position: fixed; inset: 0; width: 100%; }
#hello { position: absolute; left: 0; right: 0; top: calc(var(--tg-in-top, 0px) + 9%); margin: 0; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 0; pointer-events: none; }
#hello small { font-size: 15px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: rgba(255,255,255,.95); text-shadow: 0 1px 6px rgba(70,110,170,.65); }
#hello b { max-width: 92%; font-size: clamp(30px, 9.5vw, 44px); line-height: 1.1; font-weight: 900; letter-spacing: .5px; color: #fff; text-shadow: 0 2px 0 rgba(70,110,170,.55), 0 4px 18px rgba(255,255,255,.75), 0 0 34px rgba(255,255,255,.55); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#buttons { margin-top: auto; gap: 12px; padding: 16px 12px calc(18px + max(env(safe-area-inset-bottom, 0px), var(--tg-in-bottom, 0px))); }
#buttons::before { background: linear-gradient(to bottom, transparent, rgba(5,5,10,.14) 60%, rgba(5,5,10,.2)); }
.btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 92px; padding: 12px 8px; border-radius: 22px; font-size: 21px; font-weight: 900; letter-spacing: .6px;
  color: #fff; border: 2.5px solid rgba(255,244,200,.92);
  background: linear-gradient(180deg, rgba(255,226,130,.42), rgba(255,138,40,.34));
  -webkit-backdrop-filter: blur(3px) saturate(1.3); backdrop-filter: blur(3px) saturate(1.3);
  box-shadow: 0 8px 26px rgba(255,160,40,.42), 0 0 22px rgba(255,220,120,.35), inset 0 2px 0 rgba(255,255,255,.55);
  text-shadow: 0 2px 6px rgba(120,50,0,.85), 0 0 12px rgba(120,50,0,.5); }
.btn .ic { font-size: 34px; line-height: 1; filter: drop-shadow(0 2px 6px rgba(0,0,0,.4)); }
.btn-main { flex: 1.2; background: linear-gradient(180deg, rgba(255,214,90,.5), rgba(255,110,30,.4)); }
.btn-alt { background: linear-gradient(180deg, rgba(150,225,255,.42), rgba(60,140,235,.34)); box-shadow: 0 8px 26px rgba(70,160,255,.42), 0 0 22px rgba(150,220,255,.35), inset 0 2px 0 rgba(255,255,255,.55); text-shadow: 0 2px 6px rgba(10,50,120,.85), 0 0 12px rgba(10,50,120,.5); }
.btn:active { transform: scale(.97); }

/* ---- v4: compact buttons (icon + text in one row), SVG icons ---- */
#buttons { gap: 10px; padding: 12px 14px calc(16px + max(env(safe-area-inset-bottom, 0px), var(--tg-in-bottom, 0px))); }
.btn { flex-direction: row; gap: 9px; min-height: 54px; padding: 8px 12px; border-radius: 18px; font-size: 17px; letter-spacing: .5px; border-width: 2px;
  box-shadow: 0 5px 16px rgba(255,160,40,.38), 0 0 14px rgba(255,220,120,.3), inset 0 2px 0 rgba(255,255,255,.5); }
.btn-main { flex: 1.15; }
.btn-alt { box-shadow: 0 5px 16px rgba(70,160,255,.38), 0 0 14px rgba(150,220,255,.3), inset 0 2px 0 rgba(255,255,255,.5); }
.btn .ic { display: inline-flex; width: 30px; height: 30px; font-size: 0; filter: drop-shadow(0 2px 4px rgba(0,0,0,.45)); }
.btn .ic svg { width: 30px; height: 30px; display: block; }
