/* Buttons, chips, panels, the kilim motif system, the unweaving frame. */

/* Every panel and control is cut with the same two-step corner. This is the
   entire shape vocabulary — no radii anywhere in the build. */
.stepped {
  clip-path: polygon(
    0 var(--motif-notch),
    var(--motif-step) var(--motif-notch),
    var(--motif-step) var(--motif-step),
    var(--motif-notch) var(--motif-step),
    var(--motif-notch) 0,
    calc(100% - var(--motif-notch)) 0,
    calc(100% - var(--motif-notch)) var(--motif-step),
    calc(100% - var(--motif-step)) var(--motif-step),
    calc(100% - var(--motif-step)) var(--motif-notch),
    100% var(--motif-notch),
    100% calc(100% - var(--motif-notch)),
    calc(100% - var(--motif-step)) calc(100% - var(--motif-notch)),
    calc(100% - var(--motif-step)) calc(100% - var(--motif-step)),
    calc(100% - var(--motif-notch)) calc(100% - var(--motif-step)),
    calc(100% - var(--motif-notch)) 100%,
    var(--motif-notch) 100%,
    var(--motif-notch) calc(100% - var(--motif-step)),
    var(--motif-step) calc(100% - var(--motif-step)),
    var(--motif-step) calc(100% - var(--motif-notch)),
    0 calc(100% - var(--motif-notch))
  );
}

/* buttons */

.btn {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: var(--target-min);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: var(--display-stretch);
  font-size: var(--step-2);
  line-height: 1;
  text-transform: uppercase;
  background: var(--surface-raised);
  color: var(--text-primary);
  transition: background var(--dur-fast) var(--ease);
}

.btn:active {
  background: var(--surface-sunken);
}

.btn--primary {
  min-height: var(--target-primary);
  font-size: clamp(24px, 7.5vw, 34px);
  background: var(--color-confirm);
  color: var(--color-night);
}

.btn--primary:active {
  background: color-mix(in srgb, var(--color-confirm) 82%, black);
}

.btn--danger {
  min-height: var(--target-min);
  font-size: var(--step-1);
  letter-spacing: 0.06em;
  background: var(--color-danger);
  color: var(--color-wool);
}

.btn--danger:active {
  background: color-mix(in srgb, var(--color-danger) 82%, black);
}

.btn--secondary {
  font-size: var(--step-1);
}

/* Shares its row with the confirm button, so it is the same height but narrower, and its
   exhausted label is long enough to need a second line. */
.btn--skip {
  min-height: var(--target-primary);
  font-size: var(--step-1);
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.btn__hint {
  display: block;
  margin-top: var(--space-1);
  font-family: var(--font-ui);
  font-size: var(--step--1);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-faint);
}

.btn:disabled {
  background: var(--wool-10);
  color: var(--text-faint);
  cursor: default;
}

/* chips */

.chip-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 52px;
}

.chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-sunken);
  --motif-notch: 8px;
  --motif-step: 4px;
}

.chip__value {
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-primary);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 40px;
  margin-left: auto;
  color: var(--text-muted);
  background: var(--surface-sunken);
  --motif-notch: 8px;
  --motif-step: 4px;
}

/* the card and its unweaving frame */

.card {
  position: relative;
  display: grid;
  min-height: 0;
  background: var(--surface-raised);
}

.kilim {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.kilim__cell {
  fill: var(--weave-intact);
  transition: fill var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
}

.kilim__cell[data-state='spent'] {
  fill: var(--weave-spent);
}

.kilim__cell[data-state='fading'] {
  fill: var(--weave-intact);
  opacity: 0.35;
}

.kilim.is-endgame .kilim__cell[data-state='intact'],
.kilim.is-endgame .kilim__cell[data-state='fading'] {
  fill: var(--weave-endgame);
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .kilim__cell[data-state='fading'] {
    opacity: 1;
  }
}

/* Padding is derived from the motif the ring actually drew, so the weave can never end
   up underneath the word. The fallback covers the frame before layout runs once. */
.card__body {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: var(--space-4);
  min-height: 0;
  padding:
    calc(var(--motif-size, 20px) + var(--space-1))
    calc(var(--motif-size, 20px) + var(--space-2))
    calc(var(--motif-size, 20px) + var(--space-4));
}

.word {
  display: grid;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  text-align: center;
}

.word__text {
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: var(--display-stretch);
  font-size: var(--word-size);
  line-height: 0.92;
  letter-spacing: -0.015em;
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.word__note {
  margin-top: var(--space-2);
  font-size: var(--step--1);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-accent);
}

/* forbidden words: centred under the target, legible, subordinate, and struck by a
   broken thread rather than a printed line-through */
.taboo {
  display: grid;
  gap: var(--space-2);
  justify-items: center;
  text-align: center;
}

.taboo__item {
  display: grid;
  place-items: center;
  min-height: 30px;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* The strike hugs the word rather than the row, so a centred column still reads as
   five separate banned words instead of one ruled block. */
.taboo__word {
  display: inline-block;
  padding: 2px var(--space-1);
  background:
    repeating-linear-gradient(90deg, var(--strike) 0 7px, transparent 7px 12px)
    center / 100% 2px no-repeat;
}

/* Variant: the five words sit in their own sunken panel, separated from the target. */
.taboo--panel {
  padding: var(--space-3) var(--space-4);
  background: var(--surface-sunken);
  --motif-notch: 10px;
  --motif-step: 5px;
}

/* The clock: a numeral inside an arc that shortens as the round runs. The card frame is
   still the main countdown; this is the one you read a number off. */
.timer {
  position: relative;
  display: grid;
  flex: none;
  place-items: center;
  width: 52px;
  height: 52px;
}

.timer__ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* One circle, shortening. No motif here: at 48px the ornament read as noise, and the
   card frame is already carrying the woven version of the same information. */
.timer__track {
  fill: none;
  stroke: var(--weave-spent);
  stroke-width: 2.5;
}

.timer__arc {
  fill: none;
  stroke: var(--weave-intact);
  stroke-width: 2.5;
  stroke-linecap: butt;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
}

.timer.is-endgame .timer__arc {
  stroke: var(--weave-endgame);
}

/* Measured against the space inside the arc, not guessed: m:ss is four glyphs wide and
   was overflowing the circle, while plain seconds are two and can be larger. */
.timer__value {
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: var(--display-stretch);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  color: var(--text-primary);
}

.timer[data-digits='1'] .timer__value,
.timer[data-digits='2'] .timer__value {
  font-size: 17px;
}

.timer.is-endgame .timer__value {
  color: var(--color-danger-bright);
}

/* press-and-hold gauge */

.hold {
  display: grid;
  place-items: center;
  touch-action: manipulation;
  -webkit-touch-callout: none;
  width: min(62vw, 240px);
  aspect-ratio: 1;
  margin: 0 auto;
}

.hold__gauge {
  width: 100%;
  height: 100%;
  grid-area: 1 / 1;
}

.hold__track {
  fill: var(--wool-10);
}

.hold__outline {
  fill: none;
  stroke: var(--weave-intact);
  stroke-width: 1.4;
}

.hold__fill {
  fill: var(--color-confirm);
}

.hold__label {
  grid-area: 1 / 1;
  max-width: 66%;
  font-size: var(--step--1);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text-primary);
}

/* score bands: a woven row per team */

.band {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 52px;
  padding: var(--space-2) var(--space-4);
  background: var(--surface-raised);
}

/* The active team is marked with the motif, not with an accent slab down the side. */
.band--active::before {
  content: '';
  flex: none;
  width: 14px;
  height: 14px;
  background: var(--color-accent);
  clip-path: polygon(
    50% 0, 65% 15%, 85% 15%, 85% 35%, 100% 50%,
    85% 65%, 85% 85%, 65% 85%, 50% 100%, 35% 85%,
    15% 85%, 15% 65%, 0 50%, 15% 35%, 15% 15%, 35% 15%
  );
}

.band--active .band__name {
  color: var(--color-accent);
}

.band__name {
  font-size: var(--step-1);
  font-weight: 600;
}

.band__score {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: var(--display-stretch);
  font-size: var(--step-2);
}

/* summary rows: the dispute-resolution surface */

.row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-4);
  text-align: left;
  background: var(--surface-raised);
}

.row__mark {
  flex: none;
  width: 18px;
  height: 18px;
  background: var(--text-faint);
  clip-path: polygon(
    50% 0, 65% 15%, 85% 15%, 85% 35%, 100% 50%,
    85% 65%, 85% 85%, 65% 85%, 50% 100%, 35% 85%,
    15% 85%, 15% 65%, 0 50%, 15% 35%, 15% 15%, 35% 15%
  );
}

.row__word {
  font-size: var(--step-1);
  font-weight: 600;
  text-transform: uppercase;
}

.row__delta {
  margin-left: auto;
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: var(--display-stretch);
  font-size: var(--step-1);
  color: var(--text-faint);
}

.row[data-outcome='correct'] .row__mark {
  background: var(--color-confirm);
}

.row[data-outcome='correct'] .row__delta {
  color: var(--color-confirm);
}

.row[data-outcome='foul'] .row__mark {
  background: var(--color-danger);
}

.row[data-outcome='foul'] .row__delta {
  color: var(--color-danger);
}

.row[data-outcome='skip'] .row__mark {
  background: var(--wool-22);
}

.row[data-outcome='skip'] .row__word {
  color: var(--text-muted);
}

/* segmented choice rows: options are stepped slabs, never pill toggles */

.choice {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.choice__option {
  min-width: 56px;
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-4);
  font-size: var(--step-0);
  font-weight: 600;
  color: var(--text-primary);
  background: var(--surface-raised);
}

.choice__option--active {
  color: var(--color-night);
  background: var(--color-accent);
}

/* text field: a woven slab, not an input box with a border */

.field {
  display: grid;
  gap: var(--space-1);
  min-height: var(--target-min);
  padding: var(--space-2) var(--space-4);
  background: var(--surface-raised);
}

.field__label {
  font-size: var(--step--1);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.field__input {
  width: 100%;
  padding: 0;
  font: inherit;
  font-size: var(--step-1);
  font-weight: 600;
  color: var(--text-primary);
  background: none;
  border: 0;
}

.field__input:focus {
  outline: none;
  color: var(--color-accent);
}

.notice {
  padding: var(--space-2) var(--space-4);
  font-size: var(--step--1);
  color: var(--color-accent);
  background: var(--surface-sunken);
  --motif-notch: 10px;
  --motif-step: 5px;
}

/* overlay: a flat scrim, no blur, no frosted panel */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background: rgb(16 23 40 / 94%);
}

.overlay__panel {
  display: grid;
  gap: var(--space-3);
  width: min(92vw, 420px);
  padding: var(--space-5);
  background: var(--surface-raised);
}

.overlay__title {
  font-size: var(--step-3);
  text-align: center;
}

/* The selected option carries the same diamond the active score band uses. It is
   present on every option so that choosing one cannot shift the row sideways. */
.choice__option::before {
  content: '';
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: var(--space-2);
  vertical-align: middle;
  background: var(--wool-22);
  clip-path: polygon(
    50% 0, 65% 15%, 85% 15%, 85% 35%, 100% 50%,
    85% 65%, 85% 85%, 65% 85%, 50% 100%, 35% 85%,
    15% 85%, 15% 65%, 0 50%, 15% 35%, 15% 15%, 35% 15%
  );
}

.choice__option--active::before {
  background: var(--color-night);
}

/* a setting: its name, its options, and the consequence of the current choice */

.setting {
  display: grid;
  gap: var(--space-2);
}

.setting__note {
  font-size: var(--step--1);
  color: var(--text-muted);
}

.setting__note--warning {
  color: var(--color-danger);
}

/* Destructive actions arm in place: each one owns its confirmation, so no two
   irreversible resets can ever share a yes. */

.danger {
  display: grid;
  gap: var(--space-2);
}

.danger__ask {
  display: grid;
  gap: var(--space-2);
}

.danger__pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
}

/* a sentence in a panel row, where .row__word would shout it in uppercase */
.row__text {
  font-size: var(--step-0);
  color: var(--text-muted);
}

/* the unit trails the figure it belongs to, subordinate to it */
.band__unit {
  font-size: var(--step--1);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* Multi-selects can have every option active at once (all 18 categories by default),
   so their selected state is the marker plus accent text, not a filled slab. A filled
   slab is right for single-choice rows where exactly one option is ever active. */
.choice--multi .choice__option--active {
  color: var(--color-accent);
  background: var(--surface-raised);
}

.choice--multi .choice__option--active::before {
  background: var(--color-accent);
}

/* update toast: a slab above the safe area, tapped to take the new version */

.toast {
  position: fixed;
  right: var(--space-4);
  bottom: calc(env(safe-area-inset-bottom) + var(--space-4));
  left: var(--space-4);
  z-index: 20;
  min-height: var(--target-min);
  padding: var(--space-3) var(--space-4);
  font-size: var(--step-0);
  font-weight: 600;
  text-align: center;
  color: var(--color-night);
  background: var(--color-accent);
  --motif-notch: 10px;
  --motif-step: 5px;
}

.install__steps {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  font-size: var(--step-0);
  color: var(--text-muted);
}

.steps {
  flex: none;
  color: var(--color-accent);
}

/* woven band: the carpet border, used on screens that are not a running round */

.band-strip {
  display: block;
  width: 100%;
  height: auto;
}

.band-strip__wave {
  fill: var(--weave-intact);
}

/* The two bands mirror each other so their teeth point into the field and their
   selvedges face outward, the way a carpet's borders frame its ground. */
.band-strip--flipped {
  transform: scaleY(-1);
}

/* Utility destinations are a row of compact slabs, not three more full-width buttons
   competing with the one action that matters. */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}

.tile {
  display: grid;
  place-items: center;
  min-height: var(--target-min);
  padding: var(--space-2);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: center;
  overflow-wrap: anywhere;
  color: var(--text-primary);
  background: var(--surface-raised);
  transition: background var(--dur-fast) var(--ease);
  --motif-notch: 10px;
  --motif-step: 5px;
}

.tile:active {
  background: var(--surface-sunken);
}

/* An install chip is an offer, not a demand: compact, still a real tap target. */
.chip--action {
  min-height: 44px;
  color: var(--text-primary);
  background: var(--surface-raised);
}

/* Any text that autofit sizes reads its size from the same custom property. Bounds are
   set per host, so a team name and a target word can shrink within different limits. */
.fit-text {
  font-size: var(--word-size);
}

/* the medallion, as on the icon */

.medallion {
  width: 100%;
  height: 100%;
}

.medallion__band--wool {
  fill: var(--color-wool);
}

.medallion__band--indigo {
  fill: var(--surface-raised);
}

.medallion__band--pomegranate {
  fill: var(--color-danger);
}
