* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  width: 100%; height: 100%; overflow: hidden; background: #9fd6f5;
  font-family: "Segoe UI", "Inter", system-ui, -apple-system, sans-serif;
  color: #f8fafc; user-select: none; -webkit-user-select: none;
}
button { font-family: inherit; cursor: pointer; border: none; }
.hidden { display: none !important; }

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

/* ---------- loading ---------- */
#loading {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px;
  background: radial-gradient(circle at 50% 35%, #334155, #0f172a);
  color: #fff;
}
#loading .logo {
  font-size: clamp(30px, 7vw, 52px); font-weight: 900; letter-spacing: -0.5px;
  background: linear-gradient(180deg, #fde047, #f59e0b); -webkit-background-clip: text; color: transparent;
  filter: drop-shadow(0 4px 12px rgba(245, 158, 11, 0.35));
  text-align: center; padding: 0 16px;
}
#loading .bar { width: 280px; height: 14px; border-radius: 99px; background: rgba(255,255,255,0.12); overflow: hidden; padding: 2px; }
#loadBar { width: 5%; height: 100%; border-radius: 99px; background: linear-gradient(90deg, #22c55e, #facc15); transition: width .2s; }
#loading .hintText { font-weight: 700; color: #cbd5e1; font-size: 14px; }

/* ---------- HUD ---------- */
#hud {
  position: fixed; left: 14px; top: 14px; z-index: 10;
  pointer-events: none; display: flex; flex-direction: column; gap: 8px; align-items: flex-start;
  max-width: calc(100vw - 390px);
}
.moneyCard {
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border: 1.5px solid rgba(255, 255, 255, 0.14);
  border-radius: 18px; padding: 10px 18px 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}
.moneyRow { display: flex; align-items: center; gap: 12px; }
.coinBadge {
  width: 42px; height: 42px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 900; color: #422006;
  background: linear-gradient(145deg, #fef08a, #f59e0b);
  box-shadow: inset 0 2px 0 rgba(255,255,255,0.5), 0 3px 0 #b45309;
}
#money { font-size: 30px; font-weight: 900; color: #4ade80; line-height: 1.05; letter-spacing: -0.5px; }
#income { font-size: 13px; font-weight: 700; color: #94a3b8; margin-top: 2px; }
#starsHud {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12.5px; font-weight: 800; color: #fbbf24;
}

#boostsRow { display: flex; flex-wrap: wrap; gap: 6px; }
.boostPill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 99px; font-size: 12.5px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  border: 1.5px solid rgba(255,255,255,0.22);
}
.boostPill span { background: rgba(0,0,0,0.25); padding: 1px 7px; border-radius: 99px; font-variant-numeric: tabular-nums; }
.boostPill.starter { background: linear-gradient(135deg, #10b981, #059669); color: #fff; }
.boostPill.ad { background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff; animation: pulse 1.4s infinite; }
.boostPill.turbo { background: linear-gradient(135deg, #f59e0b, #ea580c); color: #fff; animation: pulse 0.9s infinite; }

#factoryBar { pointer-events: auto; display: flex; flex-wrap: wrap; gap: 6px; }
#factoryBar button {
  display: flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 12px;
  font-size: 13px; font-weight: 800; color: #e2e8f0;
  background: rgba(15, 23, 42, 0.78); backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255,255,255,0.14);
  box-shadow: 0 3px 0 rgba(0,0,0,0.3); transition: transform .08s, background .15s;
}
#factoryBar button:hover { background: rgba(30, 41, 59, 0.92); }
#factoryBar button:active { transform: translateY(2px); }
#factoryBar button.active {
  background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff;
  border-color: rgba(255,255,255,0.35); box-shadow: 0 3px 0 #15803d, 0 0 16px rgba(34,197,94,0.35);
}
#factoryBar button.locked { background: rgba(15, 23, 42, 0.58); color: #94a3b8; }
#factoryBar button.canBuy {
  background: linear-gradient(135deg, #fde047, #f59e0b); color: #422006;
  border-color: #fef08a; box-shadow: 0 3px 0 #b45309; animation: pulse 1.1s infinite;
}
#factoryBar button .price { font-size: 11px; opacity: 0.92; font-weight: 900; }

#product {
  background: rgba(15, 23, 42, 0.74); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12); color: #e2e8f0;
  padding: 5px 12px; border-radius: 10px; font-size: 12.5px; font-weight: 600;
}
#product b { color: #fde047; }

@keyframes pulse { 50% { transform: scale(1.04); } }

/* ---------- top utility buttons ---------- */
#topBtns { position: fixed; z-index: 12; top: 14px; right: 368px; display: flex; gap: 8px; }
#topBtns button {
  width: 42px; height: 42px; border-radius: 12px;
  background: rgba(15, 23, 42, 0.82); backdrop-filter: blur(8px);
  border: 1.5px solid rgba(255,255,255,0.16); color: #fff; font-size: 19px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.22); transition: transform .08s, background .15s;
}
#topBtns button:hover { background: rgba(30, 41, 59, 0.95); }
#topBtns button:active { transform: translateY(2px); }

/* ---------- tutorial banner ---------- */
#tutorial {
  position: fixed; z-index: 20; left: calc((100% - 354px) / 2); top: 14px; transform: translateX(-50%);
  width: min(440px, calc(100vw - 380px));
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.95));
  border: 2px solid #facc15; border-radius: 18px; padding: 12px 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4), 0 0 20px rgba(250, 204, 21, 0.2);
  color: #f8fafc; pointer-events: auto;
}
.tutTop { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tutBadge {
  background: linear-gradient(135deg, #facc15, #f59e0b); color: #422006;
  font-size: 11.5px; font-weight: 900; padding: 3px 9px; border-radius: 99px; text-transform: uppercase;
}
.tutSkip {
  background: transparent; color: #94a3b8; font-size: 12px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
}
.tutSkip:hover { color: #fff; background: rgba(255,255,255,0.1); }
#tutText { font-size: 14px; line-height: 1.42; font-weight: 600; color: #f1f5f9; }
#tutText b { color: #fde047; }
#tutActions { margin-top: 10px; display: flex; justify-content: flex-end; }
.tutNext {
  padding: 7px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #22c55e, #16a34a); box-shadow: 0 3px 0 #15803d;
}
.tutNext:active { transform: translateY(2px); }

.tut-highlight {
  outline: 3px solid #facc15 !important;
  outline-offset: 2px;
  box-shadow: 0 0 0 6px rgba(250, 204, 21, 0.35), 0 6px 20px rgba(250, 204, 21, 0.45) !important;
  animation: tutPulse 1s infinite !important;
}
@keyframes tutPulse {
  50% { box-shadow: 0 0 0 10px rgba(250, 204, 21, 0.12), 0 6px 24px rgba(250, 204, 21, 0.65); }
}

/* ---------- contextual hint ---------- */
#hint {
  position: fixed; z-index: 11; left: calc((100% - 354px) / 2); top: 14px; transform: translateX(-50%);
  max-width: 420px;
  background: rgba(15, 23, 42, 0.88); backdrop-filter: blur(8px);
  border: 2px solid #facc15; border-radius: 14px; padding: 8px 14px;
  font-weight: 700; text-align: center; font-size: 13.5px; color: #f8fafc;
  box-shadow: 0 6px 18px rgba(0,0,0,0.3); pointer-events: none; animation: bob 1.6s ease-in-out infinite;
}
#hint b { color: #fde047; }
@keyframes bob { 50% { transform: translate(-50%, 4px); } }

/* ---------- bottom action buttons ---------- */
#actions {
  position: fixed; z-index: 10; left: 14px; bottom: 14px;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  max-width: calc(100vw - 380px);
}
#actions button {
  display: flex; align-items: center; gap: 9px; padding: 11px 18px; border-radius: 15px;
  font-size: 22px; font-weight: 800; color: #fff;
  border: 1.5px solid rgba(255,255,255,0.22);
  box-shadow: 0 5px 0 rgba(0,0,0,0.32), 0 8px 20px rgba(0,0,0,0.25);
  transition: transform .06s, filter .15s;
}
#actions button span { font-size: 14.5px; letter-spacing: -0.2px; }
#actions button:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 2px 0 rgba(0,0,0,0.32); }
#spawnBtn { background: linear-gradient(135deg, #f59e0b, #d97706); }
#adBtn { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
#adBtn:disabled { filter: grayscale(0.75); opacity: 0.72; cursor: default; }
#controlsHint {
  background: rgba(15, 23, 42, 0.74); backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12); color: #cbd5e1;
  padding: 7px 12px; border-radius: 11px; font-size: 12px; font-weight: 600; pointer-events: none;
}
.shake { animation: shake .25s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

/* ---------- right panel ---------- */
#panel {
  position: fixed; z-index: 14; right: 0; top: 0; bottom: 0; width: 354px;
  background: rgba(15, 23, 42, 0.94); backdrop-filter: blur(14px);
  border-left: 1.5px solid rgba(255, 255, 255, 0.12);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 28px rgba(0, 0, 0, 0.35);
}
.tabs {
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px; gap: 6px; background: rgba(2, 6, 23, 0.55);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.tabs button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 11px; font-weight: 800; font-size: 11.5px;
  background: rgba(30, 41, 59, 0.7); color: #94a3b8;
  border: 1px solid rgba(255,255,255,0.06); transition: background .15s, color .15s;
}
.tabs button .tIcon { font-size: 17px; line-height: 1; }
.tabs button:hover { color: #e2e8f0; background: rgba(51, 65, 85, 0.75); }
.tabs button.active {
  background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff;
  border-color: rgba(255,255,255,0.25); box-shadow: 0 3px 10px rgba(37, 99, 235, 0.35);
}
.tabs button.ready { background: linear-gradient(135deg, #f59e0b, #d97706); color: #fff; }
.tabs button .dot {
  position: absolute; top: 5px; right: 7px; width: 8px; height: 8px; border-radius: 50%;
  background: #4ade80; box-shadow: 0 0 8px #4ade80;
}

.tab { display: none; flex: 1; overflow-y: auto; padding: 10px; gap: 9px; flex-direction: column; }
.tab.active { display: flex; }
.tab::-webkit-scrollbar { width: 6px; }
.tab::-webkit-scrollbar-track { background: transparent; }
.tab::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.3); border-radius: 99px; }

.sectionTitle {
  font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.8px;
  color: #94a3b8; padding: 6px 4px 2px;
}
.linePicker {
  display: flex; gap: 5px; background: rgba(2, 6, 23, 0.5); padding: 5px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.08);
}
.linePicker button {
  flex: 1; padding: 7px 4px; border-radius: 8px; font-weight: 800; font-size: 12px;
  background: rgba(30, 41, 59, 0.8); color: #94a3b8;
}
.linePicker button.active { background: linear-gradient(135deg, #22c55e, #16a34a); color: #fff; box-shadow: 0 2px 0 #15803d; }
.linePicker button:disabled { opacity: 0.4; cursor: default; }

/* ---------- cards ---------- */
.card {
  display: grid; grid-template-columns: 46px 1fr; grid-template-rows: auto auto auto; gap: 4px 10px; align-items: center;
  background: rgba(30, 41, 59, 0.82); border-radius: 15px; padding: 10px 11px;
  border: 1.5px solid rgba(255, 255, 255, 0.09);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22); transition: border-color .2s, transform .1s;
}
.card.flash { border-color: #facc15; box-shadow: 0 0 18px rgba(250, 204, 21, 0.35); }
.card.locked { opacity: 0.5; }
.card.beltCard { background: linear-gradient(145deg, rgba(66, 48, 18, 0.82), rgba(30, 41, 59, 0.9)); border-color: rgba(250, 204, 21, 0.35); }
.card.lineCard { background: linear-gradient(145deg, rgba(23, 47, 82, 0.85), rgba(30, 41, 59, 0.9)); border-color: rgba(56, 189, 248, 0.35); }
.card.equipped { border-color: #4ade80; background: linear-gradient(145deg, rgba(20, 62, 42, 0.85), rgba(30, 41, 59, 0.9)); }
.card .icon {
  width: 46px; height: 46px; border-radius: 12px; grid-row: span 2;
  display: flex; align-items: center; justify-content: center; font-size: 27px;
  background: rgba(15, 23, 42, 0.65); border: 1px solid rgba(255,255,255,0.08);
}
.card .name { font-weight: 800; font-size: 14px; color: #f8fafc; line-height: 1.25; }
.card .lvl {
  font-size: 11px; font-weight: 800; color: #052e16; background: #4ade80;
  border-radius: 6px; padding: 1px 6px; margin-left: 4px; white-space: nowrap; display: inline-block;
}
.card .desc { font-size: 11.5px; color: #94a3b8; margin-top: 1px; }
.card .stat { font-size: 12px; font-weight: 700; color: #4ade80; }
.card .ms { font-size: 11px; font-weight: 700; color: #fbbf24; margin-top: 1px; }
.card .msBar {
  grid-column: 1 / -1; height: 5px; border-radius: 99px; background: rgba(15, 23, 42, 0.7);
  overflow: hidden; margin-top: 2px;
}
.card .msBar > div { height: 100%; background: linear-gradient(90deg, #facc15, #f97316); transition: width .2s; }
.card .buy {
  grid-column: 1 / -1; margin-top: 4px; padding: 9px 10px; border-radius: 10px;
  font-weight: 900; font-size: 13.5px; color: #fff;
  background: linear-gradient(135deg, #22c55e, #16a34a);
  box-shadow: 0 3px 0 #15803d; transition: transform .06s;
}
.card .buy.equip { background: linear-gradient(135deg, #3b82f6, #2563eb); box-shadow: 0 3px 0 #1d4ed8; }
.card .buy.stars { background: linear-gradient(135deg, #f59e0b, #d97706); box-shadow: 0 3px 0 #92400e; }
.card .buy:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,0.4); }
.card .buy:disabled { background: rgba(71, 85, 105, 0.55); color: #94a3b8; box-shadow: 0 3px 0 rgba(15,23,42,0.5); cursor: default; }

/* ---------- rebirth tab ---------- */
.rebirthBox {
  background: rgba(30, 41, 59, 0.85); border: 1.5px solid rgba(250, 204, 21, 0.28);
  border-radius: 16px; padding: 14px; display: flex; flex-direction: column; gap: 12px;
}
.rebirthBox h3 { font-size: 18px; color: #fde047; }
.rebirthBox p { font-size: 13px; color: #cbd5e1; line-height: 1.45; }
.rebirthBox p b { color: #fde047; }
.rebirthStats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rStat { background: rgba(15, 23, 42, 0.7); border: 1px solid rgba(255,255,255,0.08); border-radius: 12px; padding: 9px; text-align: center; }
.rStat .v { font-size: 20px; font-weight: 900; color: #fbbf24; }
.rStat .k { font-size: 11px; font-weight: 700; color: #94a3b8; margin-top: 2px; }
.rBar { height: 11px; background: rgba(15, 23, 42, 0.8); border-radius: 99px; overflow: hidden; }
.rBar > div { height: 100%; background: linear-gradient(90deg, #facc15, #f97316); transition: width .2s; }
.rebirthBtn {
  padding: 12px; border-radius: 12px; font-size: 15px; font-weight: 900; color: #fff;
  background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 4px 0 #9a3412;
}
.rebirthBtn:disabled { background: rgba(71, 85, 105, 0.55); color: #94a3b8; box-shadow: 0 3px 0 rgba(15,23,42,0.5); cursor: default; }

/* ---------- 3D labels & floats ---------- */
#labels, #floats { position: fixed; inset: 0; pointer-events: none; z-index: 6; }
.label {
  position: absolute; transform: translate(-50%, -100%); white-space: nowrap; text-align: center;
  pointer-events: auto; cursor: pointer;
  background: rgba(15, 23, 42, 0.84); color: #f8fafc;
  border: 1.5px solid rgba(255,255,255,0.18);
  padding: 4px 10px; border-radius: 10px; font-size: 12.5px; font-weight: 800;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.label b { color: #fde047; }
.label.buyable { background: linear-gradient(135deg, #22c55e, #16a34a); border-color: #bbf7d0; box-shadow: 0 4px 14px rgba(34, 197, 94, 0.45); }
.label.beltBuy { background: linear-gradient(135deg, #d97706, #b45309); border-color: #fde68a; }
.label.beltBuy.buyable { background: linear-gradient(135deg, #22c55e, #16a34a); border-color: #bbf7d0; }
.label.locked { background: rgba(30, 41, 59, 0.6); color: #94a3b8; border-color: rgba(255,255,255,0.08); }
.label.actLabel {
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.9), rgba(30, 41, 59, 0.9));
  border: 2px solid #38bdf8; color: #fff; font-size: 12.5px;
}
.label.actLabel.ready {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border-color: #fef08a; color: #fff;
}
.label.actLabel.vip {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  border-color: #fde047; color: #fff;
}
.label.actLabel.crate {
  background: linear-gradient(135deg, #eab308, #ca8a04);
  border-color: #fef9c3; color: #422006;
}

.float {
  position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 22px; color: #4ade80;
  text-shadow: 0 2px 0 #052e16, 0 0 10px rgba(0,0,0,0.45); animation: floatUp 1.15s ease-out forwards;
}
@keyframes floatUp { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -72px; } }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, 0.65); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; }
#modal .box {
  background: #1e293b; border: 1.5px solid rgba(255,255,255,0.15); border-radius: 22px; padding: 24px;
  width: min(400px, 92vw); text-align: center; box-shadow: 0 16px 40px rgba(0,0,0,0.5); color: #f8fafc;
}
#modal h2 { font-size: 23px; margin-bottom: 10px; color: #fde047; }
#modal p { font-size: 14.5px; line-height: 1.5; margin-bottom: 18px; color: #cbd5e1; }
#modal p b { color: #4ade80; font-size: 18px; }
#modalBtns { display: flex; flex-direction: column; gap: 10px; }
#modalBtns button {
  padding: 12px; border-radius: 12px; font-size: 15.5px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, #22c55e, #16a34a); box-shadow: 0 3px 0 #15803d;
}
#modalBtns button.ad { background: linear-gradient(135deg, #8b5cf6, #6d28d9); box-shadow: 0 3px 0 #4c1d95; }
#modalBtns button.warn { background: linear-gradient(135deg, #f97316, #ea580c); box-shadow: 0 3px 0 #9a3412; }
#modalBtns button.sec { background: #475569; box-shadow: 0 3px 0 #334155; }

/* ---------- mobile / portrait ---------- */
@media (max-width: 780px), (orientation: portrait) {
  #hud { max-width: calc(100vw - 150px); }
  #panel { top: auto; left: 0; width: 100%; height: 42vh; border-left: none; border-top: 2px solid rgba(255,255,255,0.15); }
  #topBtns { right: 12px; }
  #actions { bottom: calc(42vh + 10px); left: 10px; max-width: calc(100vw - 20px); }
  #actions button { padding: 8px 13px; font-size: 18px; }
  #actions button span { font-size: 13px; }
  #controlsHint { display: none; }
  #tutorial { left: 50%; top: auto; bottom: calc(42vh + 66px); width: min(94vw, 420px); padding: 10px 12px; }
  #hint { left: 50%; top: auto; bottom: calc(42vh + 66px); font-size: 12.5px; max-width: 92vw; }
  #money { font-size: 24px; }
  .coinBadge { width: 34px; height: 34px; font-size: 20px; }
}
