:root {
  color-scheme: light;
  --ink: #14213d;
  --muted: #44506a;
  --paper: #f6f3ee;
  --card: #ffffff;
  --line: #d9d2c5;
  --accent: #1f4b8f;
  font-family: "Segoe UI", Calibri, "Helvetica Neue", sans-serif;
  font-size: 16px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
}

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  min-height: 100%;
  max-width: 100%;
}

body {
  overflow-x: hidden;
}

.banner {
  background: var(--ink);
  color: #f6f3ee;
  padding: calc(1.35rem + env(safe-area-inset-top, 0px)) max(1.25rem, env(safe-area-inset-right, 0px)) 1.2rem max(1.25rem, env(safe-area-inset-left, 0px));
}

.banner-inner { max-width: 52rem; margin: 0 auto; }

.product {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.75rem;
  font-weight: 600;
  color: #d4c49a;
}

.banner h1 {
  margin: 0.2rem 0 0.25rem;
  font-size: 1.7rem;
  font-weight: 600;
}

.election {
  margin: 0;
  color: #c9d3e3;
  font-size: 0.95rem;
}

main {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.15rem max(1.25rem, env(safe-area-inset-right, 0px)) 2.5rem max(1.25rem, env(safe-area-inset-left, 0px));
}

.chooser label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.hint, #status, footer p {
  color: var(--muted);
  line-height: 1.45;
}

.chooser .hint { margin: 0.35rem 0 0; }

.picker-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.6rem 0 0.35rem;
  width: 100%;
  min-width: 0;
}

#district-select {
  display: none;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--ink);
}

#district-picker {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  flex: 1 1 auto;
  font-size: 16px;
}

@media (max-width: 720px) {
  #district-picker {
    display: none;
  }

  #district-select {
    display: block;
  }

  .dictate-hint {
    display: block;
  }
}

#district-picker::part(control) {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 16px;
}

#district-picker::part(listbox) {
  max-width: 100%;
  /* ~10 option rows; iOS cannot scroll a listbox taller than the viewport. */
  max-height: min(22.5rem, 50dvh);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#spinner[hidden] { display: none; }

.workspace[hidden] { display: none; }

.workspace {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 0.85rem;
  align-items: stretch;
  min-width: 0;
}

.result, .chat, .ranking {
  min-width: 0;
  max-width: 100%;
}

.result {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin-top: 0;
}

.seat-card {
  padding: 0.55rem 0.85rem 0.4rem;
  background: var(--card);
  --fill-color: var(--card);
}

.seat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.45rem 1.1rem;
}

.kicker {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
}

.seat-card h2 {
  margin: 0.1rem 0 0.15rem;
  font-size: 1.05rem;
}

.lede {
  margin: 0 0 0.55rem;
  color: var(--muted);
}

.members {
  list-style: none;
  margin: 0;
  padding: 0;
}

.member {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  padding: 0.22rem 0;
  border-top: 1px solid var(--line);
}

.members.compact .member:first-child { border-top: 0; }

.member-name { font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.member-role { color: var(--muted); font-size: 0.78rem; }
.member-party { color: var(--ink); text-align: left; font-size: 0.85rem; overflow-wrap: anywhere; }

footer {
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 max(1.25rem, env(safe-area-inset-right, 0px)) calc(2.5rem + env(safe-area-inset-bottom, 0px)) max(1.25rem, env(safe-area-inset-left, 0px));
  font-size: 0.9rem;
}

footer a,
.about a,
.product a {
  color: var(--accent);
}

.product a {
  color: inherit;
  text-decoration: none;
}

.about .lede {
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--ink);
  margin: 0 0 0.4rem;
}

.about h2 {
  margin: 1.5rem 0 0.4rem;
  font-size: 1.15rem;
  font-weight: 600;
}

.about p,
.about li {
  color: var(--muted);
  line-height: 1.5;
}

.about ul {
  margin: 0.4rem 0 0.85rem;
  padding-left: 1.2rem;
}

.about li {
  margin: 0.35rem 0;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.chat, .ranking {
  margin-top: 0;
}

.chat h2, .ranking h2 {
  margin: 0.15rem 0 0.3rem;
  font-size: 1.25rem;
}

.transcript {
  list-style: none;
  margin: 0.65rem 0;
  padding: 0;
  display: grid;
  gap: 0.6rem;
  max-height: min(42vh, 28rem);
  overflow-y: auto;
}

.bubble {
  max-width: 100%;
  padding: 0.7rem 0.85rem;
  border-radius: 0.75rem;
  line-height: 1.4;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble-ellie {
  background: #e8eef7;
  justify-self: start;
}

.bubble-voter {
  background: var(--card);
  border: 1px solid var(--line);
  justify-self: end;
}

.bubble-text {
  margin: 0.15rem 0 0;
  min-height: 1.2em;
}

.bubble-text[contenteditable="true"] {
  cursor: text;
}

.bubble-text[contenteditable="true"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 0.25rem;
  background: #fff;
}

.bubble .who {
  display: block;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.chat-form textarea {
  width: 100%;
  max-width: 100%;
  font: inherit;
  font-size: 16px;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--card);
  color: var(--ink);
  resize: vertical;
  min-height: 5.5rem;
}

.dictate-hint,
.edit-hint {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.dictate-hint {
  display: none;
}

.chat-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.55rem;
}

.rank-card, .seat-card, fluent-card {
  min-width: 0;
  max-width: 100%;
}

.rank-card {
  padding: 0.8rem 0.95rem 0.7rem;
  background: var(--card);
  --fill-color: var(--card);
}

.rank-card + .rank-card { margin-top: 0.7rem; }

.rank-card h3 {
  margin: 0.1rem 0 0.35rem;
  font-size: 1.05rem;
}

.score {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 600;
}

.voter-match {
  margin: 0.3rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.conflicts {
  background: #f7e8e4;
  border: 1px solid var(--line);
  padding: 0.55rem 0.75rem 0.4rem;
  border-radius: 0.5rem;
  margin: 0.45rem 0 0.2rem;
}

.conflicts .kicker {
  color: #8a2f24;
}

.conflict-stance {
  margin: 0;
  color: #8a2f24;
  font-size: 0.92rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.conflicts .voter-match {
  color: #8a2f24;
  margin: 0.3rem 0 0.15rem;
}

.stance-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.4rem 0 0.15rem;
}

.stance-btn {
  font: inherit;
  font-size: 0.85rem;
  min-height: 44px;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.4rem;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
}

.stance-btn:active {
  background: #e8eef7;
}

.conflicts .stance-btn,
.citations-conflict .stance-btn {
  background: #fff;
}

.citations-conflict {
  background: #f7e8e4;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  padding: 0.15rem 0.75rem 0.25rem;
  margin-top: 0.45rem;
}

.citations-conflict li {
  color: #8a2f24;
}

.citations-conflict li:first-child {
  border-top: 0;
  padding-top: 0.35rem;
}

.citations.citations-conflict a {
  color: #8a2f24;
}

.rank-details {
  margin-top: 0.5rem;
}

.rank-details > summary {
  cursor: pointer;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  list-style: none;
}

.rank-details > summary::-webkit-details-marker {
  display: none;
}

.rank-details > summary::after {
  content: " ▾";
  font-size: 0.8em;
}

.rank-details[open] > summary::after {
  content: " ▴";
}

.rank-details .kicker {
  margin-top: 0.55rem;
}

.sitting-compact {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  color: var(--ink);
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.citations {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
}

.citations li {
  padding: 0.4rem 0;
  border-top: 1px solid var(--line);
  font-size: 0.92rem;
}

.citations a { color: var(--accent); overflow-wrap: anywhere; word-break: break-word; }

.quote {
  margin: 0.2rem 0;
  font-style: italic;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.note {
  color: var(--muted);
}

.unmatched {
  background: #f7efe4;
  border: 1px solid var(--line);
  padding: 0.7rem 0.85rem 0.55rem;
  border-radius: 0.5rem;
  margin: 0.55rem 0 0.85rem;
}

.unmatched h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
}

.unmatched ul {
  margin: 0.3rem 0 0;
  padding-left: 1.2rem;
}

.unmatched li {
  margin: 0.25rem 0;
  line-height: 1.35;
}

.out-of-scope {
  background: #e7eef6;
  border: 1px solid var(--line);
  padding: 0.7rem 0.85rem 0.55rem;
  border-radius: 0.5rem;
  margin: 0.55rem 0 0.85rem;
}

.out-of-scope h3 {
  margin: 0 0 0.3rem;
  font-size: 1rem;
}

.out-of-scope ul {
  margin: 0.3rem 0 0;
  padding-left: 1.2rem;
}

.out-of-scope li {
  margin: 0.25rem 0;
  line-height: 1.35;
}

.jurisdiction-tag {
  display: inline-block;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 600;
  color: #1f4b8f;
  background: #d7e3f4;
  padding: 0.08rem 0.4rem;
  border-radius: 0.25rem;
  margin-right: 0.35rem;
}

.jurisdiction-tag-federal {
  color: #1f4b8f;
  background: #d7e3f4;
}

.jurisdiction-tag-local {
  color: #1b5e3b;
  background: #d8efe3;
}

.jurisdiction-tag-mixed {
  color: #6b4a12;
  background: #f3e6c8;
}

.ranking-placeholder {
  color: var(--muted);
}


#send-btn {
  min-height: 44px;
  min-width: 44px;
  font-size: 16px;
}

@media (max-width: 899px) {
  .chat-actions {
    position: sticky;
    bottom: 0;
    z-index: 5;
    background: var(--paper);
    padding: 0.55rem 0 calc(0.55rem + env(safe-area-inset-bottom, 0px));
  }

  .member-party { text-align: left; }
}

@media (min-width: 900px) {
  .banner-inner, main, footer {
    max-width: 88rem;
  }

  .chooser {
    max-width: 52rem;
  }

  .workspace {
    display: grid;
    grid-template-columns: minmax(18rem, 1fr) minmax(20rem, 1.05fr);
    grid-template-areas:
      "result ranking"
      "chat ranking";
    column-gap: 1.6rem;
    row-gap: 0.65rem;
    align-items: start;
  }

  .result { grid-area: result; }
  .chat { grid-area: chat; }
  .ranking { grid-area: ranking; }

  .ranking {
    position: sticky;
    top: 0.75rem;
    max-height: calc(100dvh - 1.5rem);
    overflow-y: auto;
    padding-bottom: 0.5rem;
  }

  .transcript {
    max-height: min(46vh, 32rem);
  }

  .member-party { text-align: right; }
}

.jurisdiction-theme {
  color: var(--neutral-foreground-hint, #616161);
  font-size: 0.9em;
  font-weight: 500;
}
