:root {
  --sea: #0b3d5c;
  --sea2: #135f86;
  --sand: #f2c46d;
  --gold: #ffc531;
  --gold2: #e89a00;
  --red: #e2453c;
  --ink: #1d2733;
  --muted: #5d6b7a;
  --card: #fffaf0;
  --line: #ecdcbc;
  --ok: #2e9e55;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(#0b3d5c, #0a2a40);
  overscroll-behavior: none;
  user-select: none;
}
/* The VK desktop iframe has a fixed height and does not scroll the page, so only <main> scrolls. */
#app { max-width: 560px; margin: 0 auto; height: 100%; display: flex; flex-direction: column; }
main { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 8px 10px 16px; }
.hidden { display: none !important; }

.hud {
  flex-shrink: 0; z-index: 5; display: flex; gap: 6px; padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: rgba(8, 36, 56, .92); backdrop-filter: blur(6px);
}
.res {
  flex: 1; text-align: center; color: #fff; background: rgba(255,255,255,.1); border-radius: 12px;
  padding: 6px 4px; font-size: 14px; white-space: nowrap; position: relative;
}
.res b { font-size: 15px; }
.res small { display: block; font-size: 10px; opacity: .7; margin-top: -2px; min-height: 12px; }
.res.bump { animation: bump .4s; }
@keyframes bump { 50% { transform: scale(1.18); background: rgba(255,197,49,.45); } }

.tab { display: none; animation: fade .25s; }
.tab.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } }

.card { background: var(--card); border-radius: 18px; padding: 14px; margin: 10px 0; box-shadow: 0 6px 18px rgba(0,0,0,.18); }
.card.center { text-align: center; }
.title { font-weight: 700; font-size: 16px; margin-bottom: 4px; }
.title.big { font-size: 20px; }
.muted { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row.gap { gap: 10px; justify-content: flex-start; margin-top: 10px; }
.row.wrap { flex-wrap: wrap; }
.center-row { justify-content: center !important; }

.btn {
  border: 0; border-radius: 14px; padding: 10px 14px; font: inherit; font-weight: 700; cursor: pointer;
  background: var(--sea2); color: #fff; box-shadow: 0 3px 0 rgba(0,0,0,.25); transition: transform .08s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn.gold { background: linear-gradient(var(--gold), var(--gold2)); color: #3b2500; }
.btn.red { background: linear-gradient(#ff6a5c, var(--red)); }
.btn.ghost { background: transparent; color: var(--muted); box-shadow: none; width: 100%; margin-top: 6px; }
.btn.ok { background: var(--ok); }
.btn[disabled] { opacity: .5; }
.btn small { font-weight: 600; font-size: 12px; }

/* Island scene */
.scene { position: relative; height: 300px; border-radius: 22px; overflow: hidden; box-shadow: 0 10px 28px rgba(0,0,0,.35); }
.sky { position: absolute; inset: 0 0 45% 0; background: linear-gradient(#7fd3ff, #c9f0ff); }
.sun { position: absolute; right: 26px; top: 18px; width: 46px; height: 46px; border-radius: 50%; background: radial-gradient(#fff6b0, #ffd23f); box-shadow: 0 0 40px #ffe066; }
.cloud { position: absolute; width: 80px; height: 24px; background: #fff; border-radius: 20px; opacity: .9; animation: drift 40s linear infinite; }
.cloud::before { content: ""; position: absolute; width: 40px; height: 32px; background: #fff; border-radius: 50%; left: 14px; top: -14px; }
.cloud.c1 { top: 30px; left: -90px; }
.cloud.c2 { top: 70px; left: -90px; animation-delay: -22s; transform: scale(.7); }
@keyframes drift { to { left: 110%; } }
.sea { position: absolute; inset: 55% 0 0 0; background: linear-gradient(#1e9fd0, #0b5f8a); }
.wave { position: absolute; left: -50%; width: 200%; height: 14px; border-radius: 50%; background: rgba(255,255,255,.25); animation: wave 6s ease-in-out infinite; }
.w1 { top: 12px; } .w2 { top: 46px; animation-delay: -3s; opacity: .6; }
@keyframes wave { 50% { transform: translateX(10%); } }
.island { position: absolute; left: 0; right: 0; bottom: 18px; width: 100%; height: 190px; animation: bob 5s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.props { position: absolute; left: 0; right: 0; bottom: 18px; height: 190px; animation: bob 5s ease-in-out infinite; pointer-events: none; }
.prop { position: absolute; transform: translate(-50%, -100%); font-size: 34px; filter: drop-shadow(0 3px 2px rgba(0,0,0,.25)); }
.prop.new { animation: pop .6s; }
@keyframes pop { 0% { transform: translate(-50%, -100%) scale(0); } 70% { transform: translate(-50%, -100%) scale(1.3); } }
.prop.sail { animation: sail 8s ease-in-out infinite; }
@keyframes sail { 50% { margin-left: 12px; } }
.shield-dome { position: absolute; left: 6%; right: 6%; bottom: 30px; height: 220px; border-radius: 50% 50% 10% 10%; border: 3px solid rgba(120, 220, 255, .9); background: rgba(140, 220, 255, .18); box-shadow: inset 0 0 30px rgba(120,220,255,.6); pointer-events: none; animation: dome 2.5s ease-in-out infinite; }
@keyframes dome { 50% { opacity: .6; } }

.chest {
  position: absolute; right: 10px; bottom: 10px; border: 0; background: rgba(255,250,240,.95);
  border-radius: 18px; padding: 6px 10px 8px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  box-shadow: 0 6px 14px rgba(0,0,0,.3); cursor: pointer; min-width: 104px;
}
.chest-icon { font-size: 34px; line-height: 1; }
.chest.full .chest-icon { animation: shake 1s infinite; }
@keyframes shake { 10%, 30% { transform: rotate(-8deg); } 20%, 40% { transform: rotate(8deg); } 50% { transform: none; } }
.chest-bar { width: 84px; height: 8px; border-radius: 6px; background: #e6d3ad; overflow: hidden; }
.chest-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--gold2)); transition: width .5s; }
.chest-label { font-weight: 800; font-size: 14px; }
.coin { position: fixed; z-index: 50; font-size: 22px; pointer-events: none; transition: transform .8s cubic-bezier(.3,-0.4,.7,1), opacity .8s; }

.progress { margin-top: 10px; height: 8px; background: #eadbb9; border-radius: 6px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #4fc3f7, #1e88e5); transition: width .5s; }

.events .ev { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; align-items: center; }
.events .ev:first-of-type { border-top: 0; }
.events .ev .btn { padding: 6px 10px; font-size: 13px; }
.invite-cta { background: linear-gradient(135deg, #fff3cf, #ffe2a1); }

/* Raid */
.target { margin: 14px auto 4px; padding: 12px; border-radius: 16px; background: #f4e7c8; max-width: 320px; animation: fade .3s; }
.target .avatar { width: 64px; height: 64px; border-radius: 50%; display: block; margin: 0 auto 6px; background: #d9c39a; font-size: 40px; line-height: 64px; object-fit: cover; }
.target .name { font-weight: 700; font-size: 17px; }
.raid-result { min-height: 28px; margin-top: 10px; font-weight: 800; font-size: 18px; }
.raid-result.win { color: var(--ok); animation: bump .5s; }
.raid-result.lose { color: var(--red); }
.cannon { display: inline-block; animation: boom .6s; }
@keyframes boom { 30% { transform: scale(1.6) rotate(-10deg); } }

/* Map */
.map { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px auto; max-width: 320px; padding: 12px; border-radius: 16px;
  background: repeating-linear-gradient(45deg, #ecd7a4 0 10px, #e6cf97 10px 20px); border: 3px dashed #b88b47; }
.cell { aspect-ratio: 1; border: 0; border-radius: 12px; background: #d7b878; font-size: 30px; cursor: pointer; box-shadow: inset 0 -4px 0 rgba(0,0,0,.15); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; }
.cell small { font-size: 11px; }
.cell.dug { background: #b8955a; cursor: default; box-shadow: inset 0 4px 6px rgba(0,0,0,.25); }
.cell.jackpot { background: linear-gradient(var(--gold), var(--gold2)); animation: bump .6s; }

/* Tasks / shop / top */
.item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item .ic { font-size: 28px; width: 40px; text-align: center; }
.item .info { flex: 1; min-width: 0; }
.item .info b { display: block; }
.item .btn { white-space: nowrap; }
.item.done { opacity: .55; }
.item.hot { background: linear-gradient(90deg, #fff1c2, transparent); border-radius: 12px; padding-left: 6px; }
.streak { display: flex; gap: 6px; margin-top: 10px; }
.streak span { flex: 1; text-align: center; padding: 8px 0; border-radius: 10px; background: #efe2c4; font-weight: 700; font-size: 13px; }
.streak span.on { background: linear-gradient(var(--gold), var(--gold2)); }
.top-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.top-row .pos { width: 26px; font-weight: 800; text-align: center; }
.top-row img, .top-row .ph { width: 36px; height: 36px; border-radius: 50%; background: #d9c39a; object-fit: cover; text-align: center; line-height: 36px; }
.top-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-row.me { background: #fff1c2; border-radius: 10px; }
.dot { position: absolute; top: 4px; right: 18%; width: 8px; height: 8px; border-radius: 50%; background: var(--red); }

.tabs {
  flex-shrink: 0; width: 100%; z-index: 6;
  display: flex; background: #fffaf0; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs button { position: relative; flex: 1; border: 0; background: none; padding: 6px 0 8px; font: inherit; font-size: 11px; color: var(--muted); cursor: pointer; }
.tabs button span { display: block; font-size: 22px; filter: grayscale(.7); }
.tabs button.active { color: var(--sea); font-weight: 700; }
.tabs button.active span { filter: none; transform: scale(1.1); }

.modal { position: fixed; inset: 0; z-index: 40; background: rgba(5, 20, 32, .6); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.modal-box { width: 100%; max-width: 560px; background: var(--card); border-radius: 22px 22px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom)); text-align: center; }
.modal-box .big-ic { font-size: 64px; }
.modal-box h2 { margin: 6px 0; }
.modal-box p { color: var(--muted); }
.modal-box input { width: 100%; font: inherit; padding: 12px; border-radius: 12px; border: 2px solid var(--line); margin: 8px 0; user-select: text; }
.modal-box .btn { margin-top: 6px; }
.modal-box .btn.wide { width: 100%; padding: 14px; font-size: 16px; }

.toasts { position: fixed; top: 64px; left: 0; right: 0; z-index: 60; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; }
.toast { background: rgba(20, 30, 40, .92); color: #fff; padding: 10px 14px; border-radius: 14px; font-weight: 600; max-width: 90%; animation: fade .2s; text-align: center; }
.toast.err { background: rgba(190, 40, 30, .95); }
.loader { position: fixed; inset: 0; z-index: 100; background: var(--sea); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; font-weight: 700; }
.loader .ship { font-size: 64px; animation: bob 1.4s ease-in-out infinite; }

/* Short windows (VK desktop iframe is about 700px): fit every tab without scrolling. */
@media (max-height: 860px) {
  main { padding: 6px 10px 8px; }
  .hud { padding: 6px 10px; }
  .res { padding: 4px; }
  .card { padding: 10px 12px; margin: 6px 0; border-radius: 14px; }
  .title.big { font-size: 17px; }
  .scene { height: clamp(150px, calc(100vh - 470px), 300px); }
  .island, .props { height: 75%; bottom: 8px; }
  .shield-dome { height: 80%; }
  .chest { padding: 4px 8px 6px; }
  .chest-icon { font-size: 26px; }
  .prop { font-size: 28px; }
  .progress { margin-top: 6px; }
  .events .ev { padding: 4px 0; font-size: 13px; }
  .row.gap { margin-top: 6px; }
  .item { padding: 5px 0; }
  .item .ic { font-size: 22px; width: 32px; }
  .item .btn { padding: 7px 10px; }
  .item .muted { font-size: 12px; }
  .map { gap: 6px; margin: 8px auto; max-width: 250px; padding: 8px; }
  .cell { font-size: 24px; }
  .target { margin: 8px auto 2px; padding: 8px; }
  .target .avatar { width: 48px; height: 48px; line-height: 48px; font-size: 30px; }
  .raid-result { margin-top: 6px; min-height: 22px; }
  .streak { margin-top: 6px; }
  .streak span { padding: 5px 0; }
  .top-row { padding: 4px 0; }
  .tabs button { padding: 4px 0 6px; }
  .tabs button span { font-size: 19px; }
}
@media (max-height: 860px) and (min-width: 480px) {
  #tasks { display: grid; grid-template-columns: 1fr 1fr; column-gap: 12px; }
  #tasks .item:nth-child(2) { border-top: 0; }
}
@media (max-height: 860px) and (max-width: 479px) {
  .streak-card { display: none; }
}
@media (max-height: 640px) {
  .streak-card { display: none; }
}
