:root {
  --ink: #2a1d12;
  --paper: #fff8ea;
  --panel: #2b2238;
  --panel2: #3a2f4b;
  --gold: #ffcf3a;
  --accent: #ff5d73;
  --sky: #5ad1ff;
  --ok: #5bd17a;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1f2a3a; color: var(--paper); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; }
#app { position: fixed; inset: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
button { font-family: inherit; cursor: pointer; border: 0; color: inherit; }
[hidden] { display: none !important; }

/* HUD */
#hud { position: absolute; top: 8px; left: 8px; display: flex; gap: 8px; align-items: center; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
.pill { display: flex; align-items: center; gap: 6px; background: rgba(30,22,40,0.72); border: 2px solid rgba(255,255,255,0.15); padding: 4px 12px 4px 8px; border-radius: 999px; font-weight: 800; font-size: 18px; backdrop-filter: blur(4px); box-shadow: 0 3px 0 rgba(0,0,0,0.25); min-width: 70px; }
.pill .lbl { font-size: 12px; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.06em; margin-left: 4px; }
.ico { width: 20px; height: 20px; }
.heart path { fill: #ff4d6d; stroke: #8f1730; stroke-width: 1.2; }
.coin circle { fill: #ffcf3a; stroke: #a6720b; stroke-width: 1.5; }
.coin text { font: 900 12px var(--font); fill: #8a5a00; }
.pill.bump { animation: bump 0.25s ease-out; }
@keyframes bump { 40% { transform: scale(1.15); } }
.pill.hurt { animation: hurt 0.4s ease-out; }
@keyframes hurt { 30% { background: rgba(200,30,50,0.9); transform: translateX(-3px); } 60% { transform: translateX(3px); } }
.spacer { width: 4px; }
.hbtn { background: rgba(30,22,40,0.72); border: 2px solid rgba(255,255,255,0.15); border-radius: 12px; padding: 6px 10px; font-weight: 800; font-size: 13px; }
.hbtn.on { background: var(--ok); color: #0e2a16; border-color: rgba(255,255,255,0.4); }
.hbtn.off { opacity: 0.55; text-decoration: line-through; }

/* Side panel */
#panel { position: absolute; display: flex; flex-direction: column; gap: 8px; padding: 10px; background: linear-gradient(180deg, #34284a, #251c33); border-left: 3px solid rgba(255,255,255,0.08); box-shadow: -6px 0 18px rgba(0,0,0,0.35); z-index: 4; }
body.landscape #panel { top: 0; right: 0; bottom: 0; }
body.portrait #panel { left: 0; right: 0; bottom: 0; border-left: 0; border-top: 3px solid rgba(255,255,255,0.08); padding: 8px; gap: 6px; }
.ptitle { font-weight: 900; font-size: 14px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; margin: 2px 2px 6px; }
body.portrait .ptitle { display: none; }
#shop { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
body.portrait #cards { grid-template-columns: repeat(6, 1fr); gap: 5px; }
.card { position: relative; display: flex; flex-direction: column; align-items: center; padding: 6px 4px 5px; background: linear-gradient(180deg, #4a3d61, #3a2f4c); border: 2px solid rgba(255,255,255,0.12); border-radius: 14px; box-shadow: 0 3px 0 rgba(0,0,0,0.3); transition: transform 0.08s, border-color 0.1s; touch-action: none; }
.card:hover { transform: translateY(-2px); border-color: rgba(255,255,255,0.35); }
.card.sel { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(255,207,58,0.4), 0 3px 0 rgba(0,0,0,0.3); }
.card.poor { filter: saturate(0.4) brightness(0.8); }
.card.poor .price { color: #ff8a8a; }
.card.banned { opacity: 0.35; pointer-events: none; }
.card canvas { width: 56px; height: 56px; }
body.portrait .card canvas { width: 40px; height: 40px; }
.card .nm { font-size: 11px; font-weight: 800; text-align: center; line-height: 1.1; opacity: 0.9; min-height: 24px; display: flex; align-items: center; }
body.portrait .card .nm { display: none; }
.card .price { font-weight: 900; font-size: 14px; color: var(--gold); }
.card .key { position: absolute; top: 4px; left: 6px; font-size: 10px; font-weight: 900; opacity: 0.5; }
.card.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.tip { font-size: 12px; opacity: 0.75; margin-top: 10px; line-height: 1.35; min-height: 48px; }
body.portrait .tip { display: none; }
.go { padding: 14px 10px; font-size: 18px; font-weight: 900; border-radius: 16px; background: linear-gradient(180deg, #6fe08c, #2fa856); color: #0b2a14; box-shadow: 0 4px 0 #1d6b36, 0 6px 14px rgba(0,0,0,0.3); text-shadow: 0 1px 0 rgba(255,255,255,0.4); }
.go:active { transform: translateY(3px); box-shadow: 0 1px 0 #1d6b36; }
.go.ff { background: linear-gradient(180deg, #ffd86b, #f0a51e); color: #3a2400; box-shadow: 0 4px 0 #9a5f00, 0 6px 14px rgba(0,0,0,0.3); }
body.portrait .go { padding: 9px; font-size: 15px; }

/* Selected tower info */
#info { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; touch-action: pan-y; }
.ihead { display: flex; align-items: center; gap: 8px; }
.ihead canvas { width: 48px; height: 48px; flex: none; }
.ihead .t { font-weight: 900; font-size: 15px; line-height: 1.1; }
.ihead .s { font-size: 11px; opacity: 0.7; }
.ihead .x { margin-left: auto; width: 30px; height: 30px; border-radius: 10px; background: rgba(255,255,255,0.1); font-weight: 900; flex: none; }
.irow { display: flex; gap: 6px; }
.irow button { flex: 1; padding: 7px 6px; border-radius: 10px; font-weight: 800; font-size: 12px; background: rgba(255,255,255,0.1); border: 2px solid rgba(255,255,255,0.12); }
.irow .sell { background: rgba(255,93,115,0.2); border-color: rgba(255,93,115,0.5); }
.paths { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
body.portrait .paths { grid-template-columns: 1fr 1fr; }
.path { display: flex; flex-direction: column; gap: 4px; background: rgba(0,0,0,0.2); border-radius: 12px; padding: 6px; }
.pips { display: flex; gap: 4px; justify-content: center; }
.pip { width: 14px; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.15); }
.p0 .pip.on { background: var(--gold); }
.p1 .pip.on { background: var(--sky); }
.up { text-align: left; padding: 6px; border-radius: 10px; background: linear-gradient(180deg, #5d4f78, #43375a); border: 2px solid rgba(255,255,255,0.15); min-height: 76px; display: flex; flex-direction: column; gap: 2px; }
.up .n { font-weight: 900; font-size: 12px; line-height: 1.1; }
.up .d { font-size: 10.5px; opacity: 0.8; line-height: 1.2; flex: 1; }
.up .c { font-weight: 900; color: var(--gold); font-size: 13px; }
.up.poor .c { color: #ff8a8a; }
.up.poor { opacity: 0.75; }
.up.locked { opacity: 0.4; pointer-events: none; }
.up:not(.poor):not(.locked):hover { border-color: var(--gold); }
.up .k { font-size: 9px; opacity: 0.5; float: right; }
body.portrait #info { flex-direction: row; flex-wrap: wrap; overflow-y: auto; }
body.portrait .ihead, body.portrait .irow { width: 100%; }
body.portrait .paths { width: 100%; }
body.portrait .up { min-height: 0; }

/* Screens */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 10; padding: 16px; overflow-y: auto; touch-action: pan-y; }
.screen:empty { display: none; }
.screen.dim { background: radial-gradient(ellipse at center, rgba(20,14,30,0.55), rgba(10,6,18,0.85)); backdrop-filter: blur(3px); }
.box { background: linear-gradient(180deg, rgba(58,45,80,0.95), rgba(36,27,52,0.97)); border: 3px solid rgba(255,255,255,0.14); border-radius: 26px; padding: 22px 24px; max-width: 760px; width: 100%; box-shadow: 0 18px 50px rgba(0,0,0,0.5); text-align: center; animation: pop 0.35s cubic-bezier(.2,1.4,.4,1); margin: auto; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } }
.logo { font-size: clamp(40px, 8vw, 78px); font-weight: 900; line-height: 0.95; letter-spacing: -0.02em; margin: 4px 0 6px; background: linear-gradient(180deg, #fff3b0 0%, #ffcf3a 45%, #ff7a45 100%); -webkit-background-clip: text; background-clip: text; color: transparent; filter: drop-shadow(0 4px 0 #7a2d14) drop-shadow(0 10px 18px rgba(0,0,0,0.45)); }
.sub { opacity: 0.85; font-size: 15px; margin-bottom: 14px; }
.hello { color: var(--gold); font-weight: 800; margin-bottom: 8px; }
.btn { display: inline-block; padding: 13px 26px; margin: 6px; border-radius: 16px; font-size: 18px; font-weight: 900; background: linear-gradient(180deg, #6fe08c, #2fa856); color: #0b2a14; box-shadow: 0 4px 0 #1d6b36, 0 8px 18px rgba(0,0,0,0.3); }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #1d6b36; }
.btn.alt { background: linear-gradient(180deg, #8e7bb3, #614f86); color: #fff; box-shadow: 0 4px 0 #3b2f55, 0 8px 18px rgba(0,0,0,0.3); }
.btn.gold { background: linear-gradient(180deg, #ffe17a, #f0a51e); color: #3a2400; box-shadow: 0 4px 0 #9a5f00, 0 8px 18px rgba(0,0,0,0.3); }
.btn.big { font-size: 24px; padding: 16px 44px; }
.how { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; text-align: left; margin-top: 14px; font-size: 13.5px; line-height: 1.45; }
.how h3 { margin: 0 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--gold); }
.how ul { margin: 0; padding-left: 18px; }
kbd { display: inline-block; padding: 0 5px; border-radius: 5px; background: rgba(255,255,255,0.14); border-bottom: 2px solid rgba(0,0,0,0.3); font: 800 11.5px var(--font); }
.maps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 12px 0; }
.map { background: rgba(0,0,0,0.25); border-radius: 18px; padding: 8px; border: 3px solid transparent; text-align: center; transition: transform 0.1s; }
.map:hover { transform: translateY(-3px); border-color: rgba(255,255,255,0.3); }
.map canvas { width: 100%; aspect-ratio: 3 / 2; border-radius: 12px; display: block; }
.map .mn { font-weight: 900; font-size: 16px; margin-top: 6px; }
.map .md { font-size: 12px; opacity: 0.75; }
.medals { display: flex; justify-content: center; gap: 4px; margin-top: 4px; font-size: 11px; }
.medal { padding: 1px 6px; border-radius: 6px; background: rgba(255,255,255,0.08); opacity: 0.6; }
.medal.easy.got { background: #c9824a; color: #2a1405; opacity: 1; }
.medal.normal.got { background: #d6dde8; color: #1d2430; opacity: 1; }
.medal.hard.got { background: #ffcf3a; color: #3a2400; opacity: 1; }
.seg { display: inline-flex; background: rgba(0,0,0,0.3); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { padding: 8px 16px; border-radius: 10px; font-weight: 900; font-size: 14px; background: transparent; }
.seg button.on { background: var(--gold); color: #3a2400; }
.daily { margin-top: 10px; display: flex; align-items: center; gap: 12px; text-align: left; background: linear-gradient(90deg, rgba(255,207,58,0.18), rgba(255,93,115,0.12)); border: 2px dashed rgba(255,207,58,0.5); border-radius: 16px; padding: 10px 14px; }
.daily .dt { font-weight: 900; color: var(--gold); }
.daily .dd { font-size: 12.5px; opacity: 0.85; }
.daily .btn { margin-left: auto; font-size: 15px; padding: 10px 18px; }
.stats { display: flex; justify-content: center; gap: 12px; margin: 12px 0 14px; flex-wrap: wrap; }
.stat { background: rgba(0,0,0,0.25); border-radius: 14px; padding: 8px 16px; min-width: 100px; }
.stat b { display: block; font-size: 26px; color: var(--gold); }
.stat span { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.7; }
.newbest { display: inline-block; background: var(--accent); color: #fff; font-weight: 900; padding: 3px 12px; border-radius: 999px; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }
.end-title { font-size: clamp(32px, 6vw, 54px); font-weight: 900; margin: 0; }
.end-title.win { color: var(--gold); text-shadow: 0 4px 0 #7a4a00; }
.end-title.lose { color: #ff7a8a; text-shadow: 0 4px 0 #5a1020; }
.leave { position: absolute; top: 12px; right: 12px; }

/* Toasts */
#toasts { position: absolute; left: 0; right: 0; top: 56px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 8; }
.toast { background: rgba(30,22,40,0.88); border: 2px solid rgba(255,255,255,0.18); border-radius: 14px; padding: 8px 16px; font-weight: 800; font-size: 15px; animation: tin 0.3s ease-out, tout 0.4s ease-in 2.6s forwards; box-shadow: 0 6px 16px rgba(0,0,0,0.35); max-width: 90vw; text-align: center; }
.toast.warn { border-color: #ff8a3a; }
.toast.good { border-color: var(--ok); }
@keyframes tin { from { transform: translateY(-14px); opacity: 0; } }
@keyframes tout { to { transform: translateY(-10px); opacity: 0; } }

@media (max-width: 700px) {
  .how { grid-template-columns: 1fr; }
  .maps { grid-template-columns: 1fr; }
  .map canvas { aspect-ratio: 3 / 1.4; object-fit: cover; }
  .box { padding: 16px; }
  .pill { font-size: 15px; min-width: 0; padding: 3px 10px 3px 6px; }
  .pill .lbl { display: none; }
  .daily { flex-wrap: wrap; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
@media (max-width: 520px) {
  #hud { right: 6px; left: 6px; gap: 5px; top: 6px; }
  .hbtn { padding: 5px 7px; font-size: 11px; border-radius: 10px; }
  .pill { font-size: 14px; padding: 3px 8px 3px 5px; gap: 4px; }
  .ico { width: 16px; height: 16px; }
  .spacer { flex: 1; }
}
