html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

[hidden] {
  display: none !important;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  background: #808080;
  color: #000;
}

/* Play screen: bars + table. The side and bottom margins keep the
   controls clear of the system gesture strips and navigation bar. */
.sc-play {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding: 0 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: #000;
}

/* Game Dashboard over the (still loading) table. */
.sc-dashboard {
  position: fixed;
  z-index: 900;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.8em;
  box-sizing: border-box;
  padding: calc(60px + env(safe-area-inset-top, 0px))
    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: #008080;
  color: #fff;
  font:
    700 max(16px, 2.4dvh) Tahoma,
    Geneva,
    Verdana,
    sans-serif;
  text-align: center;
}

.sc-dash-title {
  margin: 0;
  font-size: 2em;
  text-shadow: 2px 2px 0 #000;
}

.sc-dash-pitch {
  max-width: 24em;
  margin: 0;
  font-weight: 400;
  line-height: 1.4;
}

.sc-dashboard .sc-btn.sc-start {
  flex: none;
  min-width: 10em;
  min-height: max(48px, 6dvh);
  font-size: 1.1em;
}

body.sc-dash .sc-play {
  visibility: hidden;
}

.game-nav {
  background: #c0c0c0;
  border-bottom: 1px solid #808080;
  box-shadow: none;
}

.sc-bar {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  box-sizing: border-box;
  background: #c0c0c0;
  padding: 6px;
}

.sc-bar--top {
  padding-top: 6px;
}

.sc-bar--bottom {
  padding-bottom: 6px;
}

.sc-btn {
  flex: 1 1 0;
  margin: 0;
  border: none;
  background: #c0c0c0;
  color: #000;
  font:
    700 15px Tahoma,
    Geneva,
    Verdana,
    sans-serif;
  min-height: 48px;
  padding: 8px 6px;
  touch-action: none;
  cursor: pointer;
  box-shadow:
    inset -1px -1px 0 #000,
    inset 1px 1px 0 #fff,
    inset -2px -2px 0 #808080,
    inset 2px 2px 0 #dfdfdf;
}

.sc-bar--top .sc-btn {
  min-height: 32px;
  font-size: 11px;
  padding: 4px 2px;
}

.sc-btn.held {
  box-shadow:
    inset 1px 1px 0 #000,
    inset -1px -1px 0 #dfdfdf,
    inset 2px 2px 0 #808080,
    inset -2px -2px 0 #fff;
}

.sc-btn--plunge {
  flex: 1.3 1 0;
}

.sc-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

/* 600×416 is the table + scoreboard without the ImGui menu bar
   (--sc-menu), which is cropped off while a match is running. */
:root {
  --sc-menu: 19px;
}

.sc-frame {
  position: relative;
  width: min(100%, calc((100dvh - 80px) * 600 / 416));
  height: min(100%, calc(100dvh - 80px));
  max-width: 100%;
  max-height: calc(100dvh - 80px);
  aspect-ratio: 600 / 416;
}

.sc-view {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.sc-playing .sc-view canvas.emscripten {
  margin-top: calc(-1 * var(--sc-menu));
  height: calc(100% + var(--sc-menu));
  max-height: none;
}

.sc-score,
.sc-options-actions,
.sc-zone--plunge {
  display: none;
}

canvas.emscripten {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: calc(100dvh - 80px);
  object-fit: contain;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  background: #000;
  touch-action: none;
}

.sc-zone,
.sc-zone.held {
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  padding: 0;
  border: 0;
  min-height: 0;
  background: transparent;
  box-shadow: none;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.sc-zone--left {
  left: 0;
}

.sc-zone--right {
  right: 0;
}

.sc-status {
  position: absolute;
  z-index: 2;
  left: 12px;
  right: 12px;
  top: 36%;
  margin: 0;
  text-align: center;
  color: #fff;
  font-size: 14px;
  pointer-events: none;
}

.sc-progress {
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 48%;
  width: min(280px, 80%);
  transform: translateX(-50%);
  pointer-events: none;
}

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

.sc-chip {
  min-width: 56px;
  padding: 8px 14px;
  border: 2px solid #808080;
  background: #c0c0c0;
  color: #000;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    inset -1px -1px 0 #000,
    inset 1px 1px 0 #fff;
}

.sc-chip.active {
  box-shadow:
    inset 1px 1px 0 #000,
    inset -1px -1px 0 #fff;
}

.rules-modal-content {
  font-size: 14px;
  line-height: 1.45;
}

.rules-modal-content ul {
  padding-left: 1.2em;
}

.sc-mute {
  width: 100%;
}

.sc-mute[aria-pressed="true"] {
  box-shadow:
    inset 1px 1px 0 #000,
    inset -1px -1px 0 #dfdfdf,
    inset 2px 2px 0 #808080,
    inset -2px -2px 0 #fff;
}

.sc-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Phone: table only, score row in the header. 0.62 is the playfield
   slice of the 600×416 frame, before the right-hand scoreboard. */
@media (max-width: 900px), (max-height: 520px) {
  .game-nav {
    height: calc(44px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 8px 0;
    background: #000;
    border-bottom: 0;
  }

  .nav-title {
    display: none;
  }

  .sc-score {
    display: block;
    width: 100%;
    height: 32px;
    background: #000;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    pointer-events: none;
  }

  .sc-bar {
    display: none;
  }

  .sc-options-actions {
    display: block;
  }

  .sc-frame {
    position: absolute;
    inset: 0;
    width: auto;
    height: auto;
    max-height: none;
    aspect-ratio: auto;
    padding-top: clamp(8px, 4dvh, 36px);
    container-type: size;
    display: flex;
    align-items: flex-start;
    justify-content: center;
  }

  .sc-view {
    --table: 0.62;
    width: min(100cqw, calc(100cqh * var(--table) * 600 / 416));
    height: min(100cqh, calc(100cqw * 416 / (600 * var(--table))));
    flex: none;
  }

  .sc-view canvas.emscripten {
    width: calc(100% / var(--table));
    height: 100%;
    max-width: none;
    max-height: none;
  }

  .sc-zone.sc-zone--plunge {
    display: block;
    left: auto;
    right: 0;
    top: auto;
    bottom: 6%;
    width: 18%;
    height: 36%;
    z-index: 2;
  }
}

/* Desktop and TV: header buttons follow the screen, 3% overscan. */
@media (min-width: 960px) and (min-height: 540px) {
  .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(16px, 3dvh);
  }

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

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

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

  .sc-dashboard {
    padding-top: calc(10dvh + env(safe-area-inset-top, 0px));
  }

  .sc-bar .sc-btn,
  .sc-bar--top .sc-btn {
    min-height: max(32px, 5dvh);
    font-size: max(11px, 1.8dvh);
  }

  .sc-frame,
  canvas.emscripten {
    max-height: calc(100dvh - 26dvh);
  }

  .sc-frame {
    width: min(100%, calc((100dvh - 26dvh) * 600 / 416));
    height: min(100%, calc(100dvh - 26dvh));
  }
}

html.tv :focus {
  outline: max(4px, 0.5dvh) solid #ffcc00 !important;
  outline-offset: max(2px, 0.3dvh);
}

/* The table itself carries the focus during play: no ring over it. */
.sc-frame:focus,
html.tv .sc-frame:focus {
  outline: none !important;
}
