.touch-controls {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 9;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

.touch-group {
  position: absolute;
  bottom: clamp(14px, 4dvh, 24px);
  display: flex;
  gap: clamp(10px, 1.8dvw, 14px);
  pointer-events: auto;
}

.touch-left {
  left: clamp(14px, 3dvw, 24px);
}

.touch-right {
  right: clamp(14px, 3dvw, 24px);
}

.touch-button {
  --touch-control-size: clamp(58px, 16vh, 68px);
  --touch-control-size: clamp(58px, 16dvh, 68px);

  position: relative;
  flex: 0 0 var(--touch-control-size);
  width: var(--touch-control-size);
  height: var(--touch-control-size);
  min-width: var(--touch-control-size);
  border: 4px solid #873600;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(
      circle at 35% 25%,
      rgba(255, 255, 255, 0.58),
      transparent 28%
    ),
    linear-gradient(180deg, #ffe27a 0%, #ffaf18 55%, #d96d00 100%);
  color: #4b2100;
  font-family: GameText, Arial, sans-serif;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  transform: translateZ(0);
  transition:
    transform 35ms linear,
    filter 35ms linear;
  will-change: transform;
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.35),
    inset 0 -5px 0 rgba(117, 47, 0, 0.38),
    0 6px 0 #5d2500,
    0 10px 16px rgba(0, 0, 0, 0.3);
}

.touch-button::before {
  content: attr(data-icon);
  position: absolute;
  inset: 0;
  padding-bottom: 4px;
  display: grid;
  place-items: center;
  color: #4b2100;
  font-size: calc(var(--touch-control-size) * 0.64);
  font-weight: 900;
  line-height: 1;
  pointer-events: none;
  text-shadow:
    2px 2px 0 rgba(255, 222, 130, 0.95),
    0 2px 0 rgba(255, 222, 130, 0.95);
}

.throw-button::before {
  padding-bottom: 0;
  font-size: calc(var(--touch-control-size) * 0.38);
  letter-spacing: 1px;
}

.touch-button.is-pressed,
.touch-button:active {
  transform: scale(0.93);
  filter: brightness(1.08);
  box-shadow:
    inset 0 3px 0 rgba(255, 255, 255, 0.25),
    inset 0 -3px 0 rgba(117, 47, 0, 0.35),
    0 3px 0 #5d2500,
    0 6px 10px rgba(0, 0, 0, 0.24);
}

.rotate-message {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  padding: max(24px, var(--safe-top)) max(24px, var(--safe-right))
    max(24px, var(--safe-bottom)) max(24px, var(--safe-left));
  overflow: hidden;
  background:
    radial-gradient(circle at top, rgba(255, 183, 3, 0.2), transparent 35%),
    linear-gradient(180deg, #1b0f06, #000);
  color: #fff;
  text-align: center;
}

.rotate-card {
  width: min(340px, 100%);
  padding: 30px 26px;
  border: 4px solid #ffb703;
  border-radius: 24px;
  background: rgba(40, 20, 8, 0.92);
  box-shadow:
    inset 0 4px 0 rgba(255, 255, 255, 0.12),
    0 16px 44px rgba(0, 0, 0, 0.5);
}

.rotate-icon {
  margin-bottom: 14px;
  color: #ffcc4d;
  font-size: 64px;
  line-height: 1;
}

.rotate-card h2 {
  margin-bottom: 10px;
  color: #ffcc4d;
  font-size: 28px;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #4d2500;
}

.rotate-card p {
  color: #fff4c2;
  font-size: 17px;
  line-height: 1.4;
}

@media (max-aspect-ratio: 3 / 2) {
  #game-container:not(.fullscreen-active) {
    width: min(var(--game-max-width), 100%);
    height: auto;
  }
}

@media (min-aspect-ratio: 3 / 2) {
  #game-container:not(.fullscreen-active) {
    width: auto;
    height: min(
      var(--game-max-height),
      calc(100vh - var(--edge-top) - var(--edge-bottom))
    );
    height: min(
      var(--game-max-height),
      calc(100svh - var(--edge-top) - var(--edge-bottom))
    );
    height: min(
      var(--game-max-height),
      calc(100dvh - var(--edge-top) - var(--edge-bottom))
    );
  }
}

@media (orientation: landscape) and (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: block;
  }
}

@media (orientation: portrait) and (hover: none) and (pointer: coarse) {
  .rotate-message {
    display: flex;
  }

  #game-container {
    display: none;
  }

  .touch-controls {
    display: none;
  }
}

@media (orientation: landscape) and (max-width: 1024px) and (max-height: 600px) {
  :root {
    --page-gap: 0px;
  }

  #game-container {
    border-radius: 0;
    box-shadow: none;
  }

  .game-title {
    font-size: 52px;
  }

  .game-subtitle {
    font-size: 14px;
  }

  .main-actions {
    margin-top: 10px;
  }

  .menu-button {
    min-width: 180px;
    height: 52px;
    font-size: 30px;
  }

  .round-actions {
    margin-top: 16px;
    gap: 24px;
  }

  .round-button {
    width: 62px;
    min-width: 62px;
    height: 62px;
  }

  .round-button img {
    width: 32px;
    height: 32px;
  }

  .round-button span {
    top: 68px;
    font-size: 12px;
  }

  .game-menu-button img {
    width: 25px;
    height: 25px;
  }
}

@media (orientation: landscape) and (max-width: 1024px) {
  .game-menu-button {
    top: max(8px, var(--safe-top));
    right: max(8px, var(--safe-right));
    width: 44px;
    height: 44px;
  }

  .game-fullscreen-button {
    top: calc(max(8px, var(--safe-top)) + 52px);
    right: max(8px, var(--safe-right));
  }
}

@media (orientation: landscape) and (max-height: 450px) {
  .game-menu-button {
    width: 40px;
    height: 40px;
  }

  .game-fullscreen-button {
    top: calc(max(6px, var(--safe-top)) + 46px);
  }
}

#game-container.fullscreen-active .touch-button {
  --touch-control-size: clamp(72px, 20vh, 84px);
  --touch-control-size: clamp(72px, 20dvh, 84px);
}

#game-container.fullscreen-active .touch-group {
  bottom: max(
    calc(var(--safe-bottom) + 12px),
    clamp(18px, 4dvh, 28px)
  );
  gap: clamp(12px, 1.8dvw, 18px);
}

#game-container.fullscreen-active .touch-left {
  left: max(calc(var(--safe-left) + 12px), clamp(16px, 3dvw, 30px));
}

#game-container.fullscreen-active .touch-right {
  right: max(calc(var(--safe-right) + 12px), clamp(16px, 3dvw, 30px));
}

#game-container:has(.game-overlay:not(.hidden)) .touch-controls,
#game-container:has(.pause-dialog:not(.hidden)) .touch-controls {
  display: none !important;
}

@media (max-height: 360px) and (orientation: landscape) {
  .touch-button {
    --touch-control-size: 56px;
  }

  #game-container.fullscreen-active .touch-button {
    --touch-control-size: 72px;
  }

  .touch-group {
    bottom: max(12px, calc(var(--safe-bottom) + 8px));
    gap: 10px;
  }

  #game-container.fullscreen-active .touch-group {
    bottom: max(14px, calc(var(--safe-bottom) + 10px));
  }
}
