:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Noto Sans SC", "Microsoft YaHei", sans-serif;
  color: #20242a;
  background: #f3f1ec;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.appShell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar,
.phaseStrip,
.panel,
.loginPanel,
.setupPanel {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid #ddd7cd;
  border-radius: 8px;
  box-shadow: 0 16px 50px rgba(36, 39, 43, 0.08);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px;
}

.eyebrow {
  margin: 0 0 6px;
  color: #7d2b36;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

h3 {
  margin: 18px 0 10px;
  font-size: 15px;
}

.topbarActions,
.buttonRow,
.inlineForm,
.formRow,
.toggleRow,
.foreignRow {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.countryGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.countryCard {
  display: grid;
  grid-template-columns: 48px 1fr;
  grid-template-rows: auto auto;
  align-items: center;
  gap: 4px 10px;
  min-height: 70px;
  padding: 8px;
  border: 1px solid #d8d1c7;
  border-radius: 6px;
  color: #30363d;
  background: #fbfaf7;
  text-align: left;
}

.countryCard.active {
  border-color: #274c77;
  box-shadow: 0 0 0 2px rgba(39, 76, 119, 0.14);
}

.countryCard img {
  grid-row: 1 / 3;
  width: 48px;
  height: 32px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.countryCard strong {
  font-size: 14px;
}

.countryCard span {
  color: #7d2b36;
  font-size: 12px;
  font-weight: 800;
}

.intelPanel {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 14px;
  padding: 12px;
  border: 1px solid #d8d1c7;
  border-radius: 6px;
  background: #fbfaf7;
}

.intelPanel img {
  width: 130px;
  height: 86px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.intelPanel h3 {
  margin-top: 0;
}

.intelPanel strong {
  display: block;
  margin-bottom: 8px;
  color: #274c77;
}

.intelPanel p {
  margin-bottom: 8px;
  line-height: 1.6;
  color: #48515a;
}

.primaryButton,
.ghostButton,
.dangerButton,
.iconButton,
.tab,
.voteRow button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 0 14px;
  font-weight: 700;
}

.primaryButton {
  color: #fff;
  background: #274c77;
  border-color: #274c77;
}

.ghostButton,
.iconButton,
.voteRow button {
  color: #30363d;
  background: #f8f6f1;
  border-color: #d6d0c6;
}

.dangerButton {
  color: #9b2332;
  background: #f8e7ea;
  border-color: #e4b7bf;
}

.iconButton {
  width: 40px;
  padding: 0;
}

.phaseStrip {
  margin-top: 14px;
  padding: 16px 18px;
}

.phaseStrip > div:first-child {
  display: flex;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 12px;
}

.phaseStrip strong {
  color: #274c77;
  font-size: 18px;
}

.patienceStrip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.patienceMeter {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #d8d1c7;
  border-radius: 6px;
  background: #fbfaf7;
}

.patienceMeter span {
  color: #69727c;
  font-size: 12px;
  font-weight: 800;
}

.patienceMeter strong {
  color: #7d2b36;
  font-size: 16px;
}

.patienceMeter i {
  display: block;
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #ead7db;
}

.patienceMeter em {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #9b2332;
}

.phaseSteps {
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 8px;
}

.phaseStep {
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 1px solid #d7d0c4;
  border-radius: 6px;
  color: #626970;
  font-size: 13px;
  text-align: center;
  background: #fbfaf7;
}

.phaseStep.active {
  color: #fff;
  background: #7d2b36;
  border-color: #7d2b36;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 16px 0;
  overflow-x: auto;
}

.tab {
  color: #333941;
  background: #ebe7de;
  border-color: #d7d0c4;
  white-space: nowrap;
}

.tab.active {
  color: #fff;
  background: #30363d;
  border-color: #30363d;
}

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

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.characterList {
  margin-top: 16px;
}

.panel {
  padding: 18px;
  min-width: 0;
}

.panel.wide {
  grid-column: 1 / -1;
}

.panelHeader {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panelHeader p {
  margin-bottom: 0;
  color: #69727c;
}

.cardActions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.scorePill,
.quota {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #274c77;
  background: #e5edf4;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.scorePill.good {
  color: #1f6b45;
  background: #dff0e6;
}

.scorePill.danger {
  color: #9b2332;
  background: #f2dde2;
}

.statGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.statGrid.compact {
  grid-template-columns: repeat(4, minmax(80px, 1fr));
}

.statInputGrid {
  display: grid;
  grid-template-columns: repeat(4, minmax(90px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric {
  min-height: 66px;
  padding: 10px;
  border: 1px solid #ded8cd;
  border-radius: 6px;
  background: #fbfaf7;
}

.metric span {
  display: block;
  color: #707881;
  font-size: 12px;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 18px;
}

.legitimacyLedger {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.ledgerRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid #e2dcd2;
  border-radius: 6px;
  color: #4b545d;
  background: #f7f4ee;
  font-size: 12px;
  font-weight: 700;
}

.ledgerRow strong {
  color: #5c6470;
  white-space: nowrap;
}

.ledgerRow.positive strong {
  color: #1f6b45;
}

.ledgerRow.negative strong {
  color: #9b2332;
}

.policyList,
.factionList,
.positionList,
.actionStack,
.parliamentStack {
  display: grid;
  gap: 10px;
}

.policyRow,
.factionRow,
.positionRow,
.voteRow {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(120px, 1.3fr);
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #ded8cd;
  border-radius: 6px;
  background: #fbfaf7;
}

.policyRow {
  display: block;
}

.policyRow summary {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) minmax(120px, 1.3fr);
  align-items: center;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

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

.policyRow summary::before {
  content: "▸";
  color: #69727c;
  font-weight: 900;
}

.policyRow[open] summary::before {
  content: "▾";
}

.policyRow summary {
  grid-template-columns: 18px minmax(110px, 1fr) minmax(120px, 1.3fr);
}

.policyOptions {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e2dcd2;
}

.policyEditor {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.policyEditor button {
  min-height: 36px;
  white-space: nowrap;
}

.policyOption {
  display: grid;
  grid-template-columns: minmax(120px, 0.8fr) minmax(180px, 1.6fr);
  gap: 10px;
  align-items: start;
  padding: 8px;
  border-radius: 6px;
  background: #f4f1ea;
}

.policyOption.current {
  background: #e5edf4;
}

.policyOption span {
  color: #59636d;
  line-height: 1.45;
}

.factionRow {
  grid-template-columns: 14px 1fr 70px 70px;
}

.positionRow.vacant span {
  color: #8c6a2e;
  font-weight: 800;
}

.positionHolders {
  display: grid;
  gap: 6px;
}

.positionHolder {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.dangerMini {
  width: 28px;
  min-height: 28px;
  color: #9b2332;
  background: #f8e7ea;
  border-color: #e4b7bf;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 4px;
}

.moodGrid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.moodEditor {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.moodEditor label {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 5px 8px;
  align-items: center;
  margin: 0;
  padding: 8px;
  border: 1px solid #ded8cd;
  border-radius: 6px;
  background: #fbfaf7;
}

.moodEditor span {
  font-size: 12px;
}

.moodEditor small {
  grid-column: 1 / -1;
  color: #69727c;
}

.mood,
.tagBlock b {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  color: #46505a;
  background: #ece8df;
}

.mood.low {
  color: #9b2332;
  background: #f3dfe2;
}

.mood.high {
  color: #1f6b45;
  background: #ddf0e4;
}

label {
  display: grid;
  gap: 7px;
  color: #48515a;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 12px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfc7bb;
  border-radius: 6px;
  background: #fff;
  color: #20242a;
  padding: 9px 10px;
}

textarea {
  min-height: 105px;
  resize: vertical;
}

.formRow > label {
  flex: 1 1 180px;
}

.toggleRow label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.toggleRow input {
  width: auto;
}

.characterForm {
  display: grid;
  gap: 4px;
}

.sheetMeters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: -2px 0 12px;
}

.sheetMeters span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: #46505a;
  background: #ece8df;
  font-size: 12px;
  font-weight: 800;
}

.sheetMeters span.good {
  color: #1f6b45;
  background: #ddf0e4;
}

.sheetMeters span.bad {
  color: #9b2332;
  background: #f3dfe2;
}

.checkLine {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin-bottom: 6px;
  font-weight: 700;
}

.checkLine input {
  width: auto;
}

.traitColumns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 10px;
}

.notice,
.errorBox,
.resultBox {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
  line-height: 1.55;
}

.notice {
  color: #5a4c20;
  background: #f6edcd;
}

.errorBox {
  color: #8a1d2b;
  background: #f2dde2;
}

.resultBox {
  color: #204d35;
  background: #e0efe6;
}

.resultBox {
  display: grid;
  gap: 4px;
}

.resultBox strong {
  font-size: 12px;
}

.resultBox.private {
  color: #4d3e73;
  background: #e8e2f3;
}

.story {
  color: #555e67;
  line-height: 1.65;
}

.tagBlock {
  margin: 12px 0;
}

.tagBlock > span {
  display: block;
  margin-bottom: 8px;
  color: #6b737c;
  font-size: 12px;
  font-weight: 800;
}

.tagBlock > div,
.retainerGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.retainerCard {
  display: grid;
  gap: 5px;
  width: min(220px, 100%);
  min-height: 112px;
  padding: 12px;
  border: 1px solid #d8d1c7;
  border-radius: 6px;
  background: #f9f7f1;
}

.peoplePanel {
  background: #ebe6dc;
}

.peopleSection {
  margin-top: 18px;
}

.peopleSection h3 {
  margin: 0 0 10px;
  color: #7d2b36;
  font-size: 16px;
}

.peopleGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.personCard {
  display: grid;
  grid-template-columns: 132px 1fr;
  min-height: 198px;
  border: 1px solid #cfc7bb;
  border-radius: 6px;
  overflow: hidden;
  background: #fbfaf7;
  box-shadow: inset 5px 0 0 #7d2b36;
}

.personCard img {
  width: 132px;
  height: 198px;
  object-fit: cover;
  background: #d7d0c4;
}

.personCard > div {
  padding: 12px 14px;
}

.personCard span {
  color: #7d2b36;
  font-size: 12px;
  font-weight: 900;
}

.personCard h4 {
  margin: 4px 0 9px;
  color: #20242a;
  font-size: 18px;
}

.personCard p {
  margin-bottom: 7px;
  color: #4b545d;
  line-height: 1.55;
}

.retainerCard span,
.retainerCard small,
.actionCard span {
  color: #68717a;
}

.actionCard {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #d8d1c7;
  border-radius: 6px;
  background: #fbfaf7;
}

.actionHeader {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.actionHeader > div {
  display: grid;
  gap: 3px;
}

.actionCard p {
  margin-bottom: 0;
  color: #3b424a;
  line-height: 1.55;
  white-space: pre-wrap;
}

.inlineForm {
  margin-bottom: 14px;
}

.inlineForm input,
.inlineForm select {
  flex: 1 1 220px;
}

.voteTable {
  display: grid;
  gap: 8px;
}

.parliamentActions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.voteRow {
  grid-template-columns: minmax(140px, 0.8fr) 70px repeat(3, minmax(150px, 1fr));
}

.voteControl {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 6px 8px;
  align-items: center;
  margin: 0;
}

.voteControl span {
  grid-column: 1 / -1;
  color: #48515a;
  font-size: 12px;
  font-weight: 800;
}

.voteControl input[type="range"] {
  padding: 0;
}

.voteControl input[type="number"] {
  padding: 6px 8px;
}

.parliamentCard {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #d8d1c7;
  border-radius: 8px;
  background: #fbfaf7;
}

.recessCard {
  min-height: 160px;
  place-items: center;
  text-align: center;
  color: #5c6470;
}

.recessCard h3 {
  margin: 0;
  color: #30363d;
  font-size: 24px;
}

.dmEditor {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e2dcd2;
}

.dmEditor summary {
  cursor: pointer;
  color: #274c77;
  font-weight: 900;
}

.dmEditor form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.parliamentHeader {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.parliamentHeader h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.parliamentHeader span {
  color: #69727c;
}

.voteTotals {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.voteTotals b {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
}

.voteTotals .yes {
  color: #1f6b45;
  background: #dff0e6;
}

.voteTotals .no {
  color: #9b2332;
  background: #f2dde2;
}

.voteTotals .abstain {
  color: #5c6470;
  background: #ece8df;
}

.chamber {
  position: relative;
  width: min(720px, 100%);
  aspect-ratio: 2 / 1;
  margin: 0 auto;
  border-bottom: 1px solid #d8d1c7;
}

.seatDot {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 1px 4px rgba(32, 36, 42, 0.18);
}

.seatDot.no {
  outline: 2px solid #9b2332;
}

.seatDot.abstain {
  opacity: 0.45;
}

.seatDot.neutral {
  opacity: 0.72;
}

.voteLegend {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

.voteLegend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #48515a;
  font-size: 12px;
  font-weight: 800;
}

.voteLegend i {
  width: 12px;
  height: 12px;
  border-radius: 4px;
}

.loginPanel,
.setupPanel {
  width: min(460px, calc(100vw - 32px));
  margin: 10vh auto 0;
  padding: 24px;
}

.setupPanel code {
  display: block;
  margin-top: 10px;
  padding: 10px;
  border-radius: 6px;
  background: #24282f;
  color: #f8f6f1;
}

.loading {
  padding: 40px;
  text-align: center;
}

@media (max-width: 980px) {
  .grid.two,
  .phaseSteps {
    grid-template-columns: 1fr;
  }

  .phaseSteps {
    display: flex;
    overflow-x: auto;
  }

  .patienceStrip {
    grid-template-columns: 1fr;
  }

  .phaseStep {
    min-width: 138px;
  }

  .statGrid,
  .statGrid.compact,
  .statInputGrid,
  .legitimacyLedger,
  .moodEditor {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .traitColumns {
    grid-template-columns: 1fr;
  }

  .countryGrid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .peopleGrid {
    grid-template-columns: 1fr;
  }

  .intelPanel {
    grid-template-columns: 1fr;
  }

  .voteRow {
    grid-template-columns: 1fr 1fr;
  }

  .voteControl {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .appShell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 24px;
  }

  .statGrid,
  .statGrid.compact,
  .statInputGrid,
  .legitimacyLedger,
  .moodEditor {
    grid-template-columns: 1fr;
  }

  .policyRow,
  .factionRow,
  .positionRow {
    grid-template-columns: 1fr;
  }

  .policyRow summary,
  .policyEditor,
  .policyOption {
    grid-template-columns: 1fr;
  }

  .countryGrid {
    grid-template-columns: 1fr;
  }

  .personCard {
    grid-template-columns: 92px 1fr;
    min-height: 138px;
  }

  .personCard img {
    width: 92px;
    height: 138px;
  }
}
