.deck-builder-page {
  max-width: 1120px;
}

.deck-builder-hero,
.deck-builder-input,
.deck-builder-preview,
.deck-builder-done {
  overflow: hidden;
}

.deck-builder-hero {
  /* Inherit the shared frosted .panel chrome so the hero reads as one family
     with the Dictionary hero, instead of overriding it with a flat fill.
     Capped at --space-12 (32px): a 24-32px inset is the correct amount of
     air for a hero card (vs. a list row), per the design system ceiling. */
  padding: clamp(var(--space-9), 4vw, var(--space-12));
}

/* Specificity fix: this h1 sits inside .panel (for the shared hero chrome),
   and app.css's `.panel h1:not(.page-title)` (2 classes + type = 0,2,1)
   otherwise outranks a bare `.deck-builder-title` (0,1,0) and silently wins,
   so the values below were dead code rendering at app.css's 2.3rem/8px
   instead. Values are kept at that already-in-production size (matches the
   home hero's ~2.35rem) rather than the old clamp's unused 3.4rem ceiling,
   which would make this the single largest heading in the app. */
.deck-builder-page .deck-builder-hero .deck-builder-title {
  margin: 0 0 var(--space-4);
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3.6vw, 2.3rem);
  line-height: 1;
}

.deck-builder-lead {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.deck-builder-section-head,
.deck-builder-phrases-head,
.deck-builder-build-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-8);
}

.deck-builder-section-head,
.deck-builder-build-bar {
  /* flex-end: both pair a taller block on the left (2-line kicker+title, or
     the 3-line progress readout) with short single-line content on the
     right, so the right side should sit on the tall block's baseline
     instead of stranding up by its first line (matches Study's
     .study8-header). .deck-builder-phrases-head keeps flex-start: its label
     and count are equal-height, and .dsl-label's own margin-bottom would
     otherwise knock them 6px out of alignment under flex-end. */
  align-items: flex-end;
}

.deck-builder-section-head .section-title {
  margin: var(--space-2) 0 0;
}

.deck-builder-scope,
.deck-builder-count,
.deck-builder-summary,
.deck-builder-kind {
  color: var(--accent-ink);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.deck-builder-name-row {
  /* Matches the 20px rhythm the rest of this section already uses
     (.deck-builder-register's own margin, the hint-to-actions gap below):
     22px was the one-off outlier in an otherwise uniform --space-9 cadence. */
  margin-top: var(--space-9);
}

.deck-builder-control {
  width: 100%;
  min-height: 48px;
  margin-top: var(--space-4);
  padding: var(--space-6) var(--space-7);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--panel-2);
  color: inherit;
  font: inherit;
}

.deck-builder-control:focus-visible {
  border-color: var(--accent-ink);
}

.deck-builder-textarea {
  min-height: 250px;
  resize: vertical;
  line-height: 1.55;
}

.deck-builder-register {
  min-width: 0;
  margin: var(--space-9) 0;
  padding: 0;
  border: 0;
}

.deck-builder-segment {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(94px, 1fr));
  margin-top: var(--space-4);
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--panel-3);
}

.deck-builder-segment label {
  cursor: pointer;
}

.deck-builder-segment input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.deck-builder-segment span {
  display: block;
  min-height: 44px;
  padding: var(--space-5) var(--space-8);
  border-radius: var(--radius-pill);
  text-align: center;
  font-weight: 600; /* canonical segmented-switch label weight */
}

.deck-builder-segment input:checked + span {
  background: var(--accent);
  color: var(--on-accent);
}

.deck-builder-segment input:focus-visible + span {
  outline: var(--focus-ring-width) solid var(--focus-ring-color);
  outline-offset: var(--focus-ring-offset);
}

.deck-builder-format-hint {
  margin-top: var(--space-5);
  line-height: 1.5;
}

.deck-builder-input-actions {
  margin-top: var(--space-9);
}

.deck-builder-status {
  min-height: 1.4em;
  margin: var(--space-6) 0 0;
}

.deck-builder-count.is-over,
.deck-builder-status[data-tone='error'] {
  color: var(--danger);
}

.deck-builder-status[data-tone='success'] {
  color: var(--accent-2);
}

.deck-builder-rows {
  display: grid;
  gap: var(--space-5);
  margin: var(--space-9) 0 var(--space-10);
  padding: 0;
  list-style: none;
}

.deck-builder-row {
  display: grid;
  /* Column matches the 36px number badge exactly (was 42px, leaving 6px of
     dead space stranded on one side since grid items start-align by
     default — the badge wasn't optically centred in its own column). */
  grid-template-columns: 36px minmax(0, 1fr) auto;
  gap: var(--space-7);
  align-items: center;
  padding: var(--space-7);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--panel-2) 82%, transparent);
}

.deck-builder-row.is-invalid,
.deck-builder-row.is-error {
  border-color: color-mix(in srgb, var(--danger) 60%, var(--border));
  background: color-mix(in srgb, var(--danger) 9%, transparent);
}

.deck-builder-row.is-working {
  border-color: var(--accent-ink);
  box-shadow: inset 3px 0 0 var(--accent);
}

.deck-builder-row.is-saved {
  border-color: color-mix(in srgb, var(--accent-2) 55%, var(--border));
}

.deck-builder-row-number {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--muted) 16%, transparent);
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 800;
}

.deck-builder-row-copy {
  min-width: 0;
}

.deck-builder-row-main,
.deck-builder-row-sub,
.deck-builder-row-message {
  margin: 0;
  overflow-wrap: anywhere;
}

/* Scoped under .deck-builder-row so the phrase reads as --text over the
   generic `.panel p { color: var(--muted) }` rule in app.css. */
.deck-builder-row .deck-builder-row-main {
  color: var(--text);
  font-size: var(--text-body);
  font-weight: 760;
}

.deck-builder-row-sub {
  margin-top: var(--space-2);
  color: var(--muted);
  font-size: var(--text-lg);
}

/* Scoped so the error reads as --danger over `.panel p`. */
.deck-builder-row .deck-builder-row-message {
  margin-top: var(--space-3);
  color: var(--danger);
  font-size: var(--text-md);
}

.deck-builder-row-state {
  min-width: 82px;
  text-align: right;
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 800;
}

.deck-builder-row.is-saved .deck-builder-row-state {
  color: var(--accent-2);
}

.deck-builder-build-bar {
  /* align-items now comes from the shared rule above (flex-end) */
  padding-top: var(--space-9);
  border-top: 1px solid var(--border);
}

.deck-builder-progress-copy {
  display: grid;
  min-width: min(420px, 100%);
  gap: var(--space-4);
}

.deck-builder-progress-copy progress {
  width: 100%;
  height: 10px;
  accent-color: var(--accent-ink);
}

.deck-builder-done {
  border-color: color-mix(in srgb, var(--accent-2) 45%, var(--border));
}

.deck-builder-done-summary {
  line-height: 1.55;
}

.deck-builder-done-actions a {
  text-decoration: none;
}

@media (max-width: 700px) {
  .deck-builder-section-head,
  .deck-builder-build-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .deck-builder-scope,
  .deck-builder-summary {
    align-self: flex-start;
  }

  .deck-builder-row {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: var(--space-5);
    padding: var(--space-6);
  }

  .deck-builder-row-number {
    width: 32px;
    height: 32px;
  }

  .deck-builder-row-state {
    grid-column: 2;
    min-width: 0;
    text-align: left;
  }

  .deck-builder-build-actions,
  .deck-builder-done-actions {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr;
  }

  .deck-builder-build-actions > *,
  .deck-builder-done-actions > * {
    width: 100%;
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .deck-builder-segment {
    display: grid;
    width: 100%;
  }

  .deck-builder-textarea {
    min-height: 220px;
  }
}
