/* Component styles. Depends on the tokens defined in styles.css. */

/* ------------------------------------------------------------------ heat */

/* One warm ramp keyed to a factor's effort (data-heat, set by app.js on each
   factor row and its group-header dot): sand (calm) to ember (hot). Each step
   is darker than the last, so levels differ in lightness and not only hue. */
[data-heat='1'] { --heat: #dad5cb; --heat-text: #16150f; --heat-tint: #efece6; --heat-ink: #4a463f; --heat-dot: #a8a29a; }
[data-heat='2'] { --heat: #f7cba4; --heat-text: #16150f; --heat-tint: #fcede0; --heat-ink: #7c2d12; --heat-dot: #e9a877; }
[data-heat='3'] { --heat: #ff9a5c; --heat-text: #16150f; --heat-tint: #ffe6d5; --heat-ink: #7c2d12; --heat-dot: #ff9a5c; }
[data-heat='4'] { --heat: #ff5a1f; --heat-text: #16150f; --heat-tint: #ffdccb; --heat-ink: #7c2d12; --heat-dot: #ff5a1f; }
[data-heat='5'] { --heat: #b83208; --heat-text: #ffffff; --heat-tint: #ffd2bf; --heat-ink: #6e1a06; --heat-dot: #b83208; }

@media (prefers-color-scheme: dark) {
  [data-heat='1'] { --heat-tint: rgba(218, 213, 203, 0.14); --heat-ink: #d6d1c6; }
  [data-heat='2'] { --heat-tint: rgba(247, 203, 164, 0.16); --heat-ink: #f7cba4; }
  [data-heat='3'] { --heat-tint: rgba(255, 154, 92, 0.18); --heat-ink: #ffb98c; }
  [data-heat='4'] { --heat-tint: rgba(255, 90, 31, 0.2); --heat-ink: #ff9a6b; }
  [data-heat='5'] { --heat-tint: rgba(184, 50, 8, 0.35); --heat-ink: #ff8a66; }
}

/* --------------------------------------------------------------- factors */

.factors { display: flex; flex-direction: column; gap: 1.75rem; }

.group { animation: rise 0.6s var(--ease-out) both; animation-delay: calc(80ms + var(--i) * 90ms); }

.group-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  padding: 0 0.25rem;
}

.group-head h2 {
  margin: 0;
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.group-num { font-family: var(--mono); font-weight: 500; letter-spacing: 0; color: var(--accent-ink); }
.group-hint { font-family: var(--mono); font-size: 0.75rem; color: var(--text-faint); white-space: nowrap; }

.group-rule {
  flex: 1;
  min-width: 1rem;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--border-strong) 0 4px, transparent 4px 8px);
}

/* One dot per factor, coloured by its heat: the group's temperature at a glance. */
.group-heat { display: inline-flex; gap: 3px; }
.group-heat i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: var(--heat-dot, var(--border-strong));
  transition: background-color 0.35s ease;
}

/* The badge's pie fills with the group's share of total effort. */
@property --share {
  syntax: '<number>';
  inherits: true;
  initial-value: 0;
}

.group-share::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--share) * 1turn), var(--border-strong) 0);
}

.group-share {
  transition: --share 0.55s var(--ease-out);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 1px 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}

/* Narrow phones: the hint drops to its own line instead of widening the page. */
@media (max-width: 479px) {
  .group-rule { display: none; }
  .group-hint { order: 3; flex-basis: 100%; }
}

.group-card {
  display: grid;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* Stacked factor (phones): label and chip share a row above the control. */
.factor {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  padding: 1rem;
  transition: background-color 0.2s ease;
}

.factor + .factor { border-top: 1px solid var(--border); }
.factor-text, .factor-control { display: contents; }
.factor-label { font-weight: 600; letter-spacing: -0.01em; }
.chip { grid-column: 2; grid-row: 1; justify-self: end; }
.factor-desc { grid-column: 1 / -1; margin: 0; font-size: 0.85rem; line-height: 1.45; color: var(--text-faint); }
.segments { grid-column: 1 / -1; margin-top: 0.5rem; }

/* Tablet: each factor becomes its own card, two to a row. */
@media (min-width: 640px) and (max-width: 959px) {
  .group-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    background: none;
    border: 0;
    box-shadow: none;
    overflow: visible;
  }

  .factor {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
  }

  .factor + .factor { border-top: 1px solid var(--border); }
  .factor-desc { min-height: 2.9em; }
}

/* Desktop: one row per factor, control on the right. */
@media (min-width: 960px) {
  .factor {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem 2rem;
    padding: 1.25rem 1.5rem;
  }

  .factor:hover { background: var(--surface-hover); }
  .factor-text { display: flex; flex-direction: column; gap: 0.25rem; flex: 1 1 220px; min-width: 0; }
  .factor-control { display: flex; flex-direction: column; align-items: flex-end; gap: 0.5rem; }
  .factor-label { font-size: 1rem; }
  .factor-desc { font-size: 0.875rem; }
  .factor-control .segments { margin-top: 0; grid-template-columns: repeat(5, 52px); }
}

/* -------------------------------------------------------------- segments */

.segments {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--surface-alt);
  border-radius: 14px;
}

/* The selected level is a single thumb that slides, rather than five
   independently coloured cells, so a change reads as movement. */
.thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: calc((100% - 24px) / 5);
  border-radius: 10px;
  background-color: var(--heat, var(--text));
  background-image: linear-gradient(rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0) 55%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 6px 16px color-mix(in srgb, var(--heat, #000) 35%, transparent);
  transform: translateX(calc((var(--level, 3) - 1) * (100% + 4px)));
  transition: transform 0.42s var(--spring), background-color 0.35s ease, box-shadow 0.35s ease;
}

.segment { position: relative; }

.segment input {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.segment span {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--text-faint);
  transition: background-color 0.25s ease, color 0.25s ease, transform 0.12s ease;
}

.segment.is-below span { background: var(--heat-tint); color: var(--heat-ink); }
.segment input:hover + span { color: var(--text); }
.segment input:checked + span { color: var(--heat-text); background: none; }
.segment input:active + span { transform: scale(0.92); }

.segment input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 26px;
  padding: 0 0.6rem 0 0.5rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--heat-tint);
  color: var(--heat-ink);
  transition: background-color 0.35s ease, color 0.35s ease;
}

.chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--heat-dot); transition: background-color 0.35s ease; }
.chip-level { font-family: var(--mono); font-weight: 500; opacity: 0.7; }

@media (max-width: 959px) {
  .chip-level { display: none; }
}

/* --------------------------------------------------------------- weights */

.weights {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.weights summary { padding: 1.1rem 1.5rem; }
.weights-title { display: flex; flex-direction: column; gap: 2px; font-weight: 600; font-size: 0.94rem; }
.weights-sub { font-family: var(--mono); font-size: 0.75rem; font-weight: 400; color: var(--text-faint); }
.weights-body { padding: 0 1.5rem 1.4rem; animation: rise 0.3s ease both; }
.weights-intro { margin: 0 0 1rem; max-width: 34rem; font-size: 0.875rem; color: var(--text-muted); }

.weight-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 8rem 2.8rem;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
}

/* Phones: each label gets its own line above its slider. */
@media (max-width: 639px) {
  .weight-row { grid-template-columns: minmax(0, 1fr) 2.8rem; row-gap: 0.15rem; margin-bottom: 0.85rem; }
  .weight-row label { grid-column: 1 / -1; }
}

.weight-row output { text-align: right; font-family: var(--mono); color: var(--text-muted); }
.weight-row input[type='range'] { width: 100%; accent-color: var(--accent); }

@media (pointer: coarse) {
  .weight-row input[type='range'] { height: 44px; }
}
