html, body {
  margin: 0;
  padding: 0;
  background: #000;
  color: #fff;
  font-family: "Courier New", Courier, monospace;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Stage keeps the canvas centered and pixel-crisp */
#stage {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

canvas {
  display: block;
  /* Portrait: fill the width, keep aspect ratio. */
  width: 100vw;
  max-width: 100vw;
  height: auto;
  /* Never let the picture get so tall the controls are pushed off-screen. */
  max-height: 62dvh;
  background: #000;
  image-rendering: -moz-crisp-edges;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#controls {
  flex: 0 0 auto;
  width: 100%;
  max-width: 640px;
  padding: 10px 14px calc(16px + env(safe-area-inset-bottom));
  box-sizing: border-box;
}

/* ---------------------------------------------------------------
   LANDSCAPE / WIDESCREEN
   Turn the phone sideways: canvas on the left, controls on the
   right, both using the full height of the screen.
   --------------------------------------------------------------- */
@media (orientation: landscape) {
  main {
    flex-direction: row;
    align-items: stretch;
    height: 100dvh;
  }

  #stage {
    height: 100dvh;
    padding-left: env(safe-area-inset-left);
  }

  canvas {
    /* Fit within both the available height and width, aspect-preserved. */
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100dvh;
  }

  #controls {
    width: 280px;
    max-width: 44vw;
    align-self: center;
    max-height: 100dvh;
    overflow-y: auto;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom)) 10px;
    padding-right: calc(14px + env(safe-area-inset-right));
  }

  /* Tighten spacing so everything fits the shorter landscape height. */
  #status { padding: 2px 0 6px; font-size: 16px; }
  label { margin: 8px 0; }
  #wind { padding: 2px 0 8px; }
  #throwButton { padding: 16px; font-size: 20px; }
  #newRoundButton { margin-top: 14px; padding: 8px 18px; font-size: 12px; }
  #newRoundButton.is-primary { padding: 12px 20px; font-size: 16px; }
  #shareButton { padding: 8px 18px; font-size: 12px; }
  #shareButton.is-primary { padding: 14px; font-size: 18px; }
}

#status {
  text-align: center;
  font-weight: bold;
  font-size: 18px;
  letter-spacing: 1px;
  padding: 6px 0 10px;
  min-height: 22px;
  color: #FFFF55;
}

label {
  display: grid;
  grid-template-columns: 68px 1fr 52px;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.lbl {
  font-size: 14px;
  letter-spacing: 1px;
}

.val {
  font-size: 16px;
  text-align: right;
  color: #55FFFF;
}

input[type="range"] {
  width: 100%;
  height: 34px;
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 8px;
  background: #555;
  border: 1px solid #C0C0C0;
}

input[type="range"]::-moz-range-track {
  height: 8px;
  background: #555;
  border: 1px solid #C0C0C0;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -10px;
  background: #FFFF55;
  border: 2px solid #fff;
  border-radius: 0;
  cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
  width: 26px;
  height: 26px;
  background: #FFFF55;
  border: 2px solid #fff;
  border-radius: 0;
  cursor: pointer;
}

#wind {
  text-align: center;
  font-size: 15px;
  padding: 4px 0 10px;
  color: #C0C0C0;
  letter-spacing: 1px;
}

/* Stack the buttons and separate them so NEW ROUND can't be hit by
   accident while aiming. */
.btnrow {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

button {
  font-family: "Courier New", Courier, monospace;
  font-weight: bold;
  letter-spacing: 1px;
  cursor: pointer;
}

/* THROW — the primary action: big, bright, unmissable. */
#throwButton {
  order: 1;
  width: 100%;
  padding: 22px;
  font-size: 24px;
  background: #FFFF55;
  color: #000;
  border: 3px solid #fff;
}

#throwButton:active {
  background: #55FF55;
}

/* SHARE — secondary by default (title "invite"), primary at match end.
   Green accent so it reads as the celebratory "spread the word" action. */
#shareButton {
  order: 1;
  align-self: center;
  width: auto;
  min-width: 160px;
  padding: 10px 22px;
  font-size: 14px;
  background: #12351a;
  color: #8fdc9f;
  border: 2px solid #2f6b3f;
}

#shareButton.is-primary {
  width: 100%;
  align-self: stretch;
  padding: 22px;
  font-size: 22px;
  background: #55FF55;
  color: #000;
  border: 3px solid #fff;
}

#shareButton:active {
  background: #2f6b3f;
}

#shareButton.is-primary:active {
  background: #33cc55;
}

/* Utility */
.hidden {
  display: none !important;
}

/* NEW ROUND — secondary: smaller, muted, and pushed well clear of THROW. */
#newRoundButton {
  order: 2;
  align-self: center;
  width: auto;
  min-width: 160px;
  margin-top: 22px;
  padding: 9px 22px;
  font-size: 13px;
  background: #161616;
  color: #8a8a8a;
  border: 2px solid #444;
}

#newRoundButton:active {
  background: #333;
}

/* When the round is over (or on the title screen) NEW ROUND becomes the
   action to take, so light it up like the primary button. */
#newRoundButton.is-primary {
  background: #FFFF55;
  color: #000;
  border-color: #fff;
  font-size: 18px;
  padding: 16px 22px;
  min-width: 220px;
}

button:disabled {
  opacity: 0.4;
  cursor: default;
}

/* Keyboard hint — only shown on devices with a real pointer/keyboard. */
#kbhint {
  display: none;
  margin-top: 14px;
  text-align: center;
  font-size: 12px;
  letter-spacing: 1px;
  color: #7a7a7a;
}

@media (hover: hover) and (pointer: fine) {
  #kbhint { display: block; }
}

/* Toast for the desktop "link copied" fallback */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  max-width: 88vw;
  padding: 12px 18px;
  background: #FFFF55;
  color: #000;
  font-family: "Courier New", Courier, monospace;
  font-weight: bold;
  font-size: 14px;
  border: 2px solid #000;
  border-radius: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
