:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #10141b;
  --panel: #1a2230;
  --panel-2: #222d3e;
  --line: #34445b;
  --text: #eef4fb;
  --muted: #a7b4c6;
  --gold: #f0c867;
  --danger: #ff9a9a;
  --good: #92ddb8;
  --accent: #9fc3ff;
  --noble: #f0c867;
  --religious: #8fc6ff;
  --trade: #8ed2a5;
  --military: #e98686;
  --unique: #c79bef;
}
* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at top, #202a3a 0, var(--bg) 42rem); color: var(--text); min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.app-shell { max-width: 1120px; margin: 0 auto; padding: 24px 16px 96px; }
.topbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.brand h1, h2, h3, p { margin-top: 0; }
.brand h1 { margin-bottom: 2px; font-size: clamp(1.6rem, 6vw, 2.5rem); letter-spacing: .02em; }
.eyebrow { text-transform: uppercase; letter-spacing: .15em; font-size: .72rem; color: var(--muted); margin-bottom: 6px; }
.muted { color: var(--muted); }
.code-badge { font-variant-numeric: tabular-nums; letter-spacing: .15em; color: var(--gold); border: 1px solid #725f35; background: #2b2618; border-radius: 999px; padding: 8px 12px; font-weight: 800; }
.panel { background: color-mix(in srgb, var(--panel) 94%, transparent); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: 0 18px 50px #0005; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.stack { display: grid; gap: 12px; }
.hero { max-width: 720px; margin: 8vh auto 0; }
.hero .panel { padding: 22px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: .88rem; }
input, select { width: 100%; border: 1px solid #53657d; border-radius: 10px; background: #0f1824; color: var(--text); padding: 12px; min-height: 44px; }
button { border: 1px solid transparent; border-radius: 10px; padding: 11px 14px; background: var(--accent); color: #11243f; font-weight: 800; min-height: 44px; }
button.secondary { background: #27374c; border-color: #455a76; color: var(--text); }
button.ghost { background: transparent; border-color: #455a76; color: var(--text); }
button.danger { background: #522a32; color: #ffd7dd; border-color: #8a4856; }
button:disabled { opacity: .45; cursor: not-allowed; }
:focus-visible { outline: 3px solid #d6e5ff; outline-offset: 3px; }
.lobby-list, .score-list { display: grid; gap: 8px; }
.player-row { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 10px 12px; background: #121b27; border: 1px solid #2f4057; border-radius: 11px; }
.player-row .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; border: 1px solid #42546d; padding: 4px 8px; color: var(--muted); font-size: .76rem; }
.badge.crown { color: var(--gold); border-color: #766438; background: #2c2719; }
.role-card { position: sticky; top: 8px; z-index: 4; border-color: #657794; background: linear-gradient(135deg, #253247, #192230); }
.role-rank { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 50%; background: #0f1722; border: 1px solid #667a98; font-weight: 900; }
.role-title { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.role-title h2 { margin: 0; }
.status-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; border-left: 4px solid var(--gold); }
.table-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.player-card { position: relative; min-height: 165px; }
.player-card.active { border-color: var(--gold); box-shadow: 0 0 0 1px #8f7130 inset, 0 18px 50px #0005; }
.player-card.me { background: #202c3c; }
.player-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.player-name { font-weight: 900; font-size: 1.05rem; }
.gold-line { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-weight: 900; color: var(--gold); font-size: 1.1rem; }
.gold-controls { display: flex; gap: 5px; flex-wrap: wrap; }
.gold-controls button { min-height: 34px; padding: 5px 8px; font-size: .78rem; }
.districts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.district { display: inline-flex; align-items: center; gap: 5px; background: #111926; border: 1px solid #3a4b62; border-radius: 999px; padding: 5px 8px; max-width: 100%; }
.district .type-dot { width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; color: #10141b; font-size: .65rem; font-weight: 1000; flex: 0 0 auto; }
.type-noble { background: var(--noble); }.type-religious { background: var(--religious); }.type-trade { background: var(--trade); }.type-military { background: var(--military); }.type-unique { background: var(--unique); }
.district .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.district .cost { color: var(--gold); font-weight: 900; }
.district button { min-height: 24px; padding: 0 4px; border: 0; background: transparent; color: var(--danger); }
.draft-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.character-option { text-align: left; background: #1c2d43; color: var(--text); border: 1px solid #4b6688; padding: 14px; }
.character-option strong { display: block; font-size: 1rem; margin-bottom: 6px; }
.character-option small { color: #c6d2df; line-height: 1.35; display: block; }
.face-up { display: flex; gap: 8px; flex-wrap: wrap; }
.face-up .badge { color: #d7e0ec; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.build-form { display: grid; grid-template-columns: 2fr 1fr 100px auto; gap: 8px; align-items: end; }
.help-button { position: fixed; right: max(18px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 10; width: 54px; height: 54px; border-radius: 50%; background: var(--gold); color: #261d09; box-shadow: 0 8px 24px #0007; font-size: 1.25rem; }
.hidden { display: none !important; }
.help-dialog { width: min(720px, calc(100% - 24px)); max-height: 82vh; border: 1px solid #5c718f; border-radius: 16px; background: #151e2b; color: var(--text); padding: 0; }
.help-dialog::backdrop { background: #000b; }
.dialog-head { position: sticky; top: 0; background: #151e2bf2; backdrop-filter: blur(10px); display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid #33445b; }
.dialog-head h2 { margin: 0; }.icon-button { width: 40px; min-height: 40px; padding: 0; border-radius: 50%; background: #26364a; color: var(--text); font-size: 1.5rem; }
.help-list { display: grid; gap: 10px; padding: 16px; }
.help-item { border: 1px solid #34465d; border-radius: 12px; padding: 12px; background: #111925; }
.help-item .rank { color: var(--gold); font-weight: 900; margin-right: 6px; }
.help-item p { color: #c6d1df; line-height: 1.5; margin: 8px 0 0; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none; background: #0d141e; border: 1px solid #556b88; color: var(--text); border-radius: 10px; padding: 10px 14px; transition: .18s ease; z-index: 30; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.score-line { display: grid; grid-template-columns: minmax(120px, 1fr) repeat(5, auto); gap: 8px; align-items: center; }
.score-line strong { font-size: 1.08rem; }
.score-number { min-width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.winner { border-color: var(--gold); background: #2b2618; }
.notice { color: #ffd8a1; }
@media (max-width: 720px) {
  .grid-2 { grid-template-columns: 1fr; }
  .build-form { grid-template-columns: 1fr 1fr; }
  .build-form label:first-child { grid-column: 1 / -1; }
  .build-form button { grid-column: 1 / -1; }
  .score-line { grid-template-columns: 1fr repeat(2, auto); }
  .score-line .optional { display: none; }
}


/* Interactive district hand + character actions */
.topbar-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head h2 { margin-bottom: 0; }
.hand-panel { border-color: #4a5f7d; }
.hand-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.district-card { display: grid; gap: 10px; padding: 12px; border: 1px solid #415570; border-radius: 13px; background: #111a27; min-width: 0; }
.district-card-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 9px; align-items: center; }
.district-card-head strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-type { display: block; color: var(--muted); font-size: .76rem; margin-top: 2px; }
.card-cost { color: var(--gold); font-weight: 900; white-space: nowrap; }
.card-cost s { color: var(--muted); font-weight: 600; }
.card-effect { color: #c7d2e0; font-size: .86rem; line-height: 1.4; margin: 0; }
.card-check { display: flex; grid-template-columns: auto 1fr; align-items: center; gap: 8px; color: var(--text); }
.card-check input { width: 20px; min-height: 20px; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.action-panel, .ability-panel { border-color: #506887; }
.compact-panel { padding: 10px 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.good { color: var(--good); border-color: #43735e; }
.danger-badge { color: #ffd2d2; border-color: #8a4856; background: #402128; }
.announcements { border-left: 4px solid var(--danger); }
.divider { height: 1px; background: var(--line); margin: 2px 0; }
.target-list { display: grid; gap: 8px; }
.target-district { display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
.nested-hand { padding: 0; }
.nested-hand .section-head { display: none; }
.nested-hand .hand-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

@media (max-width: 720px) {
  .topbar { align-items: flex-start; }
  .topbar-meta { max-width: 48%; }
  .choice-grid { grid-template-columns: 1fr; }
  .hand-grid { grid-template-columns: 1fr; }
  .district-card { padding: 11px; }
}


/* Compact hand rows and session controls */
.mini-action { min-height: 34px; padding: 6px 9px; font-size: .76rem; }
.hand-list { display: grid; gap: 7px; }
.district-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 9px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid #3b4f69;
  border-radius: 11px;
  background: #111a27;
}
.district-row .type-dot {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: inline-grid;
  place-items: center;
  color: #10141b;
  font-size: .68rem;
  font-weight: 1000;
}
.district-row-main { min-width: 0; display: grid; gap: 4px; }
.district-row-title { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; min-width: 0; }
.district-row-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-cost { color: var(--gold); font-weight: 900; white-space: nowrap; }
.row-cost s { color: var(--muted); font-weight: 600; }
.row-effect { color: #c7d2e0; font-size: .82rem; line-height: 1.35; }
.row-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.row-actions button { min-height: 34px; padding: 6px 9px; font-size: .78rem; }
.compact-check { display: flex; grid-template-columns: auto auto; align-items: center; gap: 5px; }
.compact-check input { width: 18px; min-height: 18px; }
.district-ability-list { display: grid; gap: 8px; }
.district-ability-row {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 9px 10px;
  border: 1px solid #394d66;
  border-radius: 10px;
  background: #121b27;
}
.inline-control { display: flex; gap: 7px; align-items: center; }
.inline-control select { min-width: 180px; min-height: 38px; padding: 7px 9px; }
.inline-control button, .district-ability-row > button { min-height: 38px; padding: 7px 10px; }
.small-text { font-size: .78rem; margin-top: 3px; }

@media (max-width: 720px) {
  .topbar-meta { max-width: none; width: 100%; justify-content: flex-start; }
  .topbar { flex-wrap: wrap; }
  .district-row { grid-template-columns: auto minmax(0, 1fr); }
  .row-actions { grid-column: 1 / -1; justify-content: stretch; }
  .row-actions button { flex: 1 1 auto; }
  .district-ability-row { align-items: stretch; flex-direction: column; }
  .inline-control { align-items: stretch; flex-direction: column; }
  .inline-control select { min-width: 0; width: 100%; }
}


/* Lobby setup, bots and full rules */
.bot-badge { color: var(--accent); border-color: #4b6688; }
.lobby-settings { margin-top: 14px; }
.inline-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline-form label { min-width: 180px; flex: 1; }
.unique-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}
.unique-option {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111925;
  color: var(--text);
}
.unique-option input { width: 18px; min-height: 18px; margin-top: 2px; }
.unique-option span { min-width: 0; }
.unique-option strong { display: block; color: var(--text); }
.unique-option small { display: block; color: var(--muted); line-height: 1.35; margin-top: 3px; }
.unique-option:has(input:checked) { border-color: #537d69; background: #14241e; }
.rules-section { border: 1px solid #34465d; border-radius: 12px; background: #111925; overflow: hidden; }
.rules-section summary { cursor: pointer; padding: 13px; font-weight: 900; user-select: none; }
.rules-body { padding: 0 13px 13px; line-height: 1.55; color: #d7e0ec; }
.rules-body p:last-child, .rules-body ol:last-child { margin-bottom: 0; }
.rules-body ol { padding-left: 22px; }
.help-card-grid { display: grid; gap: 8px; margin-top: 10px; }
.selected-help { border-color: #43735e; background: #14241e; }
.face-up-panel { margin-bottom: 12px; }

@media (max-width: 720px) {
  .unique-config-grid { grid-template-columns: 1fr; max-height: 380px; }
  .inline-form { align-items: stretch; flex-direction: column; }
  .inline-form label { min-width: 0; width: 100%; }
  .help-dialog { max-height: 90vh; }
}


/* Bot action feed and clearer admin controls */
.gold-admin { display: grid; gap: 4px; margin-top: 4px; }
.bot-action-panel {
  margin: 12px 0;
  display: grid;
  gap: 8px;
}
.bot-action-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: .82rem;
}
.bot-action-title span { color: var(--text); font-weight: 900; }
.bot-action-list { display: grid; gap: 7px; }
.bot-action-bubble {
  max-width: 760px;
  border: 1px solid #405672;
  border-radius: 16px 16px 16px 5px;
  background: #152235;
  padding: 10px 12px;
  box-shadow: 0 8px 24px #0003;
}
.bot-action-bubble.latest {
  border-color: #6385ad;
  background: #192a40;
}
.bot-action-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 5px;
}
.bot-action-head strong { color: var(--accent); }
.bot-action-head span { color: var(--muted); font-size: .72rem; white-space: nowrap; }
.bot-action-bubble ul { margin: 0; padding-left: 19px; color: #d5dfec; line-height: 1.45; }
.bot-action-bubble li + li { margin-top: 2px; }

@media (max-width: 720px) {
  .bot-action-bubble { max-width: 100%; }
  .gold-controls button { flex: 1 1 auto; }
}

.score-note { display: block; margin-top: 3px; color: var(--muted); font-size: .72rem; }


/* Lobby strategy controls and unique-district validation */
.lobby-player-row > div:first-child { min-width: 0; }
.bot-strategy-control {
  display: grid;
  gap: 4px;
  margin-top: 8px;
  max-width: 280px;
  color: var(--muted);
  font-size: .76rem;
}
.bot-strategy-control select { width: 100%; min-height: 40px; }
.unique-shortcuts { margin-bottom: 2px; }
.selection-notice {
  border: 1px solid #455a76;
  border-radius: 10px;
  padding: 9px 11px;
  background: #111925;
  font-size: .84rem;
}
.good-text { color: #a8dfbf; border-color: #3f6d56; background: #12231b; }
#unique-count.danger-badge { color: #ffc2cb; border-color: #8a4856; background: #2b171c; }

@media (max-width: 720px) {
  .lobby-player-row { align-items: stretch; flex-direction: column; }
  .lobby-player-row > .actions { justify-content: flex-end; }
  .bot-strategy-control { max-width: none; }
  .unique-shortcuts button { flex: 1 1 100%; }
}


/* Character variant configuration */
.character-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px;
}
.character-config-row {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #111925;
}
.character-config-row > span { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.character-config-row select { width: 100%; min-height: 42px; }

@media (max-width: 720px) {
  .character-config-grid { grid-template-columns: 1fr; }
}

.compact-check-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px;
  padding: 8px 0;
}


.dual-role-card {
  gap: 12px;
}

.owned-role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.owned-role-chip {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
}

.owned-role-chip.active {
  outline: 2px solid currentColor;
}

.owned-role-chip .role-rank {
  flex: 0 0 auto;
}

.owned-role-chip strong,
.owned-role-chip small {
  display: block;
}

.owned-role-chip small {
  margin-top: 4px;
  opacity: 0.8;
  line-height: 1.3;
}


/* Progress and last-round status are intentionally visible while playing. */
.city-progress {
  display: grid;
  gap: 8px;
  border-left: 4px solid var(--accent);
}
.city-progress .meta,
.final-round-banner .meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.city-progress p,
.final-round-banner p {
  margin-bottom: 0;
}
.final-round-banner {
  border: 2px solid #b28f48;
  border-left: 5px solid var(--gold);
  background: linear-gradient(135deg, #332d20, #1a2230 65%);
}
.final-round-banner .eyebrow,
.final-round-banner h2 {
  color: var(--gold);
}
.final-round-banner h2 {
  margin-bottom: 0;
}


/* Unread opponent character-turn summaries. */
.activity-dialog {
  width: min(94vw, 570px);
  max-height: min(85vh, 820px);
  overflow-y: auto;
  padding: 22px;
  color: var(--text, #f4f6fa);
  background: var(--surface, #1a2230);
  border: 1px solid var(--border, #657185);
  border-radius: 16px;
  box-shadow: 0 20px 70px #000a;
}
.activity-dialog::backdrop { background: #050a12b8; }
.activity-dialog h2 { margin: 0 0 6px; }
.activity-content { display: grid; gap: 12px; margin: 16px 0; }
.activity-group {
  padding: 14px;
  background: var(--surface-soft, #101824);
  border: 1px solid var(--border, #657185);
  border-radius: 12px;
}
.activity-group h3 { margin: 0 0 10px; font-size: 1.06rem; }
.activity-entry + .activity-entry { border-top: 1px solid var(--border, #657185); padding-top: 12px; margin-top: 12px; }
.activity-entry strong { display: inline-block; margin-right: 8px; }
.activity-entry small { opacity: .75; }
.activity-entry ul { margin: 8px 0 0; padding-left: 21px; }
.activity-entry li + li { margin-top: 5px; }
#activity-ack { width: 100%; min-height: 48px; }
