:root {
  color-scheme: light dark;
  --paper: #f7f3ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #0e263d;
  --muted: #566166;
  --accent: #b82e24;
  --rule: #cec9bd;
  --shadow: 0 18px 55px rgba(14, 38, 61, .09);
  --party: #566166;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; }
button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; text-underline-offset: .2em; }
a:hover { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -5rem;
  z-index: 100;
  background: var(--surface-strong);
  padding: .75rem 1rem;
  border-radius: .35rem;
}
.skip-link:focus { top: 1rem; }

.app-header {
  height: 68px;
  padding: 0 clamp(1rem, 3vw, 2.5rem);
  border-bottom: 1px solid var(--rule);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: .7rem; font-weight: 760; text-decoration: none; }
.brand img { width: 42px; height: 42px; border-radius: 10px; }
.header-status { margin: 0; color: var(--muted); font-size: .875rem; }

main { width: min(1440px, 100%); margin: 0 auto; padding: 0 clamp(1rem, 3vw, 2.5rem) 100px; }
.view { padding-top: 1.8rem; }
.eyebrow {
  margin: 0 0 .3rem;
  color: var(--accent);
  font: 700 .75rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .13em;
  text-transform: uppercase;
}
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; letter-spacing: -.025em; line-height: 1.1; }
h1 { margin: 0; font-size: clamp(2.35rem, 5vw, 4rem); font-weight: 600; }
h2 { font-size: 1.45rem; }
h3 { font-size: 1.3rem; }
.workspace-header { margin-bottom: 1.3rem; }
.progress-copy { margin: .35rem 0 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.blind-rating-note { margin: .35rem 0 0; color: var(--muted); font-size: .875rem; }

.filter-button, .primary-button, .danger-button, .text-button, .icon-button, .mobile-close {
  border: 0;
  cursor: pointer;
}
.filter-button, .primary-button {
  border-radius: .45rem;
  background: var(--ink);
  color: white;
  padding: .72rem 1rem;
  font-weight: 700;
}
.filter-button { min-height: 48px; white-space: nowrap; }
.filter-button:hover, .primary-button:hover { background: var(--accent); }
.filter-count {
  display: inline-grid;
  place-items: center;
  min-width: 1.35rem;
  height: 1.35rem;
  margin-left: .3rem;
  border-radius: 999px;
  background: white;
  color: var(--ink);
  font-size: .75rem;
}

.search-toolbar {
  position: sticky;
  top: 68px;
  z-index: 18;
  display: grid;
  grid-template-columns: minmax(0, 44rem) auto;
  align-items: stretch;
  gap: .75rem;
  width: min(52rem, 100%);
  margin: -.4rem 0 .8rem;
  padding: .4rem 0;
  background: color-mix(in srgb, var(--paper) 94%, transparent);
  backdrop-filter: blur(14px);
}
.search-wrap { min-width: 0; }
.search-wrap label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.search-wrap input {
  width: 100%;
  max-width: 44rem;
  border: 1px solid var(--rule);
  border-radius: .5rem;
  padding: .82rem 1rem .82rem 2.75rem;
  color: var(--ink);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23566166' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-4-4'/%3E%3C/svg%3E") no-repeat 1rem center;
}

.policy-workspace {
  display: grid;
  grid-template-columns: minmax(330px, .9fr) minmax(380px, 1.1fr);
  min-height: calc(100vh - 250px);
  border: 1px solid var(--rule);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.policy-list-panel { min-width: 0; border-right: 1px solid var(--rule); }
.list-summary { min-height: 2.65rem; padding: .75rem 1rem; border-bottom: 1px solid var(--rule); color: var(--muted); font-size: .875rem; }
.policy-list { max-height: calc(100vh - 295px); min-height: 460px; overflow: auto; }
.policy-card { border-bottom: 1px solid var(--rule); padding: 1.15rem; background: var(--surface); }
.policy-card.is-selected { background: color-mix(in srgb, var(--accent) 5%, var(--surface)); box-shadow: inset 4px 0 0 var(--accent); }
.policy-card-top { display: flex; justify-content: space-between; gap: .75rem; align-items: baseline; }
.party-mark { display: flex; gap: .45rem; align-items: center; font: 750 .72rem/1.3 ui-monospace, monospace; letter-spacing: .06em; text-transform: uppercase; }
.party-mark::before { content: ""; width: 4px; height: 15px; background: var(--party); border-radius: 99px; flex: 0 0 auto; }
.party-mark.is-blinded { color: var(--muted); letter-spacing: .035em; }
.topic { color: var(--muted); font: .75rem/1.4 ui-monospace, monospace; text-align: right; }
.policy-open { width: 100%; padding: 0; margin: .75rem 0 0; border: 0; background: none; text-align: left; cursor: pointer; }
.policy-open h2 { display: flex; justify-content: space-between; gap: 1rem; margin: 0; font-size: 1.16rem; }
.policy-open h2::after { content: "›"; color: var(--muted); font-family: sans-serif; }
.policy-open p { margin: .5rem 0 0; color: var(--muted); font-size: .925rem; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }

.rating-control { margin-top: .9rem; }
.rating-options { display: grid; grid-template-columns: repeat(5, 1fr); gap: .35rem; }
.rating-button {
  min-width: 0;
  min-height: 55px;
  border: 1px solid var(--rule);
  border-radius: .4rem;
  padding: .3rem .15rem;
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: .68rem;
  line-height: 1.15;
  font-weight: 680;
}
.rating-icon { display: block; width: 1.2rem; height: 1.2rem; margin: 0 auto .28rem; fill: currentColor; }
.rating-button span { display: block; }
.rating-button:hover { border-color: var(--accent); }
.rating-button.is-selected { background: var(--accent); border-color: var(--accent); color: white; }
.clear-response { margin-top: .45rem; padding: .2rem 0; background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: .78rem; }

.policy-detail-panel { position: relative; min-width: 0; }
.policy-detail-panel > article { max-height: calc(100vh - 250px); overflow: auto; }
.detail-placeholder { min-height: 100%; display: grid; place-content: center; justify-items: center; text-align: center; padding: 3rem; color: var(--muted); }
.detail-placeholder h2 { color: var(--ink); margin-bottom: .4rem; }
.detail-placeholder p { max-width: 26rem; margin-top: 0; }
.placeholder-mark { font-size: 2rem; color: var(--accent); }
.policy-detail-content { padding: clamp(1.5rem, 4vw, 3rem); max-width: 760px; margin: 0 auto; }
.detail-head { border-top: 4px solid var(--party); padding-top: 1.1rem; }
.detail-head-row { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.detail-head h2 { margin: .8rem 0 .7rem; font-size: clamp(2rem, 4vw, 3.4rem); }
.status-label { display: inline-block; color: var(--muted); border: 1px solid var(--rule); padding: .28rem .55rem; border-radius: 99px; font-size: .78rem; }
.detail-section { margin-top: 2rem; }
.detail-section h3 { margin: 0 0 .65rem; }
.detail-section p { font-size: 1.02rem; }
.source-link { display: inline-block; margin-top: .3rem; font-weight: 700; color: var(--accent); }
.source-note { margin: .45rem 0 0; color: var(--muted); font-size: .8rem !important; }
.detail-rating .rating-button { min-height: 70px; }
.detail-notes { width: 100%; min-height: 120px; resize: vertical; border: 1px solid var(--rule); background: var(--surface-strong); color: var(--ink); border-radius: .45rem; padding: .8rem; }
.detail-meta { display: grid; grid-template-columns: 1fr auto; gap: 1rem; padding-top: 1rem; border-top: 1px solid var(--rule); }
.detail-meta dt { color: var(--muted); }
.detail-meta dd { margin: 0; }

.empty-state { text-align: center; padding: 5rem 1rem; }
.empty-state p { color: var(--muted); }
.text-button { padding: .55rem .25rem; background: none; color: var(--accent); font-weight: 700; text-decoration: underline; text-underline-offset: .2em; }

.view-match, .view-about { max-width: 960px; margin: 0 auto; padding-top: clamp(2rem, 6vw, 5rem); }
.match-intro, .about-card { border-top: 5px solid var(--accent); padding-top: 1.4rem; }
.match-intro > p:last-child { max-width: 48rem; color: var(--muted); }
.match-total { color: var(--accent); font-size: 1.15rem; font-weight: 750; }
.score-list { margin-top: 2rem; border-top: 1px solid var(--rule); }
.score-card { --party: var(--muted); border-bottom: 1px solid var(--rule); }
.score-card summary { list-style: none; cursor: pointer; padding: 1.25rem 0; }
.score-card summary::-webkit-details-marker { display: none; }
.score-row { display: grid; grid-template-columns: 42px 1fr auto; gap: 1rem; align-items: center; }
.rank { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; background: color-mix(in srgb, var(--party) 14%, transparent); color: var(--party); font-weight: 800; }
.score-party { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; }
.score-party .party-mark { --party: inherit; }
.score-count { width: 100%; color: var(--muted); font-size: .82rem; }
.score-value { font: 700 1.45rem/1 ui-monospace, monospace; }
.progress-track { grid-column: 2 / 4; height: 7px; border-radius: 99px; background: var(--rule); overflow: hidden; }
.progress-track span { display: block; height: 100%; background: var(--party); }
.breakdown { margin: 0 0 1.3rem 58px; display: grid; gap: .45rem; color: var(--muted); }
.breakdown div { display: flex; justify-content: space-between; }
.method-note { color: var(--muted); font-size: .875rem; margin-top: 2rem; }

.about-card { max-width: 760px; margin: 0 auto; }
.about-card > p { color: var(--muted); }
.about-card h2 { margin-top: 2.5rem; }
.facts { margin: 0; border-top: 1px solid var(--rule); }
.facts div { display: grid; grid-template-columns: 1fr auto; gap: 1rem; border-bottom: 1px solid var(--rule); padding: .8rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
.plain-list { padding-left: 1.35rem; }
.plain-list li { margin: .55rem 0; }
.notice { padding: 1rem 1.2rem; border-left: 4px solid var(--accent); background: var(--surface); }
.danger-button { background: #98251d; color: white; padding: .72rem 1rem; border-radius: .4rem; font-weight: 700; }
.danger-button:hover { background: #721b16; }
.danger-button:disabled { opacity: .4; cursor: not-allowed; }
.about-links { display: flex; flex-wrap: wrap; gap: 1.5rem; padding: 2.5rem 0; border-top: 1px solid var(--rule); margin-top: 2.5rem; }

.tab-bar {
  position: fixed;
  z-index: 30;
  bottom: 0;
  left: 0;
  right: 0;
  min-height: 70px;
  display: flex;
  justify-content: center;
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  backdrop-filter: blur(18px);
  border-top: 1px solid var(--rule);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-bar button { min-width: 120px; border: 0; background: none; color: var(--muted); cursor: pointer; font-weight: 700; padding: .7rem 1.5rem; }
.tab-bar button span { display: block; font-size: 1.2rem; line-height: 1.15; }
.tab-bar button.is-active { color: var(--accent); }

dialog { color: var(--ink); background: var(--surface); border: 1px solid var(--rule); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(5, 18, 30, .55); backdrop-filter: blur(3px); }
.filter-dialog { width: min(720px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border-radius: .65rem; }
.filter-dialog form { padding: 1.5rem; }
.dialog-header { position: sticky; top: -1.5rem; z-index: 2; display: flex; justify-content: space-between; align-items: start; background: var(--surface); border-bottom: 1px solid var(--rule); padding: 1.5rem 0 1rem; }
.dialog-header h2 { margin: 0; font-size: 2rem; }
.icon-button { font-size: 2rem; background: none; line-height: 1; padding: .2rem .5rem; }
.toggle-row { display: flex; gap: .7rem; align-items: center; padding: 1rem 0; font-weight: 700; }
.filter-dialog fieldset { border: 0; border-top: 1px solid var(--rule); padding: 1rem 0; margin: 0; }
.filter-dialog legend { font: 700 1.1rem Georgia, serif; padding-top: 1rem; }
.check-list { display: grid; gap: .25rem; }
.check-list.two-column { grid-template-columns: 1fr 1fr; gap: .25rem 1rem; }
.check-list label { display: flex; gap: .6rem; padding: .38rem 0; align-items: start; }
.check-list input, .toggle-row input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); flex: 0 0 auto; }
.dialog-actions { position: sticky; bottom: -1.5rem; display: flex; justify-content: space-between; gap: 1rem; padding: 1rem 0 1.5rem; background: var(--surface); border-top: 1px solid var(--rule); }
.confirm-dialog { width: min(470px, calc(100% - 2rem)); padding: 1.5rem; border-radius: .65rem; }
.confirm-dialog h2 { margin-top: 0; }
.confirm-dialog .dialog-actions { position: static; padding-bottom: 0; }
.mobile-detail-dialog { width: 100%; height: 100%; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; }
.mobile-close { position: sticky; top: 0; z-index: 2; width: 100%; text-align: left; padding: 1rem; background: var(--paper); border-bottom: 1px solid var(--rule); font-weight: 700; }
.toast { position: fixed; z-index: 80; left: 50%; bottom: 90px; transform: translateX(-50%); color: white; background: var(--ink); padding: .75rem 1rem; border-radius: .35rem; box-shadow: var(--shadow); }

@media (max-width: 840px) {
  .policy-workspace { display: block; }
  .policy-list-panel { border-right: 0; }
  .policy-list { max-height: none; overflow: visible; }
  .policy-detail-panel { display: none; }
  .policy-card { padding: 1rem; }
  .rating-button { min-height: 58px; }
  .check-list.two-column { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .app-header { height: 60px; }
  .brand img { width: 36px; height: 36px; }
  .brand span { font-size: .95rem; }
  .header-status { display: none; }
  main { padding-left: .75rem; padding-right: .75rem; }
  .view { padding-top: 1.25rem; }
  h1 { font-size: 2.45rem; }
  .search-toolbar {
    top: 60px;
    grid-template-columns: minmax(0, 1fr) auto;
    width: auto;
    margin: -.4rem -.75rem .65rem;
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--rule);
  }
  .filter-button { min-height: 46px; padding: .62rem .75rem; }
  .policy-workspace { margin: 0 -.75rem; border-left: 0; border-right: 0; box-shadow: none; }
  .policy-card-top { align-items: start; }
  .rating-options { gap: .2rem; }
  .rating-button { font-size: .6rem; min-height: 57px; border-radius: .3rem; }
  .rating-icon { width: 1.05rem; height: 1.05rem; }
  .tab-bar button { min-width: 0; flex: 1; padding: .6rem .5rem; font-size: .75rem; }
  .view-match, .view-about { padding-left: .35rem; padding-right: .35rem; }
  .score-row { grid-template-columns: 38px 1fr auto; gap: .7rem; }
  .breakdown { margin-left: 48px; }
  .detail-rating .rating-button { min-height: 65px; }
  .policy-detail-content { padding: 1.25rem; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0e1114;
    --surface: #171c20;
    --surface-strong: #1c2227;
    --ink: #ebe8df;
    --muted: #a7abad;
    --accent: #ed695e;
    --rule: #383f44;
    --shadow: 0 18px 55px rgba(0, 0, 0, .3);
  }
  .rating-button.is-selected, .danger-button { color: #fff; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
