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

:root {
  --font: 'Fredoka', system-ui, sans-serif;
  --panel: #142f2b;
  --card: #1b3a35;
  --tile: #224741;
  --text: #eefcf6;
  --muted: #8fbcb0;
  --ink-on-accent: #0e2f2a;
  --mint-grad: linear-gradient(135deg, #4ceac0, #1fc39e);
  --coral-grad: linear-gradient(135deg, #ff85a3, #ff4f7d);
  --amber-grad: linear-gradient(135deg, #ffd97a, #ffb84d);
  --shadow-soft: 0 14px 34px rgba(4, 24, 20, 0.45);
  --shadow-small: 0 6px 14px rgba(4, 24, 20, 0.35);
}

body {
  font-family: var(--font);
  color: var(--text);
  overflow: hidden;
  /* prevents the stuck gray text-selection overlay when clicking UI fast */
  user-select: none;
  -webkit-user-select: none;
}

#app { position: relative; height: 100vh; }

/* ---------- full-bleed 3D viewport ---------- */
#viewport { position: absolute; inset: 0; }
#canvas { width: 100%; height: 100%; display: block; cursor: grab; }

/* rotate hint pill, above the garage tray */
#rotate-hint {
  position: absolute;
  bottom: 100px;
  left: 50%;
  margin-left: 84px; /* centered in the free space right of the panel */
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: rgba(10, 35, 30, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.3px;
  pointer-events: none;
  transition: opacity 0.6s ease;
  animation: hintPulse 2.4s ease-in-out infinite;
}
#rotate-hint.hidden { opacity: 0; }
@keyframes hintPulse {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-4px); }
}

/* ---------- loading screen ---------- */
#loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 30px;
  background: linear-gradient(135deg, #17a08f, #45c29e 55%, #f0c979);
  transition: opacity 0.5s ease, visibility 0.5s;
}
#loading.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
#loading.hidden .load-logo { transform: scale(1.15); }

.load-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transition: transform 0.5s ease;
}

.load-wheel {
  width: 112px;
  height: 112px;
  animation: wheelSpin 1.3s linear infinite;
  filter: drop-shadow(0 12px 22px rgba(8, 40, 34, 0.45));
}
@keyframes wheelSpin { to { transform: rotate(360deg); } }

.load-title { display: flex; }
.load-title span {
  font-size: 44px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 1px;
  text-shadow: 0 6px 18px rgba(8, 40, 34, 0.5);
  animation: letterBounce 1.2s ease-in-out infinite;
  animation-delay: calc(var(--i) * 0.07s);
}
.load-title .sp { width: 16px; }
@keyframes letterBounce {
  0%, 55%, 100% { transform: translateY(0); }
  25% { transform: translateY(-12px); }
  40% { transform: translateY(3px); }
}

.load-bar {
  width: 250px;
  height: 16px;
  border-radius: 999px;
  background: rgba(10, 40, 35, 0.45);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}
.load-bar-fill {
  position: relative;
  height: 100%;
  width: 8%;
  border-radius: 999px;
  background: var(--amber-grad);
  transition: width 0.25s ease;
  overflow: hidden;
}
.load-bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  animation: shine 1.1s linear infinite;
}
@keyframes shine {
  from { transform: translateX(-100%); }
  to { transform: translateX(100%); }
}

.load-tip {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 3px 10px rgba(8, 40, 34, 0.5);
}

/* ---------- side panel ---------- */
#panel {
  position: absolute;
  left: 22px;
  top: 22px;
  bottom: 22px;
  width: 320px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  border-radius: 26px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

#panel header {
  position: relative;
  padding: 20px 22px 16px;
  background: var(--mint-grad);
}
#panel h1 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ink-on-accent);
}
.tagline {
  font-size: 13px;
  font-weight: 600;
  color: #b07d18;
  margin-top: 2px;
}

.footer-reset {
  flex: 0 0 46px;
  height: 46px;
  align-self: center;
  font-size: 18px;
  color: var(--text);
  border: none;
  border-radius: 50%;
  background: var(--tile);
  box-shadow: var(--shadow-small);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.footer-reset:hover { transform: translateY(-2px); }
.footer-reset:active { transform: translateY(1px); }

/* ---------- bike nickname ---------- */
#nickname-box { padding: 16px 16px 0; }
#nickname-box label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
}
#bike-name {
  width: 100%;
  margin-top: 7px;
  padding: 11px 14px;
  border: none;
  border-radius: 12px;
  background: #0e2a26;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
  transition: box-shadow 0.15s ease;
}
#bike-name:focus { box-shadow: 0 0 0 2px #35e0b8; }
#bike-name::placeholder { color: rgba(143, 188, 176, 0.55); }

#controls {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
}
#controls::-webkit-scrollbar { width: 8px; }
#controls::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
}

/* ---------- part tile grid ---------- */
.part-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 11px;
  margin-bottom: 18px;
}

.part-tile {
  position: relative;
  aspect-ratio: 1;
  border: none;
  border-radius: 18px;
  background: var(--tile);
  box-shadow: var(--shadow-small);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: var(--font);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.part-tile:hover { transform: translateY(-3px); }
.part-tile:active { transform: translateY(1px); }
.part-tile.active {
  background: var(--coral-grad);
  box-shadow: 0 10px 24px rgba(255, 79, 125, 0.45);
  transform: translateY(-3px);
}
.part-tile.active .tile-name { color: #fff; }
.part-tile.off { opacity: 0.45; }

.tile-icon { font-size: 22px; line-height: 1; }
.tile-name {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--muted);
}
.tile-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
}

/* ---------- detail card for the selected part ---------- */
.detail-card {
  background: var(--card);
  border-radius: 20px;
  box-shadow: var(--shadow-small);
  padding: 16px 18px 18px;
  animation: pop 0.18s ease;
}
@keyframes pop {
  from { transform: scale(0.96); opacity: 0.3; }
  to { transform: scale(1); opacity: 1; }
}

.detail-card h2 {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin: 14px 0 8px;
}

.swatches { display: flex; flex-wrap: wrap; gap: 10px; }

.swatch {
  width: 42px;
  height: 36px;
  border: none;
  border-radius: 12px;
  box-shadow: 0 4px 10px rgba(4, 24, 20, 0.35);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.swatch:hover { transform: translateY(-2px); }
.swatch.active {
  box-shadow: 0 0 0 2.5px #fff, 0 6px 16px rgba(4, 24, 20, 0.4);
  transform: translateY(-2px);
}

/* ---------- unlocks section ---------- */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--muted);
  margin: 18px 4px 10px;
}

.unlock-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  padding-bottom: 10px;
}

.unlock-tile {
  position: relative;
  aspect-ratio: 1;
  border: none;
  border-radius: 16px;
  background: var(--tile);
  box-shadow: var(--shadow-small);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-family: var(--font);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.unlock-tile:hover { transform: translateY(-2px); }
.unlock-tile .tile-name { color: var(--muted); }

.unlock-tile.locked {
  background: rgba(12, 36, 32, 0.85);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: default;
}
.unlock-tile.locked:hover { transform: none; }
.unlock-tile.locked .tile-icon { opacity: 0.25; }
.unlock-lock {
  position: absolute;
  bottom: 6px;
  right: 7px;
  font-size: 11px;
  opacity: 0.7;
}

/* toggle switch */
.toggle {
  position: relative;
  width: 48px;
  height: 26px;
  border-radius: 999px;
  background: #0e2a26;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: left 0.2s ease;
}
.toggle.on { background: var(--mint-grad); }
.toggle.on::after { left: 24px; }

/* ---------- right-side tools ---------- */
#side-tools {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: calc(100vh - 44px);
}

.view-modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.mode-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  padding: 11px 6px;
  border: none;
  border-radius: 12px;
  background: var(--tile);
  box-shadow: 0 3px 8px rgba(4, 24, 20, 0.3);
  cursor: pointer;
  transition: transform 0.1s ease;
}
.mode-btn:hover { transform: translateY(-1px); }
.mode-btn:active { transform: translateY(1px); }
.mode-btn.active {
  background: var(--mint-grad);
  color: var(--ink-on-accent);
  box-shadow: 0 6px 14px rgba(46, 215, 171, 0.4);
}

.tool-panel {
  width: 260px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  padding: 16px 18px 18px;
  border-radius: 20px;
  background: rgba(16, 43, 38, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: var(--shadow-soft);
  animation: pop 0.18s ease;
}
.tool-panel::-webkit-scrollbar { width: 6px; }
.tool-panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.14);
  border-radius: 99px;
}
.tool-panel.hidden { display: none; }

.tool-panel h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

/* ---------- scene grid ---------- */
.scene-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.scene-btn {
  position: relative;
  height: 58px;
  border: none;
  border-radius: 14px;
  box-shadow: var(--shadow-small);
  cursor: pointer;
  overflow: hidden;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.scene-btn:hover { transform: translateY(-2px); }
.scene-btn.active {
  box-shadow: 0 0 0 2.5px #fff, var(--shadow-small);
}
.scene-btn span {
  position: absolute;
  left: 8px;
  bottom: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.55);
}

/* ---------- garage (saved builds tray) ---------- */
#garage {
  position: absolute;
  bottom: 20px;
  left: 50%;
  margin-left: 84px; /* centered in the free space right of the panel */
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: stretch;
  gap: 10px;
  max-width: min(58vw, 760px);
}
#garage-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  /* room for card shadows so the scroll container doesn't clip them into
     visible square corners */
  padding: 4px 4px 8px;
}
#garage-list::-webkit-scrollbar { height: 6px; }
#garage-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 99px;
}

.garage-card {
  position: relative;
  flex-shrink: 0;
  min-width: 118px;
  padding: 10px 14px;
  /* no outer shadows here: the scrolling tray clips them into visible
     squares. Active state is a border, which can never clip. */
  border: 2px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: #14322e;
  color: var(--text);
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.garage-card:hover { transform: translateY(-2px); }
.garage-card.active { border-color: #35e0b8; }
.garage-name {
  font-size: 12.5px;
  font-weight: 700;
  max-width: 130px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.garage-dots { display: flex; gap: 4px; }
.garage-dots i {
  display: block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.garage-del {
  position: absolute;
  top: 4px;
  right: 8px;
  font-size: 10px;
  color: var(--muted);
}
.garage-del:hover { color: #ff6b8d; }

#garage-new {
  flex-shrink: 0;
  min-width: 76px;
  border: none;
  border-radius: 14px;
  background: var(--mint-grad);
  color: var(--ink-on-accent);
  font-family: var(--font);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(46, 215, 171, 0.35);
  transition: transform 0.1s ease;
}
#garage-new:hover { transform: translateY(-2px); }
#garage-new:active { transform: translateY(1px); }

/* ---------- footer ---------- */
#panel footer {
  padding: 14px 16px 18px;
  display: flex;
  gap: 12px;
}

.big-btn {
  flex: 1;
  font-family: var(--font);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 0.3px;
  white-space: nowrap;
  color: var(--muted);
  padding: 13px 8px;
  border: none;
  border-radius: 999px;
  background: var(--tile);
  box-shadow: var(--shadow-small);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(1px); }
.big-btn.active {
  background: var(--mint-grad);
  color: var(--ink-on-accent);
  box-shadow: 0 10px 22px rgba(46, 215, 171, 0.4);
}
#btn-random {
  background: var(--amber-grad);
  color: var(--ink-on-accent);
  box-shadow: 0 10px 22px rgba(255, 184, 77, 0.4);
}

/* ===========================================================================
   Mobile portrait layout: 3D view on top, editor as a bottom sheet,
   garage chips top-left, scene dots top-right. Dev/camera tools hidden.
   =========================================================================== */
@media (max-width: 700px) {
  /* editor panel -> bottom sheet */
  #panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    height: 40vh;
    border: none;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 18px 18px 0 0;
  }
  /* no header bar on mobile — every pixel goes to the editor */
  #panel header { display: none; }

  #nickname-box { padding: 10px 12px 0; }
  #nickname-box label { display: none; }
  #bike-name { margin-top: 0; padding: 7px 11px; font-size: 12px; border-radius: 10px; }

  #controls { padding: 10px 10px 4px; }

  /* part tiles -> one horizontally scrollable row */
  .part-grid {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    margin-bottom: 12px;
    padding: 2px 2px 6px;
  }
  .part-grid::-webkit-scrollbar { height: 5px; }
  .part-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.14);
    border-radius: 99px;
  }
  .part-tile {
    flex: 0 0 46px;
    height: 46px;
    aspect-ratio: auto;
    border-radius: 12px;
    gap: 0;
  }
  .tile-icon { font-size: 19px; }
  .tile-name { display: none; }
  .tile-dot { top: 5px; right: 5px; width: 7px; height: 7px; }

  .detail-card { padding: 10px 12px 12px; border-radius: 14px; }
  .detail-card h2 { font-size: 14px; }
  .detail-label { margin: 8px 0 6px; font-size: 10px; }
  .swatch { width: 32px; height: 27px; border-radius: 9px; }

  .section-label { margin: 10px 2px 6px; font-size: 10px; }
  .unlock-grid { grid-template-columns: repeat(8, 1fr); gap: 6px; }
  .unlock-tile { border-radius: 10px; }
  .unlock-lock { font-size: 9px; bottom: 3px; right: 4px; }

  #panel footer { padding: 8px 10px 10px; gap: 8px; }
  .big-btn { padding: 8px 6px; font-size: 12px; }
  .footer-reset { flex: 0 0 34px; height: 34px; font-size: 14px; }

  /* right tools -> scene dots only, top right */
  #side-tools { top: 12px; right: 12px; max-height: none; }
  #view-panel { display: none; }
  #scene-panel {
    width: auto;
    max-height: none;
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    overflow: visible;
  }
  #scene-panel h3 { display: none; }
  .scene-grid { display: flex; gap: 8px; }
  .scene-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  }
  .scene-btn span { display: none; }
  .scene-btn.active {
    box-shadow: 0 0 0 2px #fff, 0 2px 6px rgba(0, 0, 0, 0.35);
  }

  /* garage -> compact chips, top left (clear of the scene dots) */
  #garage {
    top: 12px;
    bottom: auto;
    left: 12px;
    right: 178px;
    margin: 0;
    transform: none;
    max-width: none;
  }
  #garage-list { padding: 2px; }
  .garage-card { min-width: 86px; padding: 7px 10px; gap: 4px; }
  .garage-name { font-size: 11px; max-width: 86px; }
  .garage-dots i { width: 8px; height: 8px; }
  #garage-new { min-width: 52px; font-size: 12px; border-radius: 12px; }

  /* hint sits just above the bottom sheet */
  #rotate-hint {
    bottom: calc(40vh + 12px);
    margin-left: 0;
    font-size: 11px;
    padding: 6px 12px;
  }
}
