/* Tetris: dark night skin over the shared header. Mobile first; sizes grow
   with the screen (vmin) up to a 4K TV. Page frame, chips, cards, buttons
   and overlays here; start screen in screens.css, play stage in stage.css. */
html {
  font-size: clamp(16px, 2.4vmin, 64px);
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  background: linear-gradient(160deg, #0b1220 0%, #1a1530 100%);
  color: #dbe4f0;
}

.game-nav {
  flex: 0 0 auto;
  background: transparent;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.nav-title {
  color: #dbe4f0;
  font-weight: 700;
  letter-spacing: 0.12em;
}

.back-button,
.options-button {
  background: #3a4a8a;
  color: #ffffff;
}

.options-panel-sheet {
  color: #1f2937;
}

.tr-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tr-chip {
  min-width: 3em;
  min-height: 2.75em;
  padding: 0.5em 0.9em;
  border: 2px solid #d5d9e4;
  border-radius: 0.75em;
  background: #ffffff;
  color: #1f2937;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.tr-chip.active,
.tr-chip[aria-pressed="true"] {
  border-color: #4a5fc4;
  background: #e6eafb;
}

.tr-app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.tr-app [hidden] {
  display: none !important;
}

.tr-app button:focus-visible,
.tr-app input:focus-visible,
.tr-board:focus-visible,
.tr-chip:focus-visible {
  outline: 3px solid #7aa2ff;
  outline-offset: 3px;
}

.tr-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tr-card {
  width: min(100%, 24em);
  padding: 1.4em 1.2em 1.5em;
  border-radius: 1.4em;
  background: rgba(24, 30, 52, 0.94);
  text-align: center;
  box-shadow: 0 0.8em 2.4em rgba(0, 0, 0, 0.4);
  animation: tr-fade 0.35s ease-out both;
}

.tr-card p {
  margin: 0 0 0.6em;
  line-height: 1.5;
}

.tr-button {
  display: block;
  width: min(100%, 14em);
  min-height: 3em;
  margin: 0.7em auto 0;
  padding: 0.6em 1.4em;
  border: none;
  border-radius: 1em;
  background: #4a5fc4;
  color: #ffffff;
  font: inherit;
  font-size: 1.1em;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 0.2em 0 #34439a;
  cursor: pointer;
  touch-action: manipulation;
}

.tr-button:active {
  transform: translateY(0.12em);
  box-shadow: 0 0.08em 0 #34439a;
}

.tr-button-soft {
  background: #2a3358;
  color: #c7d2f0;
  box-shadow: 0 0.2em 0 #1c2342;
}

.tr-info {
  display: block;
  font-size: 0.75em;
  font-weight: 500;
  opacity: 0.85;
}

.tr-best {
  margin-top: 0.9em !important;
  font-weight: 600;
  color: #93a0c4;
}

/* Overlays: the board stays softly visible behind. */
.tr-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 1em max(24px, env(safe-area-inset-right, 0px))
    max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px))
    max(24px, env(safe-area-inset-left, 0px));
  overflow-y: auto;
  background: rgba(8, 12, 24, 0.7);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
  animation: tr-overlay-fade 0.3s ease-out both;
}

.tr-overlay-title {
  margin: 0 0 0.5em;
  font-size: 1.6em;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #eef2fb;
}

.tr-score-line {
  font-size: 1.6em;
  font-weight: 700;
  color: #8fb0ff;
}

/* The end screen waits a moment so the final stack can be seen. */
.tr-overlay-late,
.tr-overlay-late .tr-card {
  animation-delay: 0.6s;
}

@keyframes tr-fade {
  from {
    opacity: 0;
    transform: translateY(0.4em);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* The full-screen overlay only fades: sliding it would scroll the page. */
@keyframes tr-overlay-fade {
  from {
    opacity: 0;
  }
}

/* Big screens (desktop, TV): the shared header grows with the screen. */
@media (min-width: 960px) and (min-height: 500px) {
  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }

  .tr-overlay {
    padding: 2dvh max(3vw, env(safe-area-inset-right, 0px)) max(40px, 4dvh)
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .back-button svg,
  .options-button svg {
    width: 50%;
    height: 50%;
  }
}

/* TV remote: a thick, high-contrast ring on the focused control. */
html.tv :focus {
  outline: 0.25rem solid #ffd24a !important;
  outline-offset: 0.2rem;
  box-shadow: 0 0 0 0.5rem rgba(0, 0, 0, 0.6);
}

/* Short landscape screens: the overlays must fit in ~300px. */
@media (orientation: landscape) and (max-height: 500px) {
  .tr-card {
    width: min(100%, 30em);
    padding: 0.7em 1em 0.9em;
  }

  .tr-overlay-title {
    margin-bottom: 0.2em;
    font-size: 1.3em;
  }

  .tr-button {
    min-height: 2.6em;
    margin-top: 0.4em;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tr-card,
  .tr-overlay {
    animation: none;
  }
}
