/* =========================================================
   ARROWS ESCAPE – minimal UI styles
   ========================================================= */
:root {
  --bg: #ffffff; --navy: #11132f; --navy2: #191b3d; --dot: #d9dcef; --blue: #5d70ff; --lblue: #cdd4f7;
  --red: #ff4d65; --text: #171831; --text2: #69708e; --track: #f1f2f9; --btn: #d3d8f8;
  --font: "Poppins", "Nunito", "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; overflow: hidden; background: var(--bg); overscroll-behavior: none; }
body { font-family: var(--font); color: var(--text); user-select: none; -webkit-user-select: none; touch-action: manipulation; display: flex; justify-content: center; }
button { font-family: inherit; border: 0; background: none; cursor: pointer; color: inherit; }
img { pointer-events: none; -webkit-user-drag: none; }
.hidden { display: none !important; }

/* centered mobile column on desktop, full screen on phones */
#app { position: relative; width: 100%; max-width: 480px; height: 100%; overflow: hidden; background: var(--bg); }
@media (min-width: 700px) { #app { box-shadow: 0 0 0 1px #f0f1f8, 0 20px 60px rgba(30, 36, 90, 0.06); } }

.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; } }

/* ---------- logo ---------- */
.logo { display: flex; align-items: flex-end; gap: 2px; color: #2e3470; font-weight: 800; letter-spacing: -0.01em; }
.logo .logo-a { width: 40px; height: 40px; margin-bottom: 4px; }
.logo span { font-size: 46px; line-height: 1; }
.logo.big .logo-a { width: 52px; height: 52px; margin-bottom: 5px; }
.logo.big span { font-size: 60px; }

/* ---------- buttons ---------- */
.btn { min-height: 52px; padding: 0 24px; border-radius: 999px; font-size: 18px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px; transition: transform 0.12s, box-shadow 0.12s, filter 0.12s; width: 100%; }
.btn:active { transform: scale(0.97); }
.btn img { width: 20px; height: 20px; }
.btn img.inv { filter: brightness(0) invert(1); }
.btn-play { background: var(--blue); color: #fff; font-size: 26px; min-height: 68px; box-shadow: 0 8px 24px rgba(93, 112, 255, 0.28); }
.btn-play:active { box-shadow: 0 3px 10px rgba(93, 112, 255, 0.3); }
.btn-blue { background: var(--blue); color: #fff; box-shadow: 0 6px 18px rgba(93, 112, 255, 0.25); }
.btn-red { background: var(--red); color: #fff; }
.btn-ghost { background: var(--track); color: var(--text); }
.btn-ghost-red { background: #fff1f3; color: #e0324d; min-height: 46px; font-size: 16px; }
.round-btn { width: 50px; height: 50px; border-radius: 50%; background: var(--btn); display: grid; place-items: center; box-shadow: 0 2px 6px rgba(70, 80, 160, 0.12); transition: transform 0.12s; flex: none; }
.round-btn img { width: 25px; height: 25px; }
.round-btn:active { transform: scale(0.9); }
.round-btn.small { width: 42px; height: 42px; }
.round-btn.small img { width: 21px; height: 21px; }
.round-btn:disabled { opacity: 0.4; pointer-events: none; }

/* ---------- loading ---------- */
#scrLoading { justify-content: center; gap: 28px; }
.loader { width: 160px; height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; }
.loader i { display: block; height: 100%; width: 0%; background: var(--blue); border-radius: 999px; transition: width 0.25s; }
.load-msg { color: var(--text2); font-size: 14px; font-weight: 600; }
.load-error { text-align: center; display: flex; flex-direction: column; gap: 12px; width: 240px; color: var(--text2); }

/* ---------- menu ---------- */
#scrMenu { justify-content: space-between; padding: calc(16px + var(--safe-t)) 24px calc(14vh + var(--safe-b)); }
.menu-top { width: 100%; display: flex; justify-content: space-between; }
.menu-center { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-top: 4vh; }
.menu-level { color: var(--blue); font-size: 30px; font-weight: 700; }
.menu-diff { color: var(--text2); font-size: 14px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.menu-bottom { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 14px; }
.btn-levels { background: var(--track); color: #2e3470; min-height: 54px; font-size: 18px; }
.btn-levels img { width: 22px; height: 22px; }

/* ---------- game header ---------- */
.game { padding-top: var(--safe-t); }
.game-head { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 18px 16px 10px; }
.head-left { display: flex; gap: 10px; }
.head-center { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.difficulty { color: #2a9df4; font-weight: 700; font-size: 17px; line-height: 1.2; }
.difficulty.d-Expert { color: #8b5cf6; }
.hearts { display: flex; gap: 4px; }
.hearts img { width: 26px; height: 26px; transition: transform 0.2s; }
.hearts img.lost { animation: heartLose 0.6s ease; }
@keyframes heartLose { 0% { transform: scale(1); } 25% { transform: scale(1.35) rotate(-10deg); } 50% { transform: scale(0.85) rotate(8deg); } 100% { transform: scale(1); } }
.hearts.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-4px); } 40%, 80% { transform: translateX(4px); } }
.hint-btn { justify-self: end; position: relative; height: 48px; padding: 0 18px 0 14px; border-radius: 999px; background: var(--blue); color: #fff; display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 19px; box-shadow: 0 6px 16px rgba(93, 112, 255, 0.25); transition: transform 0.12s; }
.hint-btn img { width: 24px; height: 24px; }
.hint-btn:active { transform: scale(0.95); }
.hint-badge { position: absolute; right: -4px; top: -7px; min-width: 22px; height: 20px; padding: 0 6px; border-radius: 999px; background: #fff; color: var(--blue); font-size: 11px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(40, 50, 120, 0.18); }
.hint-btn.pulse { animation: hintPulse 1.4s ease-in-out infinite; }
@keyframes hintPulse { 50% { box-shadow: 0 0 0 6px rgba(93, 112, 255, 0.18), 0 6px 16px rgba(93, 112, 255, 0.25); } }

/* ---------- progress ---------- */
.progress { width: calc(100% - 32px); height: 6px; border-radius: 999px; background: var(--track); overflow: hidden; flex: none; }
.progress i { display: block; height: 100%; width: 0%; border-radius: 999px; background: var(--lblue); transition: width 0.45s cubic-bezier(0.3, 0.8, 0.3, 1); }
.progress.big { width: 100%; height: 8px; }
.progress.big i { background: var(--blue); }

/* ---------- board ---------- */
.board-wrap { position: relative; flex: 1; width: 100%; display: grid; place-items: center; min-height: 0; padding: 10px 12px; }
#board { display: block; overflow: visible; touch-action: manipulation; cursor: pointer; }
#dots circle { fill: var(--dot); }
.arrow .body { fill: none; stroke: var(--navy); stroke-linecap: round; stroke-linejoin: round; transition: stroke 0.25s; }
.arrow .head { fill: var(--navy); stroke: var(--navy); stroke-linejoin: round; transition: fill 0.25s, stroke 0.25s; }
.arrow.blocked .body { stroke: var(--red); }
.arrow.blocked .head { fill: var(--red); stroke: var(--red); }
.arrow.selected .body, .arrow.hint .body { stroke: var(--blue); }
.arrow.selected .head, .arrow.hint .head { fill: var(--blue); stroke: var(--blue); }
.arrow.hint { animation: hintGlow 1.1s ease-in-out infinite; }
@keyframes hintGlow { 0%, 100% { filter: drop-shadow(0 0 0 rgba(93, 112, 255, 0)); } 50% { filter: drop-shadow(0 0 5px rgba(93, 112, 255, 0.85)); } }
.arrow.flash .body { stroke: var(--red); }
.arrow.flash .head { fill: var(--red); stroke: var(--red); }
.arrow.appear { animation: appear 0.35s ease; }
@keyframes appear { from { opacity: 0; } }
.hint-ray { fill: none; stroke: var(--blue); stroke-linecap: round; opacity: 0.55; animation: ray 0.8s linear infinite; }
@keyframes ray { to { stroke-dashoffset: -1; } }
.sparkle { fill: var(--blue); }

.game-foot { width: 100%; display: flex; justify-content: space-between; align-items: center; padding: 6px 16px calc(14px + var(--safe-b)); }
.level-tag { color: var(--text2); font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 999px; background: var(--track); }
.level-tag::after { content: ' ›'; }

.tip { position: absolute; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); width: min(88%, 360px); padding: 12px 16px; border-radius: 16px; background: var(--navy); color: #fff; font-size: 14px; font-weight: 600; text-align: center; line-height: 1.4; box-shadow: 0 10px 30px rgba(17, 19, 47, 0.25); animation: tipIn 0.35s ease; pointer-events: none; }
.tip::after { content: ""; position: absolute; left: 50%; top: -7px; margin-left: -7px; border: 7px solid transparent; border-top: 0; border-bottom-color: var(--navy); }
@keyframes tipIn { from { opacity: 0; transform: translate(-50%, 10px); } }
.toast { position: absolute; left: 50%; top: calc(128px + var(--safe-t)); transform: translate(-50%, -8px); padding: 9px 16px; border-radius: 999px; background: var(--navy); color: #fff; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: 0.25s; white-space: nowrap; z-index: 5; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.red { background: var(--red); }
.toast.blue { background: var(--blue); }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(17, 19, 47, 0.28); animation: fadeIn 0.25s ease; }
.panel { position: relative; width: min(90%, 360px); max-height: calc(100% - 32px); overflow-y: auto; background: #fff; border-radius: 28px; padding: 26px 22px 22px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 24px 60px rgba(17, 19, 47, 0.2); animation: panelIn 0.35s cubic-bezier(0.3, 1.4, 0.5, 1); }
.panel.wide { width: min(92%, 420px); }
.panel.center { align-items: center; text-align: center; }
@keyframes panelIn { from { opacity: 0; transform: scale(0.88); } }
.panel h2 { font-size: 24px; font-weight: 800; color: var(--text); }
.panel p { color: var(--text2); font-weight: 500; font-size: 15px; }
.panel p.sub { font-size: 12px; }
.close-btn { position: absolute; right: 14px; top: 14px; width: 36px; height: 36px; border-radius: 50%; background: var(--track); display: grid; place-items: center; }
.close-btn img { width: 18px; height: 18px; }
.row2 { display: flex; gap: 10px; width: 100%; }
.success-ico { width: 64px; height: 64px; }
.stars { display: flex; gap: 8px; align-items: flex-end; height: 64px; }
.stars i { width: 48px; height: 48px; background: url(assets/icons/star-empty.svg) center / contain no-repeat; transform: scale(0.8); }
.stars i:nth-child(2) { width: 60px; height: 60px; }
.stars i.on { background-image: url(assets/icons/star.svg); animation: starPop 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) forwards; }
@keyframes starPop { 0% { transform: scale(0.3) rotate(-30deg); } 100% { transform: scale(1) rotate(0); } }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.stats div { background: var(--track); border-radius: 16px; padding: 12px 6px; display: flex; flex-direction: column; }
.stats b { font-size: 26px; font-weight: 800; }
.stats small { font-size: 12px; color: var(--text2); font-weight: 600; }
.over-hearts { display: flex; gap: 6px; }
.over-hearts img { width: 34px; height: 34px; filter: grayscale(1) opacity(0.35); }

.set-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-radius: 16px; background: var(--track); font-weight: 600; cursor: pointer; }
.set-row.col { flex-direction: column; align-items: stretch; gap: 8px; cursor: default; }
.set-row span { display: flex; align-items: center; gap: 10px; }
.set-row span img { width: 20px; height: 20px; }
.set-row input[type="checkbox"] { display: none; }
.sw { width: 48px; height: 28px; border-radius: 999px; background: var(--lblue); position: relative; transition: background 0.2s; flex: none; }
.sw::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15); transition: left 0.2s; }
input:checked + .sw { background: var(--blue); }
input:checked + .sw::after { left: 23px; }
input[type="range"] { width: 100%; accent-color: var(--blue); }
.seg { display: flex; gap: 4px; background: #e6e9f7; border-radius: 12px; padding: 4px; }
.seg button { flex: 1; padding: 8px 0; border-radius: 9px; font-weight: 700; color: var(--text2); }
.seg button.on { background: #fff; color: var(--blue); box-shadow: 0 2px 6px rgba(40, 50, 120, 0.1); }

/* ---------- level screen ---------- */
:root { --easy: #2fbf71; --medium: #5d70ff; --hard: #ff8a3d; --expert: #9b5cff; }
.d-Easy { --dc: var(--easy); } .d-Medium { --dc: var(--medium); } .d-Hard { --dc: var(--hard); } .d-Expert { --dc: var(--expert); }
.difficulty.d-Easy, .difficulty.d-Medium, .difficulty.d-Hard, .difficulty.d-Expert, .menu-diff.d-Easy, .menu-diff.d-Medium, .menu-diff.d-Hard, .menu-diff.d-Expert { color: var(--dc); }
.panel.sheet { width: min(94%, 440px); height: calc(100% - 28px); max-height: 860px; padding: 0; gap: 0; overflow: hidden; }
.lv-head { position: relative; padding: 22px 20px 14px; display: flex; flex-direction: column; gap: 12px; border-bottom: 1px solid #eef0f8; background: #fff; }
.lv-head .close-btn { top: 18px; }
.lv-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lv-stat { background: var(--track); border-radius: 14px; padding: 8px 12px; display: flex; flex-direction: column; }
.lv-stat small { font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; }
.lv-stat b { font-size: 19px; font-weight: 800; display: flex; align-items: center; gap: 4px; }
.lv-stat b img { width: 18px; height: 18px; }
.lv-legend { display: flex; gap: 6px; flex-wrap: wrap; }
.lv-legend span { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 700; color: var(--text2); padding: 4px 10px 4px 8px; border-radius: 999px; background: var(--track); }
.lv-legend span::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--dc); }
.lv-scroll { position: relative; flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; touch-action: pan-y; overscroll-behavior: contain; }
.level-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; padding: 4px 18px 22px; }
.lv-sec { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: baseline; padding: 14px 2px 2px; font-size: 13px; font-weight: 800; color: var(--text); }
.lv-sec small { font-size: 12px; font-weight: 700; color: var(--text2); }
.lvl { position: relative; aspect-ratio: 1 / 1; width: 100%; min-width: 0; border-radius: 18px; background: #fff; box-shadow: inset 0 0 0 2px #e9ecf8; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; transition: transform 0.12s; overflow: hidden; }
.lvl::before { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 5px; background: var(--dc); }
.lvl:active { transform: scale(0.94); }
.lv-shape { font-size: 9px; font-weight: 700; color: var(--text2); line-height: 1; max-width: 90%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lvl.done .lv-shape { color: rgba(255, 255, 255, 0.85); }
.lvl b { font-size: 21px; font-weight: 800; color: var(--text); line-height: 1; }
.lv-stars { display: flex; gap: 2px; }
.lv-stars i { width: 12px; height: 12px; background: url(assets/icons/star-empty.svg) center / contain no-repeat; }
.lv-stars i.on { background-image: url(assets/icons/star.svg); }
.lvl.done { background: var(--dc); box-shadow: none; }
.lvl.done::before { background: rgba(0, 0, 0, 0.12); }
.lvl.done b { color: #fff; }
.lvl.done .lv-stars i:not(.on) { filter: brightness(0) invert(1); opacity: 0.45; }
.lvl.current { box-shadow: inset 0 0 0 3px var(--dc), 0 6px 16px rgba(93, 112, 255, 0.18); animation: curPulse 1.6s ease-in-out infinite; }
.lvl.current.done { box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--dc); }
.lvl em { position: absolute; top: 6px; font-style: normal; font-size: 9px; font-weight: 800; letter-spacing: 0.08em; color: #fff; background: var(--dc); padding: 2px 6px; border-radius: 999px; }
.lvl.current b { margin-top: 8px; }
@keyframes curPulse { 50% { transform: scale(1.04); } }
.lvl.locked { background: var(--track); box-shadow: none; cursor: default; }
.lvl.locked::before { opacity: 0.35; }
.lvl.locked b { font-size: 13px; color: #b7bee6; }
.lvl.locked img { width: 20px; height: 20px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; font: 600 18px sans-serif; color: #11132f; }

/* reduced animation setting */
body.reduced *, body.reduced *::before, body.reduced *::after { animation-duration: 0.01s !important; transition-duration: 0.05s !important; }

@media (max-width: 360px) {
  .lvl em { top: 3px; font-size: 7px; padding: 1px 5px; }
  .lv-shape { display: none; }
  .lvl.current b { margin-top: 10px; font-size: 16px; }
  .lv-stars i { width: 10px; height: 10px; }
  .round-btn { width: 42px; height: 42px; }
  .round-btn img { width: 21px; height: 21px; }
  .head-left { gap: 6px; }
  .hint-btn { height: 42px; padding: 0 13px 0 10px; font-size: 16px; }
  .hint-btn img { width: 20px; height: 20px; }
  .hearts img { width: 22px; height: 22px; }
  .game-head { padding: 14px 10px 8px; }
  .logo.big span { font-size: 50px; }
}
@media (max-height: 640px) {
  .lv-head { padding: 16px 16px 10px; gap: 8px; }
  .lv-head h2 { font-size: 21px; }
  .lv-stat { padding: 6px 10px; }
  .lv-stat b { font-size: 16px; }
  .lv-legend span { font-size: 11px; padding: 3px 8px 3px 6px; }
  .level-grid { gap: 8px; padding: 2px 14px 18px; }
  .lvl b { font-size: 18px; }
}
@media (max-height: 560px) {
  #scrMenu { padding-bottom: calc(6vh + var(--safe-b)); }
  .btn-play { min-height: 54px; font-size: 22px; }
}
