* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0b0a1c;
  color: #f2f0ff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#stage { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.hidden { display: none !important; }

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.6vh, 14px);
  padding: 16px;
  text-align: center;
  overflow-y: auto;
  touch-action: pan-y;
  background: radial-gradient(ellipse at center, rgba(11, 10, 28, 0.45) 0%, rgba(11, 10, 28, 0.85) 75%);
}

.title {
  font-size: clamp(32px, 8.5vmin, 68px);
  font-weight: 800;
  letter-spacing: 0.02em;
  line-height: 1;
  color: #7df9ff;
  text-shadow: 0 0 18px rgba(125, 249, 255, 0.55);
}
.title span { display: block; color: #ffd166; text-shadow: 0 0 18px rgba(255, 209, 102, 0.5); }

h2 { font-size: clamp(24px, 5.5vmin, 40px); font-weight: 800; }
h3 { font-size: 16px; margin: 14px 0 6px; text-align: left; opacity: 0.85; }
h3 small { opacity: 0.7; font-weight: 600; }

.tagline { font-size: clamp(14px, 2.8vmin, 19px); max-width: 26em; opacity: 0.9; }
.hint { font-size: clamp(12px, 2.4vmin, 15px); opacity: 0.6; }
.best-line { font-size: clamp(14px, 2.8vmin, 18px); }
.best-line b { color: #ffd166; margin: 0 2px; }
.best-line .sep { opacity: 0.4; margin: 0 6px; }
.note { font-size: 12px; opacity: 0.65; line-height: 1.45; text-align: left; margin-top: 6px; }

.btn {
  min-width: 170px;
  min-height: 46px;
  padding: 9px 24px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-size: clamp(16px, 3.2vmin, 21px);
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.14); }
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary {
  border-color: #7df9ff;
  background: linear-gradient(180deg, #38d9e6, #1c8fb3);
  color: #06121a;
  box-shadow: 0 0 22px rgba(125, 249, 255, 0.35);
}
.btn small { font-size: 0.62em; font-weight: 600; opacity: 0.8; }
.daily-btn { border-color: #ffd166; }
/* Rewarded-ad button: deliberately NOT green (Poki rule), carries the 🎬 marker, same size as the normal buttons. */
.ad-btn { border-color: #b48cff; background: rgba(180, 140, 255, 0.16); }
.btn:focus-visible, .icon-btn:focus-visible, .tile:focus-visible, .coll-item:focus-visible { outline: 3px solid #ffd166; outline-offset: 3px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.btn-row .btn { min-width: 130px; }

.icon-btn {
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  background: rgba(11, 10, 28, 0.55);
  color: #f2f0ff;
  font-size: 18px;
  cursor: pointer;
  flex: none;
}
.icon-btn svg { fill: currentColor; stroke: currentColor; }

.menu-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.tile {
  width: 104px;
  min-height: 82px;
  padding: 8px 6px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tile:hover { background: rgba(255, 255, 255, 0.13); }
.tile-ico { font-size: 22px; color: #7df9ff; }
.tile b { color: #ffd166; font-size: 13px; }

#hud {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  z-index: 5;
  pointer-events: none;
}
#hud button { pointer-events: auto; }
.hud-buttons { display: flex; gap: 10px; margin-left: auto; }
.hud-target {
  font-size: clamp(13px, 2.4vmin, 16px);
  font-weight: 700;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(11, 10, 28, 0.55);
  color: #ffd166;
}
.hud-target:empty { display: none; }
.corner {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
}

.big-score {
  font-size: clamp(50px, 14vmin, 110px);
  font-weight: 800;
  line-height: 1;
  color: #ffd166;
  text-shadow: 0 0 24px rgba(255, 209, 102, 0.45);
}
.badge {
  padding: 4px 14px;
  border-radius: 999px;
  background: #ff4d8d;
  color: #fff;
  font-weight: 800;
  font-size: clamp(13px, 2.6vmin, 17px);
  animation: pop 0.6s ease infinite alternate;
}
@keyframes pop { from { transform: scale(1); } to { transform: scale(1.08); } }
.hint-line { font-size: clamp(14px, 2.8vmin, 18px); font-weight: 700; color: #ff9fbf; max-width: 28em; }
.hint-line:empty { display: none; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: 6px 20px;
  font-size: clamp(12px, 2.4vmin, 15px);
}
.stats div { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.stats span { opacity: 0.65; }
.stats b { font-size: 1.2em; }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, auto); } }

.reward-line { font-size: clamp(15px, 3vmin, 19px); }
.reward-line b, .dust-ico { color: #ffd166; }
.reward-line small { opacity: 0.7; font-size: 0.75em; }
.frag-ico { color: #b48cff; }
.ach-toasts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; max-width: 34em; }
.ach-toasts:empty { display: none; }
.ach-chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: rgba(255, 209, 102, 0.16); border: 1px solid rgba(255, 209, 102, 0.6); }

/* compact layout for short landscape screens (phones, 800x450 iframes) */
@media (max-height: 560px) {
  .title span { display: inline; }
  .tagline, .hint { display: none; }
  .screen { gap: 6px; padding: 10px; }
  .tile { min-height: 64px; width: 96px; padding: 6px; }
  .tile-ico { font-size: 18px; }
  .big-score { font-size: 54px; }
  .btn { min-height: 40px; padding: 6px 18px; }
}

/* panels */
.panel { background: rgba(8, 7, 20, 0.88); justify-content: center; }
.panel-box {
  width: min(560px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 18px;
  background: #15123a;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}
.panel-box header { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px 10px 18px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); }
.panel-box header h2 { font-size: 22px; }
.panel-body { padding: 12px 16px 16px; overflow-y: auto; touch-action: pan-y; text-align: left; }
.panel-body.center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }

.wallet { display: flex; gap: 18px; justify-content: center; font-size: 15px; margin-bottom: 6px; }
.cap-stage { display: flex; flex-direction: column; align-items: center; gap: 4px; margin: 4px 0 8px; }
.cap-stage canvas { width: 120px; height: 120px; }
.cap-result { min-height: 1.4em; font-weight: 800; text-align: center; }
#btn-open { display: flex; margin: 0 auto; }
.pity { font-size: 13px; text-align: center; margin-top: 8px; opacity: 0.85; }
.rates, .top-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.rates th, .rates td, .top-table th, .top-table td { padding: 5px 6px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); text-align: left; }
.rates th, .top-table th { opacity: 0.6; font-weight: 600; }
.r-common { color: #c9d3e3; } .r-rare { color: #5cb2ff; } .r-epic { color: #c08cff; } .r-legendary { color: #ffc23d; }
.top-table .me td { color: #ffd166; font-weight: 700; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: rgba(255, 209, 102, 0.2); color: #ffd166; }

.progress { position: relative; height: 22px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); overflow: hidden; margin-bottom: 10px; }
.progress-bar { position: absolute; inset: 0 auto 0 0; background: linear-gradient(90deg, #6c4cff, #7df9ff); }
.progress span { position: relative; display: block; text-align: center; font-size: 12px; line-height: 22px; font-weight: 700; }
.coll-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.coll-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 12px; border: 2px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04); color: inherit; font: inherit; font-size: 11px; cursor: pointer;
}
.coll-item canvas { width: 56px; height: 56px; }
.coll-item.locked canvas { opacity: 0.25; filter: grayscale(1); }
.coll-item.equipped { border-color: #7df9ff; box-shadow: 0 0 10px rgba(125, 249, 255, 0.4); }
.coll-item.selected { background: rgba(255, 255, 255, 0.12); }
.coll-detail { min-height: 64px; display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; margin-bottom: 10px; padding: 8px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.05); font-size: 14px; }
.coll-detail .btn { min-width: 120px; min-height: 40px; font-size: 15px; }

.ach-list { list-style: none; display: grid; gap: 6px; }
.ach-list li { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.04); font-size: 13px; }
.ach-list li.done { background: rgba(255, 209, 102, 0.12); }
.ach-list .ico { font-size: 18px; width: 22px; text-align: center; }
.ach-list li:not(.done) .ico { opacity: 0.3; }
.ach-list .txt { flex: 1; }
.ach-list .txt small { display: block; opacity: 0.65; }
.ach-list .rw { color: #ffd166; font-weight: 700; white-space: nowrap; }

.global-box { width: min(420px, 100%); }
.global-row { display: flex; gap: 8px; }
.global-row input {
  flex: 1; min-width: 0; min-height: 42px; padding: 6px 14px; border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.3); background: rgba(255, 255, 255, 0.08); color: inherit;
  font: inherit; font-size: 16px; user-select: text; -webkit-user-select: text; touch-action: manipulation;
}
.global-row input:focus { outline: none; border-color: #7df9ff; }
.btn.small { min-width: 0; min-height: 42px; padding: 6px 16px; font-size: 15px; }
.note.center { text-align: center; }
.note.ok { color: #7dffcf; opacity: 1; font-weight: 700; }
.note.err { color: #ff9fbf; opacity: 1; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.tab { padding: 4px 12px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, 0.25); background: transparent; color: inherit; font: inherit; font-size: 13px; cursor: pointer; }
.tab.active { background: rgba(125, 249, 255, 0.18); border-color: #7df9ff; }

.share-box { width: min(440px, 100%); }
.share-img { width: min(320px, 70vmin); height: auto; border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5); user-select: auto; -webkit-user-select: auto; -webkit-touch-callout: default; }

.toast {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  padding: 8px 16px; border-radius: 999px; background: rgba(21, 18, 58, 0.95); border: 1px solid rgba(255, 209, 102, 0.6);
  font-size: 14px; font-weight: 700; z-index: 20; pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(125, 249, 255, 0.2);
  border-top-color: #7df9ff;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes reveal { 0% { transform: scale(0.3) rotate(-30deg); opacity: 0; } 70% { transform: scale(1.15) rotate(6deg); opacity: 1; } 100% { transform: scale(1) rotate(0); } }
.reveal { animation: reveal 0.55s ease-out; }
