:root {
  --bg: #050814;
  --glass: rgba(12, 18, 42, 0.72);
  --glass-border: rgba(100, 210, 255, 0.28);
  --cyan: #00e5ff;
  --blue: #2979ff;
  --magenta: #e040fb;
  --gold: #ffab00;
  --text: #eef6ff;
  --muted: #8ea4cc;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  background: #03050e;
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  overflow: hidden;
  touch-action: manipulation;
}

#app {
  position: relative;
  width: 100%;
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 60px rgba(0, 229, 255, 0.12);
}

#bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

.screen {
  position: relative;
  z-index: 2;
  flex: 1;
  display: none;
  flex-direction: column;
  padding: calc(10px + var(--safe-top)) 14px 8px;
  overflow: hidden;
}

.screen.active {
  display: flex;
}

.game-screen {
  padding-bottom: calc(10px + var(--safe-bottom));
}

.hidden {
  display: none !important;
}

/* Header */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.player-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  background: rgba(13, 20, 46, 0.72);
  border: 1px solid rgba(0, 229, 255, 0.35);
  cursor: pointer;
}

.avatar-ring {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #2b3f88, #0d132e);
  border: 2px solid var(--cyan);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 12px rgba(0, 229, 255, 0.45);
}

.player-name {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.player-lv-row {
  display: flex;
  align-items: center;
  gap: 5px;
}

.player-lv {
  font-size: 10px;
  color: var(--cyan);
  font-weight: 700;
}

.xp-bar {
  width: 44px;
  height: 5px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  width: 45%;
  background: linear-gradient(90deg, var(--cyan), var(--magenta));
  border-radius: 99px;
}

.studio-mark {
  display: flex;
  align-items: center;
  gap: 6px;
}

.aenrox-svg {
  width: 24px;
  height: 22px;
  filter: drop-shadow(0 0 6px rgba(0, 229, 255, 0.55));
}

.studio-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.studio-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
}

.studio-sub {
  font-size: 7px;
  letter-spacing: 2px;
  color: var(--muted);
  margin-top: 2px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(160, 120, 255, 0.45);
  background: rgba(14, 21, 48, 0.78);
  color: #eaf6ff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(124, 77, 255, 0.3);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.icon-btn:active {
  transform: scale(0.93);
}

/* Hero Logo & Floating Blocks */
.hero-section {
  position: relative;
  flex: 1;
  min-height: 145px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 4px;
}

.logo-wrap {
  position: relative;
  z-index: 3;
  text-align: center;
}

.trubix-logo {
  font-size: clamp(34px, 9vw, 44px);
  font-weight: 900;
  font-style: italic;
  letter-spacing: 3px;
  background: linear-gradient(135deg, #ffffff 10%, #56f3ff 48%, #d966ff 90%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 18px rgba(0, 229, 255, 0.45));
  line-height: 1.02;
}

.trubix-logo span {
  -webkit-text-fill-color: #00f0ff;
}

.tagline {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 4px;
  color: #cbe2ff;
  margin-top: 2px;
}

.tagline span {
  width: 24px;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0, 229, 255, 0.7), transparent);
}

#hero-blocks-canvas {
  width: 100%;
  flex: 1;
  min-height: 92px;
  max-height: 160px;
}

/* Home Mode Cards */
.mode-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  padding-bottom: 6px;
}

.mode-card {
  position: relative;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  border-radius: 16px;
  padding: 12px 14px;
  background: linear-gradient(135deg, rgba(12, 22, 54, 0.86), rgba(9, 14, 34, 0.92));
  overflow: hidden;
  min-height: 124px;
}

.card-fall {
  border: 1.5px solid rgba(0, 229, 255, 0.65);
  box-shadow: 0 0 24px rgba(0, 229, 255, 0.2), inset 0 0 18px rgba(0, 229, 255, 0.08);
}

.card-drag {
  border: 1.5px solid rgba(224, 64, 251, 0.65);
  box-shadow: 0 0 24px rgba(224, 64, 251, 0.2), inset 0 0 18px rgba(224, 64, 251, 0.08);
}

.card-left {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  z-index: 2;
  max-width: 56%;
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mode-icon {
  font-size: 18px;
  font-weight: 900;
}
.mode-icon.cyan { color: var(--cyan); text-shadow: 0 0 10px var(--cyan); }
.mode-icon.magenta { color: var(--magenta); text-shadow: 0 0 10px var(--magenta); }

.mode-title {
  font-size: 24px;
  font-weight: 900;
  letter-spacing: 1.5px;
  font-style: italic;
}

.mode-sub {
  font-size: 9px;
  letter-spacing: 1.4px;
  color: var(--muted);
  font-weight: 700;
  margin-top: 2px;
}

.mode-mode-toggle {
  display: flex;
  gap: 6px;
  margin: 6px 0;
}

.submode-pill {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.submode-pill.active {
  color: #fff;
  background: rgba(0, 229, 255, 0.22);
  border-color: var(--cyan);
}
.card-drag .submode-pill.active {
  background: rgba(224, 64, 251, 0.22);
  border-color: var(--magenta);
}

.play-cta {
  width: 148px;
  height: 36px;
  border-radius: 10px;
  border: none;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #fff;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.play-cta:active {
  transform: scale(0.95);
}

.cyan-cta {
  background: linear-gradient(90deg, #0091ea, #00e5ff);
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.45);
}

.magenta-cta {
  background: linear-gradient(90deg, #7c4dff, #e040fb);
  box-shadow: 0 0 18px rgba(224, 64, 251, 0.45);
}

.card-preview {
  width: 44%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.card-preview canvas {
  width: 100%;
  height: 98px;
  border-radius: 10px;
}

/* Daily Challenge Bar */
.daily-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(14, 21, 48, 0.84);
  border: 1.5px solid rgba(110, 140, 255, 0.45);
  box-shadow: 0 0 18px rgba(41, 121, 255, 0.16);
  cursor: pointer;
}

.daily-left {
  display: flex;
  align-items: center;
  gap: 9px;
}

.daily-cal-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: rgba(124, 77, 255, 0.25);
  border: 1px solid rgba(179, 136, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

.daily-title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.daily-status {
  font-size: 9px;
  color: var(--muted);
  font-weight: 600;
}

.daily-divider {
  width: 1px;
  height: 28px;
  background: rgba(255, 255, 255, 0.15);
}

.daily-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.gift-icon {
  font-size: 22px;
  filter: drop-shadow(0 0 10px rgba(255, 171, 0, 0.85));
}

.daily-prog-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  margin-bottom: 4px;
}

.daily-prog-bar {
  width: 82px;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 99px;
  overflow: hidden;
}

.daily-prog-fill {
  height: 100%;
  width: 5%;
  background: linear-gradient(90deg, var(--cyan), var(--blue));
  border-radius: 99px;
}

/* Bottom Navigation */
.bottom-nav {
  position: relative;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 6px 10px calc(8px + var(--safe-bottom));
  background: rgba(9, 14, 34, 0.94);
  border-top: 1px solid rgba(100, 170, 255, 0.25);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 4px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.nav-btn.active {
  color: #fff;
  background: linear-gradient(180deg, rgba(0, 229, 255, 0.22), rgba(41, 121, 255, 0.18));
  border-color: rgba(0, 229, 255, 0.6);
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.25);
}

.nav-ico { font-size: 16px; line-height: 1; }
.nav-lbl { font-size: 9px; font-weight: 800; letter-spacing: 0.7px; }

/* Sub-Screens (Worlds, Leaderboard, Profile) */
.sub-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sub-header h2 {
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 1.5px;
  color: var(--cyan);
}

.mode-switch {
  display: flex;
  gap: 6px;
}

.tab-chip {
  flex: 1;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(15, 22, 48, 0.75);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.tab-chip.active {
  color: #fff;
  border-color: var(--cyan);
  background: rgba(0, 229, 255, 0.2);
}

.scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 2px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.world-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(14, 21, 48, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.14);
  cursor: pointer;
}

.world-card.locked {
  opacity: 0.55;
}

.levels-overlay {
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(5, 8, 20, 0.96);
  display: flex;
  flex-direction: column;
  padding: 12px 14px;
}

.levels-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.levels-grid {
  display: grid !important;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px !important;
  align-content: start;
}

.level-tile {
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid rgba(0, 229, 255, 0.4);
  background: rgba(16, 26, 58, 0.85);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  cursor: pointer;
}

.level-tile.locked {
  opacity: 0.38;
  border-color: rgba(255, 255, 255, 0.12);
  cursor: not-allowed;
}

.level-tile .stars {
  font-size: 8px;
  color: var(--gold);
  margin-top: 2px;
}

/* Gameplay HUD */
.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.spacer-40 { width: 38px; }

.game-brand {
  text-align: center;
}

.game-brand-studio {
  font-size: 8px;
  letter-spacing: 2px;
  color: var(--muted);
}

.game-brand-title {
  font-size: 22px;
  font-weight: 900;
  font-style: italic;
  letter-spacing: 2px;
  line-height: 1;
  background: linear-gradient(135deg, #fff, #00e5ff, #e040fb);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.game-brand-sub {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 2.5px;
  color: #cce8ff;
}

.hud-stats-bar {
  display: grid;
  grid-template-columns: 0.8fr 1.4fr 0.8fr;
  align-items: center;
  margin-top: 6px;
  padding: 6px 12px;
  border-radius: 14px;
  background: rgba(13, 20, 48, 0.82);
  border: 1.5px solid rgba(150, 120, 255, 0.45);
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.16);
  flex-shrink: 0;
}

.hud-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hud-lbl {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
}

.hud-val {
  font-size: 16px;
  font-weight: 900;
  color: #fff;
}

.hud-val-lg {
  font-size: 20px;
  color: #fff;
  text-shadow: 0 0 10px rgba(0, 229, 255, 0.45);
}

.objective-banner {
  margin-top: 5px;
  padding: 4px 10px;
  border-radius: 9px;
  background: rgba(0, 229, 255, 0.12);
  border: 1px solid rgba(0, 229, 255, 0.35);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  flex-shrink: 0;
}

/* FALL Arena */
.fall-arena {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin: 6px 0;
}

.fall-board-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#fall-board-canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
}

.fall-side-panels {
  width: 84px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: flex-start;
  padding-top: 6px;
  flex-shrink: 0;
}

.side-box {
  border-radius: 14px;
  background: rgba(12, 18, 44, 0.84);
  border: 1.5px solid rgba(100, 170, 255, 0.42);
  padding: 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.14);
}

.side-box-title {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  color: #dbeeff;
  margin-bottom: 4px;
}

.side-box canvas {
  width: 74px;
  height: auto;
}

.fall-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  flex-shrink: 0;
}

.fall-controls.left-handed {
  direction: rtl;
}
.fall-controls.left-handed > * {
  direction: ltr;
}

.ctrl-btn {
  height: 56px;
  border-radius: 13px;
  border: 1.5px solid rgba(0, 229, 255, 0.5);
  background: rgba(12, 20, 48, 0.85);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  box-shadow: 0 0 14px rgba(0, 229, 255, 0.16);
}

.ctrl-btn.ctrl-hard {
  border-color: rgba(224, 64, 251, 0.65);
  box-shadow: 0 0 14px rgba(224, 64, 251, 0.22);
}

.ctrl-btn:active {
  transform: scale(0.94);
  background: rgba(0, 229, 255, 0.22);
}

.ctrl-ico { font-size: 18px; line-height: 1; font-weight: 900; }
.ctrl-txt { font-size: 9px; font-weight: 800; letter-spacing: 0.4px; }

/* DRAG Arena */
.drag-arena {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
}

#drag-board-canvas {
  width: 100%;
  height: 100%;
  touch-action: none;
}

.drag-tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  height: 108px;
  flex-shrink: 0;
  padding: 6px;
  border-radius: 16px;
  background: rgba(12, 19, 44, 0.84);
  border: 1.5px solid rgba(224, 64, 251, 0.45);
}

.tray-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  cursor: grab;
  touch-action: none;
}

.tray-slot.empty {
  opacity: 0.25;
  cursor: default;
}

.tray-slot canvas {
  width: 92px;
  height: 92px;
  pointer-events: none;
}

#drag-floating-canvas {
  position: fixed;
  z-index: 50;
  pointer-events: none;
}

/* Modals */
.modal-backdrop {
  position: absolute;
  inset: 0;
  z-index: 30;
  background: rgba(4, 7, 18, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  width: 100%;
  max-width: 360px;
  max-height: 85dvh;
  overflow-y: auto;
  border-radius: 18px;
  padding: 18px;
  background: linear-gradient(160deg, rgba(16, 25, 60, 0.96), rgba(9, 13, 32, 0.98));
  border: 1.5px solid rgba(0, 229, 255, 0.5);
  box-shadow: 0 0 36px rgba(0, 229, 255, 0.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-title {
  font-size: 20px;
  font-weight: 900;
  text-align: center;
  letter-spacing: 1.5px;
  color: var(--cyan);
}

.modal-btn {
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px solid rgba(0, 229, 255, 0.45);
  background: linear-gradient(90deg, rgba(0, 145, 234, 0.4), rgba(0, 229, 255, 0.25));
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 1px;
  cursor: pointer;
}

.modal-btn.secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.modal-btn.danger {
  background: rgba(255, 42, 133, 0.25);
  border-color: rgba(255, 42, 133, 0.65);
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  font-weight: 700;
}

.coin-pill {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: 99px;
  background: rgba(255, 171, 0, 0.16);
  border: 1px solid rgba(255, 171, 0, 0.5);
  font-size: 12px;
  font-weight: 800;
}

.panel-card {
  padding: 12px;
  border-radius: 14px;
  background: rgba(14, 21, 48, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.lb-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(14, 21, 48, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.lb-row.me {
  border-color: var(--cyan);
  background: rgba(0, 229, 255, 0.14);
}

.toast {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  padding: 8px 16px;
  border-radius: 99px;
  background: rgba(12, 22, 54, 0.95);
  border: 1px solid var(--cyan);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 0 18px rgba(0, 229, 255, 0.4);
  pointer-events: none;
}
