/* The dark theme: dark wood, gold and white. (The map keeps its own colours.) */
:root {
  color-scheme: dark;
  --bg: #1b130c;          /* dark wood: the page */
  --panel: #2a1d13;       /* wood: panels and dialogs */
  --raised: #3a2919;      /* lighter wood: buttons, inputs */
  --ink: #f6f0e4;         /* white text */
  --muted: #b8a789;       /* faded parchment */
  --line: #4e3924;        /* wood grain lines */
  --gold: #d6aa4c;
  --gold-bright: #f0cd74;
  --gold-ink: #1b130c;    /* text on gold */
  --accent: var(--gold);
  --danger: #e36a58;
  /* The player's colour, as a stripe under the top bar (see applyPlayerTheme in app.js). */
  --player: var(--gold);
  --sidebar-w: 480px;     /* the right-hand panel */
  --row-hover: #3a2919;
  --row-selected: #4a3420;
  /* A faint grain on the wooden surfaces. */
  --grain: repeating-linear-gradient(100deg, rgba(255, 255, 255, .018) 0 2px, transparent 2px 9px, rgba(0, 0, 0, .05) 9px 11px, transparent 11px 19px);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--grain), var(--bg); min-height: 100vh; display: flex; flex-direction: column; }
h1 { font-size: 22px; margin: 0 0 6px; font-family: Georgia, "Palatino Linotype", serif; color: var(--gold-bright); }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--gold); margin: 0 0 10px; }
h3 { color: var(--ink); }
a { color: var(--gold-bright); }
button {
  font: inherit; font-size: 13px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--raised); color: var(--ink); cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--gold); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--gold-bright); border-color: var(--gold-bright); }
button.active { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }
input, select, textarea { background: var(--raised); color: var(--ink); border: 1px solid var(--line); }
input:focus-visible, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
::placeholder { color: var(--muted); opacity: .8; }
button.danger-btn { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger-btn:hover:not(:disabled) { border-color: #7f1b15; background: #9a1f18; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }
.hidden { display: none !important; }

.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 18px;
  background: var(--grain), var(--topbar); color: var(--ink);
  border-bottom: 2px solid var(--gold); box-shadow: 0 3px 0 var(--player);
  transition: box-shadow .3s;
  position: relative; z-index: 20; /* the Victory drop-down opens over the map */
}
/* The CrownFall logo: Aston Royal (public/fonts) in gold, top left of the header. */
@font-face { font-family: "Aston Royal"; src: url("/fonts/aston-royal.otf") format("opentype"); font-display: block; }
.brand { display: flex; align-items: center; gap: 8px; flex: none; }
/* The crown, left of the name: a little taller than its capitals. */
.brand-crown { width: 32px; height: 28px; flex: none; overflow: visible; filter: drop-shadow(0 1px 0 #5a3a10) drop-shadow(0 2px 3px rgba(0, 0, 0, .55)); }
.brand-name {
  font-family: "Aston Royal", Georgia, "Palatino Linotype", serif; font-size: 30px; line-height: 1; letter-spacing: .02em;
  /* The gold is painted on the box only: room above so the tall letters aren't cut off (the
     negative margin keeps the header as tall as before), none below. The font keeps a lot of
     empty space under its capitals, which lifts them ~.3em above the centre: moved back down. */
  white-space: nowrap; padding: .25em .1em 0; margin: -.25em 0 0; transform: translateY(.3em);
  background: linear-gradient(180deg, #fff3c4 0%, #f3d27a 30%, #d6a43e 52%, #a8741f 70%, #f0cd74 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 #5a3a10) drop-shadow(0 2px 3px rgba(0, 0, 0, .55));
}
.turn-info { flex: 1; font-size: 14px; opacity: .9; display: flex; align-items: center; flex-wrap: wrap; gap: 0 6px; }
/* ◀ ▶ after the turn's name: look back at past turns. */
/* Admin test tool: a row per seat to pick its Crest for the icon showcase. */
.showcase-seats { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.showcase-seat { display: grid; grid-template-columns: 40px 64px 1fr 1fr; align-items: center; gap: 8px; font-size: 13px; }
.showcase-crest { width: 40px; height: 40px; }
.showcase-seat select { min-width: 0; }
/* The icon before a sidebar panel's heading. */
/* (Icons with a letter in them, like the Sage's Ω, mustn't take the headings' letter spacing: it pushes the letter off centre.) */
.panel-icon, .list-icon, .btn-icon, .detail-icon, .army-svg { letter-spacing: normal; text-transform: none; }
.panel-icon { display: inline-block; width: 20px; height: 20px; object-fit: contain; object-position: left center; vertical-align: -5px; margin-right: 7px; flex: none; }.turn-nav-group { display: inline-flex; gap: 2px; }
.turn-nav { padding: 0 6px; min-width: 22px; height: 22px; font-size: 11px; line-height: 20px; background: none; border: 1px solid var(--gold); border-radius: 4px; color: var(--gold-bright); cursor: pointer; }
.turn-nav:hover:not(:disabled) { background: rgba(214, 170, 76, .18); }
.turn-nav:disabled { opacity: .3; cursor: default; }
.turn-now { padding: 2px 10px; font-size: 12px; }
.past-note { color: var(--gold-bright); }
/* Looking at a past turn: a sepia tint on the map and a gold header line, so it isn't taken for now. */
body.viewing-past .map { filter: sepia(.45) saturate(.8); }
body.viewing-past .topbar { box-shadow: 0 3px 0 var(--gold-bright); }
/* Victory track: each player's cities, a mark at the number that wins alone, the Throne's holder. */
.victory-wrap { position: relative; flex: 0 1 380px; min-width: 180px; }
.victory-bar { display: flex; align-items: center; gap: 8px; width: 100%; padding: 3px 8px; background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; color: inherit; }
.victory-bar:hover, .victory-bar.open { border-color: var(--gold); background: rgba(0, 0, 0, .12); }
.vt-track { position: relative; flex: 1; display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); border: 1px solid rgba(0, 0, 0, .5); }
.vt-seg { height: 100%; flex: none; border-right: 1px solid rgba(0, 0, 0, .45); }
.vt-seg.mine { box-shadow: inset 0 0 0 2px var(--gold-bright); }
.vt-throne { display: flex; align-items: center; gap: 2px; flex: none; }
.vt-crown { width: 20px; height: 18px; flex: none; }
.vt-crest { width: 26px; height: 26px; object-fit: contain; }
.vt-none { opacity: .7; padding: 0 4px; }
/* Inside the Victory drop-down: a bar out of all the cities, with a mark at the number needed. */
/* (.victory-pop prefix: `.panel p` would otherwise win and drop the top margin.) */
.victory-pop p.vhead { margin: 14px 0 4px; }
.victory-pop p.vhead:first-of-type { margin-top: 0; }
.vbar { position: relative; display: flex; height: 10px; border-radius: 5px; background: var(--line); overflow: visible; margin: 4px 0 6px; }
.vbar > span { height: 100%; flex: none; }
.vbar > span:first-child { border-radius: 5px 0 0 5px; }
.vbar > i { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--gold-bright); box-shadow: 0 0 0 1px rgba(0, 0, 0, .6); }
/* Partner rows: the names in one column, so every bar starts and ends at the same place. */
.treaty-list.picker { display: grid; grid-template-columns: max-content 1fr; column-gap: 10px; }
.treaty-list.picker li { display: contents; }
.treaty-list.picker li > label { padding: 2px 0; }
.treaty-list.picker li .vbar { align-self: center; margin: 0; }
.victory-pop { padding-bottom: 22px; position: absolute; top: calc(100% + 8px); right: 0; width: min(380px, 92vw); max-height: 70vh; overflow-y: auto; z-index: 50; box-shadow: 0 8px 24px rgba(0, 0, 0, .45); }
/* The Rules (📖? in the top bar): a wider drop-down with tabs. */
.victory-wrap.rules-wrap { flex: none; min-width: 0; }
.rules-btn { display: grid; place-items: center; padding: 3px 7px; background: none; border: 1px solid transparent; border-radius: 6px; cursor: pointer; color: var(--gold-bright); }
.rules-btn:hover, .rules-btn.open { border-color: var(--gold); background: rgba(0, 0, 0, .12); }
.rules-book { width: 28px; height: 24px; display: block; letter-spacing: normal; }
.victory-pop.rules-pop { width: min(640px, 94vw); max-height: 78vh; }
/* The Options drop-down (gear). */
.victory-pop.options-pop { width: min(340px, 92vw); }
.option-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; margin: 4px 0 6px; }
.option-row input { width: 17px; height: 17px; accent-color: var(--gold); flex: none; }
.option-row.disabled { cursor: default; opacity: .7; }
.panel p.option-count { margin: 0 0 6px 25px; font-size: 13px; color: var(--muted); }
.option-count strong { color: var(--gold-bright); }
.option-sep { border: 0; border-top: 1px solid rgba(214, 164, 62, .25); margin: 10px 0 8px; }
.rules-tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 0 0 10px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.rules-tab { padding: 4px 12px; font-size: 13px; }
.rules-tab.active { background: var(--row-selected); border-color: var(--gold); color: var(--gold-bright); }
.rules-body h3 { margin: 14px 0 6px; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); }
.rules-body p { margin: 4px 0; }
.rules-list { margin: 4px 0; padding-left: 18px; display: grid; gap: 4px; }
.rules-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.rules-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 3px 4px; }
.rules-table td { padding: 5px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
.rules-table td:first-child { width: 34px; text-align: center; }
.rules-icon { width: 28px; height: 28px; display: inline-block; vertical-align: middle; letter-spacing: normal; text-transform: none; }
.rules-icon.rules-building { width: 30px; height: 36px; }
.rules-result { display: inline-block; min-width: 62px; text-align: center; padding: 2px 6px; border-radius: 4px; font-weight: 700; color: #fff; }
.rules-result.kill { background: #8e2b22; }
.rules-result.advance { background: #b35b2a; }
.rules-result.hold { background: #6b6455; }
.rules-result.route { background: #3d6a8a; }
.me-badge { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.me-badge button { padding: 3px 10px; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr var(--sidebar-w); gap: 14px; padding: 14px; min-height: 0; }
/* With the Messages panel (players only): a column on the left, as wide as the
   right-hand one when open, a narrow tab when closed. */
.layout:has(> .chat:not(.hidden)) { grid-template-columns: 40px 1fr var(--sidebar-w); }
body.chat-open .layout:has(> .chat:not(.hidden)) { grid-template-columns: var(--sidebar-w) 1fr var(--sidebar-w); }

/* Messages */
.chat { display: flex; min-height: 0; min-width: 0; }
.chat-rail {
  width: 40px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 12px 0;
  border: 1px solid var(--line); border-radius: 10px; background: var(--grain), var(--panel);
}
.chat-rail-icon { font-size: 18px; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.chat-rail-label { writing-mode: vertical-rl; transform: rotate(180deg); letter-spacing: .12em; text-transform: uppercase; font-size: 12px; color: var(--gold); }
.chat.open .chat-rail { display: none; }
.chat:not(.open) .chat-panel { display: none; }
.chat-panel { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; padding: 12px; gap: 8px; }
.chat-head { display: flex; align-items: center; justify-content: space-between; }
.chat-head h2 { margin: 0; }
.chat-head button { padding: 2px 9px; }
/* The tabs: a column of crests on the left; the messages and the box to write on the right. */
.chat-main { flex: 1; display: flex; gap: 10px; min-height: 0; }
.chat-body { flex: 1; display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; }
/* Who is in the open chat: a stretch of each player's colour, with their name. */
/* (Two names a line, whole: a long one wraps rather than being cut; an odd last one takes the full line.) */
.chat-band { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; flex: none; border-radius: 5px; overflow: hidden;
  border: 1px solid rgba(0, 0, 0, .5); background: rgba(0, 0, 0, .45); }
.chat-band:empty { display: none; }
.chat-band-seg { min-width: 0; padding: 3px 8px; font-size: 12px; font-weight: 700; text-align: center;
  overflow-wrap: anywhere; text-shadow: none; display: grid; place-items: center; }
.chat-band-seg:last-child:nth-child(odd) { grid-column: 1 / -1; }
.chat-tabs {
  display: flex; flex-direction: column; gap: 6px; flex: none;
  overflow-y: auto; overflow-x: visible; padding: 6px 6px 6px 0; border-right: 1px solid var(--line);
}
.chat-tab { position: relative; display: grid; place-items: center; padding: 4px; }
.chat-tab.active { background: var(--row-selected); border-color: var(--gold); color: var(--gold-bright); }
.chat-crest { display: block; width: 56px; height: 56px; object-fit: contain; }
/* Everyone's tab: the crests in a star (a point at the top), as big as one crest. */
.chat-tab-crests { position: relative; display: block; width: 56px; height: 56px; }
.chat-crest-sm { position: absolute; width: 26px; height: 26px; object-fit: contain; transform: translate(-50%, -50%); }
.chat-tab.not-joined img { opacity: .4; filter: grayscale(.6); }
.chat-new { width: 66px; height: 66px; font-size: 32px; line-height: 1; color: var(--gold); border-style: dashed; }
/* The '+' tab's pop-up */
.chat-picker { background: var(--grain), var(--panel); color: var(--ink); border: 1px solid var(--gold); border-radius: 12px; padding: 18px; width: min(360px, calc(100vw - 32px)); }
.chat-picker::backdrop { background: rgba(0, 0, 0, .55); }
.chat-picker h2 { margin: 0 0 4px; }
.chat-picks { display: grid; gap: 4px; margin: 10px 0; }
.chat-pick { display: flex; align-items: center; gap: 10px; padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.chat-pick:has(input:checked) { border-color: var(--gold); background: var(--row-selected); }
.chat-pick.not-joined { opacity: .5; cursor: default; }
button.chat-pick { width: 100%; text-align: left; font: inherit; color: inherit; background: transparent; }
button.chat-pick:not(:disabled):hover { border-color: var(--gold); background: var(--row-selected); }
.chat-pick-crest { width: 36px; height: 36px; object-fit: contain; }
.chat-picker-or { display: flex; align-items: center; gap: 8px; margin: 14px 0 10px; color: var(--muted); font-size: 12px; }
.chat-picker-or::before, .chat-picker-or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.chat-pick-admin { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; }
.chat-pick-admin .admin-badge { font-size: 20px; }
.chat-tab .chat-unread { position: absolute; top: -4px; right: -4px; margin: 0; }
.admin-badge { display: grid; place-items: center; color: var(--gold-bright); font-size: 38px; line-height: 1; }
.name-crest.admin-badge { display: inline-grid; font-size: 13px; }
.chat-form input:disabled { opacity: .6; }
.chat-unread {
  display: inline-block; min-width: 17px; padding: 0 5px; margin-left: 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}
.chat-rail .chat-unread { margin: 0; }
.chat-log { flex: 1; min-height: 120px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding-right: 4px; }
/* A message: its bubble, with the sender's crest beside it (on the bubble's right
   for other players, on its left for your own). */
.chat-row { display: flex; align-items: flex-end; gap: 6px; max-width: 92%; align-self: flex-start; }
.chat-row.mine { align-self: flex-end; }
.chat-row > .chat-msg-crest { flex: none; width: 34px; height: 34px; object-fit: contain; }
.chat-row > .chat-msg-crest.admin-badge { font-size: 26px; }
.chat-msg { background: rgba(0, 0, 0, .18); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; min-width: 0; }
.chat-msg.mine { background: var(--row-selected); border-color: #6a4d2e; }
.chat-meta { font-size: 11px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.chat-meta .muted { margin-left: 4px; }
.chat-text { font-size: 13px; margin-top: 2px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-empty { margin: auto 0; text-align: center; }
/* Buildings and Agents panels: what a player holds, by kind */
.holdings-group + .holdings-group { margin-top: 10px; }
.holdings-group h3 { margin: 0 0 4px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); }
.holdings-group h3 .muted { font-weight: 400; margin-left: 4px; }
.holdings { list-style: none; margin: 0; padding: 0 0 0 6px; display: grid; gap: 2px; }
.holdings li { display: flex; align-items: center; gap: 8px; padding: 2px 6px; border: 1px solid transparent; border-radius: 6px; cursor: pointer; }
.holdings li:hover { background: var(--row-selected); }
.holdings li.selected { background: var(--row-selected); border-color: var(--gold); }
.holdings li.foe { cursor: default; } /* another player's agent: not selectable */
.holdings li.foe:hover { background: none; }
.building-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.building-head h2 { margin: 0; }
.detail-icon { width: 44px; height: 44px; flex: none; overflow: visible; }
.forecast td:last-child .name-crest { vertical-align: -3px; }
details.help { margin-top: 10px; }
details.help summary { cursor: pointer; color: var(--gold); font-size: 12px; }
details.help p { margin: 6px 0 0; }
/* Armies panel: every unit's icon, side by side */
.army-icons { display: flex; flex-wrap: wrap; gap: 4px; }
.army-icon { position: relative; padding: 3px; line-height: 0; border: 1px solid transparent; background: transparent; border-radius: 6px; }
.army-leader { position: absolute; top: 0; left: 0; width: 15px; height: 15px; overflow: visible; }
.army-recruit { margin-top: 10px; }
.build-action.active { border-color: var(--gold); background: var(--row-selected); color: var(--gold-bright); }
.army-icon:hover { background: var(--row-selected); }
.army-icon.selected { border-color: var(--gold); background: var(--row-selected); }
.army-svg { width: 30px; height: 30px; overflow: visible; }
.army-icon.has-order > svg { opacity: .4; } /* already has orders this turn */
.build-actions { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px; }
.build-action { display: flex; align-items: center; gap: 8px; text-align: left; padding: 5px 9px; }
.btn-icon { width: 26px; height: 26px; flex: none; overflow: visible; display: inline-block; }
.build-action:disabled .btn-icon { opacity: .5; }
.holdings li .muted { margin-left: auto; }
/* Buildings: two columns */
#buildings-panel .holdings { grid-template-columns: 1fr 1fr; column-gap: 6px; }
#buildings-panel .holdings li > span:not(.muted) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-icon { width: 24px; height: 24px; flex: none; overflow: visible; }
/* Between the messages of one turn and the next */
.chat-turn { display: flex; align-items: center; gap: 8px; align-self: stretch; margin: 4px 0 0; color: var(--gold); font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.chat-turn::before, .chat-turn::after { content: ""; flex: 1; border-top: 1px solid var(--gold); opacity: .7; }
.chat-form { display: flex; gap: 6px; }
/* The Pouch (send gold), and the line a gift leaves in the chat. */
.chat-pouch { flex: none; display: grid; place-items: center; padding: 3px 6px; }
.chat-pouch .pouch-icon { width: 24px; height: 24px; display: block; }
.chat-pouch:disabled .pouch-icon { filter: grayscale(.8); }
.chat-gift { display: flex; align-items: center; gap: 8px; align-self: stretch; padding: 6px 10px; border: 1px solid var(--gold); border-radius: 8px; background: rgba(214, 170, 76, .12); font-size: 13px; }
.chat-gift .pouch-icon { flex: none; width: 22px; height: 22px; }
.chat-gift > span:first-of-type { flex: 1; min-width: 0; color: var(--gold-bright); font-weight: 700; overflow-wrap: anywhere; }
.chat-gift b { font-weight: 800; }
.chat-gift .gift-amount { color: #ffd968; }
.chat-gift .gift-when { font-weight: 400; }
.forecast .gift-row td { color: var(--gold-bright); font-weight: 700; }
.gift-picker h2 { display: flex; align-items: center; gap: 6px; }
.gift-picker h2 .pouch-icon { width: 22px; height: 22px; }
.gift-amount-field { margin-top: 10px; }
.gift-amount-row { display: flex; align-items: center; gap: 6px; }
.gift-amount-row input { width: 110px; font: inherit; padding: 6px 8px; border-radius: 6px; }
.chat-form input { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 7px 9px; border-radius: 6px; }
.map-wrap { position: relative; background: #140e09; border: 1px solid var(--gold); border-radius: 10px; overflow: hidden; min-height: 420px; box-shadow: inset 0 0 0 3px #3a2919; }
.map { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
.map-hint {
  position: absolute; left: 12px; bottom: 12px; padding: 6px 10px; border-radius: 6px;
  background: rgba(35, 33, 29, .85); color: #fff; font-size: 13px; pointer-events: none;
}
.map-hint:empty { display: none; }

.sidebar { display: flex; flex-direction: column; gap: 12px; overflow-y: auto; }
.sidebar-fixed, .sidebar-scroll { display: flex; flex-direction: column; gap: 12px; }
/* Panels in the scrolling part fold up when their heading is clicked. */
.sidebar-scroll > .panel { flex: none; }
.sidebar-scroll > .panel > h2 { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 6px; }
.sidebar-scroll > .panel > h2::after { content: "▾"; margin-left: auto; color: var(--gold); font-size: 12px; transition: transform .15s; }
.sidebar-scroll > .panel.collapsed > h2 { margin-bottom: 0; }
.sidebar-scroll > .panel.collapsed > h2::after { transform: rotate(-90deg); }
.sidebar-scroll > .panel.collapsed > :not(h2) { display: none; }
.panel { background: var(--grain), var(--panel); border: 1px solid var(--line); border-top-color: #6a4d2e; border-radius: 10px; padding: 12px 14px; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); }
.panel p { margin: 0 0 8px; font-size: 13px; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

.order-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 6px 8px; border-radius: 6px;
  font-size: 13px; cursor: pointer;
}
.order-row:hover { background: var(--row-hover); }
.order-row.selected { background: var(--row-selected); }
.order-row .order { color: var(--muted); text-align: right; }
.order-row.has-order .order { color: var(--gold-bright); font-weight: 600; }

.power-value { font-size: 28px; font-weight: 800; line-height: 1; color: var(--gold-bright); }
.power-value.negative { color: var(--danger); }
.panel p.warning {
  margin: 8px 0 0; padding: 8px 10px; border-radius: 6px; font-size: 12px;
  background: #3d1712; color: #f3a597; border: 1px solid #7a2c22;
}
.forecast { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.forecast td { padding: 2px 0; color: var(--muted); }
.forecast td:last-child { text-align: right; color: var(--ink); font-variant-numeric: tabular-nums; }
.forecast tr.total td { border-top: 1px solid var(--line); padding-top: 4px; font-weight: 700; color: var(--ink); }
.order-row .remove { border: none; background: none; padding: 0 4px; color: var(--muted); font-size: 15px; line-height: 1; }
.order-row .remove:hover { color: var(--danger); }

.victory-dialog { text-align: center; }
.victory-swatches { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; }
.crest-victory { width: 48px; height: 48px; object-fit: contain; }
.victory-dialog .actions { justify-content: center; }
.treaty-list { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
.treaty-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.treaty-list .state { margin-left: auto; font-size: 12px; color: var(--muted); }
.treaty-list .state.yes { color: var(--gold-bright); font-weight: 700; }
.treaty-list.picker label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.treaty-list.picker input:disabled + .name-crest { opacity: .5; }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 6px 0 2px; }
.progress > div { height: 100%; }

.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; }
/* A player's Crest beside their name (where a colour square used to be). */
.name-crest { display: inline-block; width: 16px; height: 16px; object-fit: contain; flex: none; vertical-align: -3px; margin-right: 3px; }
.players { list-style: none; margin: 0; padding: 0; }
.players li { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; }
.players .name { flex: 1; }
.players .check { width: 16px; text-align: center; }

.report { margin: 0; padding-left: 18px; font-size: 12px; max-height: 260px; overflow-y: auto; }
.report li { margin-bottom: 3px; }

/* Expandable battle log */
.battles-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 6px; }
.battles { display: flex; flex-direction: column; gap: 4px; margin-bottom: 8px; max-height: 360px; overflow-y: auto; }
.battle { border: 1px solid var(--line); border-radius: 6px; font-size: 12px; }
.battle summary { display: flex; align-items: center; gap: 6px; padding: 5px 7px; cursor: pointer; list-style: none; }
.battle summary::-webkit-details-marker { display: none; }
.battle summary::before { content: '▸'; color: var(--muted); font-size: 10px; }
.battle[open] summary::before { content: '▾'; }
.battle[open] summary { border-bottom: 1px solid var(--line); }
.battle-title { flex: 1; min-width: 0; }
.battle-score { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 3px; }
.score-crest { width: 20px; height: 20px; flex: none; object-fit: contain; }
.result { font-size: 10px; font-weight: 700; text-transform: uppercase; padding: 1px 5px; border-radius: 4px; color: #fff; flex: none; }
.result { text-shadow: 0 0 2px rgba(0, 0, 0, .55); }
.roll { font-weight: 700; }
.battle-score .vs { font-size: 11px; margin: 0 1px; font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
.battle-body { padding: 6px 8px 8px; }
.battle-body p { margin: 0 0 6px; }
.battle-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; }
.battle-table th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; padding: 4px 4px 2px; }
.battle-table td { padding: 2px 4px; vertical-align: top; }
.battle-table td .swatch, .battle-table td .name-crest { margin-right: 5px; vertical-align: -1px; }
.battle-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.battle-table tr.sum td { border-top: 1px solid var(--line); font-weight: 700; }
.battle-verdict { font-size: 12px; }
.battle-outcome { margin: 0; padding-left: 16px; color: var(--muted); }
.small { font-size: 11px; }

/* (Over the header too, which has its own layer for the Victory drop-down.) */
.overlay { position: fixed; inset: 0; background: rgba(10, 6, 3, .65); display: grid; place-items: center; padding: 16px; z-index: 40; overflow-y: auto; }
.dialog { background: var(--grain), var(--panel); border: 1px solid var(--gold); border-radius: 12px; padding: 22px; width: min(420px, 100%); box-shadow: 0 10px 40px rgba(0, 0, 0, .6); }
/* The first join pop-up: the welcome (it scrolls on a short screen), then Join
   and Just watch, always in view under it. */
.dialog.lobby-intro { width: min(560px, 100%); max-height: calc(100svh - 32px); padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.welcome { overflow-y: auto; min-height: 0; padding: 22px 26px 10px; line-height: 1.45; font-size: 14px; }
.welcome p { margin: 0 0 10px; }
.welcome-lead { font-size: 15px; }
.welcome-name { font-family: "Aston Royal", Georgia, serif; font-style: normal; font-size: 1.35em; color: var(--gold-bright); letter-spacing: .03em; }
.welcome-ways { display: grid; gap: 8px; margin: 12px 0 14px; }
.welcome-way { background: var(--raised); border: 1px solid var(--line); border-left: 3px solid var(--gold); border-radius: 8px; padding: 8px 12px; }
.welcome-way h3 { margin: 0 0 2px; font-size: 15px; font-family: Georgia, "Palatino Linotype", serif; color: var(--gold-bright); }
.welcome-way p { margin: 0; font-size: 13px; }
.welcome-way strong { color: var(--gold-bright); }
.welcome-tips-title { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--gold); }
.welcome-tips { margin: 0; padding-left: 18px; font-size: 13px; color: var(--ink); }
.welcome-tips li + li { margin-top: 6px; }
.lobby-intro-actions { flex: none; display: grid; justify-items: center; gap: 8px; padding: 14px 26px 18px; border-top: 1px solid var(--line); }
.lobby-watch-btn { min-width: min(100%, 236px); }
.lobby-start-btn { font-size: 18px; padding: 10px 56px; letter-spacing: .04em; min-width: min(100%, 236px); }
@media (max-width: 480px) {
  .welcome { padding: 18px 16px 8px; }
  .lobby-intro-actions { padding: 12px 16px 14px; }
}
.seats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 14px 0; }
.seat { display: flex; align-items: center; gap: 6px; justify-content: center; min-width: 0; padding-left: 4px; padding-right: 4px; }
.seat.chosen { outline: 2px solid var(--gold); }
/* The lobby with a seat chosen: a panel at the side, so the map (the start) shows. */
/* (Over the sidebar on wide screens. On narrow ones it is the page itself: the
   whole screen under the header, with the map below it, a scroll away.) */
.overlay.side { inset: 64px 14px auto auto; background: none; padding: 0; place-items: start; max-height: calc(100vh - 78px); overflow: hidden auto; border-radius: 12px; }
.overlay.side .dialog { width: var(--sidebar-w); padding: 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, .55); }
.lobby-to-map { display: none; }
@media (max-width: 800px) {
  body:has(> .overlay.side:not(.hidden)) > .layout { order: 2; }
  .overlay.side { position: static; order: 1; inset: auto; z-index: auto; max-height: none; overflow: visible; border-radius: 0; min-height: calc(100svh - var(--header-h, 0px)); }
  .overlay.side .dialog { width: 100%; min-height: inherit; border-radius: 0; border-width: 0 0 2px; box-shadow: none; padding: 16px 14px 20px; }
  .overlay.side .lobby-to-map { display: block; width: 100%; margin: -4px 0 12px; }
}
.start-options { display: grid; gap: 6px; margin: 8px 0 12px; }
.start-option { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; text-align: left; align-items: center; }
.start-option .start-icon { grid-row: span 2; font-size: 20px; }
.start-option.chosen { outline: 2px solid var(--gold); background: var(--row-selected); }
.start-option:disabled { opacity: .5; }
/* Crests (js/crest.js): small next to names, big on your own panel, and on the map. */
.map-crest { pointer-events: none; opacity: .92; }
/* Hovering a player's crest on the map: their card. */
.crest-card { position: fixed; z-index: 50; pointer-events: none; display: flex; gap: 15px; align-items: center;
  max-width: 450px; padding: 15px 18px; border-radius: 12px; background: #1d1813; border: 1px solid #5a4a33;
  box-shadow: 0 6px 18px rgba(0,0,0,.5); color: #efe6d2; font-size: 19.5px; }
.crest-card.hidden { display: none; }
.crest-card img { width: 84px; height: 84px; object-fit: contain; flex: none; }
.crest-card strong { display: block; font-size: 21px; }
.crest-card p { margin: 3px 0 0; }
.crest-card-house { font-weight: 600; }
.crest-card-motto { font-style: italic; color: #c9bda4; }
.crest-icon { width: 20px; height: 20px; flex: none; object-fit: contain; vertical-align: -5px; }
.seat .crest-icon { width: 26px; height: 26px; }
.me-badge .crest-icon { width: 26px; height: 26px; margin-right: 4px; vertical-align: -8px; }
.me-panel { display: flex; align-items: center; gap: 12px; }
/* The crest card on the left, your gold on the right of it. */
.me-card { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.me-gold { flex: 0 1 220px; min-width: 150px; padding-left: 12px; border-left: 1px solid var(--line); }
.me-gold .power-value { text-align: right; }
.me-gold .forecast { margin-top: 4px; }
.me-gold .warning { font-size: 11px; margin: 6px 0 0; }
.me-panel h2 { margin: 0 0 2px; font-size: 15px; letter-spacing: .06em; color: var(--gold-bright); }
.me-panel p { margin: 0; }
.crest-big { width: 96px; height: 96px; flex: none; object-fit: contain; }
.symbol-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 12px; }
.symbol-option { display: flex; flex-direction: column; gap: 4px; }
.symbol-main { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; }
.symbol-main img { width: 56px; height: 56px; object-fit: contain; }
.symbol-option.chosen .symbol-main { outline: 2px solid var(--gold); background: var(--row-selected); }
.symbol-variants { display: flex; justify-content: center; gap: 3px; }
.symbol-variants button { padding: 2px; line-height: 0; }
.symbol-variants button.chosen { outline: 2px solid var(--gold); }
.symbol-variants img { width: 26px; height: 26px; object-fit: contain; }
.crest-preview { display: flex; flex-direction: column; align-items: center; gap: 2px; margin: 6px 0 10px; }
.crest-canvas { width: 160px; height: 160px; }
/* The login page (public/login.html) */
body.login-page { justify-content: center; }
.login-wrap { display: flex; flex-direction: column; align-items: center; gap: 22px; padding: 32px 16px; }
.login-brand .brand-crown { width: 52px; height: 46px; }
.login-brand .brand-name { font-size: 48px; }
.login-card { width: min(360px, 100%); padding: 24px; }
.login-card h1 { margin-bottom: 14px; }
.login-card .field input { font-size: 15px; }
.login-submit { width: 100%; padding: 9px 12px; font-size: 15px; margin-top: 6px; }
.login-switch { margin: 14px 0 0; text-align: center; color: var(--muted); }
.login-switch a { color: var(--gold-bright); }
@media (max-width: 480px) {
  .login-brand .brand-name { font-size: 34px; }
  .login-brand .brand-crown { width: 38px; height: 34px; }
}
/* The list of games (public/games.html) */
body.games-page .topbar { justify-content: space-between; }
.games-main { width: min(760px, 100%); margin: 0 auto; padding: 18px 16px 40px; display: flex; flex-direction: column; gap: 14px; box-sizing: border-box; }
.games-new-row { display: flex; gap: 8px; }
.games-new-row input { flex: 1; min-width: 0; font: inherit; padding: 7px 9px; border-radius: 6px; }
.game-list { display: grid; gap: 8px; margin-top: 8px; }
.game-card { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--raised); color: var(--ink); text-decoration: none; }
.game-card:hover, .game-card:focus-visible { border-color: var(--gold); outline: none; }
.game-name { font-family: Georgia, "Palatino Linotype", serif; font-size: 16px; color: var(--gold-bright); }
.game-status { grid-column: 1; }
.game-you { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-size: 12px; color: var(--gold); white-space: nowrap; }
.game-card.status-finished { opacity: .75; }
/* A game you play in: your Crest on the left. */
.game-card.has-crest { grid-template-columns: auto 1fr auto; }
.game-crest { grid-column: 1; grid-row: 1 / span 2; width: 44px; height: 44px; object-fit: contain; align-self: center; }
.game-card.has-crest .game-name, .game-card.has-crest .game-status { grid-column: 2; }
.game-card.has-crest .game-you { grid-column: 3; }
/* The Admin's list: a Delete button next to each game (games.html). */
.game-row { display: flex; gap: 8px; align-items: stretch; }
.game-row .game-card { flex: 1; min-width: 0; }
.game-delete { flex: none; color: var(--danger); font-size: 13px; padding: 0 12px; }
.game-delete:hover:not(:disabled) { border-color: var(--danger); }
.delete-dialog h2 { margin-top: 0; }
.delete-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
@media (max-width: 480px) {
  .game-card { grid-template-columns: 1fr; }
  .game-you { grid-column: 1; grid-row: auto; }
  .game-card.has-crest { grid-template-columns: auto 1fr; }
  .game-crest { grid-row: 1 / span 3; }
  .game-card.has-crest .game-you { grid-column: 2; }
}
/* The account in the header: its name and Log out. */
.account-box { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.account-box button { font-size: 12px; padding: 3px 8px; }
.account-box a { color: var(--gold); }
/* (A narrow desktop header has no room for the username; Log out stays.) */
/* On a narrow desktop the turn line goes on a second row of the header. */
@media (min-width: 801px) and (max-width: 1150px) { .topbar .account-box > span { display: none; } }
@media (min-width: 801px) and (max-width: 1440px) {
  .topbar { flex-wrap: wrap; row-gap: 4px; }
  .topbar > .turn-info { order: 10; flex: 1 0 100%; }
  .topbar .brand-name { font-size: 24px; }
  .topbar > .victory-wrap:not(.rules-wrap) { flex: 1 1 140px; min-width: 120px; }
}

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; margin-bottom: 8px; }
.field input, .field select { font: inherit; padding: 7px 9px; border-radius: 6px; }
.name-row { display: flex; gap: 6px; }
.name-row input { flex: 1; min-width: 0; }
.house-row { align-items: center; margin-top: 2px; }
.house-word { font-weight: 600; padding: 0 2px 0 4px; }
.field textarea { font: inherit; padding: 7px 9px; border-radius: 6px; resize: vertical; min-height: 52px; }
.me-house { margin: 2px 0 0; font-weight: 600; }
.me-motto { margin: 2px 0 0; font-style: italic; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.context-menu {
  position: fixed; z-index: 20; min-width: 170px; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  display: flex; flex-direction: column;
}
.context-menu .menu-title { font-size: 11px; color: var(--muted); padding: 4px 8px 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.context-menu button { border: none; background: none; text-align: left; padding: 7px 10px; border-radius: 5px; }
.context-menu button:hover, .context-menu button:focus-visible { background: var(--row-hover); outline: none; }
.context-menu button.danger { color: var(--danger); }
.context-menu button:disabled { color: var(--muted); cursor: not-allowed; background: none; }

/* Map */
/* Icons on the map are parchment (#ecdcb4), not white (see PARCHMENT in map-view.js). */
/* Natural, dark map colours: deep water, brown-green grassland, pine forests, grey-brown rock. */
.tile { stroke: #3c4029; stroke-width: 1; }
.tile.land { fill: #4d5134; } /* (Winter's; the other Seasons, below) */
svg[data-season="spring"] .tile.land { fill: #4f6230; } /* brighter green */
svg[data-season="summer"] .tile.land { fill: #57512f; }  /* a touch redder */
svg[data-season="autumn"] .tile.land { fill: #62522b; }  /* more orange */
.snow-cap { fill: #f4f6f8; stroke: none; pointer-events: none; }
.tile.water { fill: #1c3550; stroke: #162b42; }
.tile.mountain { fill: #4a3626; stroke: #3b2b1e; }
.river { fill: none; stroke: #3f74a6; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; stroke-opacity: .9; pointer-events: none; }
.tile.forest { fill: #284a26; stroke: #1f3b1e; }
.tree { fill: #10240e; pointer-events: none; }
.trunk { fill: #4a3524; pointer-events: none; }
.stables { fill: none; stroke-width: 4; stroke-linecap: round; pointer-events: none; }
.stables-nails { stroke-width: 1.5; pointer-events: none; }
.camp { fill: #ecdcb4; stroke-width: 2.4; stroke-linejoin: round; pointer-events: none; }
.camp-flap { pointer-events: none; }
.camp-poles { stroke-width: 2.2; stroke-linecap: round; fill: none; pointer-events: none; }
.castle { fill: #ecdcb4; stroke-width: 2; stroke-linejoin: round; pointer-events: none; }
.castle-gate { pointer-events: none; }
.village { fill: #ecdcb4; stroke-width: 2; stroke-linejoin: round; pointer-events: none; }
.peak { fill: #0d0b09; stroke: #000; stroke-width: 1; stroke-linejoin: round; pointer-events: none; }
.tint { stroke: none; opacity: .42; pointer-events: none; }
.city-label { font-size: 8px; fill: #e9e2d0; paint-order: stroke; stroke: rgba(20, 14, 9, .7); stroke-width: 2px; text-anchor: middle; pointer-events: none; font-weight: 600; }
/* Range: a dashed outline on every hex in reach; the landing hex keeps the dashes and is filled.
   The pattern fits a hex side exactly (HEX_SIZE 30 = 3 × 10), so every side, vertical or oblique,
   gets the same three short strokes centred on it: 2.5 dash + 2.5 of round caps = 5 visible, 5 gap
   (the -3.75 offset centres them; a corner gets one 5 gap, split between its two sides). */
.hl { fill: none; stroke: #f6f0e4; stroke-width: 2.5; stroke-linecap: round; stroke-dasharray: 2.5 7.5; stroke-dashoffset: -3.75; pointer-events: none; }
.hl.drop { fill: rgba(246, 240, 228, .22); }
.sel { fill: none; stroke: #f0cd74; stroke-width: 3; pointer-events: none; }
.unit { stroke: #23211d; stroke-width: 1.5; }
.unit-outline { stroke: #23211d; stroke-width: 1.5; pointer-events: none; }
.order-line { stroke-width: 3; fill: none; stroke-linecap: round; pointer-events: none; }
.order-line.support { stroke-width: 2; stroke-dasharray: 4 4; }
.hover-hex { fill: none; stroke: #f6f0e4; stroke-width: 1.5; stroke-opacity: .6; pointer-events: none; }
.port-badge { fill: #2f5f8f; stroke: #ecdcb4; stroke-width: 1.2; pointer-events: none; }
.port-anchor { fill: #ecdcb4; font-size: 9px; text-anchor: middle; pointer-events: none; font-family: "Segoe UI Symbol", "Apple Symbols", sans-serif; }
.throne-crown { fill: #e3b23c; stroke: #6b4e12; stroke-width: 1.2; stroke-linejoin: round; }
.mark-hex { fill: rgba(214, 40, 40, .12); stroke: #d62828; stroke-width: 3; stroke-linejoin: round; pointer-events: none; }
.mark-arrow { stroke-width: 3.5; stroke-linecap: round; pointer-events: none; }
.mark-move { stroke-width: 3; stroke-linecap: round; stroke-dasharray: 0.1 6; pointer-events: none; }
.mark-move-halo { stroke-width: 5.5; stroke-linecap: round; stroke-dasharray: 0.1 6; stroke-opacity: .85; pointer-events: none; }
.mark-arrow-halo { stroke-width: 6.5; stroke-linecap: round; stroke-opacity: .85; pointer-events: none; }
.hover-tag { fill: rgba(35, 33, 29, .82); pointer-events: none; }
.hover-text { fill: #fff; font-size: 15px; font-weight: 600; text-anchor: middle; pointer-events: none; font-variant-numeric: tabular-nums; }
.hover-agent { font-size: 12.5px; font-weight: 600; text-anchor: middle; pointer-events: none; paint-order: stroke; stroke: rgba(35, 33, 29, .9); stroke-width: 2.5px; }
.hover-coords { fill: rgba(255, 255, 255, .75); font-size: 11.5px; text-anchor: middle; pointer-events: none; font-variant-numeric: tabular-nums; }
.drag-line { stroke: #f6f0e4; stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }

/* On wide screens the page fills the window exactly: the map keeps its size and
   position, and only the sidebar scrolls. (Otherwise the map would move whenever
   the sidebar changed height.) */
@media (min-width: 801px) {
  body { height: 100vh; overflow: hidden; }
  .layout { min-height: 0; grid-template-rows: minmax(0, 1fr); }
  .map-wrap { min-height: 0; }
  .sidebar { min-height: 0; }
  /* The player page: the crest and the selection panel stay put; the panels
     under them scroll. (A long selection scrolls on its own.) */
  .sidebar:has(> .sidebar-scroll) { overflow: hidden; }
  .sidebar-fixed { flex: none; max-height: 55%; min-height: 0; }
  .sidebar-fixed > #selection-panel { overflow-y: auto; min-height: 0; }
  .sidebar-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; }
}

@media (max-width: 800px) {
  .layout, .layout:has(> .chat:not(.hidden)), body.chat-open .layout:has(> .chat:not(.hidden)) { grid-template-columns: 1fr; }
  /* (Messages go under everything on a narrow screen.) */
  .chat { order: 3; }
  /* Your crest panel goes above the map: the sidebar's boxes become rows of the
     page's own column, so the panel can be put first. */
  .sidebar, .sidebar-fixed { display: contents; }
  .me-panel { order: -1; }
  .map-wrap { order: 0; }
  .sidebar-fixed > #selection-panel { order: 1; }
  .sidebar-scroll { order: 2; }
  .chat-rail { width: 100%; flex-direction: row; justify-content: center; padding: 8px; }
  .chat-rail-label { writing-mode: horizontal-tb; transform: none; }
  .chat-log { max-height: 50vh; }
  .map-wrap { min-height: 60vh; }
  /* The header in rows: the logo with the Rules and your crest; the turn; the Victory track. */
  .topbar { flex-wrap: wrap; gap: 6px 12px; padding: 8px 12px; }
  .brand { order: 0; }
  .brand-name { font-size: 22px; }
  .brand-crown { width: 24px; height: 21px; }
  .rules-wrap { order: 1; margin-left: auto; }
  .rules-wrap.options-wrap { margin-left: 0; } /* (right after the Rules) */
  .me-badge, .topbar > .admin-tag, .topbar > a, .account-box { order: 2; }
  .turn-info { order: 3; flex: 1 1 100%; font-size: 13px; }
  .victory-wrap:not(.rules-wrap) { order: 4; flex: 1 1 100%; min-width: 0; }
  /* The drop-downs open across the screen, under the header (not off its edge). */
  .victory-wrap { position: static; }
  .victory-pop, .victory-pop.rules-pop { left: 8px; right: 8px; width: auto; top: calc(100% + 6px); max-height: 70vh; }
}
@media (max-width: 480px) {
  .me-badge strong { display: none; } /* (just your crest: your name is on your panel) */
  /* Your panel: the gold under your crest and name, not squeezed beside them. */
  .me-panel { flex-wrap: wrap; }
  .me-card { flex: 1 1 100%; }
  .me-gold { flex: 1 1 100%; min-width: 0; padding: 8px 0 0; border-left: none; border-top: 1px solid var(--line); }
}

/* Naming an Elite unit */
.elite-panel { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(214, 170, 76, .3); }
/* Undercities (seen by their owner only) and Spy reports */
.undercity-badge { fill: #2b2733; stroke-width: 1.4; pointer-events: none; }
.undercity-arch { fill: #d9cfa8; pointer-events: none; }
.intel-panel { border-color: #7a6a96; box-shadow: 0 0 0 2px rgba(122, 106, 150, .25); }
.intel-report + .intel-report { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.intel-report h3 { display: flex; align-items: center; gap: 6px; margin: 0 0 2px; font-size: 14px; }
.intel-gold { font-size: 22px; font-weight: 700; }
.intel-gold.negative { color: var(--danger); }
.intel-agents { margin: 4px 0; padding-left: 18px; font-size: 13px; }
.intel-agents li { cursor: default; }
/* Wizards: their spells, and the Spells tab */
.spells-panel { border-color: #8a76c4; box-shadow: 0 0 0 2px rgba(138, 118, 196, .25); }
.spell-card + .spell-card { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.spell-card h3 { margin: 0 0 2px; font-size: 14px; }
.spell-card p { margin: 2px 0; }
.wizard-spells { margin: 6px 0; }
.spell-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 3px 0; font-size: 13px; }
.spell-row button { padding: 2px 10px; }
.damage-mark { font-size: 11px; text-anchor: middle; pointer-events: none; }
.landmark-mark {
  font: 800 18px system-ui, sans-serif; text-anchor: middle; pointer-events: none;
  fill: #fff6d8; stroke: #3b2a12; stroke-width: 2.5px; paint-order: stroke;
}
.landmark-mark.lair { fill: #e02020; stroke: #2a0505; }
.landmark-mark.ank { fill: #6b4f8a; stroke: #1a1020; }
.landmark-mark.empty { fill: #a3a3a3; stroke: #4a4a4a; }
/* The Dragon (Dragonbane) */
/* Sages: the Legends tab (Chapters they Divined) */
.legend-card { margin-top: 8px; }
.legend-card + .legend-card { border-top: 1px solid var(--line); padding-top: 8px; }
.legend-card > summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.legend-chapter { margin: 4px 0 4px 14px; font-size: 13px; }
.duel-mark { font-size: 11px; text-anchor: middle; pointer-events: none; }
.spell-cast-card .result.check-ok { background: #3d7a46; }
.spell-cast-card .result.check-fail { background: #a8392f; }
.spell-cast-card .result.spell-neutral { background: #5b4a8a; }
.assassination-card .result.check-ok { background: #3d7a46; }
.assassination-card .result.check-fail { background: #a8392f; }
.check-card .result.check-ok { background: #3d7a46; }
.check-card .result.check-fail { background: #a8392f; }
.legend-card .result.legend-tag { background: #8a6a24; color: #fff4d6; }
.agent-spotted { color: var(--danger); font-weight: 600; }
.warning-text { font-size: 12px; color: var(--danger); font-weight: 600; }
.elite-form { display: flex; gap: 6px; margin-top: 6px; }
.elite-form input { flex: 1; min-width: 0; }
.error { color: var(--danger); min-height: 0; margin: 4px 0 0; }

/* Newer buildings and unit ranks on the map */
.building-icon { fill: #ecdcb4; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; pointer-events: none; }
.keep-battlements { fill: #ecdcb4; stroke-width: 2.4; stroke-linejoin: miter; pointer-events: none; }
.rank-strike { stroke-width: 3; stroke-linecap: butt; pointer-events: none; }
.rank-band { stroke: none; pointer-events: none; }

/* Agents */
.agent { fill: #ecdcb4; stroke: #23211d; stroke-width: 1.2; pointer-events: none; }
.agent.high-rank { stroke: #ffffff; stroke-width: 1.4; } /* Rank 5 and up */
.agent-leading { fill: #23211d; stroke: #f0cd74; stroke-width: 1.6; pointer-events: none; } /* leading an army: a gold ring */
.agent-letter { font-size: 8px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.agent-icon { pointer-events: none; }
.agent-selected { fill: none; stroke: #23211d; stroke-width: 2; stroke-dasharray: 2 2; pointer-events: none; }
.agent-order { stroke-width: 2; stroke-dasharray: 1 4; stroke-linecap: round; fill: none; pointer-events: none; }
.private-line { color: var(--muted); }

/* Path preview while dragging a unit or an agent */
.drag-path { fill: none; stroke: #23211d; stroke-width: 3.5; stroke-linejoin: round; stroke-linecap: round; stroke-opacity: .85; pointer-events: none; }
.drag-path.bad { stroke: #d62828; stroke-dasharray: 6 5; }
.drag-step { fill: #23211d; pointer-events: none; }
.drag-step.bad { fill: #d62828; }
.path-blocked { fill: rgba(214, 40, 40, .18); stroke: #d62828; stroke-width: 2.5; pointer-events: none; }
.path-cross { stroke: #d62828; stroke-width: 3; stroke-linecap: round; pointer-events: none; }

/* A report line whose hexes are highlighted on the map */
.report li.log-hover { background: var(--row-hover); border-radius: 4px; }
