:root {
  color-scheme: dark;
  font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  background: #090908;
  --edge-gap: clamp(8px, 1.4vmin, 16px);
  --safe-top: max(env(safe-area-inset-top, 0px), var(--edge-gap));
  --safe-right: max(env(safe-area-inset-right, 0px), var(--edge-gap));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--edge-gap));
  --safe-left: max(env(safe-area-inset-left, 0px), var(--edge-gap));
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: #090908;
  touch-action: none;
  overscroll-behavior: none;
}

body {
  display: grid;
  place-items: center;
}

#app {
  position: relative;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 35%, #24211d 0%, #0b0b0a 62%, #050505 100%);
}

#game {
  display: block;
  width: min(
    calc(100vw - var(--safe-left) - var(--safe-right)),
    calc((100vh - var(--safe-top) - var(--safe-bottom)) * 16 / 9)
  );
  width: min(
    calc(100dvw - var(--safe-left) - var(--safe-right)),
    calc((100dvh - var(--safe-top) - var(--safe-bottom)) * 16 / 9)
  );
  height: min(
    calc(100vh - var(--safe-top) - var(--safe-bottom)),
    calc((100vw - var(--safe-left) - var(--safe-right)) * 9 / 16)
  );
  height: min(
    calc(100dvh - var(--safe-top) - var(--safe-bottom)),
    calc((100dvw - var(--safe-left) - var(--safe-right)) * 9 / 16)
  );
  max-width: 100%;
  max-height: 100%;
  background: #0b0b0a;
  box-shadow: 0 0 0 1px rgba(240, 232, 215, .16), 0 28px 90px rgba(0, 0, 0, .7);
  cursor: default;
  user-select: none;
  touch-action: none;
  image-rendering: auto;
  transform: translateZ(0);
  backface-visibility: hidden;
}

#orientation-hint {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: max(28px, env(safe-area-inset-top, 0px)) 24px max(28px, env(safe-area-inset-bottom, 0px));
  text-align: center;
  color: #e8e0d0;
  background:
    radial-gradient(circle at 50% 42%, rgba(180, 50, 39, .18), transparent 34%),
    #090908;
}

#orientation-hint strong { font-size: 22px; letter-spacing: .08em; }
#orientation-hint small { color: #8f8a80; font-size: 13px; }

.orientation-phone {
  width: 38px;
  height: 66px;
  margin-bottom: 8px;
  border: 2px solid #e8e0d0;
  border-radius: 7px;
  box-shadow: inset 0 -6px 0 rgba(232, 224, 208, .12);
  animation: turn-landscape 1.8s ease-in-out infinite;
}

@keyframes turn-landscape {
  0%, 24% { transform: rotate(0deg); }
  58%, 100% { transform: rotate(90deg); }
}

@media (orientation: portrait) and (pointer: coarse) {
  :root { --edge-gap: clamp(8px, 2.4vw, 14px); }
  #app {
    place-items: center;
    background:
      linear-gradient(180deg, rgba(180, 50, 39, .09), transparent 18%, transparent 82%, rgba(180, 50, 39, .08)),
      radial-gradient(circle at 50% 50%, #24211d 0%, #0b0b0a 58%, #050505 100%);
  }
  #game {
    width: calc(100dvw - var(--safe-left) - var(--safe-right));
    height: auto;
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom));
    border-radius: clamp(4px, 1.8vw, 10px);
    box-shadow:
      0 0 0 1px rgba(240, 232, 215, .2),
      0 0 0 7px rgba(0, 0, 0, .2),
      0 24px 70px rgba(0, 0, 0, .82),
      0 0 48px rgba(180, 50, 39, .1);
  }
  #orientation-hint { display: none; }
}

@media (orientation: landscape) and (max-height: 520px) {
  :root { --edge-gap: clamp(8px, 2.5vmin, 12px); }
  #game { box-shadow: 0 0 0 1px rgba(240, 232, 215, .2), 0 12px 44px rgba(0, 0, 0, .68); }
}

@media (prefers-reduced-motion: reduce) {
  #game { transform: none; }
  .orientation-phone { animation: none; transform: rotate(90deg); }
}

.sr-only {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
