:root {
  --gold: #ffd36e;
  --gold-2: #ffb02e;
  --cyan: #7fe6ff;
  --ink: #eef1ff;
  --muted: #9aa3c7;
  --panel: rgba(13, 17, 42, 0.82);
  --panel-2: rgba(28, 34, 74, 0.75);
  --line: rgba(150, 170, 255, 0.16);
  --good: #5ee6a0;
  --bad: #ff6b7d;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #05071a; color: var(--ink);
  font-family: var(--font);
  -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
canvas#game { position: fixed; inset: 0; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font-family: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 1.1rem; top: 0.9rem;
  pointer-events: none;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.7);
}
#dust-row { display: flex; align-items: center; gap: 0.5rem; }
#dust { font-size: 2.5rem; font-weight: 900; letter-spacing: -0.02em; color: #fff; font-variant-numeric: tabular-nums; }
.dust-icon {
  display: inline-block; width: 1.4rem; height: 1.4rem; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff 0 18%, var(--gold) 40%, var(--gold-2) 70%, transparent 72%);
  box-shadow: 0 0 14px rgba(255, 190, 80, 0.7);
  flex: none;
}
#rate { font-size: 1.15rem; font-weight: 700; color: var(--gold); margin-left: 1.9rem; font-variant-numeric: tabular-nums; }
#boost, #shards {
  margin: 0.45rem 0 0 1.9rem; display: inline-block;
  font-size: 0.85rem; font-weight: 800; padding: 0.2rem 0.6rem; border-radius: 999px;
}
#boost { background: rgba(127, 230, 255, 0.18); color: var(--cyan); border: 1px solid rgba(127, 230, 255, 0.4); }
#shards { display: block; width: fit-content; background: rgba(200, 160, 255, 0.14); color: #d9c2ff; border: 1px solid rgba(200, 160, 255, 0.3); }
#boost[hidden], #shards[hidden] { display: none; }
/* optional rewarded-ad boost (Playgama build only; hidden where the platform has no rewarded ads) */
#btn-adboost {
  display: block; width: fit-content; margin: 0.45rem 0 0 1.9rem; pointer-events: auto;
  font-size: 0.85rem; font-weight: 800; padding: 0.3rem 0.75rem; border-radius: 999px;
  background: linear-gradient(180deg, rgba(127, 230, 255, 0.35), rgba(80, 160, 255, 0.25));
  color: #e9fbff; border: 1px solid rgba(127, 230, 255, 0.6);
  box-shadow: 0 0 16px rgba(127, 230, 255, 0.35);
  text-shadow: none;
}
#btn-adboost::before { content: "▶ "; color: var(--cyan); }
/* current goal (first mission) on the main screen */
#goal {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.12rem;
  margin: 0.5rem 0 0 1.9rem; padding: 0.4rem 0.7rem 0.45rem; width: 15rem; max-width: calc(100vw - 4rem);
  pointer-events: auto; text-align: left; text-shadow: none;
  background: rgba(13, 17, 42, 0.72); border: 1px solid rgba(255, 255, 255, 0.14); border-radius: 0.8rem;
}
#goal[hidden] { display: none; }
#goal small { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
#goal strong { font-size: 0.92rem; font-weight: 800; color: #fff; }
#goal i { display: block; width: 100%; height: 0.32rem; margin: 0.15rem 0 0.05rem; border-radius: 999px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
#goal i b { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--gold-2), var(--gold)); transition: width 0.3s; }
#goal span { font-size: 0.76rem; color: var(--muted); font-variant-numeric: tabular-nums; }
#goal.done { border-color: rgba(182, 245, 154, 0.75); background: rgba(40, 90, 30, 0.6); animation: goalPulse 1.2s ease-in-out infinite; }
#goal.done small, #goal.done span { color: #c9f7b5; }
#goal.done span { font-weight: 800; }
@keyframes goalPulse { 50% { box-shadow: 0 0 22px rgba(150, 240, 120, 0.55); } }
#btn-adboost:disabled { opacity: 0.6; }
#btn-adboost[hidden] { display: none; }
.modal-btns .ad { background: rgba(127, 230, 255, 0.16); color: var(--cyan); border: 1px solid rgba(127, 230, 255, 0.45); }
.modal-btns .ad:disabled { opacity: 0.65; }

/* ---------- side panel ---------- */
#panel {
  position: absolute; right: 0.8rem; top: 0.8rem; bottom: 0.8rem;
  width: 22rem;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 1rem;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  overflow: hidden;
}
.tabs { display: flex; padding: 0.4rem; gap: 0.3rem; border-bottom: 1px solid var(--line); flex: none; }
.tabs button {
  flex: 1; padding: 0.55rem 0.2rem; border-radius: 0.6rem;
  font-size: 0.92rem; font-weight: 800; color: var(--muted);
  position: relative;
}
.tabs button.on { background: var(--panel-2); color: #fff; }
.badge {
  position: absolute; top: 0.15rem; right: 0.3rem;
  min-width: 1.15rem; height: 1.15rem; padding: 0 0.3rem; border-radius: 999px;
  background: var(--bad); color: #fff; font-size: 0.72rem; line-height: 1.15rem;
  animation: pop 1.2s ease-in-out infinite;
}
.badge[hidden] { display: none; }
@keyframes pop { 50% { transform: scale(1.15); } }

.tab-body { flex: 1; overflow-y: auto; padding: 0.5rem; scrollbar-width: thin; scrollbar-color: rgba(150,170,255,0.3) transparent; }
.tab-body[hidden] { display: none; }

.up-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.55rem; margin-bottom: 0.4rem; border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid transparent;
  transition: border-color 0.2s, background 0.2s;
}
.up-row[hidden] { display: none; }
.up-row.glow { border-color: var(--gold); background: rgba(255, 211, 110, 0.1); animation: glow 1s ease-in-out infinite; }
@keyframes glow { 50% { box-shadow: 0 0 18px rgba(255, 211, 110, 0.45); } }
.up-icon {
  width: 2.5rem; height: 2.5rem; flex: none; border-radius: 0.6rem;
  display: grid; place-items: center;
  background: linear-gradient(145deg, rgba(127, 230, 255, 0.18), rgba(160, 96, 255, 0.18));
  color: var(--cyan);
}
.up-icon svg { width: 1.5rem; height: 1.5rem; }
.up-text { flex: 1; min-width: 0; }
.up-name { font-weight: 800; font-size: 0.95rem; white-space: nowrap; }
.up-lvl { color: var(--muted); font-weight: 700; font-size: 0.8rem; margin-left: 0.25rem; }
.up-eff { color: var(--muted); font-size: 0.82rem; margin-top: 0.15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-buy {
  flex: none; min-width: 5.2rem; padding: 0.55rem 0.6rem; border-radius: 0.65rem;
  font-weight: 900; font-size: 0.92rem;
  background: rgba(255, 255, 255, 0.07); color: rgba(255, 255, 255, 0.45);
  touch-action: manipulation;
  font-variant-numeric: tabular-nums;
}
.up-buy .cost::before {
  content: ""; display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; margin-right: 0.3rem; vertical-align: -0.05rem;
  background: radial-gradient(circle at 35% 35%, #fff 0 15%, var(--gold) 45%, var(--gold-2) 75%);
}
.up-buy.can { background: linear-gradient(180deg, #ffe08a, #ffb02e); color: #2b1a00; box-shadow: 0 3px 0 #b86f00; }
.up-buy.can:active { transform: translateY(2px); box-shadow: 0 1px 0 #b86f00; }
.up-buy.maxed { background: rgba(94, 230, 160, 0.15); color: var(--good); }
.up-buy.maxed .cost::before { display: none; }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }

/* missions */
.mi-row {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.65rem; margin-bottom: 0.45rem; border-radius: 0.75rem;
  background: rgba(255, 255, 255, 0.035);
}
.mi-row.done { background: rgba(94, 230, 160, 0.1); border: 1px solid rgba(94, 230, 160, 0.35); }
.mi-text { flex: 1; min-width: 0; }
.mi-title { font-weight: 800; font-size: 0.92rem; }
.mi-bar { height: 0.4rem; border-radius: 999px; background: rgba(255, 255, 255, 0.08); margin: 0.4rem 0 0.25rem; overflow: hidden; }
.mi-bar i { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--cyan), var(--good)); }
.mi-prog { font-size: 0.8rem; color: var(--muted); }
.mi-claim {
  flex: none; min-width: 5.2rem; padding: 0.45rem 0.5rem; border-radius: 0.65rem;
  font-weight: 900; font-size: 0.9rem; display: flex; flex-direction: column; align-items: center;
  background: rgba(255, 255, 255, 0.06); color: var(--muted);
}
.mi-claim span { font-size: 0.75rem; color: var(--gold); }
.mi-claim:not([disabled]) { background: linear-gradient(180deg, #7ff0b8, #2fc982); color: #062614; box-shadow: 0 3px 0 #178a52; animation: glow 1.2s infinite; }
.mi-claim:not([disabled]) span { color: #0b3d22; }
.mi-note[hidden] { display: none; }
.mi-note { text-align: center; color: var(--muted); font-size: 0.75rem; margin-top: 0.6rem; }

/* codex */
.co-head { text-align: center; color: var(--muted); font-size: 0.85rem; margin: 0.2rem 0 0.6rem; }
.co-head b { color: #fff; }
.co-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.45rem; }
.co-card { background: rgba(255, 255, 255, 0.035); border-radius: 0.7rem; padding: 0.5rem 0.25rem; text-align: center; display: flex; flex-direction: column; align-items: center; }
.co-card canvas { margin-bottom: 0.25rem; }
.co-name { font-weight: 800; font-size: 0.82rem; }
.co-sub { font-size: 0.74rem; color: var(--muted); margin-top: 0.1rem; }
.co-card.unknown .co-name { color: var(--muted); }

/* ---------- corner buttons ---------- */
#corner { position: absolute; left: 1rem; bottom: 1rem; display: flex; gap: 0.5rem; }
.round {
  width: 2.7rem; height: 2.7rem; border-radius: 50%;
  background: var(--panel); border: 1px solid var(--line);
  display: grid; place-items: center; color: #fff;
}
.round svg { width: 1.35rem; height: 1.35rem; }
.round.off { color: var(--muted); }

#btn-nova {
  position: absolute; left: 50%; bottom: 1.1rem; transform: translateX(-50%);
  padding: 0.75rem 1.6rem; border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #ffd6f0 30%, #c06bff);
  color: #2a0a3a; font-weight: 900; font-size: 1.1rem;
  box-shadow: 0 0 30px rgba(220, 120, 255, 0.7), 0 4px 0 #7a2fae;
  animation: novaPulse 1.6s ease-in-out infinite;
  display: flex; flex-direction: column; align-items: center; line-height: 1.1;
}
#btn-nova small { font-size: 0.78rem; font-weight: 800; }
#btn-nova[hidden] { display: none; }
@keyframes novaPulse { 50% { box-shadow: 0 0 50px rgba(220, 120, 255, 0.95), 0 4px 0 #7a2fae; } }

/* ---------- banner, hint, toast ---------- */
#banner {
  position: absolute; left: 50%; top: 1rem; transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem 1.3rem 0.6rem 0.8rem; border-radius: 1rem;
  background: rgba(13, 17, 42, 0.9); border: 1px solid rgba(255, 211, 110, 0.5);
  box-shadow: 0 0 40px rgba(255, 190, 80, 0.3);
  pointer-events: none;
}
#banner[hidden] { display: none; }
#banner.show { animation: bannerIn 2.6s ease forwards; }
@keyframes bannerIn {
  0% { opacity: 0; transform: translate(-50%, -20px) scale(0.9); }
  10% { opacity: 1; transform: translate(-50%, 0) scale(1.04); }
  16% { transform: translate(-50%, 0) scale(1); }
  85% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -10px); }
}
.banner-text { display: flex; flex-direction: column; white-space: nowrap; }
.banner-text small { text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.7rem; color: var(--gold); font-weight: 800; }
.banner-text b { font-size: 1.35rem; font-weight: 900; }
.banner-text span { font-size: 0.8rem; color: var(--muted); }
.banner-text .next { color: var(--gold); opacity: 0.9; }

#hint {
  position: fixed; z-index: 5; pointer-events: none;
  background: #fff; color: #111833; font-weight: 800; font-size: 0.9rem;
  padding: 0.5rem 0.8rem; border-radius: 0.6rem; white-space: nowrap;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
#hint[hidden] { display: none; }
#hint.left { transform: translate(-100%, -50%); animation: nudgeL 0.9s ease-in-out infinite; }
#hint.left::after { content: ""; position: absolute; right: -0.45rem; top: 50%; transform: translateY(-50%); border: 0.5rem solid transparent; border-right: 0; border-left-color: #fff; }
#hint.up { transform: translate(-50%, -100%); animation: nudgeU 0.9s ease-in-out infinite; }
#hint.up::after { content: ""; position: absolute; bottom: -0.45rem; left: 50%; transform: translateX(-50%); border: 0.5rem solid transparent; border-bottom: 0; border-top-color: #fff; }
@keyframes nudgeL { 50% { margin-left: -6px; } }
@keyframes nudgeU { 50% { margin-top: -6px; } }

.toast {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
  background: rgba(13, 17, 42, 0.92); border: 1px solid var(--line);
  padding: 0.7rem 1.2rem; border-radius: 0.8rem; font-weight: 800;
  pointer-events: none; animation: toast 2.6s ease forwards;
}
@keyframes toast { 0% { opacity: 0; } 10%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- modal ---------- */
#modal {
  position: absolute; inset: 0; z-index: 10;
  background: rgba(3, 4, 16, 0.6);
  display: grid; place-items: center; padding: 1rem;
}
#modal[hidden] { display: none; }
.modal-card {
  width: min(27rem, 100%);
  max-height: 100%; overflow-y: auto;
  background: linear-gradient(180deg, #161c44, #0e1230);
  border: 1px solid rgba(150, 170, 255, 0.28);
  border-radius: 1.1rem; padding: 1.2rem 1.3rem 1.1rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: modalIn 0.25s ease;
  text-align: center;
}
@keyframes modalIn { from { transform: scale(0.92); opacity: 0; } }
.modal-card h2 { margin: 0 0 0.6rem; font-size: 1.35rem; font-weight: 900; }
.modal-body { font-size: 0.95rem; color: #d6dbf5; }
.modal-body p { margin: 0.4rem 0; }
.muted { color: var(--muted) !important; font-size: 0.85rem; }
.big-reward {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  font-size: 2.1rem; font-weight: 900; color: #fff; margin: 0.7rem 0;
}
.modal-btns { display: flex; gap: 0.6rem; justify-content: center; margin-top: 1rem; flex-wrap: wrap; }
.modal-btns button {
  min-width: 7.5rem; padding: 0.7rem 1rem; border-radius: 0.75rem;
  font-weight: 900; font-size: 1rem;
  background: rgba(255, 255, 255, 0.08);
}
.modal-btns .primary { background: linear-gradient(180deg, #ffe08a, #ffb02e); color: #2b1a00; box-shadow: 0 3px 0 #b86f00; }
.modal-btns .primary.nova { background: linear-gradient(180deg, #fff, #e7b3ff 40%, #b05cff); color: #2a0a3a; box-shadow: 0 3px 0 #7a2fae; }
.modal-btns .danger { background: rgba(255, 107, 125, 0.15); color: var(--bad); }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 0.3rem; margin: 0.4rem 0; }
.day { background: rgba(255, 255, 255, 0.05); border-radius: 0.55rem; padding: 0.4rem 0.1rem; display: flex; flex-direction: column; }
.day small { font-size: 0.62rem; color: var(--muted); }
.day b { font-size: 0.85rem; }
.day.past { opacity: 0.45; }
.day.now { background: linear-gradient(180deg, rgba(255, 211, 110, 0.35), rgba(255, 176, 46, 0.2)); border: 1px solid var(--gold); }
.nova-list { text-align: left; margin: 0.6rem 0 0; padding-left: 1.2rem; }
.nova-list li { margin: 0.35rem 0; }
.nova-list li.lose { color: var(--muted); }
.set-row { display: flex; justify-content: space-between; align-items: center; padding: 0.55rem 0.2rem; border-bottom: 1px solid var(--line); font-weight: 700; }
.tog { width: 3rem; height: 1.7rem; border-radius: 999px; background: rgba(255, 255, 255, 0.12); position: relative; transition: background 0.2s; }
.tog::after { content: ""; position: absolute; left: 0.2rem; top: 0.2rem; width: 1.3rem; height: 1.3rem; border-radius: 50%; background: #fff; transition: left 0.2s; }
.tog.on { background: var(--good); }
.tog.on::after { left: 1.5rem; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.8rem; }
.stats div { background: rgba(255, 255, 255, 0.04); border-radius: 0.6rem; padding: 0.45rem; display: flex; flex-direction: column; }
.stats small { color: var(--muted); font-size: 0.72rem; }
.stats b { font-size: 1rem; }

/* ---------- portrait (phones) ---------- */
body.portrait #panel { left: 0.5rem; right: 0.5rem; top: auto; bottom: 0.5rem; width: auto; height: 41%; }
body.portrait #hud { left: 0.8rem; top: 0.6rem; }
body.portrait #dust { font-size: 2rem; }
body.portrait #corner { left: auto; right: 0.6rem; top: 0.6rem; bottom: auto; flex-direction: column; }
body.portrait #btn-nova { bottom: calc(41% + 1rem); }
body.portrait #banner { top: 5.2rem; padding: 0.4rem 1rem 0.4rem 0.6rem; }
/* the discovery banner's top is set from the HUD's height in ui.js update() */
body.portrait #goal { width: 13.5rem; }
body.portrait #banner canvas { width: 48px !important; height: 48px !important; }
body.portrait .co-grid { grid-template-columns: repeat(4, 1fr); }
