body {
  margin: 0;
  padding: 0;
  color: rgba(255, 255, 255, 0.87);
  background-color: #000000;
  /* Background image + dark overlay for text readability */
  background-image: linear-gradient(rgba(0, 0, 0, 0.58), rgba(0, 0, 0, 0.58)), url('/images/background.webp');
  background-size: cover;
  background-position: top center;
  background-repeat: no-repeat;
  font-family:
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
}

#app {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* Landing should behave like a normal page on desktop (scrollable, not locked to 100vh). */
#app.app-landing {
  height: auto;
  min-height: 100vh;
  overflow: auto;
  align-items: flex-start;
  padding: 56px 24px 32px;
  box-sizing: border-box;
}

#game-container {
  width: 721px;
  height: 721px;
  position: relative;
}

#game-container canvas {
  position: relative;
  z-index: 1;
}

.broadcast-overlay {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}

.broadcast-box {
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 8px 10px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  text-align: center;
}

.broadcast-sticky-item {
  line-height: 1.25;
  text-align: center;
}

.broadcast-sticky-item + .broadcast-sticky-item {
  margin-top: 4px;
}

.broadcast-scroll-viewport {
  overflow: hidden;
  white-space: nowrap;
}

.broadcast-scroll-text {
  display: inline-block;
  animation-name: broadcast-scroll;
  animation-timing-function: linear;
  animation-fill-mode: both;
}

/* Instant-mode coach overlay */

.coach-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  pointer-events: none;
}

.coach-spotlight {
  position: fixed;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0);
  box-shadow: 0 0 0 6px rgba(0, 0, 0, 0.35);
}

.coach-bubble {
  position: fixed;
  max-width: min(320px, calc(100vw - 24px));
  padding: 10px 12px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.7);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  text-align: center;
  font-weight: 600;
  line-height: 1.25;
}

.coach-bubble--above::after,
.coach-bubble--below::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border: 10px solid transparent;
}

.coach-bubble--above::after {
  top: 100%;
  border-top-color: rgba(0, 0, 0, 0.7);
}

.coach-bubble--below::after {
  bottom: 100%;
  border-bottom-color: rgba(0, 0, 0, 0.7);
}

@keyframes broadcast-scroll {
  0% {
    transform: translateX(100%);
  }
  100% {
    transform: translateX(-100%);
  }
}

@media (max-width: 900px) {
  #app {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: auto;
    padding: 12px;
    justify-content: flex-start;
    align-items: stretch;
    box-sizing: border-box;
    --board-size: min(100%, calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)));
  }

  /* In the game view, center the column contents horizontally. */
  #app:not(.app-landing) {
    align-items: center;
  }

  #app.app-landing {
    align-items: center;
    padding-top: 24px;
  }

  .side-panel {
    margin-left: 0;
    margin-top: 12px;
    align-self: center;
  }

  #app.app-landing .side-panel {
    margin-top: 0;
  }

  #game-container {
    width: var(--board-size);
    max-width: 100%;
    aspect-ratio: 1 / 1;
    height: auto;
    margin: 0 auto;
    align-self: center;
    display: flex;
    justify-content: center;
    align-items: center;
    box-sizing: border-box;
  }

  #game-container canvas {
    display: block;
    margin: 0 auto;
  }

  .roll-cta {
    position: sticky;
    top: 12px;
    z-index: 1000;
    margin-top: 12px;
  }
}

/* Landscape phones can exceed 900px width; use short height instead. */
@media (max-height: 520px) and (orientation: landscape) {
  #app {
    flex-direction: row;
    height: 100vh;
    height: 100svh;
    min-height: 0;
    overflow: hidden;
    padding: 12px;
    justify-content: center;
    align-items: center;
  }

  #app {
    --board-size: min(calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), calc(100vw - 360px - 48px - env(safe-area-inset-left) - env(safe-area-inset-right)));
  }

  #game-container {
    width: var(--board-size);
    height: var(--board-size);
    max-width: calc(100vw - 360px - 48px);
    max-height: calc(100svh - 24px);
    aspect-ratio: 1 / 1;
  }

  .side-panel {
    margin-top: 0;
    margin-left: 12px;
    max-height: calc(100svh - 24px);
    overflow: auto;
    align-self: stretch;
  }

  /* In landscape, avoid reducing vertical space via a fixed CTA */
  .roll-cta {
    position: static;
    left: auto;
    right: auto;
    bottom: auto;
  }
}

.roll-cta {
  width: 100%;
}

.spritePosition {
  margin: 10px 0 0 10px;
  font-size: 0.8em;
}

.button {
  width: 140px;
  margin: 10px;
  padding: 10px;
  background-color: #000000;
  color: rgba(255, 255, 255, 0.87);
  border: 1px solid rgba(255, 255, 255, 0.87);
  cursor: pointer;
  transition: all 0.3s;
}

.button:hover {
  border: 1px solid #0ec3c9;
  color: #0ec3c9;
}

.button:active {
  background-color: #0ec3c9;
}

.button:disabled {
  cursor: not-allowed;
  border: 1px solid rgba(255, 255, 255, 0.3);
  color: rgba(255, 255, 255, 0.3);
}

.button-primary {
  background-color: #0ec3c9;
  border-color: #0ec3c9;
  color: #000000;
  font-weight: 700;
}

/* Filled button variant that is NOT the primary accent color. */
.button-filled {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.26);
  color: rgba(255, 255, 255, 0.92);
  font-weight: 700;
}

.button-filled:hover {
  border-color: rgba(255, 255, 255, 0.42);
  color: rgba(255, 255, 255, 0.98);
}

.button-filled:active {
  background: rgba(255, 255, 255, 0.16);
}

.button-filled:disabled {
  background: rgba(255, 255, 255, 0.06);
}

.button-primary:hover {
  border-color: #0ec3c9;
  color: #000000;
  filter: brightness(1.05);
}

.button-primary:active {
  filter: brightness(0.95);
}

.button-primary:disabled {
  background-color: #000000;
  filter: none;
}

/* Attention animation for the main CTA (respects reduced motion). */
.button-attention {
  animation: button-attention-pulse 1.9s ease-in-out infinite;
  will-change: transform, box-shadow;
}

@keyframes button-attention-pulse {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: 0 0 0 0 rgba(14, 195, 201, 0);
    filter: brightness(1);
  }
  55% {
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 0 0 10px rgba(14, 195, 201, 0.14);
    filter: brightness(1.06);
  }
  100% {
    transform: translateY(0) scale(1);
    box-shadow: 0 0 0 0 rgba(14, 195, 201, 0);
    filter: brightness(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .button-attention {
    animation: none;
  }
}

.button-with-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-with-icon .button-icon {
  width: 1em;
  height: 1em;
  flex: 0 0 auto;
}

.button--sm {
  width: auto;
  margin: 0;
  padding: 6px 10px;
  font-size: 0.85rem;
  line-height: 1;
}

/* Online panel */

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
  width: 360px;
  max-width: calc(100vw - 24px);
  margin-left: 16px;
}

/* Game view locks the outer container to 100vh + overflow hidden; ensure the
   right-side UI can still scroll when it grows taller (e.g. dev/sandbox tools). */
#app:not(.app-landing) .side-panel {
  max-height: calc(100vh - 24px);
  overflow: auto;
}

#app.app-landing .side-panel {
  margin-left: 0;
}

/* Landing polish: avoid global button margins inside landing panels. */
#app.app-landing .online-actions .button {
  margin: 0;
}

/* Give the landing content a wider, more “website-like” layout on desktop. */
@media (min-width: 901px) {
  #app.app-landing .side-panel {
    width: min(980px, calc(100vw - 48px));
    max-width: min(980px, calc(100vw - 48px));
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    align-self: center;
  }

  #app.app-landing .side-panel > .online-panel {
    padding: 16px;
  }

  #app.app-landing .online-title {
    font-size: 1.2rem;
  }

  #app.app-landing .online-panel-games {
    grid-column: 1 / -1;
  }

  #app.app-landing .online-panel-hero {
    grid-column: 1 / -1;
  }

  #app.app-landing .online-panel-hero .button {
    font-size: 1.05rem;
    padding: 12px 14px;
  }
}

/* Desktop: when we're in the pre-game menu (no board visible yet), give the
   chooser/config panels a wider layout so they don't feel cramped. */
@media (min-width: 901px) {
  #app.app-game-menu {
    padding: 24px;
    box-sizing: border-box;
  }

  #app.app-game-menu .side-panel {
    width: min(720px, calc(100vw - 48px));
    max-width: min(720px, calc(100vw - 48px));
    margin-left: 0;
  }

  #app.app-game-menu .online-panel {
    padding: 16px;
  }

  #app.app-game-menu .online-title {
    font-size: 1.2rem;
  }
}

/* Mode chooser buttons: make both options feel "filled" and prominent. */
#app.app-game-menu .button-choice-online,
#app.app-game-menu .button-choice-offline {
  font-weight: 700;
}

#app.app-game-menu .button-choice-offline {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.26);
}

#app.app-game-menu .button-choice-offline:hover {
  border-color: #0ec3c9;
}

.online-panel {
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

/* Feedback popup */

.feedback-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  box-sizing: border-box;
  /* Match the existing page overlay tone used in the body background gradient */
  background: rgba(0, 0, 0, 0.58);
}

.feedback-modal {
  width: 420px;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Nudge the top Games panel down so background header text remains visible. */
#app.app-landing .online-panel-hero {
  margin-top: 18px;
}

/* Landing layout helpers */
.landing-hero {
  display: grid;
  gap: 12px;
}

.landing-kicker {
  font-weight: 700;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.8);
}

.landing-hero-title {
  margin: 4px 0 0;
  font-size: 1.55rem;
  line-height: 1.2;
}

.landing-hero-subtitle {
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.75);
}

.landing-games-grid {
  margin-top: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .landing-games-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.landing-game-card {
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  padding: 12px;
  background: rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition:
    transform 0.2s,
    border-color 0.2s;
}

.landing-game-card:hover {
  border-color: #0ec3c9;
  transform: translateY(-2px);
}

@media (prefers-reduced-motion: reduce) {
  .landing-game-card {
    transition: none;
  }

  .landing-game-card:hover {
    transform: none;
  }
}

.landing-game-thumb {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 10px;
}

.landing-game-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: rgba(255, 255, 255, 0.92);
}

.landing-game-desc {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.95rem;
}

.landing-bullets {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

.landing-rules {
  margin-top: 8px;
}

.landing-rules-title {
  font-weight: 600;
  margin-top: 10px;
}

.landing-about {
  display: grid;
  gap: 12px;
  align-items: start;
}

@media (min-width: 901px) {
  .landing-about {
    grid-template-columns: 240px 1fr;
    align-items: center;
  }
}

.landing-about-name {
  font-weight: 700;
  color: rgba(255, 255, 255, 0.9);
}

.landing-author-photo {
  margin: 0;
  max-width: 240px;
}

.online-title {
  margin: 0 0 10px;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

/* How to Play accordion */
.online-panel details > summary {
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

.online-panel details[open] > summary {
  margin-bottom: 6px;
}

.online-fields {
  display: grid;
  gap: 10px;
}

.online-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 10px;
  align-items: center;
}

.online-input-with-action {
  display: flex;
  gap: 8px;
  align-items: center;
}

.online-copy-button {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.9);
  cursor: pointer;
}

.online-copy-button:hover {
  border-color: #0ec3c9;
  color: #0ec3c9;
}

.online-copy-button:disabled {
  cursor: not-allowed;
  border-color: rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.3);
}

.online-label {
  color: rgba(255, 255, 255, 0.8);
  font-size: 0.95rem;
}

.online-input,
.online-select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 2px solid rgba(255, 255, 255, 0.18);
  color: rgba(255, 255, 255, 0.9);
  outline: none;
}

@media (pointer: coarse) {
  .online-input,
  .online-select {
    font-size: 16px;
  }
}

.online-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.online-input:focus,
.online-select:focus {
  border-color: #0ec3c9;
}

.online-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.online-actions .button {
  width: auto;
  flex: 1 1 0;
  margin-top: 0;
}

.online-status {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
  color: rgba(255, 255, 255, 0.75);
}

/* Turnstile widget: scale down to fit narrow panels */
.turnstile-wrap {
  overflow: hidden;
}

.turnstile-scale {
  transform-origin: 0 0;
}

.author-photo {
  width: 100%;
  max-width: 240px;
  height: auto;
  display: block;
  margin: 0 auto 12px;
  border-radius: 12px;
}

.online-hint {
  color: rgba(255, 255, 255, 0.65);
  font-size: 0.9rem;
}

.online-status-key {
  display: inline-block;
  min-width: 88px;
  color: rgba(255, 255, 255, 0.55);
}

.online-status-value {
  color: rgba(255, 255, 255, 0.9);
}

.online-notice {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.18);
  border: 2px solid rgba(255, 255, 255, 0.12);
  color: rgba(255, 255, 255, 0.9);
}

.online-notice--disconnect {
  border-color: rgba(255, 120, 120, 0.7);
  color: rgba(255, 120, 120, 0.95);
  font-size: 0.85rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.online-notice--reconnect {
  border-color: rgba(120, 255, 180, 0.65);
  color: rgba(120, 255, 180, 0.95);
  font-size: 0.85rem;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.online-error {
  color: rgba(255, 120, 120, 0.9);
}

/* Saved online games list */

.saved-games-list {
  gap: 8px;
}

.saved-game-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.saved-game-row:last-child {
  border-bottom: 0;
}

.saved-game-field {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
}

.saved-game-field .online-status-key {
  min-width: auto;
}

.saved-game-field-server {
  flex: 1 1 220px;
  min-width: 220px;
}

.saved-game-field-server .online-status-value {
  overflow-wrap: anywhere;
}

.saved-game-actions {
  margin-left: auto;
}
