:root {
  /* game theme (Arrow Escape = purple) + RATSOFT standard roles: gold primary, cyan accent, glass panels */
  --bg1: #2e1a73; --bg2: #0c0726; --panel: rgba(30,18,78,.94); --line: rgba(255,255,255,.1); --btn: #3a2a8a; --btn-edge: #20145a;
  --ink: #f2f5ff; --dim: #b9b0e8; --accent: #ffd34d; --accent-2: #5ee6ff;
  --purple: #8f7dff; --blue: #4da3ff; --yellow: #ffd34d; --coral: #ff5e7a; --mint: #5ee6ff; --pink: #ff4fae; --green: #7dff8a;
  --logo-grad: linear-gradient(90deg, #fff27a, #ff8a5c, #ff4fae, #8f7dff);
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg2); color: var(--ink);
  user-select: none; -webkit-user-select: none; touch-action: manipulation; overscroll-behavior: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; }
.hidden { display: none !important; }
#safe { position: fixed; visibility: hidden; pointer-events: none; padding: var(--st) 0 var(--sb) 0; }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; right: 0; top: 0; padding: calc(var(--st) + 10px) 14px 0; pointer-events: none; z-index: 2; }
#hud .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; max-width: 560px; margin: 0 auto; }
#hud .row.sub { margin-top: 8px; }
#hud button, #hud .coins { pointer-events: auto; }
.icon { width: 46px; height: 46px; border-radius: 12px; background: rgba(255,255,255,.1); border: 1px solid var(--line); display: grid; place-items: center; }
.icon:active { transform: scale(.92); }
.ico-pause { width: 16px; height: 18px; border-left: 6px solid #fff; border-right: 6px solid #fff; }
.lvl { text-align: center; }
#lvlNum { font-weight: 900; font-size: 22px; letter-spacing: .06em; text-shadow: 0 0 14px rgba(94,230,255,.5); }
#lvlTier { font-size: 12px; color: var(--dim); font-weight: 700; margin-top: 1px; }
.coins { min-width: 46px; height: 38px; padding: 0 12px 0 6px; border-radius: 19px; background: rgba(12,7,38,.6); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: 17px; }
.coin { width: 24px; height: 24px; border-radius: 50%; display: inline-block; flex: none;
  background: radial-gradient(circle at 35% 30%, #fff6c4, #ffd34d 45%, #c98f00); box-shadow: inset 0 -2px 0 rgba(0,0,0,.2); }
.coin.sm { width: 16px; height: 16px; vertical-align: -3px; margin: 0 2px; }
.score, .left { display: flex; flex-direction: column; min-width: 70px; }
.left { text-align: right; }
.score small, .left small { font-size: 10px; letter-spacing: .12em; color: var(--dim); font-weight: 800; }
.score span, .left span { font-size: 20px; font-weight: 900; }
.score span { color: var(--accent); }
.hearts { display: flex; gap: 6px; }
.hearts i { width: 22px; height: 20px; display: block; background: var(--coral);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.5S1 14.6 1 7.4C1 3.8 3.8 1 7.2 1c2 0 3.8 1 4.8 2.6C13 2 14.8 1 16.8 1 20.2 1 23 3.8 23 7.4c0 7.2-11 14.1-11 14.1z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 21.5S1 14.6 1 7.4C1 3.8 3.8 1 7.2 1c2 0 3.8 1 4.8 2.6C13 2 14.8 1 16.8 1 20.2 1 23 3.8 23 7.4c0 7.2-11 14.1-11 14.1z'/%3E%3C/svg%3E") center/contain no-repeat; }
.hearts i.off { background: rgba(255,255,255,.18); }

#boardArea { position: fixed; left: 12px; right: 12px; top: calc(var(--st) + 122px); bottom: calc(var(--sb) + 104px); pointer-events: none; }

/* ---------- bottom tool bar (one-handed reach) ---------- */
#bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 0 14px calc(var(--sb) + 14px); display: flex; justify-content: center; gap: 12px; z-index: 2; }
.tool { position: relative; width: 92px; height: 74px; border-radius: 16px; background: var(--panel); border: 1px solid var(--line); transition: transform .08s, filter .15s;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 13px; }
.tool b { font-weight: 800; }
.tool.main { background: linear-gradient(180deg, #ffe07a, #ffc21f); color: #1b1b1b; border: 0; box-shadow: 0 4px 0 #b88a00; animation: readyPulse 1.6s ease-in-out infinite; }
.tool:active { transform: translateY(2px) scale(.96); }
.tool i { position: absolute; top: -6px; right: -6px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: var(--coral); color: #fff; font-style: normal; font-weight: 900; font-size: 13px; display: grid; place-items: center; box-shadow: 0 2px 0 rgba(0,0,0,.25); }
.tool i.plus { background: var(--accent-2); color: #06222b; }
.ico-undo, .ico-restart, .ico-bulb { width: 26px; height: 26px; display: block; background: currentColor; }
.ico-undo { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 4 3 9.5 9 15v-4h6a4 4 0 0 1 0 8h-3v3h3a7 7 0 0 0 0-14H9z'/%3E%3C/svg%3E") center/contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 4 3 9.5 9 15v-4h6a4 4 0 0 1 0 8h-3v3h3a7 7 0 0 0 0-14H9z'/%3E%3C/svg%3E") center/contain no-repeat; }
.ico-restart { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3a9 9 0 1 0 9 9h-3a6 6 0 1 1-1.8-4.3L13 11h8V3l-2.7 2.7A9 9 0 0 0 12 3z'/%3E%3C/svg%3E") center/contain no-repeat;
               mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 3a9 9 0 1 0 9 9h-3a6 6 0 1 1-1.8-4.3L13 11h8V3l-2.7 2.7A9 9 0 0 0 12 3z'/%3E%3C/svg%3E") center/contain no-repeat; }
.ico-bulb { -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a7 7 0 0 0-4 12.7V17h8v-2.3A7 7 0 0 0 12 2zM9 19h6v1.5a1.5 1.5 0 0 1-1.5 1.5h-3A1.5 1.5 0 0 1 9 20.5z'/%3E%3C/svg%3E") center/contain no-repeat;
            mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2a7 7 0 0 0-4 12.7V17h8v-2.3A7 7 0 0 0 12 2zM9 19h6v1.5a1.5 1.5 0 0 1-1.5 1.5h-3A1.5 1.5 0 0 1 9 20.5z'/%3E%3C/svg%3E") center/contain no-repeat; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(var(--st) + 24px) 20px calc(var(--sb) + 24px); text-align: center; }
.screen.modal { background: rgba(6,3,20,.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 24px 20px 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); display: flex; flex-direction: column; gap: 12px; position: relative; overflow: hidden; }
.card h2 { margin: 0; font-size: 30px; font-weight: 900; color: var(--accent); text-shadow: 0 0 18px rgba(255,211,77,.6); }
.sub { margin: -4px 0 4px; color: var(--dim); font-weight: 700; }
.big { height: 60px; border-radius: 14px; font-size: 22px; font-weight: 900; letter-spacing: .06em; color: #1b1b1b;
  background: linear-gradient(180deg, #ffe07a, #ffc21f); box-shadow: 0 4px 0 #b88a00; transition: transform .08s, filter .15s; }
.big:active { transform: translateY(2px) scale(.97); box-shadow: 0 2px 0 #b88a00; }
.big.alt { background: var(--btn); color: var(--ink); box-shadow: 0 4px 0 var(--btn-edge); }
.ad { height: 50px; border-radius: 14px; font-weight: 800; font-size: 16px; color: #06222b; background: linear-gradient(180deg, #9cf1ff, #5ee6ff); box-shadow: 0 4px 0 #1592b0; transition: transform .08s; }
.ad:active, .ghost:active, .pill:active, .tool:active { transform: scale(.96); }
.ad.big { height: 58px; font-size: 19px; }
.ad[disabled], .ghost[disabled] { opacity: .45; }
.ghost { height: 46px; border-radius: 12px; background: var(--btn); font-weight: 700; transition: transform .08s, filter .15s; }
.pill { height: 40px; padding: 0 18px; border-radius: 20px; background: rgba(255,255,255,.1); font-weight: 800; color: var(--dim); }
.pill.on { background: rgba(94,230,255,.18); color: var(--accent-2); }
.pill::before { content: '○ '; } .pill.on::before { content: '● '; }
.toggles { display: flex; gap: 10px; justify-content: center; }

/* menu */
#menu { gap: 22px; }
.logo h1 { margin: 6px 0 0; font-size: clamp(44px, 14vw, 64px); line-height: .95; font-weight: 900; letter-spacing: .04em;
  color: #e9f6ff; text-shadow: 0 0 16px rgba(94,230,255,.7); animation: logoGlow 2.4s ease-in-out infinite alternate; }
.logo h1 span { display: block; background: var(--logo-grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo .by { margin: 10px 0 0; color: var(--dim); font-weight: 800; letter-spacing: .4em; font-size: 12px; }
.logo-arrows { display: flex; gap: 10px; justify-content: center; height: 54px; align-items: center; }
.logo-arrows { animation: shipBob 2.4s ease-in-out infinite; }
.logo-arrows i { width: 46px; height: 46px; border-radius: 12px; display: block; position: relative; box-shadow: 0 0 18px currentColor; }
.logo-arrows i::after { content: ''; position: absolute; inset: 10px; background: #fff;
  clip-path: polygon(50% 0, 100% 55%, 68% 55%, 68% 100%, 32% 100%, 32% 55%, 0 55%); }
.logo-arrows .a1 { background: var(--pink); color: rgba(255,79,174,.55); transform: rotate(-90deg); }
.logo-arrows .a2 { background: var(--accent); color: rgba(255,211,77,.55); transform: translateY(-8px); }
.logo-arrows .a2::after { background: #1b1b1b; }
.logo-arrows .a3 { background: var(--accent-2); color: rgba(94,230,255,.55); transform: rotate(90deg); }
#btnPlay { width: min(300px, 80vw); height: 84px; font-size: 32px; letter-spacing: .25em; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1; }
#btnPlay small { font-size: 14px; font-weight: 800; opacity: .85; margin-top: 6px; letter-spacing: .08em; }
.stats { display: flex; gap: 10px; }
.stats div { width: 98px; padding: 10px 6px; border-radius: 14px; background: rgba(12,7,38,.55); border: 1px solid var(--line); }
.stats b { color: var(--accent-2); }
.stats b { display: block; font-size: 22px; font-weight: 900; }
.stats small { font-size: 11px; color: var(--dim); font-weight: 700; }
.tagline { color: var(--dim); font-size: 13px; font-weight: 700; margin: 0; }

/* complete */
.win .burst { position: absolute; left: 50%; top: -120px; width: 360px; height: 360px; margin-left: -180px; pointer-events: none;
  background: repeating-conic-gradient(from 0deg, rgba(255,211,77,.16) 0 10deg, transparent 10deg 20deg);
  border-radius: 50%; animation: spin 14s linear infinite; mask: radial-gradient(circle, #000 30%, transparent 70%); -webkit-mask: radial-gradient(circle, #000 30%, transparent 70%); }
@keyframes spin { to { transform: rotate(360deg); } }
.tally { display: flex; gap: 10px; }
.tally div { flex: 1; background: rgba(12,7,38,.5); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.tally small { display: block; color: var(--dim); font-weight: 800; font-size: 12px; }
.tally b { font-size: 30px; font-weight: 1000; }
#cmpCoins { color: var(--yellow); }
.bonus { margin: 0; color: var(--green); font-weight: 800; min-height: 1.2em; }

#toast { position: fixed; left: 50%; bottom: calc(var(--sb) + 110px); transform: translateX(-50%); z-index: 9; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line); padding: 12px 18px; border-radius: 12px; font-weight: 800; opacity: 0; max-width: 86vw; text-align: center; }

@media (min-width: 700px) { .tool { width: 104px; } }
.legal { margin-top: 10px; font-size: 12px; color: var(--dim); text-decoration: underline; opacity: .8; }

/* ---------- RATSOFT motion vocabulary (same as Star Drift) ---------- */
#menu:not(.hidden) > * { animation: menuIn .5s cubic-bezier(.2,1.2,.4,1) both; }
#menu:not(.hidden) > *:nth-child(2) { animation-delay: .06s; } #menu:not(.hidden) > *:nth-child(3) { animation-delay: .12s; }
#menu:not(.hidden) > *:nth-child(4) { animation-delay: .18s; } #menu:not(.hidden) > *:nth-child(5) { animation-delay: .24s; }
#menu:not(.hidden) > *:nth-child(6) { animation-delay: .3s; }
#menu:not(.hidden) > #btnPlay { animation: menuIn .5s cubic-bezier(.2,1.2,.4,1) .06s both, playPulse 1.6s ease-in-out .6s infinite; }
@keyframes menuIn { from { transform: translateY(24px); opacity: 0; } }
@keyframes logoGlow { to { text-shadow: 0 0 26px rgba(94,230,255,1), 0 0 70px rgba(143,125,255,.7); } }
@keyframes shipBob { 50% { transform: translateY(-8px); } }
@keyframes playPulse { 50% { box-shadow: 0 4px 0 #b88a00, 0 0 34px rgba(255,211,77,.75); transform: scale(1.02); } }
@keyframes readyPulse { 0%, 100% { box-shadow: 0 4px 0 #b88a00, 0 0 0 0 rgba(255,211,77,.6); } 50% { box-shadow: 0 4px 0 #b88a00, 0 0 20px 4px rgba(255,211,77,.5); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; } }
