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

:root {
  /* Shrinks for long words so they fit the screen; --letters is set by script */
  --letters: 4;
  --word-size: min(clamp(80px, 20vw, 160px), calc((100vw - 64px) / (var(--letters) * 0.62)));
  --glass: rgba(255,255,255,0.2);
  --glass-hover: rgba(255,255,255,0.3);
  --muted-text: rgba(255,255,255,0.75);
}

body {
  font-family: "Comic Sans MS", "Comic Neue", cursive;
  background: repeating-linear-gradient(
    135deg,
    #e84040 0px,   #e84040 60px,
    #d4700a 60px,  #d4700a 120px,
    #f0c000 120px, #f0c000 180px,
    #16a34a 180px, #16a34a 240px,
    #1a6fe8 240px, #1a6fe8 300px,
    #7c3aed 300px, #7c3aed 360px,
    #db2777 360px, #db2777 420px
  );
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

button, textarea { font-family: inherit; }

/* ── Buttons ── */
.btn {
  border: none;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
}
.btn:active:not(:disabled) { transform: scale(0.94); }
.btn:disabled { opacity: 0.3; cursor: default; }

.btn-glass { background: var(--glass); color: #fff; }
.btn-glass:hover:not(:disabled) { background: var(--glass-hover); }

.btn-round {
  width: 64px; height: 64px;
  border-radius: 50%;
  font-size: 26px;
}

/* ── Setup screen ── */
#setup {
  width: 100%;
  max-width: 520px;
  padding: 28px 32px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 20px;
}
#setup h1 { font-size: 36px; color: #fff; margin-bottom: 8px; }
.field { border: none; margin-bottom: 16px; }
.field-label { display: block; font-size: 14px; color: var(--muted-text); margin-bottom: 8px; }

#unit-select {
  width: 100%;
  padding: 12px;
  font: inherit;
  font-size: 15px;
  color: #1a1a1a;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.92);
}

/* Radio buttons and checkboxes drawn as pill buttons */
.segmented, .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.segmented label, .chips label { flex: 1; cursor: pointer; }
.segmented input, .chips input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span, .chips span {
  display: block;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--glass);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.segmented input:checked + span, .chips input:checked + span { background: #fff; color: #1a6fe8; }
.segmented input:focus-visible + span, .chips input:focus-visible + span { outline: 2px solid #fff; outline-offset: 2px; }
.chips em { font-style: normal; font-weight: 400; opacity: 0.7; }

#count-row { margin: 10px 0 20px; }
#count-label { font-size: 14px; color: var(--muted-text); margin-bottom: 10px; display: block; }
#count-label strong { color: #fff; font-size: 16px; }

#count-slider {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: var(--glass-hover);
  outline: none;
  cursor: pointer;
}
#count-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
#count-slider::-moz-range-thumb {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

#start-btn {
  width: 100%;
  padding: 16px;
  border-radius: 10px;
  font-size: 18px;
  letter-spacing: 0.5px;
}
#start-btn:active { transform: scale(0.98); }

/* ── Practice screen ── */
#practice {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: background 0.4s;
}
#practice.active { display: flex; }

#reset-btn {
  position: fixed;
  top: 20px; right: 20px;
  border-radius: 50px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 600;
}

#word-display {
  display: flex;
  align-items: flex-start;
  /* Room below the letters for hearts, so the buttons don't jump */
  min-height: 1.45em;
  font-size: var(--word-size);
  font-weight: 700;
  color: #fff;
  line-height: 1;
  padding: 0 32px;
  user-select: none;
  animation: wordPop 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
/* Outline b and d to help tell them apart */
#word-display .bd { -webkit-text-stroke: 2px #000; }

/* Each part is a column: letters, then a heart under heart parts */
.part { display: flex; flex-direction: column; align-items: center; }
.letters { padding-bottom: 0.12em; }
.part.heart .letters {
  /* Inset underline, so neighbouring heart parts get separate lines */
  background: linear-gradient(#fff, #fff) center bottom / calc(100% - 0.1em) 0.03em no-repeat;
}
.part.heart::after {
  content: '';
  width: 0.3em;
  height: 0.27em;
  margin-top: 0.01em;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 22'%3E%3Cpath d='M12 20.5S3 15 1.5 9.3C.5 5.4 2.9 1.5 6.7 1.5c2.3 0 4 1.2 5.3 3.1 1.3-1.9 3-3.1 5.3-3.1 3.8 0 6.2 3.9 5.2 7.8C21 15 12 20.5 12 20.5z' fill='%23e11d48' stroke='white' stroke-width='1.6'/%3E%3C/svg%3E") center / contain no-repeat;
}
@keyframes wordPop {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

#spoken-flash {
  font-size: 18px;
  font-weight: 600;
  color: rgba(255,255,255,0.9);
  margin-top: 20px;
  height: 28px;
  opacity: 0;
  transition: opacity 0.3s;
}
#spoken-flash.show { opacity: 1; }

#controls { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; align-items: center; }
#controls-row { display: flex; gap: 16px; align-items: center; }

#say-btn {
  height: 48px;
  padding: 0 20px;
  border-radius: 50px;
  font-size: 14px;
  letter-spacing: 0.3px;
  background: #fff;
}
#say-btn:hover { opacity: 0.9; }

#word-counter {
  position: fixed;
  bottom: 22px; right: 22px;
  font-size: 16px;
  color: rgba(255,255,255,0.7);
}

/* ── Celebration overlay ── */
#celebration {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 10;
}
#celebration.active { display: block; }

#celebration-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
}

/* Positioned by script to sit exactly where the practice word was */
#celebration-word {
  position: absolute;
  left: 0; right: 0;
  font-size: var(--word-size);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  letter-spacing: -2px;
  text-align: center;
  text-shadow: 0 0 40px rgba(255,255,255,0.8);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s;
}
#celebration-word.show { opacity: 1; }

#start-over-btn {
  position: absolute;
  bottom: 36px;
  left: 0; right: 0;
  width: max-content;
  margin: 0 auto;
  border-radius: 50px;
  padding: 14px 32px;
  font-size: 18px;
}
