:root {
  color-scheme: light;
}

html,
body {
  margin: 0;
  height: 100%;
  background: #b7b4ff;
  color: #1f2040;
  font-family: 'Trebuchet MS', 'Segoe UI', sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 100vh;
  padding: 0;
  box-sizing: border-box;
  position: relative;
  overflow: hidden;
}

#top-bar {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  --top-bar-horizontal-padding: clamp(16px, 4vw, 28px);
  padding: 18px var(--top-bar-horizontal-padding);
  padding-top: calc(18px + env(safe-area-inset-top, 0px));
  padding-left: calc(
    var(--top-bar-horizontal-padding) + env(safe-area-inset-left, 0px)
  );
  padding-right: calc(
    var(--top-bar-horizontal-padding) + env(safe-area-inset-right, 0px)
  );
  background: rgba(23, 24, 60, 0.92);
  color: #f6f7ff;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  z-index: 15;
}

.top-bar-left {
  display: inline-flex;
  align-items: center;
  gap: 12px;
}

#status {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 600;
  letter-spacing: 0.4px;
}

#play {
  padding: 8px 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 217, 102, 0.85);
  background: rgba(255, 217, 102, 0.9);
  color: #1f2040;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease;
}

#play:disabled {
  opacity: 0.6;
  cursor: default;
  transform: none;
}

#play:not(:disabled):hover {
  background: #f7c948;
  transform: translateY(-1px);
}

#play:not(:disabled):active {
  transform: translateY(0);
}

#run-stats {
  display: inline-flex;
  gap: 16px;
  box-sizing: border-box;
  align-items: center;
  padding: 8px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  font-weight: 600;
  letter-spacing: 0.4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

#run-stats span {
  white-space: nowrap;
}

main {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

canvas {
  display: block;
  background: #b7b4ff;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 0;
  box-shadow: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
}

canvas:focus-visible {
  outline: none;
}

#chat {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 10px 16px;
  box-shadow: 0 16px 32px rgba(31, 32, 64, 0.35);
  align-items: center;
  width: min(480px, 90vw);
  z-index: 15;
}

#chat button,
#chat input {
  font-family: inherit;
}

#say {
  border: none;
  background: #1f2040;
  color: #f6f7ff;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease;
}

#say:hover {
  background: #2d2f6d;
}

#saytext {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(31, 32, 64, 0.25);
  font-size: 15px;
}

.bubble {
  position: absolute;
  background: #fff;
  color: #000;
  padding: 2px 6px;
  border-radius: 8px;
  font-size: 12px;
}

.mobile-controls-column {
  position: fixed;
  bottom: calc(clamp(32px, 5vw, 120px) + env(safe-area-inset-bottom, 0px));
  display: none;
  flex-direction: column;
  gap: 16px;
  z-index: 20;
  user-select: none;
  -webkit-user-select: none;
  -ms-user-select: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
}

#mobile-controls-left {
  left: calc(clamp(32px, 5vw, 64px) + env(safe-area-inset-left, 0px));
}

#mobile-controls-right {
  right: calc(clamp(32px, 5vw, 64px) + env(safe-area-inset-right, 0px));
  flex-direction: row;
  align-items: center;
}

.mobile-control-button {
  width: clamp(64px, 17vw, 80px);
  height: clamp(64px, 17vw, 80px);
  border-radius: 50%;
  border: 3px solid #1f2040;
  background: rgba(255, 255, 255, 0.9);
  color: #1f2040;
  font-size: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  -webkit-touch-callout: none;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.25);
}

.mobile-control-button.active {
  background: #ffd966;
}

@media (pointer: coarse) {
  .mobile-controls-column {
    display: flex;
  }

  #chat {
    bottom: calc(clamp(32px, 5vw, 120px) + clamp(64px, 17vw, 80px) + 32px + env(safe-area-inset-bottom, 0px));
    display: none;
  }

  /* Hide the chat input until a mobile-friendly experience is ready */
  #chat input {
    display: none;
  }

  /* Prevent text selection on mobile to avoid accidental selection when using controls */
  body, main {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none;
  }

  #chat button {
    display: none;
  }
}

#mobile-controls-right .mobile-control-button {
  min-width: clamp(64px, 17vw, 80px);
}

#intro-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(23, 24, 60, 0.58);
  backdrop-filter: blur(8px);
  z-index: 30;
  transition: opacity 0.25s ease;
  padding: 16px;
}

#intro-modal.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.modal-card {
  background: rgba(246, 247, 255, 0.95);
  color: #1f2040;
  padding: 36px;
  border-radius: 28px;
  box-shadow: 0 28px 72px rgba(23, 24, 60, 0.4);
  width: min(420px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 18px;
  text-align: center;
}

.modal-card h1 {
  margin: 0;
  font-size: clamp(32px, 6vw, 46px);
  letter-spacing: 1px;
}

.modal-card p {
  margin: 0;
  font-size: 16px;
  opacity: 0.8;
}

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.modal-actions input {
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(31, 32, 64, 0.25);
  font-size: 16px;
}

.modal-actions button {
  padding: 12px 16px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  border: none;
  cursor: pointer;
}

#intro-submit {
  background: linear-gradient(135deg, #ffd966, #ffb347);
  color: #1f2040;
  box-shadow: 0 12px 24px rgba(255, 179, 71, 0.35);
  transition: transform 0.18s ease;
}

#intro-submit:active {
  transform: translateY(1px);
}

#intro-spectate {
  background: rgba(31, 32, 64, 0.1);
  color: #1f2040;
  border: 1px solid rgba(31, 32, 64, 0.25);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  #top-bar {
    --top-bar-horizontal-padding: clamp(12px, 6vw, 20px);
    flex-direction: column;
    gap: 12px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
    padding-bottom: 12px;
  }

  #run-stats {
    justify-content: center;
    width: 100%;
  }
}
