* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  overscroll-behavior: none;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: #f6f4ff;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background:
    radial-gradient(40vmax 40vmax at 8% 6%, rgba(112, 103, 245, 0.22), transparent 70%),
    radial-gradient(36vmax 36vmax at 96% 14%, rgba(255, 109, 168, 0.20), transparent 70%),
    radial-gradient(42vmax 42vmax at 90% 96%, rgba(72, 201, 223, 0.22), transparent 70%),
    radial-gradient(34vmax 34vmax at 4% 92%, rgba(255, 200, 87, 0.24), transparent 70%),
    linear-gradient(160deg, #f7f5ff 0%, #f1fbff 55%, #fff8ec 100%);
  background-attachment: fixed;
}

.app {
  width: min(560px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Header ---------- */
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding-top: 6px;
}
.brand-mark { width: 40px; height: 40px; flex: none; }
.brand h1 {
  margin: 0;
  font-size: clamp(28px, 7vw, 38px);
  font-weight: 850;
  letter-spacing: 0.06em;
  line-height: 1;
  background: linear-gradient(90deg, var(--purple), var(--pink) 55%, #ff9a6d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Card ---------- */
.card {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  backdrop-filter: blur(18px) saturate(1.3);
  padding: 16px;
}

.status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(112, 103, 245, 0.09);
  font-weight: 750;
  font-size: 14px;
  white-space: nowrap;
}
.chip.level { background: var(--purple); color: #fff; }
.chip .label { color: var(--muted); font-weight: 650; }
.chip.level .label { color: rgba(255, 255, 255, 0.8); }

.progress {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(112, 103, 245, 0.12);
  overflow: hidden;
  min-width: 40px;
}
.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--purple), var(--pink));
  transition: width 260ms ease;
}

/* ---------- Board ---------- */
.board-wrap {
  position: relative;
  width: min(100%, calc(100dvh - 300px));
  min-width: min(100%, 288px);
  aspect-ratio: 1;
  margin: 0 auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.board-wrap canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: pointer;
}

.message {
  min-height: 22px;
  margin: 12px 4px 0;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
  transition: color 200ms;
}
.message.hint { color: var(--pink); }

/* ---------- Controls ---------- */
.controls {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}
.btn {
  appearance: none;
  border: 0;
  border-radius: 16px;
  padding: 12px 18px;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font: inherit;
  font-size: 15px;
  font-weight: 750;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 2px 0 rgba(37, 35, 74, 0.06), 0 6px 16px rgba(64, 56, 160, 0.10);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:active { transform: translateY(1px) scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary {
  color: #fff;
  background: linear-gradient(135deg, var(--purple), #8f6cf7);
  box-shadow: 0 3px 0 #5148cf, 0 10px 22px rgba(112, 103, 245, 0.35);
}
.btn:focus-visible, .icon-btn:focus-visible, .lvl:focus-visible, .pack:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
button { touch-action: manipulation; }
.btn.big { width: 100%; justify-content: center; min-height: 60px; font-size: 19px; border-radius: 20px; }
.btn.big svg { width: 22px; height: 22px; }
.btn.small { min-height: 38px; padding: 8px 14px; font-size: 14px; border-radius: 12px; flex: none; }
.btn.danger { color: #d93d6a; }
.btn.primary.danger { color: #fff; background: linear-gradient(135deg, #ff6d8f, #e5484d); box-shadow: 0 3px 0 #b8323d, 0 10px 22px rgba(229, 72, 77, 0.3); }

/* ---------- Screens ---------- */
.screen[hidden] { display: none !important; }
.screen { animation: screen-in 220ms ease; }
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.home-card { display: flex; flex-direction: column; gap: 14px; padding: 26px 20px 20px; text-align: center; }
.tagline { margin: 0 0 6px; font-size: 18px; font-weight: 650; line-height: 1.45; color: var(--muted); }
.home-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.home-row .btn { justify-content: center; }
.stars-total { margin: 4px 0 0; font-weight: 750; color: var(--muted); }
.star-ico { color: var(--yellow); text-shadow: 0 1px 0 #e0a93a; }
.install-cta {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 4px; padding: 12px 14px; border-radius: 16px;
  border: 2px dashed rgba(112, 103, 245, 0.35); background: rgba(112, 103, 245, 0.06);
  color: var(--purple); font: inherit; font-weight: 750; font-size: 15px; cursor: pointer;
}
.install-cta svg { width: 20px; height: 20px; flex: none; }

.screen-head { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; margin-bottom: 14px; }
.screen-head h2 { margin: 0; text-align: center; font-size: 22px; font-weight: 850; }
.icon-btn {
  width: 40px; height: 40px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: #fff; color: var(--ink); cursor: pointer;
  box-shadow: 0 2px 0 rgba(37, 35, 74, 0.06), 0 6px 16px rgba(64, 56, 160, 0.10);
}
.icon-btn svg { width: 20px; height: 20px; }
.status .icon-btn { width: 36px; height: 36px; border-radius: 11px; }

.packs { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; scrollbar-width: none; }
.packs::-webkit-scrollbar { display: none; }
.pack {
  flex: none; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 9px 13px; border: 0; border-radius: 14px; background: #fff; color: var(--ink);
  font: inherit; cursor: pointer; box-shadow: 0 2px 8px rgba(64, 56, 160, 0.08);
}
.pack strong { font-size: 14px; font-weight: 800; }
.pack small { font-size: 12px; color: var(--muted); font-weight: 650; }
.pack[aria-selected="true"] { background: var(--purple); color: #fff; }
.pack[aria-selected="true"] small { color: rgba(255, 255, 255, 0.8); }
.pack.locked { opacity: 0.55; }

.level-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.lvl {
  aspect-ratio: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; border-radius: 16px; background: #fff; color: var(--ink); font: inherit; cursor: pointer;
  box-shadow: 0 2px 0 rgba(37, 35, 74, 0.05), 0 5px 12px rgba(64, 56, 160, 0.09);
}
.lvl b { font-size: 18px; font-weight: 850; }
.lvl .s { font-size: 11px; letter-spacing: 1px; color: #cfd1e4; }
.lvl .s i { font-style: normal; }
.lvl .s i.on { color: var(--yellow); }
.lvl.current { outline: 3px solid var(--pink); outline-offset: -3px; }
.lvl:disabled { background: rgba(255, 255, 255, 0.5); color: #b7b8cc; box-shadow: none; cursor: default; }
.lvl:disabled svg { width: 18px; height: 18px; }

.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 14px 4px; border-bottom: 1px solid rgba(112, 103, 245, 0.1); cursor: default;
}
.setting > span { display: flex; flex-direction: column; gap: 3px; }
.setting strong { font-size: 16px; }
.setting small { color: var(--muted); font-size: 13px; line-height: 1.4; }
.setting input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none; width: 52px; height: 32px; margin: 0;
  border-radius: 999px; background: #dcdcef; position: relative; cursor: pointer; transition: background 160ms;
}
.setting input[type="checkbox"]::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 5px rgba(37, 35, 74, 0.2); transition: transform 160ms;
}
.setting input[type="checkbox"]:checked { background: var(--purple); }
.setting input[type="checkbox"]:checked::after { transform: translateX(20px); }
.setting input[type="checkbox"]:focus-visible { outline: 3px solid var(--cyan); outline-offset: 2px; }
label.setting { cursor: pointer; }
.version { margin: 16px 0 2px; text-align: center; font-size: 12px; color: var(--muted); }

.win-stars { display: flex; justify-content: center; gap: 6px; font-size: 40px; line-height: 1; }
.win-stars i { font-style: normal; color: #e6e7f4; -webkit-text-stroke: 1.5px #c3c5dc; transform: scale(0.6); transition: transform 300ms cubic-bezier(.2, 1.6, .4, 1), color 200ms; }
.win-stars i.on { color: var(--yellow); -webkit-text-stroke: 0; text-shadow: 0 2px 0 #e0a93a; transform: scale(1); }
.win-stars i:nth-child(2) { font-size: 50px; transition-delay: 120ms; }
.win-stars i:nth-child(3) { transition-delay: 240ms; }
.link-btn { margin-top: 12px; border: 0; background: none; color: var(--purple); font: inherit; font-weight: 750; cursor: pointer; padding: 6px; }
.install-icon { border-radius: 18px; box-shadow: 0 8px 20px rgba(112, 103, 245, 0.3); }
.install-steps { text-align: left; margin: 6px 0 18px; padding-left: 22px; line-height: 1.6; font-weight: 600; }
.install-steps li { margin: 6px 0; }
.install-steps .ios-share { display: inline-block; vertical-align: -4px; width: 20px; height: 20px; color: #2f7cf6; }

/* ---------- Win dialog ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(37, 35, 74, 0.28);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 220ms ease;
  z-index: 10;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.dialog {
  width: min(360px, 100%);
  text-align: center;
  padding: 28px 22px 22px;
  transform: translateY(14px) scale(0.96);
  transition: transform 260ms cubic-bezier(.2, 1.4, .4, 1);
}
.overlay.show .dialog { transform: none; }
.dialog h2 { margin: 6px 0 4px; font-size: 26px; font-weight: 850; }
.dialog p { margin: 0 0 18px; color: var(--muted); font-weight: 600; line-height: 1.45; }
.dialog .controls { margin-top: 0; }
.burst { display: flex; justify-content: center; gap: 8px; }
.burst i {
  width: 14px; height: 14px; border-radius: 50%;
  animation: hop 900ms ease-in-out infinite;
}
.burst i:nth-child(1) { background: var(--purple); }
.burst i:nth-child(2) { background: var(--pink); animation-delay: 90ms; }
.burst i:nth-child(3) { background: var(--cyan); animation-delay: 180ms; }
.burst i:nth-child(4) { background: var(--yellow); animation-delay: 270ms; }
@keyframes hop { 0%, 100% { transform: translateY(0); } 40% { transform: translateY(-10px); } }

@media (max-width: 400px) {
  body { padding-left: 10px; padding-right: 10px; }
  .card { padding: 12px; border-radius: 22px; }
  .chip { padding: 6px 10px; font-size: 13px; }
  .btn { padding: 11px 14px; font-size: 14px; }
  .btn .txt-opt { display: none; }
  .status { gap: 5px; }
  .status .progress { display: none; }
  .level-grid { gap: 7px; }
  .lvl { border-radius: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* Home sits a little lower on tall screens instead of hugging the logo. */
@media (min-height: 700px) {
  #screen-home { margin-top: clamp(0px, 8vh, 96px); }
}
