:root {
  --hab3d-sky: #07151c;
  --hab3d-ink: #f7f3ea;
  --hab3d-muted: #9aa8ad;
  --hab3d-player: #ff7a45;
  --hab3d-enemy: #3ec6d8;
  --hab3d-panel: rgba(7, 21, 28, 0.78);
  --hab3d-card: rgba(12, 22, 28, 0.88);
  --hab3d-line: rgba(247, 243, 234, 0.12);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

.hab3d-root, .hab3d-root * { box-sizing: border-box; }

.hab3d-root {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100%;
  background: #07151c;
  color: var(--hab3d-ink);
  font-family: Tajawal, Cairo, "Noto Sans Arabic", system-ui, sans-serif;
  overflow: hidden;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.hab3d-hud-layer {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.hab3d-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-t) + 10px) 14px 0;
}
.hab3d-top-left { display: flex; gap: 6px; pointer-events: auto; }
.hab3d-icon {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.hab3d-brand-mark {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
}

.hab3d-bars {
  margin: 8px 12px 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 18px;
  background: var(--hab3d-panel);
  backdrop-filter: blur(10px);
}
.hab3d-count { flex: 1; min-width: 0; }
.hab3d-count-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}
.hab3d-count.player { color: var(--hab3d-player); }
.hab3d-count.enemy { color: var(--hab3d-enemy); }
.hab3d-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
.hab3d-track i {
  display: block;
  height: 100%;
  width: 50%;
  border-radius: inherit;
}
.hab3d-count.player .hab3d-track i { background: var(--hab3d-player); }
.hab3d-count.enemy .hab3d-track i { background: var(--hab3d-enemy); }
.hab3d-stage { text-align: center; flex: 0 0 auto; }
.hab3d-stage p { margin: 0; }
#hab3dPart { color: var(--hab3d-player); font-size: 12px; font-weight: 800; }
#hab3dStageName { font-size: 15px; font-weight: 800; }

.hab3d-labels { position: absolute; inset: 0; }
.hab3d-lab {
  position: absolute;
  transform: translate(-50%, -110%);
  min-width: 34px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(7, 21, 28, 0.82);
  font-weight: 800;
  font-size: 16px;
  text-align: center;
}
.hab3d-lab.you { color: var(--hab3d-player); }
.hab3d-lab.them { color: var(--hab3d-enemy); }
.hab3d-lab.neutral { color: var(--hab3d-ink); }
.hab3d-lab.sel { box-shadow: 0 0 0 1px var(--hab3d-player); }

.hab3d-hint {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-b) + 132px);
  text-align: center;
  color: #d7ddd8;
  font-weight: 700;
  font-size: 14px;
  text-shadow: 0 2px 10px #07151c;
}

.hab3d-playbar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-b) + 12px);
  pointer-events: auto;
}
.hab3d-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--hab3d-panel);
  font-weight: 800;
  font-size: 14px;
}
.hab3d-status .you { color: var(--hab3d-player); }
.hab3d-status .them { color: var(--hab3d-enemy); }
.hab3d-pause-pill {
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--hab3d-ink);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.hab3d-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.hab3d-act {
  min-height: 48px;
  border: 0;
  border-radius: 16px;
  background: rgba(18, 28, 34, 0.92);
  color: var(--hab3d-ink);
  font: inherit;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}
.hab3d-act.on {
  background: var(--hab3d-player);
  color: #2a1208;
}

.hab3d-card-wrap {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 16px calc(var(--safe-b) + 28px);
  pointer-events: none;
}
.hab3d-card {
  pointer-events: auto;
  width: min(420px, 100%);
  padding: 22px 20px 20px;
  border-radius: 22px;
  background: var(--hab3d-card);
  border: 1px solid var(--hab3d-line);
  backdrop-filter: blur(14px);
  text-align: right;
}
.hab3d-kicker {
  margin: 0;
  color: var(--hab3d-player);
  font-weight: 800;
  font-size: 14px;
}
.hab3d-root h1, .hab3d-card h2 {
  margin: 6px 0 0;
  font-size: 36px;
  line-height: 1.15;
}
.hab3d-card h2 { font-size: 28px; }
.hab3d-blurb {
  margin: 12px 0 0;
  color: var(--hab3d-muted);
  font-size: 15px;
  line-height: 1.7;
}
.hab3d-cta {
  appearance: none;
  border: 0;
  width: 100%;
  margin-top: 18px;
  padding: 14px 18px;
  border-radius: 14px;
  background: var(--hab3d-player);
  color: #1a0d08;
  font: inherit;
  font-size: 20px;
  font-weight: 800;
  cursor: pointer;
}
.hab3d-cta.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--hab3d-ink);
}
.hab3d-row { display: flex; gap: 8px; }
.hab3d-row .hab3d-cta { flex: 1; }
.hab3d-result.win { color: var(--hab3d-player); }
.hab3d-result.lose { color: #f0a598; }

.hidden { display: none !important; }

@media (max-height: 640px) {
  .hab3d-root h1 { font-size: 28px; }
  .hab3d-card { padding: 16px; }
  .hab3d-hint { bottom: calc(var(--safe-b) + 118px); }
}
