/* JezzBall: dark retro skin over the shared header. The play area locks
   touch gestures (no scroll, pull-to-refresh, zoom or text selection).
   Mobile first; sizes grow with the screen (vmin) up to a 4K TV. */
[hidden] {
  display: none !important;
}

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;
  overflow: hidden;
  background: #0d1320;
  color: #e8edf5;
}

.game-nav {
  flex: 0 0 auto;
  background: #0d1320;
  border-bottom: 1px solid #222c40;
  box-shadow: none;
}

.nav-title {
  color: #ff5a4f;
  letter-spacing: 0.04em;
}

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

.jb-lang-switch {
  display: flex;
  gap: 8px;
}

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

.jb-chip.active,
.jb-chip[aria-pressed="true"] {
  border-color: #2f6fe0;
  background: #dbe8ff;
}

/* Android bars can cover the bottom even when the safe-area inset is 0:
   nothing essential in the bottom 40px nor in the 24px side strips. */
.jb-app {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  box-sizing: border-box;
  padding: 8px 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));
  background: #0d1320;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

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

/* --- Start screen and overlay cards --- */
.jb-start {
  flex: 1;
  min-width: 0;
  display: grid;
  place-items: center;
  padding: 0;
  background:
    repeating-linear-gradient(
      0deg,
      transparent 0 31px,
      rgba(255, 255, 255, 0.04) 31px 32px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0 31px,
      rgba(255, 255, 255, 0.04) 31px 32px
    ),
    #131b2b;
}

.jb-card {
  box-sizing: border-box;
  width: min(100%, 24em);
  padding: 1.4em 1.2em;
  border: 2px solid #34415c;
  border-radius: 1em;
  background: #0a0f19;
  text-align: center;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
}

.jb-card p {
  margin: 0 0 0.6em;
  line-height: 1.4;
  color: #c4cddb;
}

.jb-logo {
  margin: 0 0 0.4em;
  font-size: 2.6em;
  font-weight: 900;
  color: #ffffff;
  text-shadow:
    0.07em 0.07em 0 #e8413c,
    0.14em 0.14em 0 #2f6fe0;
}

.jb-overlay-title {
  margin: 0 0 0.5em;
  font-size: 1.5em;
  color: #ffffff;
}

.jb-best {
  font-weight: 700;
  color: #ffd23f !important;
}

.jb-new-best {
  display: block;
}

.jb-score-line {
  font-size: 1.2em;
  font-weight: 800;
  color: #ffffff !important;
}

.jb-button {
  margin: 0.5em 0.2em 0;
  min-width: 10em;
  min-height: 2.9em;
  padding: 0.6em 1.3em;
  border: none;
  border-radius: 0.8em;
  background: #e8413c;
  color: #ffffff;
  font: inherit;
  font-size: 1.1em;
  font-weight: 800;
  box-shadow: 0 0.2em 0 #8f1d19;
  cursor: pointer;
  touch-action: manipulation;
}

.jb-button:active {
  transform: translateY(0.15em);
  box-shadow: 0 0.05em 0 #8f1d19;
}

.jb-button-soft {
  background: #34415c;
  box-shadow: 0 0.2em 0 #1b2335;
}

.jb-app button:focus-visible,
.jb-canvas:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 3px;
}

.jb-start .jb-button {
  display: block;
  margin: 0.6em auto 0;
}

.jb-continue {
  background: #2f6fe0;
  box-shadow: 0 0.2em 0 #173d85;
}

.jb-continue:active {
  box-shadow: 0 0.05em 0 #173d85;
}

.jb-continue-info {
  display: block;
  font-size: 0.75em;
  font-weight: 600;
  opacity: 0.85;
}

/* --- Difficulty buttons: two big side-by-side targets --- */
.jb-modes {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6em;
  margin-top: 0.7em;
}

.jb-start .jb-mode {
  min-width: 0;
  min-height: 4.6em;
  margin: 0;
  padding: 0.5em;
}

.jb-mode-icon {
  display: block;
  font-size: 1.7em;
  line-height: 1.1;
}

.jb-mode-easy {
  background: #3fae4a;
  box-shadow: 0 0.2em 0 #1f6a27;
}

.jb-mode-easy:active {
  box-shadow: 0 0.05em 0 #1f6a27;
}

/* --- Easy-mode help: three illustrated steps --- */
.jb-intro-steps {
  margin: 0 0 4px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.jb-intro-steps li {
  display: grid;
  grid-template-columns: 5.25em 1fr;
  gap: 0.75em;
  align-items: center;
  margin-bottom: 0.6em;
}

.jb-intro-steps p {
  margin: 0;
  font-size: 0.95em;
}

.jb-intro-art {
  width: 5.25em;
  height: 3.5em;
}

/* --- Play stage: board + HUD (below in portrait, right side in landscape) --- */
.jb-stage {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Portrait: the board is 99% of the screen wide, past the 24px side
   strips (platform rule 6.3); the HUD keeps them. */
.jb-board {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  margin-inline: calc(50% - 49.5vw);
  background: #0d1320;
}

.jb-canvas {
  position: absolute;
  inset: 0;
  touch-action: none;
  cursor:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M2 16 9 9v4h14V9l7 7-7 7v-4H9v4z' fill='white' stroke='black' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E")
      16 16,
    ew-resize;
}

.jb-canvas[data-axis="v"] {
  cursor:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M16 2 23 9h-4v14h4l-7 7-7-7h4V9H9z' fill='white' stroke='black' stroke-width='1.5' stroke-linejoin='round'/%3E%3C/svg%3E")
      16 16,
    ns-resize;
}

.jb-hud {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(6em, 30%);
  grid-template-rows: auto auto;
  gap: 0.4em;
  padding: 0.5em 0 0;
  background: #0d1320;
  border-top: 1px solid #222c40;
}

.jb-stat {
  min-width: 0;
  padding: 0.25em 0.4em;
  border-radius: 0.5em;
  background: #151d2d;
  text-align: center;
}

.jb-stat-label {
  display: block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #8d9bb3;
}

.jb-stat-value {
  display: block;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font:
    800 1.1em / 1.2 ui-monospace,
    "SFMono-Regular",
    Consolas,
    monospace;
  color: #ffffff;
}

.jb-stat-value[data-hud="area"] {
  font-size: 0.95em;
}

.jb-stat.is-urgent .jb-stat-value {
  color: #ff5a5a;
  animation: jb-blink 0.5s steps(2) infinite;
}

@keyframes jb-blink {
  50% {
    opacity: 0.35;
  }
}

/* --- Axis toggle: big, always reachable with a thumb --- */
.jb-axis {
  grid-column: 4;
  grid-row: 1 / span 2;
  min-height: 4.6em;
  padding: 0.3em 0.5em;
  border: 3px solid #e8413c;
  border-radius: 1em;
  background: #2a1414;
  color: #ffffff;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.12s,
    border-color 0.12s;
}

.jb-axis[data-axis="v"] {
  border-color: #2f6fe0;
  background: #121c33;
}

.jb-axis:active {
  transform: scale(0.96);
}

.jb-axis-icon {
  display: block;
  font-size: 2.2em;
  line-height: 1;
}

.jb-axis-label {
  display: block;
  margin-top: 0.1em;
  font-size: 0.65em;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.jb-axis[data-axis="h"] .jb-axis-v,
.jb-axis[data-axis="v"] .jb-axis-h {
  display: none;
}

.jb-option-hint {
  margin: 0 0 8px;
  font-size: 0.85rem;
  color: #4b5563;
}

.jb-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 0.5em;
  overflow-y: auto;
}

/* The dimming is as wide as the board; the card keeps the side strips. */
.jb-overlay::before {
  content: "";
  position: absolute;
  inset: 0 calc(50% - 49.5vw);
  z-index: -1;
  background: rgba(6, 9, 16, 0.72);
}

@media (orientation: landscape) and (min-width: 560px) {
  .jb-stage {
    flex-direction: row;
  }

  .jb-board,
  .jb-overlay::before {
    margin-inline: 0;
    inset: 0;
  }

  .jb-hud {
    width: max(9.5em, 18vw);
    grid-template-columns: 1fr 1fr;
    grid-template-rows: none;
    align-content: center;
    padding: 0 0 0 0.6em;
    border-top: 0;
    border-left: 1px solid #222c40;
  }

  .jb-stat {
    padding: 0.35em 0.25em;
  }

  .jb-stat-wide {
    grid-column: 1 / -1;
  }

  .jb-axis {
    grid-column: 1 / -1;
    grid-row: auto;
    min-height: 5em;
    margin-top: 0.25em;
  }
}

/* Landscape phones are ~360px tall: compact HUD and cards. */
@media (orientation: landscape) and (max-height: 500px) {
  .jb-card {
    width: min(100%, 30em);
    padding: 0.6em 1em 0.8em;
  }

  .jb-card p {
    margin-bottom: 0.25em;
  }

  .jb-logo {
    font-size: 1.8em;
    margin-bottom: 0.1em;
  }

  /* The pitch is repeated in the rules; the buttons need the room. */
  .jb-pitch {
    display: none;
  }

  .jb-intro {
    width: min(100%, 38em);
  }

  .jb-intro-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.6em;
  }

  .jb-intro-steps li {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0.3em;
    margin: 0;
    text-align: center;
  }

  .jb-intro-steps p {
    font-size: 0.8em;
  }

  .jb-overlay-title {
    margin-bottom: 0.2em;
    font-size: 1.25em;
  }

  .jb-button {
    min-height: 2.5em;
    margin-top: 0.3em;
  }

  .jb-start .jb-mode {
    min-height: 3.4em;
  }

  .jb-mode-icon {
    font-size: 1.3em;
  }

  .jb-intro-steps li {
    margin-bottom: 0.3em;
  }

  .jb-hud {
    gap: 0.25em;
  }

  .jb-stat {
    padding: 0.1em 0.25em;
  }

  .jb-stat-label {
    font-size: 0.55rem;
  }

  .jb-axis {
    min-height: 3.6em;
  }

  .jb-axis-icon {
    font-size: 1.6em;
  }
}

/* Desktop and TV, 960x540 up to 3840x2160: the header grows with the
   screen and everything stays 3% away from the edges (TV overscan). */
@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));
  }

  .nav-title {
    font-size: max(1.1rem, 3.4dvh);
  }

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

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

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

  .jb-card {
    width: min(100%, 30em);
  }
}

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