/* ==========================================================================
   Republic of Rome - client
   Light theme only (dark mode removed until it is designed properly).
   ========================================================================== */

/* ---- Colours ------------------------------------------------------------ */
:root {
    --bg: #e9e4d6;
    --fg: #222222;
    --header-bg: #6b2d2d;
    --header-fg: #ffffff;
    --line: #b8ae94;
    --cell: #f7f3e8;
    --th-bg: #ded7c2;
    --th-fg: #665555;
    --private: #aa6600;
    --good: #176b2a;
    --bad: #aa1111;
}

/* ---- Page --------------------------------------------------------------- */
* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    padding: 12px;
    transition: background 0.25s;
    background: var(--bg);
    color: var(--fg);
    font: 14px/1.4 system-ui, sans-serif;
}

main {
    max-width: 1400px;
    margin: 0 auto;                 /* the content column is centred on the page */
}

h1 {
    margin: 0 0 12px;
    font-size: 22px;
}

h2 {
    margin: 0 0 6px;
    font-size: 15px;
}

button {
    font: inherit;
    padding: 2px 10px;
    cursor: pointer;
}

button.primary {
    padding: 6px 18px;
    background: var(--header-bg);
    border: 1px solid var(--header-bg);
    border-radius: 3px;
    color: var(--header-fg);
    font-weight: 600;
}

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

input[type="text"],
select {
    font: inherit;
    padding: 2px 4px;
}

.muted {
    color: #776;
}

.error {
    min-height: 1.4em;
    font-weight: 600;
    color: var(--bad);
}

.ok {
    color: var(--good);
}

/* ---- Cards and forms ---------------------------------------------------- */
.card {
    margin-bottom: 12px;
    padding: 8px 12px;
    background: var(--cell);
    border: 1px solid var(--line);
}

fieldset {
    margin: 0 0 12px;
    padding: 6px 12px 8px;
    background: var(--cell);
    border: 1px solid var(--line);
}

legend {
    padding: 0 6px;
    font-weight: 600;
}

fieldset label {
    display: block;
    padding: 1px 0;
}

fieldset label .hint {
    margin-left: 6px;
    color: #776;
    font-size: 12px;
}

.columns {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.columns > fieldset {
    flex: 1;
    min-width: 260px;
}

.order-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.order-row label {
    flex: 1;
}

.order-row button {
    padding: 0 6px;
}

/* ---- Link boxes (invite, your URL) -------------------------------------- */
.linkbox {
    display: flex;
    gap: 8px;
    align-items: center;
}

.linkbox input {
    flex: 1;
    padding: 4px 6px;
    font: 13px ui-monospace, monospace;
}

.banner {
    margin-bottom: 12px;
    padding: 8px 12px;
    background: #fff3c4;
    border: 2px solid #c9a227;
}

.banner b {
    color: #7a5b00;
}

/* ---- Top bar ------------------------------------------------------------ */
.top {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.pill {
    padding: 2px 8px;
    border-radius: 10px;
    background: #dddddd;
    font-size: 12px;
}

.pill.on {
    background: #bfe3bf;
}

.pill.off {
    background: #f0c0c0;
}

/* ---- Lobby seat list ---------------------------------------------------- */
table.seats {
    width: 100%;
    border-collapse: collapse;
}

table.seats td {
    padding: 4px 6px;
    border-top: 1px solid var(--line);
}

table.seats tr:first-child td {
    border-top: none;
}

table.seats td.action {
    width: 8em;
    text-align: right;
    white-space: nowrap;
}

table.seats td.action button + button {
    margin-left: 6px;
}

table.seats tr.off {
    background: #ddd5c0;
}

table.seats tr.mine {
    background: #efe6c8;
}

/* ---- Senate: one table per faction -------------------------------------- */
#senate {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 12px;
}

table.faction {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    background: var(--cell);
    border: 1px solid var(--line);
}

table.faction.mine {
    border: 2px solid var(--header-bg);
}

table.faction caption {
    text-align: left;
    padding: 5px 8px;
    background: var(--header-bg);
    color: var(--header-fg);
    font-weight: 600;
}

table.faction caption .right {
    float: right;
    font-weight: 400;
}

table.faction td,
table.faction th {
    padding: 4px 8px;
    border-top: 1px solid var(--line);
    text-align: left;
}

table.faction td {
    color: var(--fg);
}

table.faction th {
    background: var(--th-bg);
    color: var(--th-fg);
    font-weight: 600;
}

table.faction td.empty {
    color: #776;
}

table.faction td.num,
table.faction th.num {
    width: 3.5em;
    text-align: right;
}

table.faction td.nr {
    width: 4em;
    color: #776;
}

table.faction td.matching {
    color: #665555;
    font-size: 12px;
}

/* ---- The frame: shown whenever the game waits for a draw or a decision -- */
.frame {
    border: 2px solid var(--header-bg);
}

.frame-head {
    display: flex;
    gap: 12px;
    align-items: baseline;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.frame-head .who {
    margin-left: auto;
    color: #665555;
}

.tabs button {
    margin-right: 4px;
    background: var(--th-bg);
    border: 1px solid var(--line);
}

.tabs button.active {
    background: var(--header-bg);
    color: var(--header-fg);
}

.control {
    margin: 8px 0;
}

.dragpad {
    padding: 18px 12px;
    text-align: center;
    background: #fff;
    border: 2px dashed var(--header-bg);
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.dragpad.active {
    background: #f3dede;
    cursor: grabbing;
}

table.faction.drop {
    border: 2px dashed var(--good);
}

table.faction.drop caption::after {
    content: "  - drop the card here";
    font-weight: 400;
}

table.pool tr.card-row[draggable="true"] {
    cursor: grab;
}

table.pool tr.card-row[draggable="true"]:hover td {
    background: #efe6c9;
}

/* ---- Log: one compact box, folds inside ---- */
.logbox {
    margin-top: 18px;
    max-height: 260px;
    padding: 4px 6px;
    overflow: auto;
    background: #ffffff;
    border: 1px solid var(--line);
    font: 11px/1.3 ui-monospace, monospace;
}

.logbox details {
    margin: 0;
}

.logbox details details {
    margin-left: 12px;
}

.logbox summary {
    padding: 1px 0;
    cursor: pointer;
    color: #554;
    font-family: inherit;
}

.logbox summary:hover {
    background: #f4efdc;
}

.logbox .count {
    color: #998;
}

.logbox .lines {
    padding-left: 12px;
    border-left: 2px solid #e3dcc2;
    white-space: pre-wrap;
}

.logbox .private,
.hint-private {
    color: var(--private);
}

/* ---- Header title as a button, and the about popup ---- */
.title-button {
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

dialog.about {
    max-width: 520px;
}

dialog.about::backdrop {
    background: rgba(0, 0, 0, 0.35);
}

.options button {
    margin: 4px 4px 0 0;
}

/* ---- Frame (pool) next to the faction tables, so a card can be dragged from one to the other ---- */
.board {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 12px;
}

.board > * {
    flex: 1 1 540px;
    min-width: 0;
}

/* ---- Card ID numbers, drop targets, the Continue row ---- */
.idn {
    display: inline-block;
    min-width: 2em;
    margin-right: 2px;
    color: #776;
    font-size: 11px;
    text-align: right;
}

table.faction td.matching .idn {
    min-width: 0;
}

table.faction.droppable {
    outline: 1px dashed var(--line);
}

table.faction.droppable:hover,
table.pool:hover {
    outline-color: var(--good);
}

.dragpad.off {
    opacity: 0.45;
    cursor: not-allowed;
}

.continue-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 8px 0;
    padding: 6px 8px;
    border: 1px solid var(--line);
    background: #eef3e6;
}

.continue-row.incomplete {
    background: #fbefc9;
    border-color: #c9a227;
}

button.warn {
    background: #e8b923;
    border: 1px solid #a27d00;
    font-weight: 600;
}

dialog {
    border: 2px solid var(--header-bg);
    background: var(--cell);
    max-width: 420px;
}

dialog button {
    margin-right: 8px;
}

.continue-row:not(.incomplete) button {
    background: var(--good);
    color: #ffffff;
    border: 1px solid #0f4a1c;
    font-weight: 600;
}

/* ---- "You act": strong signal, top right, and the whole page changes colour ---- */
body.acting {
    background: #f2c46d;
}

.status-row {
    display: flex;
    gap: 12px;
    align-items: stretch;
    margin-bottom: 12px;
}

.act-badge {
    display: flex;
    align-items: center;
    margin: -8px -12px 8px;             /* the top of the interaction frame: shares its border */
    padding: 4px 18px;
    border: 0;
    border-bottom: 2px solid var(--header-bg);
    background: #b71c1c;
    color: #ffffff;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 2px;
    white-space: nowrap;
}

.state-frame {
    flex: 1;
    padding: 6px 12px;
    border: 2px solid var(--line);
    background: var(--cell);
}

.state-frame b {
    margin: 0 6px;
}

@media (prefers-reduced-motion: no-preference) {
    .act-badge {
        animation: act-pulse 1.6s ease-in-out infinite;
    }
}

@keyframes act-pulse {
    50% {
        background: #d32f2f;
    }
}

table.faction caption .nick {
    font-weight: 400;
    opacity: 0.85;
}

table.faction tr.totals th {
    border-top: 2px solid var(--line);
    background: #e6dfc9;
    color: var(--fg);
}

/* ---- Setup: faction rows with name and nickname fields (Gamemaster mode) ---- */
.faction-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.faction-row .faction-name {
    min-width: 9em;
}

.faction-row input[type=text] {
    width: 11em;
}

/* ---- Start page ---- */
main.narrow, main.home {
    max-width: 900px;
}

.start-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.start-box label {
    flex: 0 0 100%;
}

.start-box input[type="text"] {
    flex: 1 1 260px;
}

.start-box .error {
    flex: 0 0 100%;
}

a button {
    cursor: pointer;
}

.logbox .txn {
    color: #998;
}

/* ---- Faction tables after the deal (board style) ---- */
table.board-style td.badges {
    width: 6em;
    white-space: nowrap;
    text-align: right;
}

table.board-style th.num,
table.board-style td.num {
    width: 3em;
    text-align: right;
}

table.board-style tr.hand td {
    background: #efe9d6;
    font-size: 12px;
}

.badge {
    display: inline-block;
    min-width: 1.9em;
    margin-right: 3px;
    padding: 0 4px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
}

.badge.leader {
    background: #e0b020;
    color: #222222;
}

.badge.office {
    background: #b71c1c;
    color: #ffffff;
}

.chip {
    display: inline-block;
    margin-right: 4px;
    padding: 0 6px;
    border-radius: 3px;
    background: #2c2c2c;
    color: #ffffff;
}

.chip.hiddencards {
    background: #777777;
}

/* ---- Faction Leader choice: every player at once ---- */
.leader-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 6px 0;
    padding: 4px 8px;
    border: 1px solid var(--line);
    background: #ffffff;
}

.leader-row > b {
    min-width: 9em;
}

.leader-options button {
    margin: 2px 4px 2px 0;
}

.leader-options button.chosen {
    background: #e0b020;
    border: 1px solid #a27d00;
    font-weight: 600;
}

table.board-style td {
    white-space: nowrap;
}

table.board-style td .idn {
    min-width: 1.6em;
}

table.board-style {
    table-layout: fixed;
}

table.board-style th {
    padding: 2px 6px;
    font-size: 11px;
    text-transform: uppercase;
    text-align: center;
}

table.board-style td.num {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

table.board-style td.act {
    text-align: right;
}

table.board-style tr.pickable {
    cursor: pointer;
}

table.board-style tr.pickable:hover td {
    background: #efe6c9;
}

table.board-style tr.pickable.chosen td {
    background: #f6e7a8;
}

/* ---- Board areas ---- */
.column {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#areas {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

table.area td,
table.area th {
    text-align: left;
}

table.area th {
    font-size: 11px;
    text-transform: uppercase;
}

table.area td.num {
    width: 3.5em;
    text-align: center;
}

table.area td.empty {
    color: #776;
}

table.stateinfo th {
    width: 11em;
}

.box {
    display: inline-block;
    margin: 1px 3px 1px 0;
    padding: 0 6px;
    border: 1px solid #666666;
    border-radius: 3px;
    background: #ffffff;
    font-size: 12px;
}

.box.activewar {
    background: #b71c1c;
    border-color: #b71c1c;
    color: #ffffff;
}

.box.activebill {
    background: #2a8a3a;
    border-color: #2a8a3a;
    color: #ffffff;
    font-weight: 700;
}

.box.deckbox {
    background: #2b2b2b;
    color: #ffffff;
}

.box.force {
    background: #dde8f5;
}

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

.cardname {
    cursor: pointer;
}

.cardname:hover {
    background: rgba(0, 0, 0, 0.07);
}

button.chip {
    border: 0;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
}

table.carddetails th {
    width: 11em;
    text-align: left;
}

#card-dialog {
    min-width: 320px;
}

.board > .frame {
    flex: 1 1 340px;
}

.board > .column {
    flex: 2 1 640px;
}

/* ==========================================================================
   Palette for what the board shows (hue = kind of thing, filled = held / an office, outline = marker)
   authority: burgundy   military: slate blue   land: teal   money: ochre   law: plum   events: sage
   ========================================================================== */
:root {
    --office: #8f2d2d;
    --leader: #e2b53f;
    --prior: #3f7a4a;
    --legion: #c0453f;
    --veteran: #a33d93;
    --knight: #555555;
    --special: #efd36a;
    --prov-light: #cfe3de;
    --prov-dark: #2e7d76;
    --commander: #d8def0;
    --commander-ink: #2c3d68;
    --captive: #2d4a7a;
    --event: #c5dcbf;
    --concession: #e0a64a;
    --law: #6e3a5c;
    --intrigue: #a02020;
    --war-on: #b5523b;
}

.badge.leader {
    background: var(--leader);
    color: #2a2108;
}

.badge.office {
    background: var(--office);
    color: #ffffff;
}

.box.prior {
    background: var(--prior);
    border-color: var(--prior);
    color: #ffffff;
    font-weight: 700;
}

.box.knight {
    background: var(--knight);
    border-color: var(--knight);
    color: #ffffff;
    font-weight: 700;
}

.box.priest {
    background: #f3dede;
    border-color: var(--office);
    color: var(--office);
    font-weight: 700;
}

.box.legion {
    background: var(--legion);
    border-color: var(--legion);
    color: #ffffff;
    font-weight: 700;
}

.box.special {
    background: var(--special);
    border-color: #a58a1c;
    color: #2a2108;
    font-weight: 700;
}

.box.special.usedup {
    opacity: 0.55;
}

.box.prov {
    background: var(--prov-light);
    border-color: var(--prov-dark);
    color: #17433e;
    font-weight: 700;
}

.box.prov.dev {
    background: var(--prov-dark);
    color: #ffffff;
}

.box.prov.corrupt,
.box.corrupt {
    font-style: italic;
}

.box.honest,
.box.corrupt {
    background: #e4e0d2;
    border-color: #7a7360;
    color: #3a3426;
    font-weight: 700;
}

.box.commander {
    background: var(--commander);
    border-color: var(--commander-ink);
    color: var(--commander-ink);
    font-weight: 700;
}

.box.rebel {
    background: #3a3a3a;
    border-color: #3a3a3a;
    color: #f08a6a;
    font-weight: 700;
}

.box.exile {
    background: #ffffff;
    border-color: #555555;
    color: #555555;
    font-weight: 700;
}

.box.captive {
    background: var(--captive);
    border-color: var(--captive);
    color: #ffffff;
    font-weight: 700;
}

.box.conc {
    background: var(--concession);
    border-color: #a8731f;
    color: #2b1d0a;
    font-weight: 700;
}

/* hand cards and card names by kind */
.chip.intrigue {
    background: #ffffff;
    border-color: var(--intrigue);
    color: var(--intrigue);
    font-weight: 700;
}

.chip.concession,
.cardname.concession {
    background: var(--concession);
    color: #2b1d0a;
    font-weight: 700;
}

.chip.law,
.cardname.law {
    background: var(--law);
    color: #ffffff;
    font-weight: 700;
}

.chip.statesman {
    background: #f1e6e0;
    border-color: #c01f1f;
    color: #c01f1f;
    font-weight: 700;
}

.chip.event {
    background: var(--event);
    color: #1f3a1c;
    font-weight: 700;
}

.chip.money {
    background: #e8c85a;
    color: #2a2108;
    font-weight: 700;
}

.cardname.concession,
.cardname.law {
    padding: 0 6px;
    border-radius: 3px;
}

/* wars */
.cardname.war {
    padding: 0 6px;
    border-radius: 3px;
    font-weight: 700;
}

.cardname.war.on {
    background: var(--war-on);
    color: #ffffff;
}

.cardname.war.off {
    background: #f7f3e8;
    box-shadow: inset 0 0 0 1px #5a4a3a;
    color: #5a4a3a;
}

.cardname.leader {
    font-weight: 700;
    color: #2c3d68;
}

table.area td.wide {
    width: 8em;
    white-space: nowrap;
}

/* Land Bills: white on black when in effect, black on white otherwise */
.bill {
    display: inline-block;
    margin: 1px 3px 1px 0;
    padding: 0 8px;
    border: 1px solid #111111;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 700;
}

.bill.on {
    background: #111111;
    color: #ffffff;
}

.bill.off {
    background: #ffffff;
    color: #111111;
}

/* rows */
table.board-style tr.away td {
    background: #d9d3c0;
    color: #6a6252;
}

table.board-style tr.statesman td.name {
    color: #c01f1f;
    font-weight: 700;
}

table.board-style td.matching {
    white-space: normal;
}

caption .right span {
    margin-left: 10px;
}

/* ---- State and Forum lines, Deck and Discard beside them ---- */
.toprow {
    display: grid;
    grid-template-columns: 1fr 8em;
    gap: 12px;
    margin-bottom: 14px;
}

.toprow:not(:has(.deckcard)) {
    grid-template-columns: 1fr;                  /* no card counts: State and Forum take the whole width */
}

.toprow table.faction {
    margin: 0;
}

td.boxline {
    min-height: 2.4em;
    padding: 5px 8px;
}

.boxes {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 3px;
    min-height: 1.6em;
}

.boxes .box,
.boxes .bill {
    margin: 0;
    line-height: 1.5;
}

.box.money {
    background: #e8c85a;
    border-color: #a58a1c;
    color: #2a2108;
    font-weight: 700;
}

.box.unrest {
    background: #f3dede;
    border-color: var(--office);
    color: var(--office);
    font-weight: 700;
}

.bill.off {
    opacity: 0.55;
}

.deckcard {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #2b2b2b;
    border: 1px solid #111111;
    color: #ffffff;
}

.deckcard span {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.deckcard b {
    font-size: 20px;
}

/* wars and leaders */
tr.groupstart td {
    border-top: 3px solid #b8ae94;
}

td.status {
    width: 7.5em;
    font-size: 12px;
}

.cardname.leaderi {
    font-style: italic;
}

/* ---- Forces next to Wars and Enemy Leaders ---- */
/* the four frames of the forces: Legions left, Fleets right, active above, pool below */
.halves {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.box.fleet {
    background: var(--legion);
    border-color: var(--legion);
    color: #ffffff;
    font-weight: 700;
}

.box.legion.veteran {
    background: var(--veteran);
    border-color: #e2b53f;
}

/* Status badges and Other boxes are the same size */
.badge {
    min-width: 0;
    margin: 0 3px 0 0;
    padding: 0 6px;
    border: 1px solid transparent;
    font-size: 12px;
    line-height: 1.5;
}

.badge.leader {
    border-color: #a58a1c;
}

.badge.office {
    border-color: var(--office);
}

.box {
    line-height: 1.5;
}

/* Statesmen that go with a Family card, told in its Other cell */
.matchtext {
    color: #6b6b6b;
    font-style: italic;
    font-size: 12px;
}

/* Faction cards: red text, Concessions keep their own colour, Laws stay plum */
.chip.leadercard,
.cardname.intrigue,
.cardname.leadercard {
    color: var(--intrigue);
    font-weight: 400;
}

.chip.leadercard {
    background: #ffffff;
    border-color: var(--intrigue);
}

.cardname.statesman {
    color: #c01f1f;
    font-weight: 400;
}

#result {
    margin: 8px 0;
}

#ctl-reset {
    margin: 4px 0;
}

/* centered columns of the wars table */
table.area th.center,
table.area td.center {
    text-align: center;
}

table.area td.wide {
    width: 9em;
}

.spacelabel {
    font-size: 12px;
    color: #4a4a4a;
}

table.board-style tr.dropzone td {
    padding: 3px 6px;
    color: #8a8a8a;
    font-size: 12px;
    text-align: center;
    border-top: 1px dashed var(--line);
}

/* a little space between the Legions and the Fleets */
td.boxline .boxes + .boxes {
    margin-top: 7px;
}

/* the status boxes sit closer to the Senator: 13 px to the right, the Senator column stays */
table.board-style td.badges .badge,
table.board-style td.badges .spacelabel {
    position: relative;
    left: 13px;
}


/* ==========================================================================
   Settings button and dialog
   ========================================================================== */
.settings-button {
    margin-left: auto;
}

.settings-button.floating {
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: 5;
}

#settings-dialog {
    min-width: 340px;
}

/* ==========================================================================
   Game page, wide window (class `wide` on <html>, set by common.js for a window of at least 1500 x 640 CSS px
   after zoom: Full HD and up). The shell (head, banner, board) is exactly one screen high: three panes that
   scroll on their own, no page scroll. Left to right: what there is to do (the pool, while one is shown) |
   game state, State, Forum, forces, wars, provinces | the factions. The log, when shown, is below the shell.
   Smaller windows keep the flowing layout above.
   ========================================================================== */
.head {
    display: block;
}

.head .top {
    margin-bottom: 8px;
}

.log-toggle {
    margin-left: auto;
}

.top .log-toggle + .settings-button {
    margin-left: 0;
}

/* flowing layout: the side pane dissolves, so state, senate and areas keep their old order */
#side-pane {
    display: contents;
}

.column .status-row {
    order: 0;
}

#top {
    order: 1;
}

#senate-pane {
    order: 2;
}

#areas {
    order: 3;
}

html.wide body {
    padding: 8px 10px;
}

html.wide main.game {
    max-width: none;
}

html.wide .shell {
    display: flex;
    flex-direction: column;
    height: calc(var(--app-h) - 16px);
}

html.wide .shell > * {
    flex: 0 0 auto;
}

html.wide .shell > .board {
    flex: 1 1 0;
    min-height: 0;
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 10px;
}

html.wide .board > .frame {
    flex: 0 0 clamp(300px, 17.5%, 400px);
    margin: 0;
}

html.wide .board > .column {
    flex: 1 1 0;
    min-width: 0;
    display: grid;
    grid-template-columns: minmax(0, 0.66fr) minmax(0, 1fr);      /* the state side is about 66% as wide as the factions */
    gap: 10px;
}

html.wide .pane {
    min-height: 0;
    overflow-y: auto;
}

html.wide #side-pane {
    display: flex;
    flex-direction: column;
    gap: 12px;
    order: 1;
}

html.wide #senate-pane {
    order: 2;
}

html.wide #senate {
    margin-bottom: 0;
}

html.wide #side-pane > * {
    order: 0;
}

html.wide .logbox {
    height: 260px;
    max-height: none;
    margin-top: 12px;
}

html.wide .status-row {
    margin-bottom: 0;
}

/* ---- Start page: the two lists side by side when there is room ---- */
.twin {
    display: block;
}

html.wide .twin {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    align-items: start;
}

html.wide main.narrow {
    max-width: 1400px;
}

html.wide .banner {
    margin-bottom: 8px;
    padding: 0;
}

html.wide .banner .linkbox {
    display: flex;
    flex: 1 1 auto;
    gap: 6px;
    margin: 0;
}

html.wide .banner .linkbox input {
    flex: 1 1 auto;
    min-width: 0;
}

/* ==========================================================================
   Compact faction tables: the header row carries the name and M O L I P T; the hand is a frame on the right
   ========================================================================== */
table.board-style tr.facthead th {
    padding: 4px 6px;
    background: var(--header-bg);
    color: var(--header-fg);
    font-size: 14px;
    font-weight: 600;
    text-transform: none;
    text-align: left;
}

table.board-style tr.facthead th.facttitle {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

table.board-style tr.facthead th.stat {
    padding: 4px 0;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    color: #ecd9d9;
}

table.board-style tr.facthead th.figures {
    font-size: 13px;
    font-weight: 600;
    text-align: right;
    white-space: nowrap;
}

table.board-style tr.facthead th.figures span + span {
    margin-left: 8px;
}

.badge.hrao {
    margin-right: 6px;
}

.factionrow {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 12.5em;
    gap: 8px;
    align-items: stretch;                  /* the hand is as high as the table; a higher hand makes the row, and the gap, bigger */
}

.factionrow > table {
    align-self: start;
}

.handbox {
    padding: 4px 6px;
    background: #efe9d6;
    border: 1px solid var(--line);
    font-size: 12px;
}

.handbox.empty {
    visibility: hidden;
    padding: 0;
    border: 0;
}

.handbox .chip {
    display: block;
    margin: 0 0 3px;
    padding: 1px 6px;
    text-align: left;
    white-space: normal;
    width: fit-content;
    max-width: 100%;
}

table.board-style tr.keyrow td {
    padding: 0;
    white-space: normal;
}

.keybox {
    padding: 10px 12px;
    background: #fff3c4;
    font-size: 13px;
}

.keybox b {
    color: #7a5b00;
}

.keybox .linkbox {
    margin-top: 10px;
}

.keybox input.seatkey {
    min-width: 0;
}

/* ---- the frame: tabs with Start over beside them; Continue is always in view at the bottom ---- */
.tabrow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.tabrow .tabs {
    display: contents;
}

#frame-reset button {
    background: var(--th-bg);
    border: 1px solid var(--line);
}

/* the frame is one screen high at most: what is above Continue scrolls, Continue stays under it */
.frame {
    display: flex;
    flex-direction: column;
    max-height: calc(var(--app-h, 100vh) - 24px);
}

.frame-scroll {
    flex: 0 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.frame > * {
    flex: 0 0 auto;
}

.frame > .frame-scroll {
    flex: 0 1 auto;
}

html.wide .frame.pane {
    overflow: hidden;
}

html.wide .board > .frame {
    max-height: 100%;                   /* never taller than the board: Continue stays above the log */
}


/* ==========================================================================
   New game page: the settings in columns; three of them, on one screen, in a wide window
   ========================================================================== */
.setupcols {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(440px, 1fr));
    gap: 0 12px;
    align-items: start;
}

.setupcol {
    min-width: 0;
}

html.wide .setupcols {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

html.wide main:not(.narrow):not(.game) {
    max-width: none;
}

html.wide #setup-form fieldset {
    margin-bottom: 10px;
}

html.wide #setup-form fieldset label.row {
    padding: 0;
}

html.wide #setup-form fieldset > p.muted {
    margin: 4px 0;
}


/* ==========================================================================
   Boxes in the interaction area: the same boxes as in the faction hands, in frames like State and Forum
   ========================================================================== */
.boxes .chip {
    margin: 0;
    padding: 0 6px;
    font-size: 12px;
    line-height: 1.5;
}

.chip.mortality {
    background: #111111;
    color: #ffffff;
    font-weight: 700;
}

.chip.family {
    background: #e9e1c8;
    border-color: #8a7f5a;
    color: #2a2a2a;
}

/* the bottom block: cards of the gray deck (Middle Republic) have a gray ring, the Era Ends card a gold one */
.chip.gray {
    border-color: #8f8f8f;
}

.chip.eraends {
    border-color: #e2b53f;
    font-weight: 700;
}

/* the status of a war or Enemy Leader: a box, coloured by status */
.box.warstatus {
    margin: 0;
    font-weight: 700;
}

.box.warstatus.active {
    background: #b71c1c;
    border-color: #b71c1c;
    color: #ffffff;
}

.box.warstatus.unprosecuted {
    background: #e08a1e;
    border-color: #b36a0c;
    color: #2b1a02;
}

.box.warstatus.imminent {
    background: #f1d27a;
    border-color: #b99a2e;
    color: #3a2d08;
}

.box.warstatus.inactive {
    background: #d9d4c4;
    border-color: #a9a28a;
    color: #4a4638;
}

.box.warstatus.matching {
    background: #2a8a3a;
    border-color: #1d6a2a;
    color: #ffffff;
}

.box.warstatus.unmatched {
    background: #ffffff;
    border-color: #a9a28a;
    color: #8a8372;
}

/* the frame is as high as its content (up to one screen): Continue sits right below the items */
.board > .frame, html.wide .board > .frame {
    align-self: flex-start;
}


/* ==========================================================================
   Item boxes: one look everywhere (State, Forum, forces, hands, interaction area, status).
   Colours (background, text, outline) differ; height, outline weight, shape and type size do not.
   The height is that of the string "Xy" at 12px: 18px of line plus a 1px outline on both sides.
   ========================================================================== */
.box, .chip, .badge, .bill, .handbox .chip, .boxes .chip, .boxes .box, .boxes .bill {
    box-sizing: border-box;
    display: inline-block;
    height: 20px;
    margin: 0 3px 0 0;
    padding: 0 6px;
    border-width: 1px;
    border-style: solid;
    border-radius: 3px;
    font-size: 12px;
    line-height: 18px;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    outline: 0;
    box-shadow: none;
}

.boxes .box, .boxes .chip, .boxes .bill {
    margin: 0;
}

.chip {
    border-color: #2c2c2c;
}

.chip.hiddencards { border-color: #777777; }
.chip.concession { border-color: #a8731f; }
.chip.law { border-color: var(--law); }
.chip.event { border-color: #7d9a78; }
.chip.money { border-color: #a58a1c; }
.chip.mortality { border-color: #111111; }
.chip.gray { border-color: #8f8f8f; }
.chip.eraends { border-color: #e2b53f; }

.bill.on { border-color: #111111; }
.bill.off { border-color: #111111; }
button.chip {
    border-width: 1px;
    border-style: solid;
    font: inherit;
    font-size: 12px;
    line-height: 18px;
}

.handbox .chip {
    display: block;
    margin: 0 0 3px;
    width: fit-content;
}

/* a warning before Continue while the position is not legal */
#continue-button.warn::before {
    content: "\26A0\FE0E  ";
}

/* Settings: the seat key box and its Copy button on one line */
.settings-keyrow {
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-keyrow label {
    display: flex;
    flex: 1 1 auto;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.settings-keyrow input.seatkey {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
}

.settings-keyrow button {
    flex: 0 0 auto;
}

#continue-button {
    white-space: nowrap;
}

.settings-keyrow label span {
    white-space: nowrap;
}

#settings-dialog, dialog#settings {
    min-width: 560px;
}

/* the strip for everybody who does not act: who does */
.act-badge.waiting {
    background: #44546a;
    text-transform: uppercase;
    animation: none;
}

.act-badge.waiting {
    white-space: normal;
    font-size: 15px;
    letter-spacing: 1px;
    overflow-wrap: anywhere;
}

/* New game page: the title and the buttons span all columns, centred */
h1.centered {
    text-align: center;
}

.setupbuttons {
    display: flex;
    justify-content: center;
    gap: 12px;
}

#setup-form .error {
    text-align: center;
}

/* Start page: the title, the narrow name box and one button */
h1.startTitle {
    margin: 32px 0 28px;
    font-size: 30px;
    text-align: center;
}

.start-box {
    justify-content: center;
}

.start-box input.gamename {
    flex: 0 1 auto;
    width: 48ch;                      /* a whole seat key (43 characters) fits comfortably */
    max-width: 100%;
    text-align: center;
    font: 15px ui-monospace, monospace;
}

table.games th {
    padding: 2px 8px;
    text-align: left;
}

.start-box .error:empty {
    display: none;
}

/* ---- Log text can be selected and copied ---- */
.logbox, .logbox * {
    user-select: text;
}

.pill.mode {
    background: var(--th-bg);
}

/* ---- Deck and Discard: the hand of the Unaligned ---- */
.deckpair {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-self: stretch;
}

.deckpair .deckcard {
    min-height: 4em;
}

/* ==========================================================================
   Start, New game and Lobby pages: the look of the game scene
   (dark red header bars, light frames, the same table headers)
   ========================================================================== */
.card > h2:first-child {
    margin: -8px -12px 8px;
    padding: 5px 8px;
    background: var(--header-bg);
    color: var(--header-fg);
    font-size: 14px;
    font-weight: 600;
}

.card > h2:first-child .muted {
    color: #e6d5d5;
    font-weight: 400;
}

fieldset {
    padding: 0 0 8px;
    overflow: hidden;
}

fieldset > legend {
    float: left;
    width: 100%;
    margin: 0 0 6px;
    padding: 5px 8px;
    background: var(--header-bg);
    color: var(--header-fg);
}

fieldset > legend + * {
    clear: both;
}

fieldset > :not(legend) {
    margin-left: 12px;
    margin-right: 12px;
}

fieldset > select {
    max-width: calc(100% - 24px);
}

.card.start-box {
    border: 2px solid var(--header-bg);
}

table.seats {
    table-layout: fixed;
    border: 1px solid var(--line);
    background: var(--cell);
}

table.seats th {
    padding: 4px 8px;
    background: var(--th-bg);
    color: var(--th-fg);
    font-weight: 600;
    text-align: left;
}

table.seats td {
    overflow-wrap: anywhere;
}

table.games td.action {
    width: auto;
}

table.games td.action button {
    min-width: 5em;
}

.card:has(table.seats) {
    padding: 0 0 8px;
}

.card:has(table.seats) > h2:first-child {
    margin: 0 0 8px;
}

.card:has(table.seats) > div,
.card:has(table.seats) > table {
    margin: 0 8px;
}

html.wide #setup-form fieldset > :not(legend) {
    margin-left: 12px;
    margin-right: 12px;
}

.card:has(table.seats) > table {
    width: calc(100% - 16px);
}

#pool.reporting .chip.mortality {
    cursor: pointer;
}

/* Continue in a faction table is as high as the Leader button: only the padding differs from button.primary */
table.board-style td.act button.primary {
    padding: 2px 10px;
    border-width: 2px;
}

/* ==========================================================================
   Buttons with their own colours (primary, warning, tabs, start over, chosen) take the box of the plain
   buttons (Leader): the same padding and 2px border, so the same height. The plain buttons are not touched.
   ========================================================================== */
button.primary,
button.warn,
.tabs button,
#frame-reset button,
.continue-row:not(.incomplete) button,
.leader-options button.chosen {
    padding: 2px 10px;
    border-width: 2px;
    border-style: solid;
}

button:not(.chip):not(.title-button) {
    font-size: 14px;                     /* also inside the 13px banner: one text size, one height */
    line-height: 19.6px;
}

/* ==========================================================================
   HRAO.online start page: input frames, the two lists, the disclaimer
   ========================================================================== */
main.home {
    max-width: 1500px;
}

.frames {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: repeat(3, auto);
    gap: 16px;
    margin-bottom: 16px;
}

.frames > .card {
    margin: 0;
}

#f-new { grid-area: 1 / 1; }
#f-seat { grid-area: 2 / 1; }
#f-join { grid-area: 3 / 1; }
#f-claim { grid-area: 1 / 2; }
#f-login { grid-area: 2 / 2; }
#f-member { grid-area: 1 / 2 / span 2 / 2; }
#f-claim.keyed { grid-area: 1 / 2 / span 2 / 2; }
#f-watch { grid-area: 3 / 2; }

.frame .inputwrap {
    box-sizing: border-box;
    height: 36px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px;
    border: 1px solid var(--line);
    background: #fff;
}

.frame .inputwrap input {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: 0;
    padding: 3px 6px;
    background: transparent;
    font: 15px ui-monospace, monospace;
}

.frame .inputwrap input::placeholder {
    color: #aaa;
}

.frame .error {
    margin-top: 4px;
    min-height: 0;
}

.frame .error:empty {
    display: none;
}

.frame.member {
    text-align: center;
}

.frame.member > h2:first-child {
    text-align: center;
    font-size: 16px;
}

.frame.member .rank {
    margin: 4px 0 8px;
    color: #555;
}

.frame.member table.statline {
    width: 60%;
    margin: 0 auto 10px;
    border: 1px solid var(--line);
    background: var(--cell);
}

.frame.member table.statline th {
    background: var(--th-bg);
    color: var(--th-fg);
}

.frame.member table.statline td.num {
    padding: 2px 6px;
}

.frame.member .buttons {
    display: flex;
    justify-content: center;
    gap: 8px;
}

#f-left { grid-area: 4 / 1; }
#f-live { grid-area: 4 / 2; }

/* every frame has the same 2px border; the lists are attached to the frame above them
   (Join to a Forming Game / Watch Game) and share its border */
.frames > .card, .leftlists > .card {
    border: 2px solid var(--header-bg);
}

.leftlists {
    display: flex;
    flex-direction: column;
    gap: 16px;
    align-self: start;
    margin-top: -18px;
}

.leftlists > .card {
    margin: 0;
}

.frames > #f-live {
    align-self: start;
    margin-top: -18px;
}

table.games th.c, table.games td.c {
    text-align: center;
}

table.games td b {
    user-select: text;
}

.disclaimer p {
    margin: 0;
    color: #444;
    text-align: justify;
    hyphens: auto;
}

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

    .frames > .card {
        grid-area: auto !important;
        margin-top: 0 !important;
    }
}


/* ---- The personal key right after an invite was claimed (start page) ---- */
.newkey .keybox {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin: 6px 0 10px;
    padding: 14px 16px;
    background: #fff4c2;
    border: 3px solid var(--header-bg);
    border-radius: 4px;
}

.newkey .keybox span {
    flex: 1 1 auto;
    font: 700 22px/1.3 ui-monospace, Consolas, monospace;
    letter-spacing: 0.04em;
    color: var(--header-bg);
    user-select: all;
    word-break: break-all;
}
