:root {
  --ink: #101531;
  --deep: #161a3a;
  --violet: #7c3aed;
  --cyan: #2dd4bf;
  --lime: #a3e635;
  --pink: #fb7185;
  --gold: #facc15;
  --glass: rgba(255, 255, 255, 0.76);
  --glass-strong: rgba(255, 255, 255, 0.9);
  --shadow: 0 24px 70px rgba(10, 15, 44, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top, #dff8ff 0%, #b9e6ff 32%, #8fb3ff 70%, #5f6caf 100%);
  color: var(--ink);
  user-select: none;
}

button {
  border: 0;
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

#app,
#gameCanvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

#gameCanvas {
  display: block;
  outline: none;
}

.hidden {
  display: none !important;
}

.screen,
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: calc(20px + var(--safe-top)) 18px calc(20px + var(--safe-bottom));
}

.screen.active,
.modal:not(.hidden) {
  display: flex;
}

.screen {
  background:
    radial-gradient(circle at 20% 15%, rgba(255,255,255,0.9), transparent 25%),
    radial-gradient(circle at 84% 80%, rgba(45,212,191,0.45), transparent 28%),
    linear-gradient(135deg, rgba(124,58,237,0.18), rgba(14,165,233,0.18));
  backdrop-filter: blur(7px);
}

.modal {
  background: rgba(8, 13, 36, 0.48);
  backdrop-filter: blur(12px);
}

.glass-card {
  background: var(--glass);
  border: 1px solid rgba(255,255,255,0.66);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.menu-shell {
  width: min(980px, 100%);
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
  gap: 18px;
  align-items: stretch;
}

.hero-card,
.menu-panel,
.modal-card,
.loading-card {
  border-radius: 34px;
}

.hero-card {
  min-height: 440px;
  padding: 38px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  right: -90px;
  bottom: -100px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, var(--cyan), var(--lime), var(--violet), var(--cyan));
  opacity: 0.38;
  filter: blur(1px);
}

.logo-orb {
  width: 86px;
  height: 86px;
  border-radius: 30px;
  display: grid;
  place-items: center;
  margin-bottom: 18px;
  font-size: 38px;
  font-weight: 1000;
  color: white;
  background: radial-gradient(circle at 35% 30%, #ffffff, #2dd4bf 32%, #7c3aed 80%);
  box-shadow: 0 20px 40px rgba(124, 58, 237, 0.35), inset 0 0 24px rgba(255,255,255,0.45);
  transform: rotate(-8deg);
}

.eyebrow {
  margin: 0 0 8px;
  color: #126c8d;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 12px;
  font-weight: 1000;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(44px, 8vw, 78px);
  line-height: 0.9;
  letter-spacing: -0.075em;
  margin-bottom: 16px;
  max-width: 660px;
}

h2 {
  font-size: clamp(30px, 5vw, 48px);
  line-height: 0.96;
  letter-spacing: -0.06em;
  margin-bottom: 10px;
}

.tagline,
.modal-card p,
.how-list span {
  color: rgba(16, 21, 49, 0.7);
  line-height: 1.55;
}

.tagline {
  max-width: 560px;
  font-size: 18px;
  position: relative;
  z-index: 1;
}

.menu-panel {
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 16px;
}

.primary-btn,
.soft-btn,
.ghost-btn {
  width: 100%;
  min-height: 58px;
  border-radius: 22px;
  font-weight: 950;
  letter-spacing: -0.02em;
}

.primary-btn {
  color: white;
  background: linear-gradient(135deg, var(--violet), #2563eb 45%, var(--cyan));
  box-shadow: 0 18px 32px rgba(37,99,235,0.28);
}

.soft-btn {
  color: var(--deep);
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(255,255,255,0.8);
}

.ghost-btn {
  color: rgba(16,21,49,0.7);
  background: transparent;
}

.primary-btn:active,
.soft-btn:active,
.ghost-btn:active,
.dir-btn:active,
.pulse-btn:active,
.round-btn:active {
  transform: scale(0.98);
}

.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stats-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stats-strip div {
  padding: 16px 8px;
  text-align: center;
  border-radius: 20px;
  background: rgba(255,255,255,0.62);
}

.stats-strip strong {
  display: block;
  font-size: 28px;
  line-height: 1;
}

.stats-strip span {
  display: block;
  margin-top: 6px;
  color: rgba(16,21,49,0.58);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

.loading-card {
  width: min(460px, 100%);
  padding: 32px;
  text-align: center;
  display: grid;
  place-items: center;
}

.loading-card h1 {
  font-size: clamp(36px, 7vw, 54px);
}

.loading-bar {
  width: 100%;
  height: 12px;
  border-radius: 99px;
  overflow: hidden;
  background: rgba(16,21,49,0.12);
  margin-top: 12px;
}

.loading-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--violet), var(--cyan), var(--lime));
  animation: load 1.1s infinite ease-in-out;
}

@keyframes load {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(260%); }
}

.hud {
  position: fixed;
  top: calc(10px + var(--safe-top));
  left: 12px;
  right: 12px;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr minmax(190px, 380px) 1fr;
  gap: 10px;
  align-items: start;
  pointer-events: none;
}

.hud-left,
.hud-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-right {
  justify-content: flex-end;
}

.hud-pill,
.orb-card,
.gravity-panel {
  background: rgba(255,255,255,0.84);
  border: 1px solid rgba(255,255,255,0.7);
  box-shadow: 0 12px 30px rgba(16,21,49,0.16);
  backdrop-filter: blur(14px);
}

.hud-pill {
  min-width: 92px;
  padding: 10px 14px;
  border-radius: 18px;
}

.hud-pill span,
.orb-card span,
.gravity-panel span {
  display: block;
  color: rgba(16,21,49,0.58);
  font-size: 11px;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.hud-pill strong {
  font-size: 24px;
  line-height: 1;
}

.orb-card {
  padding: 13px 16px;
  border-radius: 22px;
}

.orb-bar {
  height: 12px;
  margin-top: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(16,21,49,0.12);
}

.orb-bar i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--violet), var(--cyan), var(--lime));
  transition: width 0.18s ease;
}

.hearts {
  color: var(--pink);
  font-size: 28px;
  letter-spacing: 1px;
  text-shadow: 0 5px 18px rgba(251,113,133,0.28);
}

.round-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255,255,255,0.84);
  color: var(--deep);
  font-weight: 1000;
  pointer-events: auto;
  box-shadow: 0 12px 30px rgba(16,21,49,0.12);
}

.gravity-panel {
  position: fixed;
  left: 14px;
  top: calc(92px + var(--safe-top));
  z-index: 10;
  min-width: 104px;
  padding: 12px 16px;
  border-radius: 20px;
  text-align: center;
}

.gravity-panel strong {
  display: block;
  font-size: 32px;
  line-height: 1;
}

.touch-controls {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(460px, calc(100% - 26px));
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  z-index: 10;
}

.dir-btn,
.pulse-btn {
  min-height: 58px;
  border-radius: 22px;
  font-weight: 1000;
  color: white;
  box-shadow: 0 14px 30px rgba(16,21,49,0.2);
}

.dir-btn {
  font-size: 28px;
  background: rgba(16,21,49,0.72);
  backdrop-filter: blur(12px);
}

.dir-btn.active {
  background: linear-gradient(135deg, var(--violet), #2563eb);
}

.pulse-btn {
  grid-column: span 1;
  font-size: 13px;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, var(--cyan), #0f766e);
}

.toast {
  position: fixed;
  left: 50%;
  top: 22%;
  transform: translate(-50%, -10px) scale(0.96);
  z-index: 30;
  padding: 14px 20px;
  border-radius: 999px;
  background: rgba(255,255,255,0.88);
  color: var(--deep);
  font-weight: 950;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: 0.2s ease;
}

.toast.show {
  transform: translate(-50%, 0) scale(1);
  opacity: 1;
}

.modal-card {
  width: min(430px, 100%);
  padding: 26px;
  text-align: center;
  position: relative;
}

.wide-card {
  width: min(660px, 100%);
  text-align: left;
}

.x-btn {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(16,21,49,0.08);
  color: var(--deep);
  font-size: 28px;
  line-height: 1;
}

.how-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.how-list div {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255,255,255,0.64);
}

.result-stars {
  font-size: 38px;
  color: var(--gold);
  text-shadow: 0 8px 18px rgba(250,204,21,0.28);
  letter-spacing: 5px;
  margin: 10px 0;
}

.result-score {
  font-size: 58px;
  font-weight: 1000;
  line-height: 1;
  letter-spacing: -0.06em;
  margin: 4px 0 12px;
}

.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-top: 16px;
}

.level-btn {
  min-height: 74px;
  border-radius: 20px;
  background: rgba(255,255,255,0.68);
  color: var(--deep);
  font-weight: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.level-btn.locked {
  opacity: 0.42;
}

.level-btn span {
  font-size: 12px;
  color: rgba(16,21,49,0.54);
}

.noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 50;
  background: white;
  color: var(--deep);
  font-weight: 900;
}

@media (max-width: 780px) {
  .menu-shell {
    grid-template-columns: 1fr;
  }

  .hero-card {
    min-height: auto;
    padding: 28px;
  }

  .menu-panel {
    padding: 18px;
  }

  h1 {
    font-size: clamp(42px, 14vw, 66px);
  }

  .tagline {
    font-size: 16px;
  }

  .hud {
    grid-template-columns: auto 1fr auto;
  }

  .hud-pill {
    min-width: 70px;
    padding: 9px 10px;
  }

  .hud-pill span {
    font-size: 9px;
  }

  .hud-pill strong {
    font-size: 18px;
  }

  .hearts {
    font-size: 22px;
  }

  .round-btn {
    width: 42px;
    height: 42px;
  }

  .gravity-panel {
    top: auto;
    bottom: calc(86px + var(--safe-bottom));
    left: 12px;
  }

  .how-list div {
    grid-template-columns: 1fr;
  }

  .level-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-height: 620px) {
  .touch-controls {
    width: min(390px, calc(100% - 24px));
  }

  .dir-btn,
  .pulse-btn {
    min-height: 48px;
    border-radius: 17px;
  }

  .hero-card {
    padding: 24px;
  }
}

/* Premium tilt-control upgrade */
.control-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: 24px;
  background: rgba(255,255,255,0.58);
  border: 1px solid rgba(255,255,255,0.78);
}

.control-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-card-head span,
.sensitivity-row span,
.tilt-panel span {
  color: rgba(16,21,49,0.58);
  font-size: 11px;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

.control-card-head strong {
  padding: 8px 12px;
  border-radius: 999px;
  color: white;
  font-size: 13px;
  background: linear-gradient(135deg, var(--violet), var(--cyan));
  box-shadow: 0 10px 18px rgba(37,99,235,0.18);
}

.control-actions,
.sensitivity-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.sensitivity-row {
  grid-template-columns: 1fr repeat(3, 0.78fr);
  align-items: center;
}

.mini-btn,
.sensitivity-btn,
.tiny-btn {
  min-height: 38px;
  border-radius: 15px;
  font-size: 12px;
  font-weight: 1000;
}

.mini-btn {
  color: white;
  background: linear-gradient(135deg, var(--violet), #2563eb, var(--cyan));
}

.mini-btn.secondary,
.sensitivity-btn,
.tiny-btn {
  color: var(--deep);
  background: rgba(255,255,255,0.78);
  border: 1px solid rgba(255,255,255,0.82);
}

.sensitivity-btn.active {
  color: white;
  background: linear-gradient(135deg, #0f766e, var(--cyan));
}

.control-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(16,21,49,0.62);
}

.tilt-panel {
  position: fixed;
  left: 14px;
  top: calc(172px + var(--safe-top));
  z-index: 10;
  width: 158px;
  padding: 12px;
  border-radius: 22px;
  display: grid;
  gap: 10px;
  background: rgba(255,255,255,0.84);
  border: 1px solid rgba(255,255,255,0.72);
  box-shadow: 0 12px 30px rgba(16,21,49,0.16);
  backdrop-filter: blur(14px);
}

.tilt-meter {
  position: relative;
  height: 64px;
  margin-top: 8px;
  border-radius: 18px;
  background:
    radial-gradient(circle at center, rgba(45,212,191,0.24), transparent 32%),
    linear-gradient(135deg, rgba(124,58,237,0.12), rgba(45,212,191,0.16));
  border: 1px solid rgba(16,21,49,0.08);
  overflow: hidden;
}

.tilt-meter::before,
.tilt-meter::after {
  content: "";
  position: absolute;
  background: rgba(16,21,49,0.14);
}

.tilt-meter::before {
  left: 50%; top: 9px; bottom: 9px; width: 1px;
}

.tilt-meter::after {
  top: 50%; left: 9px; right: 9px; height: 1px;
}

.tilt-meter i {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 35% 28%, #fff, var(--cyan) 38%, var(--violet));
  box-shadow: 0 0 18px rgba(45,212,191,0.72);
  transition: left 0.08s linear, top 0.08s linear;
}

.touch-controls.tilt-active {
  width: min(210px, calc(100% - 28px));
  grid-template-columns: 1fr;
}

.touch-controls.tilt-active .dir-btn {
  display: none;
}

.touch-controls.tilt-active .pulse-btn {
  min-height: 64px;
  border-radius: 24px;
  font-size: 15px;
}

body.tilt-ready .logo-orb {
  animation: logoFloat 2.2s infinite ease-in-out;
}

@keyframes logoFloat {
  0%, 100% { transform: rotate(-8deg) translateY(0); }
  50% { transform: rotate(-4deg) translateY(-4px); }
}

@media (max-width: 780px) {
  .control-actions,
  .sensitivity-row {
    grid-template-columns: 1fr;
  }

  .sensitivity-row span {
    text-align: center;
  }

  .tilt-panel {
    top: auto;
    bottom: calc(154px + var(--safe-bottom));
    left: 12px;
    width: 136px;
  }
}

@media (max-height: 620px) {
  .tilt-panel {
    display: none !important;
  }
}


/* Mobile UX cleanup: keep the gameplay screen clear.
   Tilt/swipe/calibrate status panel is intentionally hidden. */
.tilt-panel {
  display: none !important;
}
