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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#renderCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

/* ---- HUD ---- */
#hud {
  position: fixed;
  top: 14px;
  left: 16px;
  z-index: 5;
  pointer-events: none;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
}
#title {
  font-size: 20px;
  font-weight: bold;
}
#status {
  font-size: 15px;
  margin-top: 4px;
  opacity: 0.9;
}

#timer {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  color: #fff;
  font-size: 40px;
  font-weight: bold;
  text-shadow: 0 3px 6px rgba(0, 0, 0, 0.7);
}

#toast {
  position: fixed;
  top: 30%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 6;
  pointer-events: none;
  color: #fff;
  font-size: 38px;
  font-weight: bold;
  text-shadow: 0 3px 8px rgba(0, 0, 0, 0.85);
  opacity: 0;
  transition: opacity 0.35s ease;
}
#toast.show {
  opacity: 1;
}

/* ---- left-side menu buttons ---- */
#side-buttons {
  position: fixed;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 35;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
#side-buttons button {
  font-family: inherit;
  font-size: 17px;
  font-weight: bold;
  color: #fff;
  background: rgba(27, 63, 140, 0.85);
  border: 3px solid #ffd166;
  border-radius: 14px;
  padding: 14px 18px;
  width: 140px;
  cursor: pointer;
}
#side-buttons button:active {
  transform: scale(0.96);
}

/* ---- shared panel styling (avatars + best times) ---- */
.panel,
#player-picker,
#finish-screen {
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.62);
}
.panel {
  display: none;
  z-index: 40;
}
#player-picker {
  display: flex;
  z-index: 50;
}
#finish-screen {
  display: none;
  z-index: 30;
}

.panel-card,
.picker-card,
.finish-card {
  background: linear-gradient(160deg, #2d6cdf, #1b3f8c);
  border: 4px solid #ffd166;
  border-radius: 22px;
  color: #fff;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
}

/* ---- panels ---- */
.panel-card {
  width: 460px;
  max-width: 92vw;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 26px;
  font-weight: bold;
  color: #ffd166;
  padding: 18px 22px;
}
.panel-close {
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  color: #1b3f8c;
  background: #ffd166;
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
}
.panel-body {
  padding: 0 22px 22px;
  overflow-y: auto;
}
.panel-sub {
  font-size: 16px;
  font-weight: bold;
  opacity: 0.8;
  margin: 14px 0 8px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---- avatars gallery ---- */
#avatars-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.av-card {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px 6px 8px;
  text-align: center;
}
.av-name {
  margin-top: 6px;
  font-weight: bold;
  font-size: 15px;
}

/* ---- the little CSS avatar figure ---- */
.fig {
  width: 48px;
  height: 86px;
  position: relative;
  margin: 0 auto;
}
.fig-head {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  position: absolute;
  left: 9px;
  top: 4px;
}
.fig-hair {
  position: absolute;
  left: -3px;
  top: -5px;
  width: 36px;
  height: 17px;
  border-radius: 18px 18px 0 0;
}
.fig-body {
  position: absolute;
  left: 8px;
  top: 32px;
  width: 32px;
  height: 32px;
  border-radius: 11px;
}
.fig-legs {
  position: absolute;
  left: 8px;
  top: 62px;
  width: 32px;
  display: flex;
  justify-content: space-between;
}
.fig-leg {
  width: 13px;
  height: 22px;
  border-radius: 0 0 5px 5px;
}
.fig-beak {
  position: absolute;
  right: -7px;
  top: 11px;
  width: 11px;
  height: 8px;
  border-radius: 2px 3px 3px 2px;
}
.fig-stripes {
  background: repeating-linear-gradient(
    180deg,
    #d62b2b 0 6px,
    #ffffff 6px 12px,
    #1d3fb8 12px 18px
  );
}

/* ---- best times rows ---- */
.time-row {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: bold;
  padding: 9px 12px;
  border-radius: 9px;
}
.time-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.1);
}
.time-empty {
  font-size: 16px;
  opacity: 0.8;
  padding: 10px 12px;
}

/* ---- player picker ---- */
.picker-card {
  padding: 26px 30px 30px;
  text-align: center;
}
.picker-title {
  font-size: 30px;
  font-weight: bold;
  color: #ffd166;
  margin-bottom: 18px;
}
.picker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.pick-btn {
  font-family: inherit;
  background: rgba(255, 255, 255, 0.12);
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-radius: 16px;
  padding: 14px 8px 10px;
  cursor: pointer;
  color: #fff;
}
.pick-btn:active {
  transform: scale(0.96);
}
.pick-btn span {
  display: block;
  margin-top: 6px;
  font-weight: bold;
  font-size: 16px;
}

/* ---- finish screen ---- */
.finish-card {
  padding: 40px 56px;
  text-align: center;
}
.finish-title {
  font-size: 56px;
  font-weight: bold;
  color: #ffd166;
}
.finish-sub {
  font-size: 18px;
  margin-top: 10px;
  opacity: 0.85;
}
#finish-time {
  font-size: 64px;
  font-weight: bold;
  margin: 4px 0 4px;
}
#finish-note {
  font-size: 20px;
  font-weight: bold;
  color: #8effa6;
  min-height: 26px;
  margin-bottom: 16px;
}
#play-again {
  font-family: inherit;
  font-size: 26px;
  font-weight: bold;
  color: #1b3f8c;
  background: #ffd166;
  border: none;
  border-radius: 14px;
  padding: 16px 40px;
  cursor: pointer;
}
#play-again:active {
  transform: scale(0.96);
}

/* ---- touch controls ---- */
#touch-joystick {
  position: fixed;
  left: 28px;
  bottom: 28px;
  z-index: 10;
  width: 130px;
  height: 130px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  border: 3px solid rgba(255, 255, 255, 0.4);
  touch-action: none;
}
#joystick-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.7);
  transform: translate(-50%, -50%);
}
#jump-button {
  position: fixed;
  right: 32px;
  bottom: 36px;
  z-index: 10;
  width: 116px;
  height: 116px;
  border-radius: 50%;
  background: rgba(255, 209, 102, 0.55);
  border: 3px solid rgba(255, 255, 255, 0.55);
  color: #fff;
  font-weight: bold;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#jump-button:active {
  background: rgba(255, 209, 102, 0.9);
}
