/* --- Global Scaling Strategy --- */
:root {
  font-size: clamp(12px, 1.2vw, 16px);
}

body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  font-family: 'Helvetica', sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: none; 
}

canvas {
  display: block;
}

#ui-container {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 1.5rem 2rem; 
  box-sizing: border-box;
  pointer-events: none;
  z-index: 10;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* --- Top Bar Layout --- */
.top-bar {
  width: 100%;
  pointer-events: none;
}

.ui-group {
  pointer-events: auto;
  display: flex;
  gap: 0.6rem;
}

.left-group {
  /* Keep horizontal on desktop, switch to column on mobile */
  flex-wrap: nowrap; 
  flex-direction: row;
}

.right-group {
  position: absolute;
  top: 1.5rem;
  right: 2rem;
}

/* --- Typography Unification --- */
button, input, select, label, span, .ui-pill, .sentence-item {
  font-family: 'Helvetica', sans-serif;
  font-size: 1rem !important; 
  font-weight: 400;
  color: #333;
}

/* --- Pill Components --- */
.ui-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 2.5rem; 
  padding: 0 1rem;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #333;
  border-radius: 50px;
  box-sizing: border-box;
  white-space: nowrap;
  transition: background 0.2s, transform 0.1s;
  position: relative;
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.ui-pill.clickable, .pointer-label {
  cursor: pointer;
  user-select: none;
}

.ui-pill.clickable:hover {
  background: #f0f0f0;
}

.ui-pill.clickable:active {
  transform: scale(0.96);
}

/* --- Bottom Center Group --- */
.ui-group.center {
  position: absolute;
  bottom: 2rem; 
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 0.8rem;
  width: auto; 
}

/* --- Color Inputs & Invisible Selects --- */
.full-cover-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  border: none;
  padding: 0;
  z-index: 5;
}

.full-cover-select {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0; /* Crucial: Hides the default text/arrow */
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  border: none;
  z-index: 10; /* Covers the text */
}

.color-dot {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  border: 1px solid #ccc;
  background-color: #fff;
  pointer-events: none;
}

.color-wrapper {
  position: relative;
  width: 1.2rem;
  height: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Higher Z-Index ensures the small dot is clickable ON TOP of the invisible select */
  z-index: 20; 
  margin-left: 0.2rem;
}

.pill-text {
  pointer-events: none; /* Let clicks pass through to the invisible select */
}

/* --- Input Row --- */
.input-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #333;
  padding-bottom: 0.3rem;
  margin-bottom: 0.3rem;
  background: rgba(255,255,255,0.4); 
  padding: 0.3rem 0.6rem;
  /* Updated Width */
  width: 32rem; 
  max-width: 90vw;
  box-sizing: border-box;
}

#sentence-input {
  border: none;
  background: transparent;
  width: 100%; 
  text-align: center;
  outline: none;
}

#add-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 0.3rem;
  font-size: 1.4rem !important; 
  line-height: 1rem; 
  display: flex;
  align-items: center;
}

#add-btn:hover {
  transform: scale(1.1);
}

.button-row {
  display: flex;
  gap: 0.6rem;
  /* Match Input Width */
  width: 32rem;
  max-width: 90vw;
}

.button-row button {
  flex: 1; /* Stretch buttons */
}

/* --- Sentence List --- */
#active-sentences-list {
  position: absolute;
  bottom: 2rem;
  left: 2rem;
  display: flex;
  flex-direction: column; 
  gap: 0.4rem;
  pointer-events: none;
  max-width: calc(50vw - 18rem); 
  max-height: 40vh; 
  overflow-y: hidden; 
  transition: opacity 2s ease-out; 
}

.sentence-item {
  background-color: rgba(255, 255, 255, 0.75);
  padding: 0.3rem 0.6rem;
  border-radius: 4px;
  align-self: flex-start;
  backdrop-filter: blur(2px);
  overflow-wrap: break-word; 
}

.fading {
  opacity: 0;
}

/* =========================================
   MOBILE OPTIMIZATION
   ========================================= */

@media (max-width: 600px) {
  
  #ui-container {
    padding: 1rem; 
  }

  .right-group {
    top: 1rem;
    right: 1rem;
  }

  /* Synced Wrapping: Left group becomes column exactly when mobile layout triggers */
  .left-group {
    flex-direction: column;
    align-items: flex-start;
  }

  .ui-group.center {
    width: 90%; 
    bottom: 1.5rem;
  }

  .input-row {
    width: 100%;
    justify-content: space-between;
  }

  #sentence-input {
    width: 100%;
    text-align: left;
  }

  .button-row {
    width: 100%;
    justify-content: center;
  }
  
  /* Sentence List on Mobile */
  #active-sentences-list {
    bottom: 9rem; 
    left: 1rem;
    max-width: 60vw;
  }

  .sentence-item {
    max-width: 100%;
    white-space: normal; 
    word-break: break-word;
  }
}