:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --border: #d9deea;
  --text: #1b2236;
  --muted: #5b6479;
  --brand: #1f3a8a;
  --brand-hover: #182f73;
  --brand-contrast: #ffffff;
  --accent: #a87b1c;
  --ok: #1d7a3a;
  --ok-bg: #e3f4e8;
  --live: #1f5fbf;
  --live-bg: #e3edfc;
  --warn: #8a5a00;
  --warn-bg: #fdf1dc;
  --bad: #b3261e;
  --bad-bg: #fbe5e3;
  --focus: #2563eb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1220;
    --surface: #161b2c;
    --surface-2: #1d2338;
    --border: #2a3250;
    --text: #e7eaf3;
    --muted: #a0a8bc;
    --brand: #8ea6ff;
    --brand-hover: #a9bbff;
    --brand-contrast: #0e1220;
    --accent: #e3b85a;
    --ok: #6fd28c;
    --ok-bg: #173424;
    --live: #8eb4ff;
    --live-bg: #1b2a4d;
    --warn: #f3bf5b;
    --warn-bg: #3a2c12;
    --bad: #ff8a80;
    --bad-bg: #3d1c1c;
    --focus: #8ea6ff;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--brand);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

h1,
h2,
h3 {
  line-height: 1.3;
  margin: 0 0 0.5rem;
}

h1 {
  font-size: 1.6rem;
}

h2 {
  font-size: 1.2rem;
}

h3 {
  font-size: 1.05rem;
}

p {
  margin: 0.4rem 0;
}

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.person {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.person-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 14ch;
}

.avatar {
  border-radius: 50%;
  flex: none;
  background: var(--surface-2);
  object-fit: cover;
}

.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--live-bg);
  color: var(--live);
  font-weight: 700;
  line-height: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand);
  color: var(--brand-contrast);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.card-head h2,
.card-head h3 {
  margin: 0;
  margin-right: auto;
}

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-link:hover {
  border-color: var(--brand);
}

.card-title {
  font-weight: 700;
  font-size: 1.1rem;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid-cards {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

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

.small {
  font-size: 0.85rem;
}

.rich {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* {`裁判官`}: roles are written as inline code wrapped in braces, as in the bot's Discord messages. */
.role-tag {
  font-weight: 600;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.role-tag code,
.rich code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Noto Sans Mono CJK JP", monospace;
  font-size: 0.9em;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.05em 0.35em;
  margin: 0 0.1em;
}

.brand .role-tag {
  color: var(--text);
}

.chip {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}

.chip-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.chip-live {
  background: var(--live-bg);
  color: var(--live);
}

.chip-warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.chip-bad {
  background: var(--bad-bg);
  color: var(--bad);
}

.notice {
  border-radius: 10px;
  padding: 10px 14px;
  margin: 10px 0;
  background: var(--live-bg);
  color: var(--text);
}

.notice-ok {
  background: var(--ok-bg);
}

.notice-warn {
  background: var(--warn-bg);
}

.notice-bad {
  background: var(--bad-bg);
}

.loading,
.empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 12px;
}

/* Hero */
.hero {
  text-align: center;
  padding: 48px 12px 24px;
}

.hero h1 {
  font-size: clamp(1.6rem, 5vw, 2.4rem);
}

.hero p {
  color: var(--muted);
  max-width: 40rem;
  margin: 0.8rem auto 1.4rem;
}

.features {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  margin-top: 28px;
  text-align: left;
}

/* Guild */
.guild-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 14px;
  margin-bottom: 10px;
}

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
  scrollbar-width: thin;
}

.tab {
  padding: 10px 14px;
  color: var(--muted);
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  font-weight: 600;
}

.tab:hover {
  color: var(--text);
}

.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.factions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
  align-items: start;
}

.faction-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  margin: 0 0 8px;
}

.faction-title::before {
  content: "";
  width: 6px;
  height: 1.1em;
  border-radius: 3px;
  background: var(--faction-color, var(--brand));
}

.faction-admin {
  --faction-color: var(--accent);
}

.faction-representative {
  --faction-color: #2e9d57;
}

.faction-neutral {
  --faction-color: #1a9c8c;
}

.branch {
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 14px 0 6px;
  font-weight: 700;
}

.office {
  padding: 8px 0;
  border-top: 1px solid var(--border);
}

.office:first-of-type {
  border-top: 0;
}

.office-label {
  font-weight: 600;
  display: flex;
  gap: 6px;
  align-items: center;
}

.holders {
  list-style: none;
  padding: 0;
  margin: 6px 0 0;
  display: grid;
  gap: 6px;
}

.holder {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
}

.holder.me .holder-name::after {
  content: "（あなた）";
  color: var(--accent);
  font-size: 0.85rem;
}

.vacant {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.catalog {
  margin-top: 8px;
}

.catalog summary {
  cursor: pointer;
  font-weight: 700;
}

.catalog ol {
  padding-left: 1.3rem;
}

.catalog li {
  margin: 10px 0;
}

/* Election */
.timeline {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0;
  margin: 12px 0;
}

.timeline li {
  border-top: 4px solid var(--border);
  padding-top: 6px;
  font-size: 0.9rem;
}

.timeline li.done {
  border-top-color: var(--brand);
}

.timeline li.current {
  border-top-color: var(--accent);
}

.timeline strong {
  display: block;
}

.candidates {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  margin: 12px 0;
}

.candidate {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  padding: 12px;
  border-radius: 10px;
  border: 2px solid var(--border);
  background: var(--surface);
  color: inherit;
  font: inherit;
}

button.candidate {
  cursor: pointer;
}

button.candidate:hover {
  border-color: var(--brand);
}

.candidate[aria-checked="true"] {
  border-color: var(--brand);
  background: var(--live-bg);
}

.candidate-name {
  font-weight: 700;
}

.vote-actions {
  display: flex;
  justify-content: flex-end;
}

.confirm {
  margin-top: 12px;
  padding: 14px;
  border-radius: 10px;
  background: var(--warn-bg);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.results {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: grid;
  gap: 8px;
}

.result {
  display: grid;
  grid-template-columns: auto minmax(6rem, 10rem) 1fr auto auto;
  grid-template-areas: "avatar name bar votes badge";
  align-items: center;
  gap: 10px;
}

.result > .avatar {
  grid-area: avatar;
}

.result > .bar {
  grid-area: bar;
}

.result-name {
  grid-area: name;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-votes {
  grid-area: votes;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.result-badge {
  grid-area: badge;
  justify-self: end;
}

.bar {
  display: block;
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  min-width: 40px;
}

.bar-fill {
  display: block;
  height: 100%;
  background: var(--brand);
  border-radius: 999px;
}

.bar-fill.against {
  background: var(--bad);
}

.bar-fill.abstain {
  background: var(--muted);
}

.result.elected .bar-fill {
  background: var(--accent);
}

/* Lists with expandable details (bills, cases) */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.filter {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 4px 14px;
  font: inherit;
  cursor: pointer;
}

.filter[aria-pressed="true"] {
  background: var(--brand);
  color: var(--brand-contrast);
  border-color: var(--brand);
}

details.item {
  padding: 0;
}

details.item > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
}

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

details.item[open] > summary {
  border-bottom: 1px solid var(--border);
}

.item-body {
  padding: 12px 16px 16px;
}

.item-title {
  font-weight: 700;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.88rem;
  color: var(--muted);
  margin-top: 4px;
}

.tally {
  display: grid;
  grid-template-columns: 4rem 1fr 3rem;
  gap: 6px 10px;
  align-items: center;
  margin: 10px 0;
}

.voters {
  display: grid;
  gap: 4px;
  font-size: 0.92rem;
}

.section-label {
  font-weight: 700;
  margin-top: 12px;
}

/* Petitions */
.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.progress .bar {
  flex: 1;
  height: 12px;
}

/* Gazette */
.entry-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 0.85rem;
  color: var(--muted);
}

.entry-number {
  font-weight: 700;
  color: var(--text);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  max-width: calc(100% - 32px);
}

@media (max-width: 560px) {
  .timeline {
    grid-template-columns: 1fr;
  }

  .result {
    grid-template-columns: auto 1fr auto auto;
    grid-template-areas:
      "avatar name votes badge"
      "bar bar bar bar";
    row-gap: 4px;
  }

  .tabs {
    gap: 0;
  }

  .tab {
    padding: 8px 10px;
  }

  .person-name {
    display: none;
  }
}
