:root{
  --bg:#f7f2ea;
  --card:#ffffff;
  --line: rgba(0,0,0,.10);
  --accent:#d6b98c;
  --ink:#2b2b2b;
  --muted: rgba(43,43,43,.70);

  /* kimpun juuripiste (desktop) */
  --root-y: 78%;
  --tie-offset: 74px;
}

*{ box-sizing:border-box; }

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
}

/* =========================
   Builder layout (desktop)
   ========================= */
.builder-page{
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
  display:grid;
  grid-template-columns: 1fr 1.12fr;
  gap: 20px;
}
@media (max-width: 900px){
  .builder-page{ grid-template-columns: 1fr; }
}

/* =========================
   Catalog
   ========================= */
.catalog{
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid var(--line);
}
.catalog-head{ display:flex; flex-direction:column; gap:6px; }
.catalog-sub{ font-size: 13.5px; color: var(--muted); }

/* Automaattikimppu */
.auto-card{
  margin-top: 12px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(0,0,0,.08);
  background: linear-gradient(#fff, #faf6ef);
}
.auto-title{ font-weight: 900; margin-bottom: 8px; }
.auto-row{
  display:flex;
  gap: 10px;
  align-items:center;
  flex-wrap: wrap;
}
.auto-label{ font-size: 13px; color: var(--muted); }
.auto-input{
  width: 90px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.92);
  font: inherit;
  font-weight: 700;
}
.auto-btn{
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  cursor: pointer;
  font-weight: 900;
}
.auto-hint{ margin-top: 8px; font-size: 12.5px; color: var(--muted); }

.product-grid{
  margin-top: 16px;
  display:grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}

.product{
  background: linear-gradient(#fff, #f9f5ee);
  border-radius: 14px;
  border: 1px solid var(--line);
  overflow:hidden;
  display:flex;
  flex-direction:column;
}

.product__media{
  height: 140px;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 10px;
  background: rgba(214,185,140,.10);
  border-bottom: 1px solid var(--line);
}
.product__media img{
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
}

.product__body{
  padding: 10px 10px 12px;
  display:flex;
  flex-direction:column;
  gap: 10px;
}
.product__top{
  display:flex;
  justify-content:space-between;
  gap: 10px;
  align-items:baseline;
}
.product__name{ font-weight: 900; font-size: 13px; }
.product__price{ font-size: 13px; color: var(--muted); white-space:nowrap; }

.product__tag{
  display:inline-flex;
  align-items:center;
  gap: 6px;
  font-size: 12px;
  color: rgba(43,43,43,.70);
  background: rgba(255,255,255,.60);
  border: 1px solid rgba(0,0,0,.08);
  border-radius: 999px;
  padding: 6px 10px;
  width: fit-content;
}

.product__controls{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  margin-top: auto;
}
.stepper{ display:flex; align-items:center; gap:8px; }
.stepper button{
  width: 30px; height: 30px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background:#fff;
  cursor:pointer;
  font-size: 18px;
  line-height: 0;
}
.qty{
  width: 18px;
  text-align:center;
  font-weight: 900;
}

/* =========================
   Bouquet
   ========================= */
.bouquet-panel{
  background: var(--card);
  border-radius: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  display:flex;
  flex-direction:column;
}

.bouquet-header{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  gap: 12px;
}
.bouquet-header h2{ margin:0; }
.muted{
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.45;
  max-width: 70ch;
}

.bouquet-total{ text-align:right; }
.bouquet-total span{ font-size: 13px; color: var(--muted); }
.bouquet-total strong{ display:block; font-size: 22px; margin-top: 2px; }

.bouquet-stage-wrapper{
  position: relative;
  margin-top: 14px;
  height: 600px;
  border-radius: 18px;
  border: 1px dashed rgba(0,0,0,.18);
  background: linear-gradient(#fff, #faf6ef);
  overflow:hidden;
}

.bouquet-stage{
  position:absolute;
  inset:0;
}

.bouquet-flower{
  position:absolute;
  left: 50%;
  top: var(--root-y);
  transform-origin: 50% calc(100% - var(--tie-offset));
  pointer-events:none;
  user-select:none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.12));
}

.bouquet-tie{
  position:absolute;
  left:50%;
  top: var(--root-y);
  transform: translate(-50%, calc(-1 * var(--tie-offset)));
  width: 190px;
  height: 44px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 50%, rgba(214,185,140,.70) 0 10px, transparent 11px),
    linear-gradient(180deg, rgba(214,185,140,.65), rgba(214,185,140,.35));
  border: 1px solid rgba(0,0,0,.10);
  opacity: .85;
  z-index: 9999;
}

.bouquet-actions{
  margin-top: 16px;
  display:flex;
  justify-content:flex-end;
  gap: 10px;
  flex-wrap: wrap;
}
.bouquet-actions button{
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  cursor:pointer;
}
.bouquet-actions .primary{
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 900;
}

/* ======================================================
   MOBIILI: korjaukset
   - Nosta kimpun ankkuria -> kukka mahtuu kokonaan
   - Bottom shelf mallistolle -> alaosa näkyy aina
   ====================================================== */
@media (max-width: 900px){

  /* 1) NOSTA kimpun ankkuria mobiilissa */
  :root{
    --root-y: 68%;
    --tie-offset: 62px;
  }

  .builder-page{
    padding: 12px;
    gap: 12px;
  }

  /* 2) Kimpun stage: riittävä mutta ei liian iso.
        tärkeää: jätetään tilaa malliston shelfille */
  .bouquet-stage-wrapper{
    height: 42svh;
    min-height: 300px;
    margin-top: 10px;
  }

  .bouquet-actions{
    margin-top: 10px;
    gap: 8px;
  }
  .bouquet-actions button{
    padding: 9px 12px;
  }

  /* 3) Mallisto “bottom shelf” -tyyliin */
  .catalog{
    position: sticky;
    bottom: 0;
    z-index: 50;

    /* kiinteä korkeus: tämä estää “venymisen” */
    height: 210px;
    padding: 10px 10px 12px;

    border-radius: 16px 16px 0 0;
    background: rgba(255,255,255,.94);
    backdrop-filter: blur(8px);
    overflow: hidden;

    /* pieni varjo erottaa taustasta */
    box-shadow: 0 -10px 24px rgba(0,0,0,.08);
  }

  /* Otsikko tiiviiksi */
  .catalog-head{
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
  }
  .catalog-head h2{
    margin: 0;
    font-size: 16px;
  }
  .catalog-sub{
    font-size: 12px;
    max-width: 52vw;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* 4) Itse rullaus tapahtuu gridissä -> alaosa ei leikkaudu */
  .product-grid{
    margin-top: 8px;

    display:flex;
    gap: 10px;

    overflow-x: auto;
    overflow-y: hidden;

    /* tärkeää: jätä tilaa scroll-barille ja nappuloille */
    padding: 2px 2px 14px;

    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;

    /* vie loppu-korkeus shelfin sisällä */
    height: calc(210px - 44px); /* 44px ~ otsikkorivi+väli */
    align-items: stretch;
  }

  /* 5) Tiivistä tuotekortti niin että stepper mahtuu aina näkyviin */
  .product{
    min-width: 165px;
    max-width: 175px;

    height: 150px;           /* koko kortin korkeus */
    display:flex;
    flex-direction:column;

    scroll-snap-align: start;
  }

  .product__media{
    height: 58px;            /* matala kuva-alue */
    padding: 6px;
  }
  .product__media img{
    max-height: 46px;
  }

  .product__body{
    padding: 8px 8px 10px;
    gap: 6px;
  }

  .product__name{ font-size: 12.5px; }
  .product__price{ font-size: 12.5px; }

  .product__tag{
    font-size: 11.5px;
    padding: 4px 8px;
  }

  .stepper button{
    width: 30px;
    height: 30px;
    font-size: 18px;
  }
  .qty{
    width: 18px;
    font-size: 13px;
  }
}

/* extra pienet luurit */
@media (max-width: 420px){
  :root{
    --root-y: 66%;
    --tie-offset: 60px;
  }
  .catalog{ height: 200px; }
  .product-grid{ height: calc(200px - 44px); }
  .product{
    min-width: 155px;
    max-width: 165px;
    height: 146px;
  }
}
