.mobile-splash[hidden],
.touch-controls[hidden] {
  display: none;
}

html.is-mobile-startup {
  overflow: hidden;
}

html.has-mobile-started .game-title,
html.has-mobile-started .credit-bar {
  display: none;
}

.mobile-splash {
  position: fixed;
  inset: 0;
  z-index: 20;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(24px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  background:
    linear-gradient(rgba(8, 12, 18, 0.68), rgba(8, 12, 18, 0.88)),
    url("assets/shaman_dance_bg.webp") center / cover no-repeat;
}

.mobile-splash img {
  display: block;
  width: min(468px, 92vw);
  height: auto;
  filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.72));
  animation: mobileSplashReveal 500ms ease-out both;
}

.mobile-start-button {
  min-width: 190px;
  min-height: 52px;
  padding: 12px 24px;
  border: 2px solid rgba(255, 229, 155, 0.68);
  border-radius: 6px;
  color: #fff0b2;
  background:
    linear-gradient(rgba(255, 205, 116, 0.22), rgba(74, 28, 9, 0.3)),
    rgba(95, 48, 18, 0.94);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    inset 0 0 12px rgba(0, 0, 0, 0.42),
    0 8px 16px rgba(0, 0, 0, 0.5);
  text-shadow: 0 2px 1px rgba(0, 0, 0, 0.96);
}

.mobile-start-button:focus-visible {
  outline: 3px solid #ffe9a5;
  outline-offset: 4px;
}

.mobile-start-button:active {
  transform: translateY(2px);
  filter: brightness(1.12);
}

.mobile-splash-credit {
  position: absolute;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  left: max(20px, env(safe-area-inset-left));
  text-align: center;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  color: #fff0b2;
  text-shadow:
    0 2px 1px rgba(0, 0, 0, 0.98),
    0 0 8px rgba(241, 189, 98, 0.24);
}

.touch-controls {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    ". rotate ."
    "left down right"
    "drop drop drop";
  gap: 7px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.touch-control {
  min-width: 0;
  min-height: 50px;
  padding: 6px;
  border: 2px solid rgba(255, 229, 155, 0.58);
  border-radius: 7px;
  color: #fff0b2;
  background:
    linear-gradient(rgba(255, 205, 116, 0.2), rgba(74, 28, 9, 0.28)),
    url("assets/info-panel-wood.webp") center / 100% 100% no-repeat;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 0 0 10px rgba(0, 0, 0, 0.48),
    0 4px 8px rgba(0, 0, 0, 0.4);
  text-shadow: 0 2px 1px rgba(0, 0, 0, 0.98);
  -webkit-tap-highlight-color: transparent;
}

.touch-control:focus-visible {
  outline: 3px solid #ffe9a5;
  outline-offset: 2px;
}

.touch-control:active,
.touch-control.is-pressed {
  transform: translateY(2px);
  filter: brightness(1.18);
}

.touch-control-rotate {
  grid-area: rotate;
}

.touch-control-left {
  grid-area: left;
}

.touch-control-down {
  grid-area: down;
}

.touch-control-right {
  grid-area: right;
}

.touch-control-drop {
  grid-area: drop;
  min-height: 44px;
  font-size: 17px;
  text-transform: uppercase;
}

@media (orientation: portrait) {
  html.has-mobile-started.is-small-layout {
    --mobile-board-width: min(78vw, calc((100dvh - 294px) / 2));
  }

  html.has-mobile-started.is-small-layout .game-shell {
    min-height: 100dvh;
    justify-content: flex-start;
    gap: 0;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  html.has-mobile-started.is-small-layout .game-layout,
  html.has-mobile-started.is-small-layout .game-body {
    width: 100%;
  }

  html.has-mobile-started.is-small-layout .game-layout {
    align-items: center;
    gap: 10px;
  }

  html.has-mobile-started.is-small-layout .game-body {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-areas:
      "info"
      "board";
    justify-items: center;
    gap: 8px;
  }

  html.has-mobile-started.is-small-layout .board-frame {
    grid-area: board;
    width: calc(var(--mobile-board-width) + 16px);
    height: calc(var(--mobile-board-width) * 2 + 16px);
  }

  html.has-mobile-started.is-small-layout #game-board {
    width: var(--mobile-board-width);
    height: calc(var(--mobile-board-width) * 2);
  }

  html.has-mobile-started.is-small-layout .game-info {
    grid-area: info;
    width: min(calc(var(--mobile-board-width) + 16px), 100%);
    max-width: none;
    height: 82px;
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr 1.2fr;
    grid-template-rows: 82px;
    gap: 5px;
  }

  html.has-mobile-started.is-small-layout .info-section,
  html.has-mobile-started.is-small-layout .info-section:last-child {
    min-width: 0;
    min-height: 0;
    padding: 8px 4px 6px;
    grid-column: auto;
  }

  html.has-mobile-started.is-small-layout .info-section h2 {
    margin-bottom: 3px;
  }

  html.has-mobile-started.is-small-layout .info-section h2 img {
    max-width: 56px;
  }

  html.has-mobile-started.is-small-layout .number-display {
    min-height: 30px;
  }

  html.has-mobile-started.is-small-layout .number-display img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="1"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="4"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="5"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="6"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="7"] img {
    width: 14px;
    height: 24px;
  }

  html.has-mobile-started.is-small-layout .number-display img + img {
    margin-left: -4px;
  }

  html.has-mobile-started.is-small-layout .next-piece-preview {
    width: 52px;
    height: 39px;
  }

  html.has-mobile-started.is-small-layout .touch-controls {
    width: min(calc(var(--mobile-board-width) + 16px), 100%);
  }
}

@media (orientation: landscape) and (max-height: 700px) {
  html.has-mobile-started.is-small-layout {
    --mobile-board-width: min(42vw, calc((100dvh - 24px) / 2));
  }

  html.has-mobile-started.is-small-layout .game-shell {
    min-height: 100dvh;
    justify-content: center;
    gap: 0;
    padding:
      max(8px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-left));
  }

  html.has-mobile-started.is-small-layout .game-layout {
    width: auto;
    display: grid;
    grid-template-columns:
      calc(var(--mobile-board-width) + 16px)
      min(34vw, 230px);
    grid-template-areas:
      "board info"
      "board controls";
    grid-template-rows: minmax(0, 1fr) auto;
    align-items: stretch;
    gap: 8px 12px;
  }

  html.has-mobile-started.is-small-layout .game-body {
    display: contents;
  }

  html.has-mobile-started.is-small-layout .board-frame {
    grid-area: board;
    width: calc(var(--mobile-board-width) + 16px);
    height: calc(var(--mobile-board-width) * 2 + 16px);
    filter: none;
  }

  html.has-mobile-started.is-small-layout #game-board {
    width: var(--mobile-board-width);
    height: calc(var(--mobile-board-width) * 2);
  }

  html.has-mobile-started.is-small-layout .game-info {
    grid-area: info;
    width: min(34vw, 230px);
    height: auto;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  html.has-mobile-started.is-small-layout .info-section,
  html.has-mobile-started.is-small-layout .info-section:last-child {
    min-width: 0;
    min-height: 0;
    padding: 8px 5px 6px;
    grid-column: auto;
  }

  html.has-mobile-started.is-small-layout .info-section h2 {
    margin-bottom: 3px;
  }

  html.has-mobile-started.is-small-layout .info-section h2 img {
    max-width: 64px;
  }

  html.has-mobile-started.is-small-layout .number-display {
    min-height: 32px;
  }

  html.has-mobile-started.is-small-layout .number-display img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="1"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="4"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="5"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="6"] img,
  html.has-mobile-started.is-small-layout .number-display[data-digit-count="7"] img {
    width: 15px;
    height: 25px;
  }

  html.has-mobile-started.is-small-layout .number-display img + img {
    margin-left: -4px;
  }

  html.has-mobile-started.is-small-layout .next-piece-preview {
    width: 58px;
    height: 44px;
  }

  html.has-mobile-started.is-small-layout .touch-controls {
    grid-area: controls;
    width: min(34vw, 230px);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "left rotate right"
      "down drop drop";
    gap: 6px;
  }

  html.has-mobile-started.is-small-layout .touch-control {
    min-height: 45px;
    font-size: 25px;
  }

  html.has-mobile-started.is-small-layout .touch-control-drop {
    min-height: 45px;
    font-size: 13px;
  }

  html.has-mobile-started.is-small-layout .game-status {
    width: calc(100% - 28px);
    padding: 16px 8px;
    font-size: 23px;
  }

  html.has-mobile-started.is-small-layout .scoreboard-panel {
    position: fixed;
    top: 50dvh;
    left: 50vw;
    width: min(360px, calc(100vw - 24px));
    min-height: min(360px, calc(100dvh - 20px));
    padding: 18px 12px 14px;
    transform: translate(-50%, -50%);
  }
}

@keyframes mobileSplashReveal {
  0% {
    opacity: 0;
    transform: scale(0.96);
  }

  100% {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-splash img {
    animation: none;
  }
}
