/* Mobu Race — cozy farm-game UI */

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #87c46b;
  font-family: 'Reddit Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-weight: 800;
  color: #5a3a1a;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* UI root sits above the canvas (canvas z-index 0) */
#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}

.panel, .overlay, button, input, textarea, select, ul, ol {
  pointer-events: auto;
}

/* ---------- Panels ---------- */
.panel {
  background: rgba(255, 246, 224, 0.95);
  border: 3px solid #8a5a2b;
  border-radius: 16px;
  box-shadow: 0 6px 0 rgba(90, 58, 26, 0.25), 0 10px 24px rgba(0, 0, 0, 0.25);
  padding: 14px 16px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.panel.small { padding: 8px 12px; font-size: 14px; border-radius: 14px; }

.panel h3 {
  font-size: 15px;
  color: #8a5a2b;
  margin-bottom: 6px;
  letter-spacing: 0.5px;
}

/* ---------- Overlays (centered) ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  pointer-events: none;
  z-index: 20;
}

.overlay.panel {
  position: relative;
  inset: auto;
  width: min(420px, 88vw);
  background: #fff6e0;
  pointer-events: auto;
}

/* The join card is the screen's welcome: pin it to the exact center
   (.overlay.panel otherwise places it in normal flow, top-left). */
#join.overlay.panel {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.overlay.big {
  pointer-events: none;
}

/* ---------- Buttons ---------- */
button {
  font-family: inherit;
  font-weight: 800;
  font-size: 16px;
  color: #fff;
  background: #58b24a;
  border: none;
  border-bottom: 4px solid #3d7d33;
  border-radius: 14px;
  padding: 10px 18px;
  cursor: pointer;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  transition: transform 0.08s ease, filter 0.12s ease;
}

button:hover { filter: brightness(1.08); transform: translateY(-2px); }
button:active { transform: translateY(2px); border-bottom-width: 2px; }

.btn-green { width: 100%; }

.btn-secondary {
  background: #e8b64c;
  border-bottom-color: #b07d1e;
}

/* ---------- Inputs ---------- */
input, textarea, select {
  font-family: inherit;
  font-weight: 700;
  font-size: 16px;
  color: #5a3a1a;
  background: #fffdf5;
  border: 3px solid #d9b98a;
  border-radius: 12px;
  padding: 10px 12px;
  width: 100%;
  outline: none;
}

input:focus, textarea:focus, select:focus { border-color: #58b24a; }

textarea { resize: vertical; min-height: 110px; }

label, .field-label {
  display: block;
  font-size: 14px;
  color: #8a5a2b;
  margin: 10px 0 4px;
}

/* ---------- Join screen ---------- */
#join h1 {
  font-size: 44px;
  color: #ffc93c;
  text-shadow:
    0 3px 0 #8a5a2b,
    0 6px 12px rgba(0, 0, 0, 0.3);
  letter-spacing: 2px;
  text-align: center;
}

.logo-mascot {
  display: inline-block;
  width: 1.15em;
  height: 1.25em;
  object-fit: contain;
  vertical-align: -0.22em;
  margin-left: 0.06em;
}

#subtitle {
  color: #8a5a2b;
  font-size: 16px;
  margin-top: -6px;
  text-align: center;
}

/* ---------- Topbar ---------- */
#topbar {
  position: fixed;
  top: 12px;
  left: 12px;
  max-width: 46vw;
}

#roleBadge { font-size: 15px; }

/* ---------- User panel ---------- */
#userPanel {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 230px;
  max-height: 60vh;
  overflow-y: auto;
}

#userList { list-style: none; }

#userList li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#userList li .make-host {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 9px;
  border-bottom-width: 3px;
  margin-left: auto;
  flex-shrink: 0;
}

#setupPanel { margin-top: 10px; border-top: 2px dashed #d9b98a; padding-top: 10px; }

#createBtn { margin-top: 10px; }

/* numbered-racer quick generator row: the count and Generate button stay on one line. */
.quick-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: 0;
}

/* Reddit Sans has tall font metrics, so Chrome gives the number input a
   ~40px natural height; both controls get that same explicit height. */
.quick-row input,
.quick-row button {
  box-sizing: border-box;
  height: 40px;
  margin: 0;
  padding: 0 10px;
}

.quick-row input {
  flex: 1;
  width: auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  border-radius: 10px;
  border-width: 2px;
  appearance: textfield;
  -moz-appearance: textfield;
}

.quick-row input::-webkit-outer-spin-button,
.quick-row input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.quick-row button {
  flex: 0 0 auto;
  width: auto;
  padding: 0 13px;
  font-size: 14px;
  white-space: nowrap;
  border-radius: 10px;
  border-bottom-width: 2px;
  text-shadow: none;
}

/* keep the Generate button flush with the input, even under the cursor */
.quick-row button:hover,
.quick-row button:active {
  transform: none;
}

#readyPanel {
  margin-top: 10px;
  border-top: 2px dashed #d9b98a;
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#readyPanel p { font-size: 13px; color: #8a5a2b; }

#readyWaiting { margin-top: 10px; border-top: 2px dashed #d9b98a; padding-top: 10px; }

#readyWaiting p { font-size: 13px; color: #8a5a2b; }

#waitingPanel p { font-size: 13px; color: #8a5a2b; margin-top: 8px; }

/* ---------- Camera panel ---------- */
#camPanel {
  position: fixed;
  right: 12px;
  bottom: 12px;
  text-align: center;
}

.cam-row { display: flex; gap: 6px; margin-top: 6px; }

.cam-btn {
  flex: 1;
  font-size: 13px;
  padding: 8px 6px;
  border-radius: 10px;
  background: #e8b64c;
  border-bottom-color: #b07d1e;
}

.cam-btn.active {
  background: #58b24a;
  border-bottom-color: #3d7d33;
}

.hint { font-size: 11px; color: #a07840; margin-top: 6px; }

/* ---------- Race HUD ---------- */
#timer {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 34px;
  color: #8a5a2b;
  min-width: 130px;
  text-align: center;
  padding: 6px 20px;
}

#leaderboard {
  position: fixed;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  min-width: 170px;
}

#lbList {
  list-style: none;
}

#lbList li {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 3px 6px;
  border-radius: 8px;
  /* gold :first-child highlight eases off/on as rows slide past each other */
  transition: background-color 0.35s ease;
}

/* First place gets gold */
#lbList li:first-child {
  background: #ffe9a8;
  border: 2px solid #e8b64c;
  font-size: 14px;
}

/* ---------- Countdown ---------- */
#countdown {
  font-size: 22vmin;
  color: #ffc93c;
  font-weight: 800;
  text-shadow:
    -4px -4px 0 #8a5a2b, 4px -4px 0 #8a5a2b,
    -4px 4px 0 #8a5a2b, 4px 4px 0 #8a5a2b,
    0 10px 24px rgba(0, 0, 0, 0.4);
}

/* ---------- Winner celebration ---------- */
#confetti {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

#congratsBox {
  position: relative;
  text-align: center;
}

#congratsTitle {
  font-size: clamp(40px, 9vmin, 96px);
  color: #ffc93c;
  letter-spacing: 4px;
  text-shadow:
    -4px -4px 0 #8a5a2b, 4px -4px 0 #8a5a2b,
    -4px 4px 0 #8a5a2b, 4px 4px 0 #8a5a2b,
    0 12px 28px rgba(0, 0, 0, 0.4);
}

#congratsName {
  margin-top: 12px;
  font-size: clamp(26px, 6vmin, 60px);
  color: #fff6e0;
  text-shadow:
    0 4px 0 #8a5a2b,
    0 8px 22px rgba(0, 0, 0, 0.35);
}

.btn-back {
  width: auto;
  margin-top: 10px;
  font-size: 17px;
  padding: 12px 26px;
}

#resultWaiting {
  color: #8a5a2b;
  font-size: 15px;
  background: rgba(255, 246, 224, 0.9);
  padding: 6px 14px;
  border-radius: 12px;
  border: 2px solid #d9b98a;
}

/* ---------- Narrow screens ---------- */
@media (max-width: 640px) {
  #join h1 { font-size: 34px; }

  #userPanel {
    width: 170px;
    /* Keep the setup controls above the camera panel on short viewports. */
    max-height: calc(100vh - 156px);
    font-size: 13px;
  }

  #topbar { max-width: 50vw; font-size: 13px; }
  #roleBadge { font-size: 13px; }

  #timer { font-size: 24px; min-width: 100px; top: 8px; }

  #leaderboard {
    top: auto;
    bottom: 12px;
    left: 12px;
    transform: none;
    max-width: 45vw;
    max-height: 30vh;
    overflow-y: auto;
  }

  #camPanel { bottom: 12px; }
  #camPanel .cam-row { flex-wrap: wrap; }
  .cam-btn { padding: 6px 4px; font-size: 12px; }
}
