:root {
  --ink: #1b1640;
  --paper: #fff8ee;
  --orange: #ff8a2b;
  --orange-d: #d9661a;
  --pink: #ff4fa3;
  --gold: #ffd23f;
  --mint: #5fd6a4;
  --muted: #7a7398;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2a2770;
  color: var(--ink);
  font-family: var(--font);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

.hidden { display: none !important; }

button { font-family: inherit; color: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.06s, box-shadow 0.06s;
}
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--orange); color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.25); }
.btn.big { font-size: 22px; padding: 16px; }
.btn.ghost { background: #ece6ff; }
.btn.danger { background: #ff5a5a; color: #fff; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn-row { display: flex; gap: 12px; }
.btn-row > .btn { flex: 1; }
.col { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: none;
  border-radius: 14px;
  border: 3px solid var(--ink);
  background: #fff;
  font-size: 20px;
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
.hud-top {
  position: absolute;
  top: calc(8px + var(--safe-t));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.hud-top > *, .hud-bottom > * { pointer-events: auto; }
.hud-info { flex: 1; min-width: 0; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
#hud-label { font-size: 17px; font-weight: 900; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hud-sub { font-size: 12px; opacity: 0.85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-right { text-align: right; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); }
#hud-score { font-size: 24px; font-weight: 900; line-height: 1; font-variant-numeric: tabular-nums; }
#hud-shots { margin-top: 4px; font-size: 14px; letter-spacing: 1px; white-space: nowrap; font-weight: 800; }
#hud-shots .pip { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--orange); border: 2px solid var(--ink); margin-left: 3px; vertical-align: middle; }
#hud-shots .pip.used { background: rgba(255, 255, 255, 0.25); border-color: rgba(27, 22, 64, 0.5); }

.hud-bottom {
  position: absolute;
  bottom: calc(10px + var(--safe-b));
  left: 10px;
  right: 10px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}
.hint {
  flex: 1;
  max-width: 560px;
  margin: 0 auto;
  min-height: 0;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.4;
  text-align: center;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  opacity: 0;
  transition: opacity 0.4s;
  pointer-events: none !important;
}
.hint.show { opacity: 1; }
.hint:not(:empty) { background: rgba(27, 22, 64, 0.55); border-radius: 12px; padding: 6px 10px; }
.hint b { color: var(--gold); }

.banner {
  position: absolute;
  top: 34%;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 34px;
  font-weight: 900;
  color: #fff;
  -webkit-text-stroke: 2px var(--ink);
  text-shadow: 0 4px 0 var(--ink);
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.2s, transform 0.25s cubic-bezier(0.2, 1.6, 0.4, 1);
  pointer-events: none;
}
.banner.show { opacity: 1; transform: scale(1); }
.banner small { display: block; font-size: 18px; -webkit-text-stroke: 1px var(--ink); margin-top: 4px; }

.tutorial {
  position: absolute;
  left: 50%;
  top: 62%;
  transform: translateX(-50%);
  text-align: center;
  color: #fff;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.tutorial .hand { font-size: 46px; animation: drag 2.2s ease-in-out infinite; }
.tutorial .tut-text { margin-top: 8px; font-size: 16px; background: rgba(27, 22, 64, 0.55); padding: 6px 12px; border-radius: 12px; }
@keyframes drag {
  0% { transform: translate(-40px, 30px); opacity: 0; }
  15% { transform: translate(-40px, 30px); opacity: 1; }
  60% { transform: translate(30px, -50px); opacity: 1; }
  75% { transform: translate(30px, -50px); opacity: 0; }
  100% { opacity: 0; }
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  z-index: 10;
}
.screen.show { display: flex; animation: fade 0.2s ease-out; }
.screen.dim { background: rgba(10, 8, 30, 0.55); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.panel {
  width: 100%;
  max-width: 400px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--ink);
  padding: 18px;
  animation: pop 0.28s cubic-bezier(0.2, 1.5, 0.4, 1);
}
.panel.wide { max-width: 520px; height: 100%; }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.panel h2 { margin: 0; text-align: center; font-size: 24px; font-weight: 900; }
.panel header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.panel header h2 { flex: 1; }
.panel header > span { min-width: 44px; text-align: right; font-weight: 900; }
.scroll { overflow-y: auto; flex: 1; margin: 0 -6px; padding: 0 6px 8px; -webkit-overflow-scrolling: touch; }
.note { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 12px 0 0; }

/* ---------- menu ---------- */
#scr-menu { background: linear-gradient(rgba(20, 16, 60, 0.15), rgba(20, 16, 60, 0.55)); }
.menu-wrap { width: 100%; max-width: 360px; display: flex; flex-direction: column; align-items: center; }
.logo { text-align: center; margin-bottom: 8px; animation: bob 3s ease-in-out infinite; }
.logo-en {
  font-size: clamp(34px, 12.5vw, 56px);
  font-weight: 900;
  line-height: 1;
  color: var(--orange);
  -webkit-text-stroke: 3px var(--ink);
  text-shadow: 0 6px 0 var(--ink);
  letter-spacing: 1px;
  font-family: 'Arial Black', 'Helvetica Neue', var(--font);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.logo-ball {
  width: 0.72em;
  height: 0.72em;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: radial-gradient(circle at 35% 30%, #ffc07a, #ff8a2b 60%);
  box-shadow: 0 5px 0 var(--ink), inset 0 0 0 0 transparent;
  position: relative;
  animation: spin 4s linear infinite;
}
.logo-ball::before, .logo-ball::after { content: ''; position: absolute; background: #5a2a08; }
.logo-ball::before { left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; }
.logo-ball::after { top: 50%; left: 0; right: 0; height: 2px; margin-top: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes bob { 50% { transform: translateY(-6px); } }
.logo-cn { margin-top: 10px; font-size: 26px; font-weight: 900; color: #fff; letter-spacing: 8px; text-shadow: 0 3px 0 var(--ink); }
.lang-en .logo-cn { font-size: 20px; letter-spacing: 2px; }
.menu-stars { color: var(--gold); font-weight: 900; font-size: 18px; margin: 6px 0 22px; text-shadow: 0 2px 0 var(--ink); }
.menu-buttons { width: 100%; display: flex; flex-direction: column; gap: 14px; }

/* ---------- level select ---------- */
.hdr-stars { color: #c98a00; }
.toggle-line { display: flex; align-items: center; gap: 10px; font-weight: 800; padding: 8px 2px; font-size: 16px; cursor: pointer; }
.toggle-line small { font-weight: 600; color: var(--muted); font-size: 12px; }
.toggle-line input { width: 22px; height: 22px; accent-color: var(--orange); flex: none; }
.chapter { margin-top: 14px; }
.chapter h3 { margin: 0 0 8px; font-size: 15px; display: flex; justify-content: space-between; }
.chapter h3 span { color: var(--muted); font-weight: 700; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tile {
  aspect-ratio: 1;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 0 var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 20px;
  cursor: pointer;
  padding: 0;
}
.tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.tile .st { font-size: 11px; color: #ccc; letter-spacing: 0; margin-top: 2px; }
.tile .st b { color: #f5a800; font-weight: 900; }
.tile.locked { background: #d9d4ea; color: #8f88aa; box-shadow: 0 4px 0 #8f88aa; border-color: #8f88aa; cursor: default; }
.tile.next { background: var(--gold); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- result ---------- */
.stars { display: flex; justify-content: center; gap: 8px; margin: 10px 0 4px; }
.stars span {
  font-size: 50px;
  line-height: 1;
  color: #d6d0e6;
  -webkit-text-stroke: 2px var(--ink);
  transform: scale(0.6);
  transition: transform 0.3s cubic-bezier(0.2, 1.8, 0.4, 1), color 0.2s;
}
.stars span:nth-child(2) { transform: translateY(-10px) scale(0.6); }
.stars span.on { color: var(--gold); transform: scale(1); }
.stars span:nth-child(2).on { transform: translateY(-10px) scale(1.1); }
.goals { list-style: none; padding: 0; margin: 6px 0; font-size: 14px; }
.goals li { padding: 3px 0; display: flex; gap: 8px; align-items: center; }
.goals li::before { content: '☆'; color: var(--muted); font-weight: 900; }
.goals li.ok::before { content: '★'; color: #f5a800; }
.goals li.ok { font-weight: 800; }
.breakdown { font-size: 14px; border-top: 2px dashed #d6cfe8; padding-top: 8px; }
.breakdown div { display: flex; justify-content: space-between; padding: 2px 0; }
.breakdown div span:last-child { font-weight: 800; font-variant-numeric: tabular-nums; }
.total { display: flex; justify-content: space-between; font-size: 20px; font-weight: 900; border-top: 2px solid var(--ink); margin-top: 8px; padding-top: 8px; }
.total .best { font-size: 12px; color: var(--orange-d); }
.over-body { text-align: center; font-size: 16px; line-height: 1.7; margin-top: 8px; }
.over-body .big-num { font-size: 48px; font-weight: 900; color: var(--orange); -webkit-text-stroke: 2px var(--ink); line-height: 1.1; }
.over-body .row { display: flex; justify-content: space-between; border-bottom: 1px dashed #d6cfe8; padding: 4px 0; }
.over-body .row b { font-weight: 900; }

/* ---------- settings ---------- */
.settings { display: flex; flex-direction: column; gap: 4px; }
.seg-line { display: flex; align-items: center; justify-content: space-between; font-weight: 800; padding: 8px 2px; }
.seg { display: flex; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 12px; font-weight: 800; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--orange); color: #fff; }
.settings .btn.danger { margin-top: 16px; }

/* ---------- collection ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.tabs button { flex: 1; border: 3px solid var(--ink); background: #fff; border-radius: 12px; padding: 8px; font-weight: 900; font-size: 15px; cursor: pointer; }
.tabs button.on { background: var(--ink); color: #fff; }
.items { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.item { border: 3px solid var(--ink); border-radius: 16px; background: #fff; padding: 10px 6px; text-align: center; cursor: pointer; box-shadow: 0 4px 0 var(--ink); }
.item canvas { width: 56px; height: 56px; display: block; margin: 0 auto 4px; }
.item .nm { font-weight: 900; font-size: 13px; }
.item .req { font-size: 11px; color: var(--muted); margin-top: 2px; }
.item.locked { opacity: 0.55; cursor: default; }
.item.sel { background: #fff0c2; outline: 3px solid var(--orange); }
.ach { display: flex; gap: 12px; align-items: center; border-bottom: 2px dashed #e1dbef; padding: 10px 2px; }
.ach .ic { font-size: 28px; width: 40px; text-align: center; filter: grayscale(1); opacity: 0.4; }
.ach.done .ic { filter: none; opacity: 1; }
.ach .tx { flex: 1; }
.ach .tx b { display: block; font-size: 15px; }
.ach .tx small { color: var(--muted); }
.ach .pg { font-weight: 800; font-size: 13px; color: var(--muted); }
.ach.done .pg { color: #2fae6a; }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: calc(70px + var(--safe-t)); left: 0; right: 0; display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 30; pointer-events: none; }
.toast {
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 4px 0 var(--ink);
  padding: 8px 14px;
  font-weight: 800;
  font-size: 14px;
  animation: toast 3s ease forwards;
}
@keyframes toast {
  0% { transform: translateY(-20px); opacity: 0; }
  10%, 85% { transform: translateY(0); opacity: 1; }
  100% { transform: translateY(-10px); opacity: 0; }
}

#confirm { z-index: 40; }
#confirm p { font-weight: 800; text-align: center; margin: 4px 0 16px; line-height: 1.5; }

@media (max-height: 640px) {
  .menu-stars { margin-bottom: 12px; }
  .menu-buttons { gap: 10px; }
  .btn { padding: 10px 14px; font-size: 16px; }
  .btn.big { padding: 12px; font-size: 19px; }
}
