:root {
  --ink: #132c2a;
  --ink-soft: #405b57;
  --forest: #173f39;
  --forest-2: #21594e;
  --cream: #f5f3e8;
  --paper: #fffef8;
  --line: #d6d9ca;
  --line-strong: #b9c0ad;
  --orange: #ef5b32;
  --orange-dark: #ca4021;
  --blue: #3e7fc4;
  --green: #369667;
  --pink: #d76ba5;
  --muted: #72827d;
  --shadow: 0 12px 32px rgb(24 52 47 / 10%);
  --pixel-shadow: 4px 4px 0 rgb(19 44 42 / 10%);
  --radius: 5px;
}

html {
  min-height: 100%;
  background: #e8ebdf;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body.app-shell {
  min-height: 100vh;
  background:
    linear-gradient(rgb(19 44 42 / 3%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(19 44 42 / 3%) 1px, transparent 1px),
    #eef0e8;
  background-size: 24px 24px;
  color: var(--ink);
}

#file-launch { display: none; }

.file-mode {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: var(--forest);
}

.file-mode #file-launch {
  display: grid;
  width: min(620px, 100%);
  place-items: center;
}

.file-mode #app,
.file-mode .mobile-nav,
body.file-mode > .overlay,
.file-mode #map-editor-bar { display: none !important; }

.file-launch__card {
  position: relative;
  overflow: hidden;
  padding: clamp(30px, 6vw, 54px);
  border: 1px solid #0e342f;
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 12px 14px 0 rgb(0 0 0 / 16%);
}

.file-launch__card::after {
  position: absolute;
  right: -60px;
  bottom: -75px;
  width: 190px;
  height: 190px;
  border: 30px solid rgb(239 91 50 / 10%);
  border-radius: 50%;
  content: "";
}

.brand__mark--notice {
  margin-bottom: 24px;
  border-color: var(--forest);
}

.brand__mark--notice span { background: var(--forest); }
.brand__mark--notice span:nth-child(3) { background: var(--orange); }

.file-launch__eyebrow {
  margin-bottom: 10px;
  color: var(--orange-dark);
  font-size: 0.64rem;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.file-launch__card h1 {
  max-width: 500px;
  margin: 0 0 18px;
  color: var(--ink);
  font-size: clamp(2rem, 6vw, 3.2rem);
  line-height: 0.98;
  letter-spacing: -0.06em;
}

.file-launch__card p:not(.file-launch__eyebrow) {
  max-width: 500px;
  margin: 0 0 24px;
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.65;
}

.file-launch__button {
  position: relative;
  z-index: 1;
  display: inline-flex;
  min-height: 48px;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  border-radius: 3px;
  background: var(--orange);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 850;
  text-decoration: none;
  box-shadow: 3px 3px 0 var(--orange-dark);
}

.file-launch__card code {
  position: relative;
  z-index: 1;
  display: block;
  width: fit-content;
  max-width: 100%;
  margin-top: 18px;
  padding: 7px 9px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  background: #eef1e8;
  color: var(--ink-soft);
  font-size: 0.67rem;
}

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

button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 3px;
  background: #f4f5ec;
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 820;
  letter-spacing: 0.015em;
  transition: transform 140ms, box-shadow 140ms, background 140ms, border-color 140ms;
}

button:hover:not(:disabled) {
  border-color: #93a391;
  background: #fff;
  transform: translateY(-1px);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid rgb(62 127 196 / 45%);
  outline-offset: 2px;
}

button.primary,
#end-turn {
  border: 2px solid transparent;
  background: var(--orange);
  color: #fff;
  box-shadow: 3px 3px 0 var(--orange-dark);
}

button.primary:hover:not(:disabled),
#end-turn:hover:not(:disabled) {
  background: #f46840;
  box-shadow: 4px 5px 0 var(--orange-dark);
}

button:disabled {
  opacity: 0.48;
}

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

#app {
  min-height: 100vh;
}

/* Navigation and command bar, adapted from the ChatGPT AWBW2 shell. */
#topbar {
  position: sticky;
  z-index: 50;
  top: 0;
  display: block;
  padding: 0;
  border: 0;
  border-bottom: 3px solid #0c2925;
  background: var(--forest);
  color: #fff;
  box-shadow: 0 4px 15px rgb(15 42 38 / 18%);
}

.topbar__inner {
  display: flex;
  width: min(1380px, calc(100% - 40px));
  min-height: 68px;
  align-items: center;
  gap: clamp(24px, 4vw, 58px);
  margin: 0 auto;
}

.brand {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 10px;
  color: #fff;
}

.brand__mark {
  display: grid;
  grid-template-columns: repeat(3, 8px);
  width: 28px;
  height: 27px;
  align-items: end;
  gap: 2px;
  padding: 4px 2px;
  border: 2px solid #d9e7d8;
  border-radius: 2px;
  transform: skew(-5deg);
}

.brand__mark span { background: #d9e7d8; }
.brand__mark span:nth-child(1) { height: 7px; }
.brand__mark span:nth-child(2) { height: 13px; }
.brand__mark span:nth-child(3) { height: 18px; background: var(--orange); }

.brand__name {
  color: #fff;
  font-size: 1.3rem;
  font-style: italic;
  font-weight: 950;
  letter-spacing: -0.07em;
}

.brand__name span { color: var(--orange); }

.brand__tag {
  margin-left: 2px;
  padding: 4px 6px;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 2px;
  color: #bcd0ca;
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.12em;
}

.desktop-nav {
  display: flex;
  align-self: stretch;
  gap: 3px;
}

.nav-link {
  position: relative;
  display: flex;
  min-width: 88px;
  min-height: 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: #bdd0c9;
  font-size: 0.78rem;
  font-weight: 750;
}

.nav-link > span {
  color: var(--account-color, #8ca9a0);
  font-size: 1rem;
}

.nav-link::after {
  position: absolute;
  right: 12px;
  bottom: -3px;
  left: 12px;
  height: 3px;
  background: var(--orange);
  content: "";
  transform: scaleX(0);
  transition: transform 140ms;
}

.nav-link:hover:not(:disabled),
.nav-link.is-active {
  border: 0;
  background: rgb(255 255 255 / 5%);
  color: #fff;
  transform: none;
}

.nav-link.is-active::after { transform: scaleX(1); }

.account-menu {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: #e7efeb;
  font-size: 0.75rem;
  font-weight: 750;
}

.player-dot,
.site-footer__status i {
  width: 8px;
  height: 8px;
  border: 2px solid rgb(255 255 255 / 65%);
  border-radius: 50%;
  background: var(--orange);
  box-shadow: 0 0 0 3px rgb(103 209 142 / 12%);
}

.settings-shortcut {
  display: grid;
  width: 34px;
  min-height: 34px;
  place-items: center;
  padding: 0;
  border-color: rgb(255 255 255 / 11%);
  background: transparent;
  color: #b8cbc4;
  font-size: 0.9rem;
}

.settings-shortcut:hover:not(:disabled) {
  border-color: rgb(255 255 255 / 22%);
  background: rgb(255 255 255 / 7%);
  color: #fff;
}

#tools-menu {
  position: relative;
}

#tools-menu summary {
  display: grid;
  width: 40px;
  min-height: 40px;
  place-items: center;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 11%);
  border-radius: 3px;
  background: transparent;
  color: #b8cbc4;
  font-size: 0.9rem;
  letter-spacing: 0.08em;
}

#tools-menu[open] summary,
#tools-menu summary:hover {
  background: rgb(255 255 255 / 7%);
  color: #fff;
}

.tools-drop {
  top: calc(100% + 10px);
  right: 0;
  display: flex;
  min-width: 230px;
  padding: 10px;
  gap: 6px;
  border: 1px solid #264f48;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.tools-drop::before {
  position: absolute;
  top: -7px;
  right: 14px;
  width: 12px;
  height: 12px;
  border-top: 1px solid #264f48;
  border-left: 1px solid #264f48;
  background: var(--paper);
  content: "";
  transform: rotate(45deg);
}

.tools-drop strong {
  padding: 6px 7px 8px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.61rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.tools-drop button,
.tools-drop select,
.tools-drop .tools-link {
  position: relative;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 2px;
  background: #f5f6ee;
  color: var(--ink);
  font-size: .72rem;
  font-weight: 820;
  text-decoration: none;
  text-align: left;
}

.tools-drop .tools-link { display: flex; align-items: center; gap: 7px; }

.tools-drop select { border-color: var(--line); }
.tools-drop button:hover:not(:disabled),
.tools-drop .tools-link:hover { border-color: var(--line); background: #fff; }

.commandbar {
  display: flex;
  width: min(1380px, calc(100% - 40px));
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 0 auto;
  border-top: 1px solid rgb(255 255 255 / 8%);
}

#hud {
  display: flex;
  min-width: 0;
  flex: 1;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

#hud::-webkit-scrollbar { display: none; }

#hud span {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: 2px;
  background: rgb(255 255 255 / 5%);
  color: #bfd1ca;
  font-size: 0.68rem;
  font-weight: 750;
}

#hud #hud-player { color: #fff; }
#hud #hud-funds { color: #f8d47a; }
#hud #power-log { border: 0; background: transparent; color: #8da79f; }

.top-buttons {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 7px;
}

.top-buttons button {
  min-height: 38px;
  border-color: rgb(255 255 255 / 14%);
  background: rgb(255 255 255 / 7%);
  color: #e7efeb;
  font-size: 0.68rem;
}

.top-buttons button:hover:not(:disabled) {
  border-color: rgb(255 255 255 / 25%);
  background: rgb(255 255 255 / 12%);
}

.top-buttons .icon-button {
  width: 38px;
  padding: 0;
  font-size: 1rem;
}

#end-turn {
  min-width: 128px;
  border-color: transparent;
}

.power-btn {
  min-height: 30px;
  padding: 0 10px;
  border-color: #966fd0;
  background: #7443b8;
  color: #fff;
  font-size: 0.66rem;
}

.power-btn.super { border-color: #de71b7; background: #b8438f; }

/* Game surface */
#layout {
  display: flex;
  width: min(1380px, calc(100% - 40px));
  align-items: flex-start;
  justify-content: center;
  gap: 18px;
  padding: 32px 0 48px;
  margin: 0 auto;
}

#board-wrap {
  min-width: 0;
  padding: 16px;
  border: 1px solid #153f38;
  border-radius: var(--radius);
  background:
    radial-gradient(rgb(255 255 255 / 5%) 1px, transparent 1px),
    #0f302b;
  background-size: 14px 14px;
  box-shadow: var(--shadow);
}

#board {
  border: 6px solid #082720;
  border-radius: 0;
  box-shadow: 8px 10px 0 rgb(0 0 0 / 18%);
}

#eval-bar {
  height: 20px;
  margin-bottom: 12px;
  border: 1px solid rgb(255 255 255 / 14%);
  border-radius: 2px;
}

#replay-bar {
  margin-bottom: 12px;
  border: 1px solid rgb(255 255 255 / 13%);
  border-radius: 3px;
  background: #12352f;
}

#replay-bar button {
  border-color: rgb(255 255 255 / 18%);
  background: rgb(255 255 255 / 8%);
  color: #fff;
}

#macro-bar {
  margin-bottom: 12px;
  border: 1px solid rgb(255 255 255 / 18%);
  border-radius: 4px;
  background: #12352f;
}

#macro-order-btn.active {
  background: #1e5249;
  border-color: #48c78e;
  color: #fff;
  box-shadow: 0 0 8px rgba(72, 199, 142, 0.4);
}

#sidebar {
  top: 150px;
  flex: 0 0 290px;
  width: 290px;
  max-height: calc(100vh - 170px);
  gap: 12px;
  padding-right: 2px;
}

#sidebar section {
  padding: 17px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 4px 13px rgb(25 48 44 / 5%);
  color: var(--ink-soft);
  font-size: 0.72rem;
  line-height: 1.58;
}

#sidebar h3,
.wz-h3,
.lobby-head {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 900;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.info-title { color: var(--ink); }
.dmg-preview { color: var(--orange-dark); }
.dmg-preview.counter { color: var(--blue); }

/* Menus over the board */
#action-menu,
#build-menu {
  padding: 6px;
  gap: 2px;
  border: 1px solid #315a52;
  border-radius: 4px;
  background: rgb(19 63 55 / 97%);
  box-shadow: 0 12px 28px rgb(0 0 0 / 28%);
}

#action-menu button,
#build-menu button {
  min-height: 38px;
  border-radius: 2px;
  color: #eef5f1;
}

#action-menu button:hover,
#build-menu button:hover:not(:disabled) {
  background: rgb(255 255 255 / 10%);
}

#action-menu .sub,
#build-menu .bm-title { color: #a9c1b9; }
.bm-cost { color: #f8d47a; }

/* Dialogs and setup cards */
.overlay {
  z-index: 80;
  padding: 24px;
  background: rgb(10 31 28 / 76%);
  backdrop-filter: blur(5px);
}

.panel {
  width: 430px;
  max-width: min(94vw, 430px);
  padding: 28px;
  gap: 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 24px 60px rgb(7 29 25 / 36%);
  color: var(--ink);
}

.panel.wide {
  width: 840px;
  max-width: min(95vw, 840px);
}

#setup .panel {
  width: 760px;
  max-width: min(96vw, 760px);
}

/* The first screen is a real document page, not a modal floating over a game
   that has not started yet. The same setup can still open as a modal from an
   active match by removing .is-page. */
body.lobby-page {
  min-height: 100svh;
  overflow: auto;
}

body.lobby-page #app { display: block; min-height: 0; }
body.lobby-page #layout,
body.lobby-page .site-footer,
body.lobby-page .commandbar { display: none; }
body.lobby-page .mobile-nav { display: none; }

#setup.is-page {
  position: relative;
  inset: auto;
  z-index: 1;
  display: block;
  min-height: 100svh;
  padding: clamp(22px, 4vw, 54px) clamp(14px, 3vw, 34px) 80px;
  overflow: visible;
  background:
    linear-gradient(rgb(19 44 42 / 4%) 1px, transparent 1px),
    linear-gradient(90deg, rgb(19 44 42 / 4%) 1px, transparent 1px),
    #eef0e8;
  background-size: 24px 24px;
  backdrop-filter: none;
}

#setup.is-page > .panel {
  width: min(100%, 980px);
  max-width: 980px;
  max-height: none;
  margin: 0 auto;
  padding: clamp(18px, 4vw, 42px);
  overflow: visible;
  border: 1px solid var(--line);
  border-top: 5px solid var(--orange);
  background: var(--paper);
  box-shadow: 0 12px 32px rgb(24 52 47 / 10%);
}

#setup.is-page .setup-heading {
  padding-bottom: 15px;
  border-bottom: 1px solid var(--line);
}

.panel h2 {
  margin: 0;
  color: var(--ink);
  font-size: 1.55rem;
  letter-spacing: -0.035em;
}

.panel label,
.wz-grid label,
.online-grid label {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.025em;
}

.panel input,
.panel select,
.wz-grid input,
.wz-grid select,
.online-grid input,
.online-grid select,
.me-row input,
.me-row select {
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid var(--line-strong);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.panel input[type="number"],
.panel input[type="text"],
.panel input[type="password"],
.panel input:not([type]),
#login-pass {
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid var(--line-strong);
  border-radius: 3px;
  background: #fff;
  color: var(--ink);
}

.panel input:focus,
.panel select:focus,
.wz-grid input:focus,
.wz-grid select:focus,
.online-grid input:focus,
.online-grid select:focus {
  border-color: var(--forest-2);
  box-shadow: 0 0 0 3px rgb(33 89 78 / 13%);
}

.panel-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 4px;
}

.panel-buttons button {
  min-width: 115px;
  min-height: 44px;
  padding: 0 15px;
}

.mode-picks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.mode-pick {
  min-height: 104px;
  padding: 15px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--forest-2);
  border-radius: 3px;
  background: #f6f7ef;
  color: var(--ink);
}

.mode-pick.primary {
  border-color: #e6a18d;
  border-left-color: var(--orange);
  background: #fff1eb;
  color: var(--ink);
  box-shadow: none;
}

.mode-pick b { font-size: 0.83rem; }
.mode-pick span { color: var(--muted); font-size: 0.65rem; line-height: 1.45; }

.lobby-grid {
  padding: 13px;
  border: 1px solid var(--line);
  background: #f4f5ec;
}

.lobby-name { color: var(--ink); }
.lobby-grid select { width: 100%; min-width: 0; }
.lobby-player-picks { display: grid; gap: 5px; }
.lobby-player-picks .country-select { font-size: 11px; opacity: .86; }

.classic-options {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f8f8f2;
}

.hotseat-option {
  margin: 8px 0 12px;
  padding: 12px 14px;
  border: 1px solid rgba(110, 168, 153, .28);
  border-radius: 12px;
  background: rgba(21, 68, 60, .18);
}
.hotseat-option .check-row { margin: 0 0 8px; }
.hotseat-option p { margin: 8px 0 0; }
.campaign-stage.locked { opacity: .58; }
.campaign-briefing { margin: 7px 0 0; padding-left: 10px; border-left: 3px solid rgba(122,190,170,.45); font-size: 12px; }

.setup-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.setup-heading h2 { margin: 0; }

.setup-actions { display: flex; align-items: center; gap: 8px; }
#back-to-game { min-height: 44px; padding: 0 18px; font-size: 15px; white-space: nowrap; }
@media (max-width: 560px) {
  #back-to-game { font-size: 14px; padding: 0 12px; }
  .setup-heading h2 { font-size: 1.25rem; }
}

.settings-inline {
  width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1rem;
}

.classic-options > summary {
  cursor: pointer;
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 800;
}

.classic-options__grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.unit-rule-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.unit-rule-columns fieldset {
  min-width: 0;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
}

.unit-rule-columns legend {
  padding: 0 5px;
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
}

.unit-check-list {
  display: grid;
  max-height: 145px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 5px 8px;
  overflow: auto;
}

.unit-check-list label {
  display: flex;
  min-width: 0;
  flex-direction: row;
  align-items: center;
  gap: 5px;
  font-size: 0.68rem;
  font-weight: 650;
}

.unit-check-list input { min-height: auto; }

.rule-check-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.rule-check-list fieldset {
  border: 1px solid var(--line, #3a3f4a);
  border-radius: 8px;
  padding: 6px 8px 8px;
  margin: 0;
  min-width: 0;
}
.rule-check-list legend {
  font-size: 0.67rem;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0 4px;
}
.rule-check-list .check-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 0;
}
.rule-check-list input { min-height: auto; }
.rule-actions { display: flex; align-items: center; gap: 10px; margin: 6px 0; }

.panel.compact { width: min(430px, calc(100vw - 32px)); }

body[data-lobby-ruleset="classic"] .expansion-only,
body[data-game-ruleset="classic"] .expansion-only { display: none !important; }

#online-box {
  padding-top: 14px;
  border-top-color: var(--line);
}

#online-box summary,
#tick-preview-box summary {
  color: var(--forest-2);
  font-size: 0.72rem;
  font-weight: 850;
}

#online-box p,
.proj-row .proj-desc { color: var(--muted); }
.warn { color: var(--orange-dark); }

.save-row,
.book-row,
.proj-row {
  border: 1px solid var(--line);
  border-radius: 3px;
  background: #f5f6ee;
  color: var(--ink);
}

.profile-table,
.score-table { color: var(--ink); }

.profile-table tr:nth-child(even),
.score-table tr:nth-child(even),
.ms-row:nth-child(odd),
.aw-row:nth-child(odd) { background: #f1f3ea; }

.profile-table td:first-child,
.score-table td:first-child,
.score-table th:first-child { color: var(--muted); }

#editor-tabs button {
  border-color: var(--line);
  border-radius: 3px 3px 0 0;
  background: #edf0e6;
  color: var(--ink-soft);
}

#editor-tabs button.active {
  border-color: var(--forest-2);
  background: var(--forest);
  color: #fff;
}

#editor-text {
  border-color: #315a52;
  border-radius: 0 3px 3px 3px;
  background: #102f2a;
  color: #e0ede8;
}

.craft-cell {
  border-color: var(--line-strong);
  border-radius: 3px;
  background: #eef1e8;
}

.craft-cell:hover { background: #fff; }

#map-editor-bar {
  width: min(1380px, calc(100% - 40px));
  margin: 18px auto 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--orange);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.me-size { color: var(--muted); }
#me-palette button.active { border-color: var(--orange-dark); background: var(--orange); color: #fff; }
#me-palette .me-unit { border-color: #315a52; background: var(--forest-2); color: #fff; }

#me-text-panel {
  margin: 12px 0 4px;
  padding: 12px;
  border: 1px solid var(--line);
  background: #f3f5ef;
}

.me-text-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
#me-text { width: 100%; min-height: 220px; resize: vertical; font: 12px/1.45 Consolas, monospace; }
#me-text-panel p { margin: 7px 0 0; }

#player-chat { display: grid; gap: 6px; max-height: 220px; overflow: auto; }
.player-message { display: grid; grid-template-columns: auto 1fr auto; gap: 7px; align-items: baseline;
  padding: 6px 7px; border: 1px solid var(--line); border-radius: 4px; background: #f3f5ef; }
.player-message span { min-width: 0; overflow-wrap: anywhere; }
.player-message small { color: var(--muted); }
.player-chat-form { display: grid; grid-template-columns: 1fr auto; gap: 6px; margin-top: 8px; }
.player-chat-form input { min-width: 0; }

.lobby-co-picks { display: grid; gap: 4px; min-width: 150px; }
.lobby-co-picks select[data-backup="1"] { border-left-color: #8e5db7; }

.param-bar {
  border-color: var(--line-strong);
  background: #e4e8dd;
}

.param-row .p-num,
#world-engine-status,
#world-prestige { color: var(--ink); }
.proj-row .proj-cost,
.ms-claimed { color: #a27300; }
.proj-row .proj-req { color: var(--orange-dark); }

#boot-error {
  width: min(1180px, calc(100% - 40px));
  margin: 18px auto;
  border: 1px solid #c5745e;
  border-radius: 3px;
  background: #fff0eb;
  color: #8b2f1d;
}

.site-footer {
  display: flex;
  width: min(1380px, calc(100% - 40px));
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  margin: auto auto 0;
  border-top: 1px solid #cfd3c7;
  color: #7c8983;
  font-size: 0.67rem;
  letter-spacing: 0.04em;
}

.site-footer__status {
  display: flex;
  align-items: center;
  gap: 7px;
}

.site-footer__status i {
  width: 6px;
  height: 6px;
  border: 0;
  background: #67d18e;
}

.mobile-nav { display: none; }
.touch-only,
#touch-hint { display: none; }
.asset-loader {
  position: absolute;
  z-index: 45;
  inset: 0;
  min-height: 260px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 7px;
  border-radius: 5px;
  background: #082720f2;
  color: #f4fbf8;
  text-align: center;
}
.asset-loader span { color: #a9c9bd; font-size: .76rem; }
.lobby-row { display: contents; }

/* Mobile/tablet interaction layer. Large maps keep readable tiles and live in
   their own scrollable viewport; action menus become bottom sheets so a tap
   can never open a command outside the visible part of the map. */
@media (pointer: coarse) {
  html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  button,
  summary,
  .mobile-nav__link {
    min-width: 44px;
    min-height: 44px;
  }

  input,
  select,
  textarea,
  .panel input,
  .panel select,
  .me-row input,
  .me-row select {
    min-height: 44px;
    font-size: 16px !important;
  }

  .touch-only { display: inline-flex; align-items: center; justify-content: center; }

  #touch-hint {
    position: sticky;
    z-index: 12;
    top: 0;
    display: block;
    margin: -9px -9px 9px;
    padding: 7px 10px;
    border-bottom: 1px solid rgb(255 255 255 / 13%);
    background: rgb(8 39 32 / 94%);
    color: #c8d9d3;
    font-size: 0.68rem;
    font-weight: 750;
    line-height: 1.35;
    text-align: center;
    backdrop-filter: blur(4px);
  }

  #board { touch-action: pan-x pan-y pinch-zoom; }
  body.map-editor-active:not(.map-pan-mode) #board { touch-action: none; }

  #action-menu,
  #build-menu {
    position: fixed !important;
    z-index: 100;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: calc(var(--mobile-dock-offset, 12px) + env(safe-area-inset-bottom)) !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    top: auto !important;
    width: auto;
    max-height: min(48dvh, 460px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px;
    border-radius: 12px 12px 5px 5px;
  }

  #action-menu button,
  #build-menu button {
    min-height: 48px;
    font-size: 0.92rem;
  }

  .panel,
  #sidebar,
  #board-wrap {
    -webkit-overflow-scrolling: touch;
  }
}

/* iPads, including 1024px landscape models, get the full-width board instead
   of a narrow desktop board squeezed beside the information column. */
@media (pointer: coarse) and (max-width: 1180px) {
  #layout {
    align-items: center;
    flex-direction: column;
  }

  #board-wrap { max-width: 100%; }

  #sidebar {
    position: static;
    width: 100%;
    max-width: 900px;
    max-height: none;
    flex: 1 1 auto;
    overflow: visible;
  }
}

@media (max-width: 1050px) {
  .topbar__inner,
  .commandbar,
  #layout,
  #map-editor-bar,
  .site-footer { width: calc(100% - 28px); }

  .topbar__inner { gap: 18px; }
  .nav-link { min-width: auto; padding: 0 9px; }
  .nav-link > span { display: none; }
  .account-label { display: none; }
  #sidebar { flex-basis: 260px; width: 260px; }
}

@media (max-width: 900px) {
  #topbar { position: static; }

  .commandbar {
    align-items: stretch;
    flex-direction: column;
    gap: 9px;
    padding: 10px 0 12px;
  }

  #hud { width: 100%; flex-wrap: nowrap; }
  #hud .power-btn[data-icon] {
    min-width: 40px;
    width: 40px;
    padding: 0;
    font-size: 0;
  }
  #hud .power-btn[data-icon]::before {
    content: attr(data-icon);
    font-size: 1rem;
  }

  .top-buttons {
    width: 100%;
    flex-wrap: nowrap;
    gap: 3px;
    overflow: visible;
    padding: 1px 0 4px;
  }
  .top-buttons button[data-icon] {
    width: auto;
    min-width: 34px;
    max-width: 64px;
    flex: 1 1 0;
    padding: 0 5px;
    font-size: 0;
  }
  .top-buttons button[data-icon]::before {
    content: attr(data-icon);
    font-size: 1.12rem;
    line-height: 1;
  }
  #end-turn { order: -1; flex: 1 1 0; }

  #layout {
    align-items: center;
    flex-direction: column;
    padding-top: 20px;
  }

  #sidebar {
    position: static;
    width: 100%;
    max-width: 720px;
    max-height: none;
    flex: 1 1 auto;
    overflow: visible;
  }
}

@media (max-width: 720px) {
  :root { --mobile-dock-offset: 72px; }

  body.app-shell { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }

  #topbar {
    position: sticky;
    top: 0;
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .topbar__inner {
    width: calc(100% - 28px);
    min-height: 50px;
  }

  .brand { display: flex; }
  .brand__tag,
  .desktop-nav { display: none; }
  .account-menu { margin-left: auto; }
  .account-label,
  .account-menu > .player-dot { display: none; }

  .commandbar,
  #layout,
  #map-editor-bar { width: calc(100% - 20px); }

  .commandbar {
    gap: 6px;
    padding: 6px 0 8px;
  }

  #end-turn {
    position: static;
    z-index: 2;
    min-width: 34px;
    box-shadow: 3px 3px 0 var(--orange-dark);
  }

  #layout { padding-bottom: 28px; }

  #board-wrap {
    width: 100%;
    max-height: clamp(240px, calc(100dvh - 230px), 680px);
    padding: 9px;
    overflow: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    scrollbar-color: #789188 #0b2924;
  }

  #board { max-width: none; }

  #sidebar { max-width: none; }

  .panel,
  .panel.wide {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - max(24px, env(safe-area-inset-top)) - max(24px, env(safe-area-inset-bottom)));
    padding: 22px 18px;
  }

  .overlay {
    align-items: flex-start;
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .overlay > .panel { margin: auto; }
  .mode-picks { grid-template-columns: 1fr; }
  .classic-options__grid,
  .unit-rule-columns { grid-template-columns: 1fr; }
  #setup .lobby-grid { display: block; overflow: visible; padding: 0; border: 0; background: transparent; }
  #setup .lobby-head { display: none; }
  #setup .lobby-rows { display: grid; gap: 9px; }
  #setup .lobby-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 7px;
    padding: 10px;
    border: 1px solid var(--line);
    border-left: 4px solid currentColor;
    border-radius: 4px;
    background: #f4f5ec;
  }
  #setup .lobby-name { grid-column: 1 / -1; }
  #setup .lobby-co-picks,
  #setup .lobby-player-picks { min-width: 0; }
  .online-grid,
  .wz-grid { grid-template-columns: 1fr 1fr; }
  .panel-buttons button { flex: 1 1 135px; }

  #profiles-table,
  #scores-table,
  #gameover-scores,
  .match-history { max-width: 100%; overflow-x: auto; }

  .campaign-stage,
  .proj-row { align-items: stretch; grid-template-columns: 1fr; flex-direction: column; }

  .campaign-stage button,
  .proj-row button { width: 100%; }

  #map-editor-bar { padding: 10px; }
  #map-editor-bar .me-row {
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    padding-bottom: 6px;
  }
  #map-editor-bar .me-row > * { flex: 0 0 auto; }
  #me-palette { max-height: 124px; overflow-y: auto; }
  #me-text { min-height: 42dvh; font-size: 16px; }

  .co-speech {
    position: fixed;
    right: max(10px, env(safe-area-inset-right));
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: max(10px, env(safe-area-inset-left));
    width: auto;
  }

  .site-footer { display: none; }

  .mobile-nav {
    position: fixed;
    z-index: 60;
    right: 0;
    bottom: 0;
    left: 0;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    min-height: calc(65px + env(safe-area-inset-bottom));
    padding: 0 7px env(safe-area-inset-bottom);
    border-top: 2px solid #0b2a26;
    background: var(--forest);
    box-shadow: 0 -8px 20px rgb(20 48 43 / 16%);
  }

  .mobile-nav__link {
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 65px;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 3px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #9eb5ad;
    box-shadow: none;
  }

  .mobile-nav__link:hover:not(:disabled) { border: 0; background: rgb(255 255 255 / 5%); transform: none; }
  .mobile-nav__link > span { font-size: 1.05rem; }
  .mobile-nav__link small { font-size: 0.58rem; font-weight: 750; }
  .mobile-nav__link.is-active { color: #fff; }

  .mobile-nav__link.is-active::before {
    position: absolute;
    top: 0;
    width: 34px;
    height: 3px;
    background: var(--orange);
    content: "";
  }
}

@media (max-width: 480px) {
  .brand { display: flex; }
  .brand__name { font-size: 1.15rem; }
  #hud span { padding: 5px 8px; font-size: 0.64rem; }
  .top-buttons button { min-height: 42px; }
  .panel { padding: 18px 14px; }
  .panel-buttons { flex-direction: column; }
  .panel-buttons button { width: 100%; flex-basis: auto; }
  #save-row { flex-direction: column; }
  #setup .lobby-row { grid-template-columns: 1fr; }
  #setup .lobby-name { grid-column: 1; }
  .online-grid,
  .wz-grid { grid-template-columns: 1fr; }
  .craft-area { display: block; }
  #craft-book { margin-top: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
.animations-off *, .animations-off *::before, .animations-off *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}

/* --- Global Tiago iPad interface + visible commander controls --- */
.tools-control,
.tools-check {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  color: #bfd1ca;
  font-size: 0.7rem;
  font-weight: 700;
}
.tools-control { flex-direction: column; align-items: stretch; gap: 4px; }
.tools-check { cursor: pointer; }
.tools-check input { accent-color: #e8703a; }
.tools-control select { width: 100%; }

.co-power-cluster {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 0;
}
.co-power-cluster #hud-co {
  flex: 0 0 auto;
  padding: 5px 9px;
  border: 1px solid rgb(255 255 255 / 10%);
  border-radius: 2px;
  background: rgb(255 255 255 / 5%);
  color: #e9dcff;
  font-size: 0.68rem;
  font-weight: 750;
  white-space: nowrap;
}
.co-power-cluster #power-log {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #8da79f;
  font-size: 0.66rem;
}
.sidebar-primary-info { order: -100; }

@media (max-width: 900px) {
  .top-buttons {
    flex-wrap: wrap;
  }
  .co-power-cluster {
    order: -20;
    flex: 0 0 100%;
    width: 100%;
    min-height: 36px;
    overflow-x: auto;
    padding-bottom: 3px;
    scrollbar-width: none;
  }
  .co-power-cluster::-webkit-scrollbar { display: none; }
  .co-power-cluster .power-btn[data-icon] {
    min-width: 40px;
    width: auto;
    flex: 0 0 auto;
    padding: 0 10px;
    font-size: 0;
  }
  .co-power-cluster .power-btn[data-icon]::before {
    content: attr(data-icon);
    font-size: 1rem;
  }
  .co-power-cluster #power-log { max-width: 130px; }
}
.cpu-observe-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  border: 1px solid rgb(255 255 255 / 12%);
  border-radius: 3px;
  background: rgb(255 255 255 / 5%);
  color: #cfe0da;
  font-size: 0.66rem;
  font-weight: 750;
  white-space: nowrap;
  cursor: pointer;
}
.cpu-observe-toggle input { accent-color: #e8703a; }
@media (max-width: 600px) {
  .cpu-observe-toggle span { font-size: 0; }
  .cpu-observe-toggle span::after { content: '🎬 1 a 1'; font-size: 0.66rem; }
}

/* iPad landscape: keep CO stars/powers on their own row so zoom never covers them. */
@media (min-width: 901px) and (max-width: 1180px) {
  .commandbar { align-items: flex-start; }
  .top-buttons { flex-wrap: wrap; justify-content: flex-end; max-width: 58%; }
  .co-power-cluster { flex: 0 0 100%; justify-content: flex-end; order: -20; }
}
