#app {
  display: flex;
  flex-direction: column;
  width: min(100%, var(--mobile-shell-width));
  max-width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  margin: 0 auto;
  position: relative;
  z-index: 1;
  background: transparent;
  overflow: hidden;
  box-shadow: none;
}

#app::before {
  content: none;
}

html,
body {
  width: 100%;
  margin: 0;
  height: 100%;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  background-color: var(--scene-ground);
  background-image: none;
  overflow: hidden;
}

body {
  position: relative;
  background-color: var(--scene-ground);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  background-color: var(--scene-ground);
  background-image: var(--scene-background);
  background-repeat: no-repeat;
  background-position: center top;
  background-size: 100% 100%;
  pointer-events: none;
  transform: translateZ(0);
}

.orientation-lock {
  position: fixed;
  inset: 0;
  z-index: calc(var(--z-splash) + 10);
  display: none;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background:
    linear-gradient(180deg, rgba(88, 213, 220, .94), rgba(146, 231, 186, .96)),
    var(--scene-background);
  background-size: cover;
  color: #172033;
  text-align: center;
}

.orientation-lock__panel {
  width: min(100%, 24rem);
  display: grid;
  justify-items: center;
  gap: 18px;
  padding: 22px;
  border-radius: var(--radius-panel);
  background: rgba(255, 255, 255, .88);
  border: 2px solid rgba(255, 255, 255, .78);
  box-shadow: var(--shadow-game-panel);
}

.orientation-lock__phone {
  position: relative;
  width: 78px;
  height: 116px;
  border-radius: 20px;
  background: linear-gradient(180deg, #26364f, #172033);
  box-shadow: inset 0 0 0 4px rgba(255,255,255,.18), 0 14px 28px rgba(29, 42, 65, .22);
  animation: orientationPhoneTilt 1.8s ease-in-out infinite;
}

.orientation-lock__phone::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  width: 22px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .38);
  transform: translateX(-50%);
}

.orientation-lock__phone-screen {
  position: absolute;
  inset: 18px 10px 14px;
  border-radius: 12px;
  background: linear-gradient(180deg, #8bf3d0, #58d5dc);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.42);
}

.orientation-lock__copy {
  display: grid;
  gap: 7px;
}

.orientation-lock__title,
.orientation-lock__text {
  font-family: var(--font-heading);
  font-weight: 900;
  line-height: 1.08;
}

.orientation-lock__title {
  font-size: clamp(1.35rem, 6vw, 1.9rem);
}

.orientation-lock__text {
  max-width: 18rem;
  color: rgba(23, 32, 51, .78);
  font-size: clamp(.98rem, 4vw, 1.15rem);
}

html.orientation-lock--landscape #app {
  pointer-events: none;
  filter: blur(2px) saturate(.9);
}

html.orientation-lock--landscape .orientation-lock {
  display: grid;
}

@media (orientation: landscape) and (max-height: 600px) and (pointer: coarse) {
  #app {
    pointer-events: none;
    filter: blur(2px) saturate(.9);
  }

  .orientation-lock {
    display: grid;
  }
}

@keyframes orientationPhoneTilt {
  0%, 100% { transform: rotate(0deg); }
  50% { transform: rotate(-8deg); }
}

@supports (-webkit-touch-callout: none) {
  html,
  body,
  #app {
    min-height: -webkit-fill-available;
  }

  body::before {
    height: -webkit-fill-available;
    min-height: -webkit-fill-available;
  }
}

.app-top-bar {
  position: sticky;
  top: max(10px, env(safe-area-inset-top));
  z-index: var(--z-sticky);
  height: auto;
  min-height: var(--top-bar-height);
  width: var(--mobile-panel-width);
  margin: max(10px, env(safe-area-inset-top)) auto 8px;
  border-radius: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) minmax(58px, auto);
  align-items: center;
  gap: 8px;
  padding: 0;
  flex-shrink: 0;
}

.app-top-bar--title-only {
  grid-template-columns: 58px minmax(0, 1fr) 58px;
}

/* Empty action space must not squeeze a long title over the Home button. */
.app-top-bar--without-actions {
  grid-template-columns: 56px minmax(0, 1fr);
  column-gap: 12px;
}

.app-top-bar--without-actions .top-bar__actions { display: none; }

.app-top-bar--title-only.app-top-bar--without-actions {
  grid-template-columns: minmax(0, 1fr);
}

.app-top-bar--title-only.app-top-bar--without-actions .top-bar__spacer { display: none; }

.top-bar__home,
.screen-home-button {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #314564;
  background: rgba(255,255,255,.66);
  cursor: pointer;
  transition: all var(--transition-fast);
  box-shadow: inset 0 -2px 0 rgba(36, 51, 70, .08), 0 8px 16px rgba(42, 63, 98, .1);
}

.top-bar__spacer {
  width: 56px;
  height: 56px;
}

.top-bar__home:hover,
.screen-home-button:hover {
  background: #ffffff;
}

.top-bar__home::before,
.screen-home-button::before {
  content: none;
}

.top-bar__home .app-icon,
.screen-home-button .app-icon {
  width: 26px;
  height: 26px;
  color: #526079;
}

.top-bar__home .home-house-icon,
.screen-home-button .home-house-icon {
  width: 37px;
  height: 37px;
  font-size: 30px;
}

.top-bar__title {
  container-type: inline-size;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: visible;
  text-align: center;
}

.top-bar__actions {
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.app-top-bar--with-player-status {
  row-gap: 7px;
}

.top-bar__player-status {
  grid-column: 1 / -1;
  width: 100%;
}

.player-status {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  width: var(--mobile-panel-width);
  max-width: 100%;
}

.player-status__chip {
  min-width: 0;
  min-height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 6px 9px;
  overflow: hidden;
  border-radius: var(--radius-control);
  background: rgba(255,255,255,.74);
  box-shadow: inset 0 -3px 0 rgba(36, 51, 70, .08), 0 8px 16px rgba(42, 63, 98, .08);
  color: #26364f;
}

.player-status__chip--score {
  background: rgba(255, 244, 173, .88);
  color: #754414;
}

.player-status__chip--coins {
  color: #5f3b10;
}

.player-status__icon {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  display: grid;
  place-items: center;
}

.player-status__icon .app-icon {
  width: 20px;
  height: 20px;
}

.player-status__chip--coins .player-status__icon {
  border-radius: 50%;
  background: linear-gradient(135deg, #ffd96b, #f79a2e);
  box-shadow: inset 0 -2px 0 rgba(146, 84, 20, .22);
}

.player-status__chip--coins .app-icon {
  width: 12px;
  height: 12px;
  color: rgba(129, 80, 17, .58);
}

.player-status__text {
  min-width: 0;
  display: grid;
  gap: 1px;
  line-height: 1;
}

.player-status__label {
  overflow: hidden;
  text-overflow: ellipsis;
  color: rgba(45, 59, 81, .68);
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.player-status__value {
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-heading);
  font-size: clamp(15px, 3.6vw, 19px);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
}

/* Compact strip: icon + value only, the label lives in the tooltip. */
.player-status--compact {
  gap: 6px;
}

.player-status--compact .player-status__chip {
  min-height: 40px;
  gap: 6px;
  padding: 5px 8px;
}

.player-status--compact .player-status__icon {
  flex-basis: 18px;
  width: 18px;
  height: 18px;
}

.player-status--compact .player-status__icon .app-icon {
  width: 17px;
  height: 17px;
  font-size: 15px;
}

.player-status--compact .player-status__text {
  justify-items: center;
}

.player-status--compact .player-status__label {
  display: none;
}

.player-status--compact .player-status__value {
  font-size: clamp(14px, 3.4vw, 18px);
}

.top-bar__balance {
  height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  box-shadow: inset 0 -2px 0 rgba(36, 51, 70, .08);
  color: #26364f;
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.top-bar__balance .app-icon {
  width: 23px;
  height: 23px;
}

.top-bar__balance--coins {
  color: #6c4214;
}

.app-content {
  flex: 1;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-height) + var(--safe-area-bottom) + 22px);
}

.app-content--full {
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  overflow: hidden;
  padding-bottom: 0;
}

.app-content--full > .screen--full {
  height: 100%;
  min-height: 0;
}

/* Bottom nav (mobile) */
.app-nav {
  position: fixed;
  bottom: max(12px, var(--safe-area-bottom));
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: var(--z-nav);
  width: min(var(--mobile-content-width), 23.5rem);
  min-width: min(19rem, calc(100% - var(--mobile-shell-gutter) * 2));
  max-width: calc(100% - var(--mobile-shell-gutter) * 2);
  border-radius: var(--radius-panel);
  background: rgba(244, 250, 255, .84);
  border: 1px solid rgba(255,255,255,.76);
  box-shadow: 0 18px 38px rgba(43, 60, 91, .22), inset 0 3px 0 rgba(255,255,255,.38), inset 0 -5px 0 rgba(36, 51, 70, .07);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding-bottom: 0;
  overflow: hidden;
}

.screen {
  padding: var(--space-md);
  animation: screenFadeIn 300ms ease;
  min-height: calc(100vh - var(--top-bar-height) - var(--nav-height));
  min-height: calc(100dvh - var(--top-bar-height) - var(--nav-height));
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.screen--no-nav {
  min-height: calc(100vh - var(--top-bar-height));
  min-height: calc(100dvh - var(--top-bar-height));
  padding-bottom: var(--space-md);
  max-width: var(--content-max-width);
  margin: 0 auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

.screen--full {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
  max-width: 100%;
  min-width: 0;
}

.screen-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.screen-center--loading {
  min-height: 300px;
}

@keyframes screenFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ═══ Tablet (640px+) ═══ */
@media (min-width: 640px) {
  .screen {
    padding: var(--space-lg);
  }
}

@media (max-width: 360px) {
  .app-nav {
    width: min(var(--mobile-content-width), calc(100% - 18px));
    min-width: 0;
    max-width: calc(100% - 18px);
  }
}

/* ═══════════════════════════════════════════════════════════════ */
/* Desktop (1024px+) — 3-panel game layout                       */
/* ═══════════════════════════════════════════════════════════════ */
@media (min-width: 1024px) {
  html {
    background: var(--scene-ground);
  }

  #app {
    width: var(--mobile-shell-width);
    margin: 0 auto;
    background: transparent;
    border: 0;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .app-nav {
    top: auto;
    bottom: 18px;
    width: auto;
    max-width: var(--mobile-content-width);
    height: auto;
  }

  .app-content {
    padding-bottom: calc(var(--nav-height) + 38px);
  }

  .app-content--full {
    padding-bottom: 0;
  }

  .screen {
    padding: var(--space-xl);
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    min-height: auto;
  }
}
