:root {
  color-scheme: dark;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #07110f;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

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

html,
body {
  width: 100%;
  height: 100%;
  width: 100dvw;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 42%, rgba(42, 105, 83, 0.28), transparent 45%),
    linear-gradient(145deg, #07100f, #111b1a 55%, #060b0b);
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

body {
  position: fixed;
  inset: 0;
}

#safe-frame {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  overflow: hidden;
}

#game-frame {
  position: relative;
  width: min(100%, calc((100dvh - var(--safe-top) - var(--safe-bottom)) * 16 / 9));
  height: min(100%, calc((100dvw - var(--safe-left) - var(--safe-right)) * 9 / 16));
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #050909;
  box-shadow: 0 0 0 1px rgba(188, 255, 226, 0.12), 0 1.5rem 6rem rgba(0, 0, 0, 0.58);
  isolation: isolate;
}

#canvas {
  position: absolute;
  inset: 0;
  display: none;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: #000;
  touch-action: none;
  image-rendering: auto;
}

#canvas:fullscreen {
  width: 100vw;
  height: 100vh;
  object-fit: contain;
  background: #000;
}

#spinner {
  display: none !important;
}

#loading-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(1rem, 4vw, 3.25rem);
  padding: 6%;
  color: #f6f3e8;
  background:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 4px),
    radial-gradient(circle at 25% 50%, rgba(54, 138, 105, 0.32), transparent 42%),
    #0b1714;
  transition: opacity 220ms ease, visibility 220ms ease;
}

#loading-screen.is-ready {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loading-card {
  position: relative;
  width: clamp(4.6rem, 12vw, 8rem);
  aspect-ratio: 0.714;
  flex: 0 0 auto;
  border: clamp(3px, 0.5vw, 6px) solid #e8e5d9;
  border-radius: 0.55rem;
  color: #252943;
  background: #f7f5eb;
  box-shadow:
    0.35rem 0.38rem 0 #2f3844,
    0.7rem 0.72rem 0 rgba(0, 0, 0, 0.45),
    inset 0 0 0 2px rgba(38, 45, 65, 0.1);
  transform: rotate(-5deg);
  animation: card-float 2.2s ease-in-out infinite;
}

.loading-card .corner {
  position: absolute;
  left: 10%;
  top: 7%;
  font-weight: 900;
  font-size: clamp(0.72rem, 1.8vw, 1.25rem);
  line-height: 0.78;
  text-align: center;
}

.loading-card .corner.bottom {
  inset: auto 10% 7% auto;
  transform: rotate(180deg);
}

.loading-card .suit {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(2.3rem, 6vw, 4.2rem);
}

.loading-copy {
  width: min(52vw, 28rem);
}

.wordmark {
  color: #f5f0df;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(2.35rem, 8vw, 6.4rem);
  line-height: 0.9;
  letter-spacing: 0.015em;
  text-shadow: 0.06em 0.07em 0 #34434a, 0.11em 0.13em 0 rgba(0, 0, 0, 0.5);
  transform: skew(-4deg);
}

.loading-label {
  margin-top: clamp(0.9rem, 2.4vw, 1.6rem);
  color: #c5d8cf;
  font-size: clamp(0.72rem, 1.6vw, 1rem);
  font-weight: 750;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.chip-track {
  position: relative;
  width: 100%;
  height: clamp(0.42rem, 1vw, 0.65rem);
  margin-top: 0.65rem;
  overflow: hidden;
  border: 2px solid rgba(237, 239, 221, 0.2);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
}

.chip-track span {
  position: absolute;
  inset: 0 auto 0 0;
  width: 36%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1b76df, #42d49a, #f2c14e);
  box-shadow: 0 0 1.1rem rgba(65, 211, 153, 0.65);
  animation: loading-chip 1.4s ease-in-out infinite;
}

#fatal-error {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: 10%;
  text-align: center;
  color: #f7eee8;
  background: rgba(27, 12, 12, 0.96);
}

#fatal-error[hidden] {
  display: none;
}

#fatal-error strong {
  font-size: clamp(1.2rem, 3vw, 2rem);
}

#fatal-error span {
  color: #d9b9b3;
}

#fatal-error button {
  min-width: 8rem;
  min-height: 3rem;
  margin-top: 0.5rem;
  border: 0;
  border-radius: 0.6rem;
  color: #fff;
  background: #d84b45;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 0.28rem 0 #73312e;
}

#rotate-screen {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8rem;
  padding: max(2rem, var(--safe-top)) max(2rem, var(--safe-right)) max(2rem, var(--safe-bottom)) max(2rem, var(--safe-left));
  color: #f4efe2;
  text-align: center;
  background: #0a1513;
}

#rotate-screen[hidden] {
  display: none;
}

#rotate-screen .phone {
  width: 3.3rem;
  height: 5.4rem;
  display: grid;
  place-items: center;
  border: 0.24rem solid #dfeae2;
  border-radius: 0.65rem;
  color: #44d49b;
  font-size: 1.75rem;
  animation: phone-turn 1.8s ease-in-out infinite;
}

#rotate-title {
  margin-top: 0.8rem;
  font-size: 1.15rem;
}

#rotate-copy {
  max-width: 20rem;
  color: #aebfb7;
  font-size: 0.9rem;
}

@keyframes loading-chip {
  0% { transform: translateX(-105%); }
  50% { transform: translateX(90%); }
  100% { transform: translateX(280%); }
}

@keyframes card-float {
  0%, 100% { transform: translateY(0) rotate(-5deg); }
  50% { transform: translateY(-0.45rem) rotate(-2deg); }
}

@keyframes phone-turn {
  0%, 20% { transform: rotate(0deg); }
  65%, 100% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  #rotate-screen:not([hidden]) { display: flex; }
}

@media (max-height: 440px) {
  #game-frame { box-shadow: none; }
  #loading-screen { gap: 1.35rem; }
  .loading-label { margin-top: 0.55rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
