/* FutureWorld. A big, friendly casual-strategy look: bright pale sheets, chunky two-tone buttons,
   a rounded display face for numbers and labels, a readable face for small text.
   Mobile first: phones in landscape are the base layout, tablets and desktops widen it.
   House rule: no shadows of any kind and no black borders. Depth comes from flat two-tone fills
   (a lighter band at the top of each button, inside its shape) and pale tinted hairlines. */
@font-face { font-family: 'Fredoka'; font-style: normal; font-weight: 300 700; font-stretch: 75% 125%; font-display: swap;
  src: url(fonts/fredoka-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Archivo'; font-style: normal; font-weight: 400 800; font-stretch: 62% 125%; font-display: swap;
  src: url(fonts/archivo-latin-ext.woff2) format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: 'Archivo'; font-style: normal; font-weight: 400 800; font-stretch: 62% 125%; font-display: swap;
  src: url(fonts/archivo-latin.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  /* surfaces */
  --sky: #2a6fd6; --sky-hi: #4b8ff0; --sky-pale: #a9d6ff;
  --sheet: #f1f7ff; --sheet-2: #deedfd; --sheet-3: #cfe3fa; --hair: #bcd3ee;
  --ink: #1b2a44; --muted: #4c5d7a; --on: #ffffff;
  --bad: #b02a22; --bad-tint: #ffe4e0; --good-tint: #ddf6e1;
  /* resources: each has its own colour */
  --food: #e03a5f; --wood: #c06a14; --stone: #5f7293; --alloy: #0a87a3; --pop: #7a55f0;
  /* button hues: top band / body */
  --go-hi: #63d46f; --go: #1f7a33;
  --blue-hi: #5fabf6; --blue: #1d68cc;
  --red-hi: #ff8b7b; --red: #c2362d;
  --amber-hi: #ffc04f; --amber: #a95204;
  --violet-hi: #a98dff; --violet: #6543d4;
  --gem-hi: #f06bb8; --gem: #b8237e; --gem-tint: #fde8f3; --gem-hair: #f3bfdc;   /* gems, and only gems */
  --grey-hi: #e3eaf3; --grey: #c3cfdd;
  --accent: #89c9a1; --accent-ink: #13201a;   /* the player's nation colour, set from JS */
  --r: 18px;
  --display: 'Fredoka', 'Archivo', system-ui, sans-serif;
  --font: 'Archivo', system-ui, sans-serif;
  --spring: cubic-bezier(.34, 1.8, .5, 1);
  --sa-t: env(safe-area-inset-top, 0px); --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px); --sa-l: env(safe-area-inset-left, 0px);
  --edge: 6px; --bar: 46px; --mm: 112px; --side-w: 210px;
  --below-bar: calc(var(--sa-t) + var(--edge) + var(--bar) + 10px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: var(--sky); color: var(--ink); font-family: var(--font); font-size: 15px; line-height: 1.45;
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
svg { flex: none; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- chunky buttons: flat two-tone fill, lighter band on top, spring on tap ---------- */
.btn, .act, .qbtn, .pill, .chip, .qi, .nation, .seg button, .desel {
  transition: transform .28s var(--spring), filter .15s;
}
.btn:active, .act:active, .qbtn:active, .pill:active, .chip:active, .qi:active, .nation:active, .seg button:active, .desel:active {
  transform: scale(.92); transition-duration: .06s;
}
.btn {
  --hi: var(--blue-hi); --c: var(--blue); --t: var(--on);
  background: linear-gradient(var(--hi) 0 8px, var(--c) 8px 100%);
  color: var(--t); border: 2px solid var(--hi); border-radius: 16px; padding: 8px 16px; cursor: pointer; min-height: 44px;
  font-family: var(--display); font-weight: 600; font-size: 16px; letter-spacing: .01em;
}
.btn:disabled { --hi: var(--grey-hi); --c: var(--grey); --t: #33425e; cursor: not-allowed; }
.btn.primary { --hi: var(--go-hi); --c: var(--go); }
.btn.danger { --hi: var(--red-hi); --c: var(--red); }
.btn.soft { --hi: var(--sheet); --c: var(--sheet-2); --t: var(--ink); border-color: var(--hair); }
.btn.big { min-height: 56px; padding: 10px 24px; font-size: 19px; border-radius: 20px; }
.btn.sq { width: 50px; min-height: 50px; padding: 0; font-size: 26px; border-radius: 50%; line-height: 1; }
@media (hover: hover) { .btn:hover:not(:disabled), .act:hover:not(:disabled), .qbtn:hover:not(:disabled) { filter: brightness(1.07); } }
.badge { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 99px; background: var(--red); color: var(--on); font-family: var(--display); font-weight: 700; font-style: normal; text-align: center; font-size: 13px; line-height: 22px; border: 2px solid var(--on); }
.panel { background: var(--sheet); border: 2px solid var(--hair); border-radius: var(--r); color: var(--ink); }

/* ================= title ================= */
.screen { position: fixed; inset: 0; z-index: 30; }
#title {
  display: grid; background: var(--sky); color: var(--on);
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  grid-template-areas: "head art" "main art" "setup art" "start art";
  padding: 0 0 0 var(--sa-l);
}
.title-head { grid-area: head; padding: calc(var(--sa-t) + 12px) 20px 6px; }
.wordmark { margin: 0; font-family: var(--display); font-size: 42px; line-height: 0.95; font-weight: 700; font-stretch: 112%; letter-spacing: -0.01em; color: var(--on); }
.wordmark.small { font-size: 46px; }
.lede { font-size: 16px; color: var(--on); max-width: 32ch; margin: 10px 0 0; line-height: 1.5; }
.title-main { grid-area: main; overflow-y: auto; -webkit-mask-image: linear-gradient(transparent, #000 12px, #000 calc(100% - 26px), transparent); mask-image: linear-gradient(transparent, #000 12px, #000 calc(100% - 26px), transparent); overscroll-behavior: contain; padding: 10px 20px 16px; -webkit-overflow-scrolling: touch; }
.pick-h { font-family: var(--display); font-size: 18px; font-weight: 600; margin: 0 0 8px; color: var(--on); }
#nations { display: grid; grid-template-columns: 1fr; gap: 8px; }
.nation { display: grid; grid-template-columns: 30px 1fr; gap: 0 12px; align-items: center; text-align: left; padding: 8px 14px 8px 10px; border-radius: 18px; background: var(--sheet); color: var(--ink); border: 3px solid var(--sheet); cursor: pointer; min-height: 60px; }
.nation .sw { grid-row: span 2; width: 30px; height: 30px; border-radius: 50%; }
.nation b { font-family: var(--display); font-weight: 600; font-size: 17px; line-height: 1.2; }
.nation span { font-size: 13px; color: var(--muted); line-height: 1.4; }
.nation[aria-checked="true"] { border-color: var(--nc); background: #fff; }
#setup { grid-area: setup; display: flex; flex-wrap: wrap; gap: 10px 16px; padding: 8px 20px 4px; }
.field { display: grid; gap: 6px; }
.flabel { font-family: var(--display); font-size: 15px; font-weight: 500; color: var(--on); }
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper output { min-width: 40px; text-align: center; font-family: var(--display); font-size: 26px; font-weight: 700; }
.seg { display: flex; gap: 6px; padding: 4px; background: rgba(255, 255, 255, .16); border-radius: 18px; }
.seg button { flex: 1; background: var(--sheet); color: var(--ink); border: 0; border-radius: 14px; padding: 0 12px; min-height: 46px; cursor: pointer; font-family: var(--display); font-weight: 600; font-size: 16px; }
.seg button[aria-checked="true"] { background: linear-gradient(var(--go-hi) 0 8px, var(--go) 8px 100%); color: var(--on); }

.title-art { grid-area: art; position: relative; min-height: 0; background: var(--sky-pale); overflow: hidden;
  margin: calc(var(--sa-t) + 12px) calc(12px + var(--sa-r)) calc(12px + var(--sa-b)) 4px; border-radius: 26px; border: 2px solid rgba(255, 255, 255, .45); }
#diorama { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#nation-card { position: absolute; left: 12px; right: calc(12px + var(--sa-r)); bottom: 12px; max-width: 380px; padding: 12px 16px; background: var(--sheet); color: var(--ink); border: 2px solid var(--hair); border-radius: 20px; font-size: 14px; line-height: 1.45; }
#nation-card h2 { margin: 0; font-family: var(--display); font-size: 26px; font-weight: 700; line-height: 1.05; display: flex; align-items: center; gap: 10px; }
#nation-card h2::before { content: ''; flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); }
#nation-card p { margin: 4px 0 0; }
#nation-card dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
#nation-card dt { color: var(--muted); font-weight: 600; }
#nation-card dd { margin: 0; }
.start-bar { grid-area: start; position: relative; display: flex; flex-wrap: wrap; gap: 10px; padding: 10px 20px calc(12px + var(--sa-b)); background: var(--sky); }
.start-bar .btn { flex: 1; }
.start-bar .btn.primary { flex: 1.4; }

#loading { display: grid; place-content: center; text-align: center; background: var(--sky); color: var(--on); gap: 8px; }
#loading p { margin: 0; color: var(--on); font-family: var(--display); font-size: 18px; }
#loading .wordmark { color: var(--on); }

/* phones held upright and narrow windows: one column, the list scrolls, Start stays at the bottom */
@media (max-width: 760px) and (orientation: portrait), (max-width: 560px) {
  #title { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto auto; grid-template-areas: "head" "art" "main" "setup" "start"; padding: 0; }
  .title-head { padding: calc(var(--sa-t) + 14px) calc(16px + var(--sa-r)) 10px calc(16px + var(--sa-l)); }
  .lede { display: none; }
  .wordmark { font-size: 38px; }
  .title-art { height: clamp(130px, 22vh, 210px); margin: 0 calc(16px + var(--sa-r)) 4px calc(16px + var(--sa-l)); border-radius: 22px; }
  #nation-card dl { display: none; }
  #nation-card { left: 8px; right: auto; bottom: 8px; padding: 6px 12px; border-radius: 14px; }
  #nation-card p { font-size: 13px; }
  #nation-card { left: 10px; right: 10px; bottom: 10px; padding: 10px 14px; }
  #nation-card h2 { font-size: 18px; }
  #n-about { display: none; }
  .title-main { padding: 12px calc(16px + var(--sa-r)) 16px calc(16px + var(--sa-l)); }
  #setup { display: grid; gap: 8px; padding: 6px calc(16px + var(--sa-r)) 4px calc(16px + var(--sa-l)); }
  #setup .field { grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; }
  #setup .seg button { padding: 0 12px; min-height: 44px; font-size: 15px; }
  #setup .btn.sq { width: 44px; min-height: 44px; }
  .stepper output { min-width: 30px; font-size: 22px; }
  .start-bar { padding-left: calc(16px + var(--sa-l)); padding-right: calc(16px + var(--sa-r)); flex-direction: column-reverse; gap: 8px; }
  .start-bar .btn { flex: none; }
}
@media (max-width: 760px) and (orientation: portrait) and (max-height: 780px) {
  #nation-card dt:nth-of-type(n+2), #nation-card dd:nth-of-type(n+2) { display: none; }
  #nation-card dl { margin-top: 4px; }
}
/* short landscape phones */
@media (max-height: 500px) and (orientation: landscape) {
  .lede { display: none; }
  .wordmark { font-size: 32px; }
  .title-head { padding-top: calc(var(--sa-t) + 10px); }
  #n-about { display: none; }
  .title-art { margin: calc(var(--sa-t) + 8px) calc(8px + var(--sa-r)) calc(8px + var(--sa-b)) 2px; border-radius: 20px; }
  #nation-card { left: 8px; right: 8px; bottom: 8px; padding: 8px 12px; }
  #nation-card h2 { font-size: 19px; }
  #nation-card dl { font-size: 12px; }
  #nations { grid-template-columns: 1fr 1fr; }
  .nation { grid-template-columns: 12px 1fr; padding: 6px 10px; min-height: 54px; gap: 0 8px; align-content: center; }
  .nation .sw { width: 12px; height: 12px; }
  .nation b { line-height: 1.15; }
  .nation b { font-size: 15px; }
  .nation span { font-size: 12px; }
  .start-bar .btn.big { min-height: 50px; padding: 8px 14px; font-size: 18px; }
}
/* tablets and desktops */
@media (min-width: 900px) and (min-height: 560px) {
  #title { grid-template-columns: minmax(440px, 1.3fr) minmax(0, 1fr); }
  .title-art { margin: 24px 24px 24px 8px; border-radius: 32px; }
  .title-head { padding: 32px 40px 6px 56px; }
  .wordmark { font-size: clamp(52px, 5.6vw, 100px); line-height: 0.9; }
  .lede { font-size: 19px; margin: 12px 0 6px; }
  .title-main { padding: 14px 40px 20px 56px; }
  #nations { grid-template-columns: 1fr 1fr; gap: 10px; }
  #setup { align-items: flex-start; gap: 12px 24px; padding: 10px 40px 0 56px; }
  .seg button { flex: none; padding: 0 16px; }
  .start-bar { padding: 14px 40px 20px 56px; }
  .start-bar .btn { flex: none; }
  #nation-card { left: 18px; right: 18px; top: auto; bottom: 18px; max-width: 420px; padding: 14px 18px; font-size: 15px; }
  #nation-card h2 { font-size: 26px; }
  #nation-card dl { margin-top: 14px; gap: 6px 14px; font-size: 14px; }
}

/* ================= game ================= */
#view, #overlay { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#overlay { pointer-events: none; z-index: 2; }
#view { touch-action: none; -webkit-user-select: none; user-select: none; }
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; font-size: 14px; }
#hud > * { pointer-events: auto; }
#hud svg { width: 20px; height: 20px; }

/* top strip: floating pills, no slab */
#topbar.panel { position: absolute; top: calc(var(--sa-t) + var(--edge)); left: calc(var(--sa-l) + var(--edge)); right: calc(var(--sa-r) + var(--edge)); height: var(--bar);
  display: flex; align-items: center; gap: 10px; padding: 0; white-space: nowrap; background: none; border: 0; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.icon-btn { display: inline-grid; justify-items: center; align-content: center; gap: 0; padding: 2px 8px; min-height: 46px; min-width: 52px; border-radius: 16px; font-size: 12px; line-height: 1.1; }
#hud .icon-btn svg { width: 20px; height: 20px; }
#btn-map { --hi: var(--sheet); --c: var(--sheet-2); --t: var(--ink); border-color: var(--hair); }
#btn-map[aria-pressed="true"] { --hi: var(--violet-hi); --c: var(--violet); --t: var(--on); border-color: var(--violet-hi); }
#btn-menu { margin-left: auto; }
.res-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
#cmd .grid ~ .rounds, #cmd .grid + .act { margin-top: 10px; }
.pill { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 12px 0 4px; border-radius: 99px; background: var(--sheet); border: 2px solid var(--hair); color: var(--ink); cursor: pointer; }
.pill .pi { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--rc); color: var(--on); }
#hud .pill .pi svg { width: 20px; height: 20px; }
.pill b { font-family: var(--display); font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.pill .rname { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.pill .fill { position: absolute; left: 40px; right: 12px; bottom: 5px; height: 4px; border-radius: 2px; background: var(--sheet-3); overflow: hidden; }
.pill .fill > span { display: block; height: 100%; width: 100%; transform: scaleX(0); transform-origin: left; border-radius: 2px; background: var(--rc); transition: transform .4s ease-out; }
.r-food { --rc: var(--food); } .r-wood { --rc: var(--wood); } .r-stone { --rc: var(--stone); } .r-alloy { --rc: var(--alloy); } .r-pop { --rc: var(--pop); }
.pill.short { background: var(--bad-tint); border-color: #f3b4ab; }
.pill.full { background: #fff3d6; border-color: #f0c674; }
.pill.short b { color: var(--bad); }
.pill.gain .pi { animation: pop .42s var(--spring); }
.pill.gain b { animation: bump .42s var(--spring); }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.35) rotate(-8deg); } 100% { transform: scale(1); } }
@keyframes bump { 0% { transform: translateY(0); } 40% { transform: translateY(-3px) scale(1.08); } 100% { transform: none; } }
.delta { display: none; font-style: normal; font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--go); } .delta.down { color: var(--bad); }
.era { display: none; padding: 0 14px; height: 36px; align-items: center; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-family: var(--display); font-weight: 600; font-size: 15px; border: 2px solid var(--on); }
#clock { display: none; font-family: var(--display); font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 600; color: var(--ink); background: var(--sheet); border: 2px solid var(--hair); border-radius: 99px; padding: 6px 12px; }

/* minimap, top-left */
#mini-wrap { position: absolute; top: calc(var(--below-bar) + 50px); left: calc(var(--sa-l) + var(--edge)); padding: 5px; line-height: 0; border-radius: 20px; }
#minimap { width: var(--mm); height: var(--mm); border-radius: 14px; cursor: pointer; touch-action: none; }
#hud.map-off #mini-wrap { display: none; }

/* guide chip, top-right under the menu */
#guide { position: relative; width: max-content; max-width: 100%; padding: 0; overflow: hidden; border-radius: 22px; }
.guide-h { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 8px; width: 100%; min-height: 44px; padding: 6px 14px 6px 8px; font-family: var(--display); font-weight: 600; font-size: 15px; }
.guide-h:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; border-radius: 20px; }
#hud .guide-h svg { flex: none; width: 30px; height: 30px; padding: 6px; border-radius: 50%; background: linear-gradient(var(--amber-hi) 0 45%, var(--amber) 45%); color: var(--on); }
#guide-next { flex: 1; min-width: 0; overflow: hidden; line-height: 1.2; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
#guide-count { font-size: 13px; font-weight: 600; color: var(--muted); }
#guide-list { margin: 0; padding: 0 8px 8px; list-style: none; display: grid; gap: 6px; max-height: calc(100dvh - var(--below-bar) - 60px - var(--sa-b)); overflow-y: auto; }
#guide-list li { padding: 8px 12px; border-radius: 14px; background: #fff; border: 2px solid var(--sheet-3); font-size: 13px; line-height: 1.45; }
#guide-list li b { display: block; font-family: var(--display); font-weight: 600; font-size: 15px; line-height: 1.3; }
#guide-list li span { color: var(--muted); font-size: 13px; }
#guide-list li.done { background: transparent; border-color: transparent; color: var(--muted); padding: 2px 12px; }
#guide-list li.done b { font-weight: 500; text-decoration: line-through; }
#guide.closed #guide-list { display: none; }
#guide:not(.closed) { z-index: 3; width: min(300px, 44vw); max-width: none; }
#guide:not(.closed) #guide-next { white-space: normal; }

/* toasts, top-centre between the minimap and the guide: a full tint and a small icon mark the kind */
#toasts { position: absolute; top: var(--below-bar); left: 50%; transform: translateX(-50%); width: min(420px, calc(100vw - 2 * var(--side-w) - 24px - var(--sa-l) - var(--sa-r))); display: grid; gap: 6px; justify-items: center; pointer-events: none; z-index: 4; }
.toast { background: var(--sheet); color: var(--ink); border: 2px solid var(--hair); border-radius: 18px; padding: 7px 14px 7px 8px; font-size: 13px; line-height: 1.45; max-width: 100%; animation: tin .38s var(--spring); pointer-events: auto; display: flex; align-items: center; gap: 8px; }
.toast::before { content: ''; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--tc, var(--go)); }
.toast.bad { background: var(--bad-tint); border-color: #f3b4ab; --tc: var(--red); }
.toast .btn { min-height: 44px; padding: 2px 14px; flex: none; font-size: 15px; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px) scale(.9); } }

/* bottom-left: quick buttons over the selection summary */
#left { position: absolute; left: calc(var(--sa-l) + var(--edge)); bottom: calc(var(--sa-b) + var(--edge)); width: min(296px, calc(50vw - var(--sa-l) - 14px)); display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; pointer-events: none; }
#left > * { pointer-events: auto; }
#quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.qbtn { --hi: var(--blue-hi); --c: var(--blue); position: relative; display: grid; justify-items: center; align-content: center; gap: 1px; min-height: 56px; padding: 4px 2px; background: linear-gradient(var(--hi) 0 8px, var(--c) 8px 100%); color: var(--on); border: 2px solid var(--hi); border-radius: 18px; cursor: pointer; font-family: var(--display); font-size: 12px; line-height: 1.15; font-weight: 600; text-align: center; }
#hud .qbtn svg { width: 24px; height: 24px; }
#btn-idle { --hi: var(--amber-hi); --c: var(--amber); }
#btn-army { --hi: var(--red-hi); --c: var(--red); }
#btn-home { --hi: var(--go-hi); --c: var(--go); }
#btn-area { --hi: var(--violet-hi); --c: var(--violet); }
.qbtn .badge { position: absolute; top: 2px; right: 2px; min-width: 22px; padding: 0 5px; }
.qbtn:disabled { --hi: var(--grey-hi); --c: var(--grey); color: #33425e; cursor: default; }
.qbtn:disabled .badge { display: none; }
.qbtn[aria-pressed="true"] { --hi: #fff; --c: var(--sheet-2); color: var(--violet); border-color: var(--violet); }

#sel { position: relative; padding: 4px 50px 4px 6px; min-height: 0; }
#sel.empty { padding: 10px 14px; min-height: 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.sel-top { display: flex; align-items: center; gap: 8px; }
.portrait { flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-family: var(--display); font-weight: 700; font-size: 16px; background: var(--pc, var(--accent)); color: var(--pi, var(--accent-ink)); border: 2px solid #fff; }
.sel-txt { min-width: 0; flex: 1; }
#sel h3 { margin: 0; font-family: var(--display); font-size: 16px; font-weight: 600; line-height: 1.15; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sel .who { display: none; font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 4px; }
#sel h3 .lv { display: inline-grid; place-items: center; min-width: 22px; height: 22px; margin-left: 6px; padding: 0 6px; border-radius: 99px; background: var(--violet); color: var(--on); font-size: 13px; vertical-align: 2px; }
#sel .status { margin: 0; font-size: 12px; line-height: 1.35; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--muted); }
.desel { position: absolute; top: 50%; margin-top: -22px; right: 3px; width: 44px; height: 44px; display: grid; place-items: center; background: var(--sheet-2); border: 2px solid var(--hair); border-radius: 50%; cursor: pointer; color: var(--muted); }
#hud .desel svg { width: 18px; height: 18px; }
.hp { height: 5px; background: var(--sheet-3); border-radius: 3px; overflow: hidden; margin-top: 3px; }
.hp > span { display: block; height: 100%; background: #3cc25a; border-radius: 4px; }
.hp.mid > span { background: #f0b429; } .hp.low > span { background: var(--red); }
.stats { display: none; flex-wrap: wrap; gap: 2px 12px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.stats b { color: var(--ink); font-weight: 700; }
.chips { display: flex; gap: 6px; margin-top: 6px; overflow-x: auto; scrollbar-width: none; }
.chip { flex: none; background: #fff; color: var(--ink); border: 2px solid var(--hair); border-radius: 99px; padding: 0 14px; cursor: pointer; min-height: 44px; font-family: var(--display); font-weight: 600; font-size: 14px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; line-height: 1.45; }

/* bottom-right: the command card */
#cmd { position: absolute; right: calc(var(--sa-r) + var(--edge)); bottom: calc(var(--sa-b) + var(--edge)); width: max-content; max-width: min(340px, calc(50vw - var(--sa-r) - 14px)); max-height: calc(100dvh - var(--below-bar) - var(--sa-b) - var(--edge) - 50px); overflow-y: auto; overscroll-behavior: contain; padding: 8px 10px 10px; border-radius: 24px; }
#cmd:empty { display: none; }
#cmd.sheet { max-width: none; width: min(470px, calc(100vw - 2 * var(--edge) - var(--sa-l) - var(--sa-r) - 310px)); min-width: min(300px, 60vw); z-index: 3; }
.cmd-top { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; min-height: 28px; }
.cmd-h { margin: 0; flex: 1; font-family: var(--display); font-size: 16px; color: var(--ink); font-weight: 600; }
.cmd-top .cmd-x { position: static; flex: none; margin: 0 0 0 auto; }
.cmd-top .btn { min-height: 44px; padding: 4px 14px; font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
#cmd:not(.sheet) .grid { display: flex; flex-wrap: wrap; gap: 10px; }
#cmd:not(.sheet) .act { flex: 1 1 120px; max-width: 100%; }
#cmd:not(.sheet) .act.wide { flex-basis: 100%; }
#cmd .grid.gather { display: grid; grid-template-columns: repeat(4, minmax(58px, 1fr)); gap: 10px; }
#cmd .grid.gather .act { min-height: 52px; padding: 5px 2px; justify-items: center; text-align: center; gap: 2px; max-width: none; }
#hud #cmd .grid.gather .act > svg, #cmd .grid.gather .act > svg { position: static; width: 22px; height: 22px; margin: 0; color: var(--rc); }
#cmd .grid.gather .act b { font-size: 14px; }
#cmd .grid.crew { display: grid; grid-template-columns: repeat(auto-fit, minmax(128px, 1fr)); gap: 8px; }
#cmd .grid.crew.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#cmd .grid.crew.two .act { padding-left: 12px; padding-right: 12px; }
#cmd .grid.crew .act { max-width: none; }
#cmd .hint, #cmd .why { width: 0; min-width: 100%; }
#cmd:not(.sheet) .cmd-top, #cmd .queue { width: 0; min-width: 100%; }

/* a command tile: pale card with a coloured cost line (build menu); coloured two-tone when it is an order */
.act { --hi: #fff; --c: var(--sheet-2); --t: var(--ink); position: relative; text-align: left; background: linear-gradient(var(--hi) 0 8px, var(--c) 8px 100%); color: var(--t); border: 2px solid var(--hair); border-radius: 18px; padding: 7px 10px; cursor: pointer; min-height: 56px; display: grid; align-content: center; gap: 3px; -webkit-touch-callout: none; }
.act b { font-family: var(--display); font-weight: 600; font-size: 16px; line-height: 1.15; }
.act.locked { --hi: var(--sheet); --c: var(--sheet); color: var(--muted); border-style: dashed; }
.act.locked b { font-weight: 500; }
.act:disabled { opacity: .55; cursor: not-allowed; }
.act.wide { grid-column: 1 / -1; }
.act.go, .act.blue, .act.red, .act.violet { --t: var(--on); }
.act.go { --hi: var(--go-hi); --c: var(--go); border-color: var(--go-hi); }
.act.blue { --hi: var(--blue-hi); --c: var(--blue); border-color: var(--blue-hi); }
.act.red { --hi: var(--red-hi); --c: var(--red); border-color: var(--red-hi); }
.act.go .cost, .act.blue .cost, .act.red .cost { color: var(--on); }
.act.go .cost svg, .act.blue .cost svg, .act.red .cost svg { color: var(--on) !important; }
.act.go .cost .no, .act.blue .cost .no, .act.red .cost .no { color: #fff3c4; text-decoration: underline; text-underline-offset: 2px; }
.act .badge { position: absolute; top: 4px; right: 4px; }
.act:not(.round) > svg { position: absolute; right: 12px; top: 50%; width: 26px; height: 26px; margin-top: -13px; }
#hud .act:not(.round) > svg { width: 26px; height: 26px; }
.act.wide:has(> svg) { padding-right: 46px; }
.act.big { min-height: 60px; }
.act.big b { font-size: 17px; }
/* the main actions: big round buttons by the right thumb */
.act.round { background: linear-gradient(var(--hi) 0 40%, var(--c) 40% 100%); flex: none !important; width: 88px; height: 88px; min-height: 0; border-radius: 50%; padding: 6px; justify-items: center; align-content: center; text-align: center; gap: 1px; }
#hud .act.round > svg { width: 28px; height: 28px; }
.act.round b { font-size: 16px; }
.act.round .cost { justify-content: center; }
.act.round.small { width: 72px; height: 72px; }
.act.round.small b { font-size: 14px; }
.rounds { display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.cost { font-size: 12px; color: var(--muted); display: flex; gap: 2px 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; font-family: var(--display); font-weight: 600; }
.cost > span { display: inline-flex; align-items: center; gap: 3px; }
#hud .cost svg { width: 14px; height: 14px; }
.cost .c-food svg { color: var(--food); } .cost .c-wood svg { color: var(--wood); } .cost .c-stone svg { color: var(--stone); } .cost .c-alloy svg { color: var(--alloy); }
.cost .no { color: var(--bad); }
.queue { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.qi { position: relative; display: inline-flex; align-items: center; gap: 6px; background: #fff; color: var(--ink); border: 2px solid var(--hair); border-radius: 14px; padding: 0 12px; min-height: 44px; font-family: var(--display); font-weight: 600; font-size: 14px; cursor: pointer; overflow: hidden; }
#hud .qi svg { width: 12px; height: 12px; color: var(--muted); }
.qi .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--go-hi); }
.qi.blocked { background: var(--bad-tint); border-color: #f3b4ab; }
.why { font-size: 12px; color: var(--bad); margin: 6px 0 0; line-height: 1.45; font-weight: 600; }

/* long-press or hover description */
#tip { position: fixed; z-index: 20; width: max-content; max-width: min(300px, calc(100vw - 24px)); padding: 10px 14px; font-size: 13px; line-height: 1.45; pointer-events: none; background: #fff; border-radius: 16px; animation: tin .3s var(--spring); }
#tip b { display: block; font-family: var(--display); font-weight: 600; font-size: 16px; margin-bottom: 2px; }

/* portrait during a match */
#rotate { z-index: 50; display: grid; place-content: center; justify-items: center; gap: 10px; padding: 24px; text-align: center; background: var(--sky); color: var(--on); }
#rotate h2 { margin: 0; font-family: var(--display); font-size: 28px; font-weight: 700; max-width: 16ch; line-height: 1.15; }
#rotate p { margin: 0; max-width: 28ch; color: var(--on); line-height: 1.5; }
.rot-ic { width: 84px; height: 84px; color: var(--on); animation: tilt 2.4s ease-in-out infinite; }
@keyframes tilt { 0%, 30% { transform: rotate(0); } 55%, 80% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }

/* menus and game over */
#modal { display: grid; place-items: center; z-index: 40; }
#modal.dim { background: rgba(22, 56, 110, 0.55); }
.dialog { width: min(540px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; padding: 24px; background: var(--sheet); border-radius: 28px; animation: tin .38s var(--spring); }
.dialog h2 { margin: 0 0 10px; font-family: var(--display); font-size: 32px; font-weight: 700; line-height: 1.1; }
#modal-body p { margin: 0 0 10px; line-height: 1.5; }
#modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
#modal-actions .btn { min-height: 56px; font-size: 18px; border-radius: 20px; }
#modal-actions .btn:not(.primary) { --hi: #fff; --c: var(--sheet-2); --t: var(--ink); border-color: var(--hair); }
#modal-actions .btn.primary { grid-column: 1 / -1; font-size: 21px; min-height: 62px; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 20px; margin: 8px 0; }
.kv span:nth-child(even) { text-align: right; font-family: var(--display); font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; line-height: 1.45; }
.keys kbd { align-self: start; justify-self: start; font-family: var(--display); font-weight: 600; background: #fff; border: 2px solid var(--hair); border-radius: 10px; padding: 1px 8px; }
.help-h { margin: 14px 0 8px; font-family: var(--display); font-size: 17px; color: var(--ink); font-weight: 600; }
/* phones: full-screen sheets with big buttons */
@media (max-width: 760px), (max-height: 520px) {
  #modal { place-items: stretch; }
  .dialog { width: 100%; max-height: none; height: 100%; border-radius: 0; border: 0; display: flex; flex-direction: column;
    padding: calc(var(--sa-t) + 18px) calc(var(--sa-r) + 20px) calc(var(--sa-b) + 16px) calc(var(--sa-l) + 20px); }
  #modal-body { flex: 1; overflow-y: auto; min-height: 0; }
  #modal-actions { margin-top: 12px; }
  .dialog h2 { font-size: 28px; }
}
@media (max-height: 520px) and (orientation: landscape) {
  .dialog { display: grid; grid-template-columns: 1fr minmax(240px, 0.8fr); grid-template-rows: auto 1fr; column-gap: 24px; }
  .dialog h2 { grid-column: 1; }
  #modal-body { grid-column: 1; grid-row: 2; }
  #modal-actions { grid-column: 2; grid-row: 1 / 3; grid-template-columns: 1fr; align-content: center; margin: 0; }
}

@media (max-height: 400px) { :root { --mm: 84px; } }

/* ================= wider screens: tablets and desktop ================= */
@media (min-width: 900px) and (min-height: 600px) {
  :root { --edge: 10px; --bar: 50px; --mm: 168px; --side-w: 310px; }
  #hud { font-size: 15px; }
  .res-row { gap: 8px; }
  .pill { height: 48px; padding-right: 16px; }
  .pill .pi { width: 36px; height: 36px; }
  .pill b { font-size: 20px; }
  .pill .rname { position: static; width: auto; height: auto; clip: auto; font-size: 13px; color: var(--muted); font-weight: 600; }
  .pill .fill { left: 44px; right: 16px; }
  .icon-btn { grid-auto-flow: column; gap: 6px; padding: 2px 14px; font-size: 16px; min-height: 48px; }
  #clock { display: inline; }
  .era { display: inline-flex; }
  #left { width: 340px; }
  #sel { padding: 8px 52px 8px 10px; }
  #sel .who { display: block; }
  #sel .status { white-space: normal; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; font-size: 13px; }
  .portrait { width: 44px; height: 44px; font-size: 19px; }
  #sel h3 { font-size: 18px; }
  .hp { height: 8px; }
  .stats { display: flex; }
  #cmd { width: 400px; max-width: none; }
  #cmd:not(.sheet) .act { flex-basis: 118px; }
  #guide { width: 300px; }
}
@media (min-width: 1200px) and (min-height: 600px) {
  :root { --mm: 196px; }
  .delta { display: inline; }
  #cmd { width: 440px; }
}
/* ================= empire: status, side chips, bubbles, sheets ================= */
/* top-left under the bar: empire level and builders */
#status { position: absolute; top: var(--below-bar); left: calc(var(--sa-l) + var(--edge)); display: flex; gap: 10px; pointer-events: none; }
#status > * { pointer-events: auto; }
.stat { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 12px 0 4px; border-radius: 99px; background: var(--sheet); border: 2px solid var(--hair); color: var(--ink); cursor: pointer; font-family: var(--display); }
.stat .si { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: var(--on); }
#hud .stat .si svg { width: 18px; height: 18px; }
.stat b { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1; }
.stat .stext { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat.lvl .si { background: var(--violet); }
.stat.lvl b { padding-bottom: 4px; }
.stat .xp { position: absolute; left: 40px; right: 12px; bottom: 6px; height: 4px; border-radius: 2px; background: var(--sheet-3); overflow: hidden; }
.stat .xp > span { display: block; height: 100%; width: 100%; transform: scaleX(0); transform-origin: left; background: var(--violet); transition: transform .4s ease-out; }
#p-builders.busy { background: var(--bad-tint); border-color: #f3b4ab; }
#p-builders.busy .si { background: var(--red); }

/* top-right column: next steps, goals, chest, next ready, raid warning */
#side { position: absolute; top: var(--below-bar); right: calc(var(--sa-r) + var(--edge)); width: var(--side-w); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
#side > * { pointer-events: auto; }
.side-chip { position: relative; display: inline-flex; align-items: center; gap: 8px; min-height: 44px; max-width: 100%; padding: 4px 14px 4px 6px; border-radius: 99px; background: var(--sheet); border: 2px solid var(--hair); color: var(--ink); font-family: var(--display); font-weight: 600; font-size: 15px; cursor: pointer; white-space: nowrap; }
.side-chip .si { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--blue); color: var(--on); }
#hud .side-chip .si svg { width: 18px; height: 18px; }
.side-chip .st { overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.side-chip b { font-variant-numeric: tabular-nums; }
.side-chip .badge { position: static; margin-left: -2px; }
.side-chip.goals .si { background: var(--go); }
.side-chip.chest { background: #fff3d6; border-color: #f0c674; }
.side-chip.chest .si { background: var(--amber); }
.side-chip.chest .si { animation: wiggle 2.4s ease-in-out infinite; }
.side-chip.raid { background: var(--bad-tint); border-color: #f3b4ab; color: #8f1f19; }
.side-chip.raid .si { background: var(--red); }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-12deg); } 90% { transform: rotate(10deg); } 95% { transform: rotate(-6deg); } }

/* collect bubbles: placed over producers from JS (left/top), under every panel */
#hud > #bubbles { position: absolute; inset: 0; pointer-events: none; overflow: visible; z-index: 0; }
:where(#hud > :not(#bubbles)) { z-index: 1; }   /* bubbles stay under the bars and panels */
.bubble { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); pointer-events: auto; display: inline-flex; align-items: center; gap: 4px; height: 44px; min-width: 44px; padding: 0 12px 0 4px; border-radius: 22px; background: #fff; border: 3px solid var(--rc); color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; cursor: pointer; animation: bob 1.8s ease-in-out infinite; touch-action: manipulation; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -9px; margin-left: -7px; border: 7px solid transparent; border-bottom: 0; border-top-color: var(--rc); }
.bubble .pi { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--rc); color: var(--on); }
#hud .bubble .pi svg { width: 18px; height: 18px; }
.bubble.max { background: #fff3d6; }
.bubble.pop { animation: bpop .26s ease-out forwards; pointer-events: none; }
@keyframes bob { 0%, 100% { transform: translate(-50%, -100%); } 50% { transform: translate(-50%, calc(-100% - 5px)); } }
@keyframes bpop { 0% { transform: translate(-50%, -100%) scale(1); } 45% { transform: translate(-50%, -100%) scale(1.3); opacity: 1; } 100% { transform: translate(-50%, -100%) scale(.2); opacity: 0; } }
.fly { position: fixed; z-index: 60; display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--rc); color: var(--on); pointer-events: none; }
.fly svg { width: 18px; height: 18px; }
.pop-num { position: fixed; z-index: 60; transform: translate(-50%, -100%); padding: 2px 12px; border-radius: 99px; background: #fff; border: 2px solid var(--rc); color: var(--ink); font-family: var(--display); font-weight: 700; font-size: 20px; pointer-events: none; animation: rise .9s ease-out forwards; }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -60%) scale(.7); } 20% { opacity: 1; transform: translate(-50%, -110%) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -260%) scale(1); } }

/* the Upgrade button and other command-card additions */
.act.up { padding-right: 46px; }
.act.up.go .c-time, .act.up.go .c-time svg { color: var(--on); }
.act.up.cant { --hi: #fff; --c: var(--sheet-2); --t: var(--ink); }
.act.up.running { --hi: #fff; --c: var(--sheet-2); --t: var(--ink); overflow: hidden; }
.act.up.running .bar { position: absolute; left: 0; bottom: 0; height: 6px; background: var(--go); }
.c-time { display: inline-flex; align-items: center; gap: 3px; color: var(--ink); }
.up-row { align-items: center; }
#cmd .up-row:has(.running) { display: flex; gap: 8px; }
#cmd .up-row .act.up.running { flex: 1 1 0; min-width: 0; }
.act.up.running .bar { height: 8px; }
#cmd .hint.keep { width: 0; min-width: 100%; }

/* sheets: goals, level, while you were away */
.res-line { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; font-family: var(--display); font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; vertical-align: middle; }
.res-line > span { display: inline-flex; align-items: center; gap: 4px; }
.res-line svg { width: 20px; height: 20px; }
.res-line .c-food svg, .cost .c-food svg { color: var(--food); } .res-line .c-wood svg { color: var(--wood); } .res-line .c-stone svg { color: var(--stone); } .res-line .c-alloy svg { color: var(--alloy); }
.goal-list { display: grid; gap: 8px; margin-top: 4px; }
.goal { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 18px; background: #fff; border: 2px solid var(--sheet-3); }
.goal.done { background: var(--good-tint); border-color: #a9e2b4; }
.goal.claimed { background: transparent; border-color: var(--sheet-3); color: var(--muted); }
.g-txt { flex: 1; min-width: 0; display: grid; gap: 4px; }
.g-txt > b { font-family: var(--display); font-weight: 600; font-size: 17px; line-height: 1.25; }
.g-bar { height: 8px; border-radius: 4px; background: var(--sheet-3); overflow: hidden; }
.g-bar.big { height: 12px; border-radius: 6px; margin: 4px 0 10px; }
.g-bar > span { display: block; height: 100%; background: var(--go); }
.g-bar.big > span { background: var(--violet); }
.g-n { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.g-rw { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 14px; }
.g-rw .res-line { font-size: 15px; }
.g-rw .res-line svg { width: 16px; height: 16px; }
.g-xp { font-family: var(--display); font-weight: 700; color: var(--violet); }
.g-state { font-family: var(--display); font-weight: 600; color: var(--muted); }
.goal .btn { flex: none; min-width: 96px; }
.away-sec { margin-top: 6px; }
.away-sec .help-h { margin: 10px 0 6px; }
.away-item { margin: 0 0 6px !important; }
.away-item.good { color: #17612a; font-weight: 600; }
.away-item.bad { color: #8f1f19; font-weight: 600; }

/* title: a clear second step before replacing an empire */
#new-confirm { flex: 1 1 100%; display: grid; gap: 8px; }
#new-confirm p { margin: 0; color: var(--on); font-size: 15px; line-height: 1.45; }
#new-confirm .row { display: flex; gap: 10px; }
#new-confirm .row .btn { flex: 1; }

/* ================= short phones in landscape: keep the map in view ================= */
@media (max-height: 500px) {
  :root { --side-w: 190px; }
  #sel.empty { display: none; }
  .qbtn { min-height: 48px; font-size: 12px; }
  .qbtn .lw { display: none; }
  #hud .qbtn svg { width: 20px; height: 20px; }
  #cmd { padding: 6px; border-radius: 26px; }
  #cmd:not(.sheet) .cmd-top { min-height: 0; margin-bottom: 8px; }
  #cmd:not(.sheet) .grid, #cmd .grid.crew, #cmd .grid.gather { gap: 10px; }
  #cmd:not(.sheet) .grid + .grid, #cmd:not(.sheet) .grid + .act { margin-top: 10px; }
  #cmd:not(.sheet) .cmd-top:not(:first-child) { display: none; }
  #cmd .hint:not(.keep) { display: none; }
  #cmd:not(.sheet) .act { flex: 0 1 auto; min-height: 50px; padding: 5px 12px 4px; border-radius: 22px; gap: 1px; }
  #cmd:not(.sheet) .act b { font-size: 14px; }
  #cmd:not(.sheet) .act.up { padding-right: 40px; }
  #cmd:not(.sheet) .act.wide { flex-basis: 100%; }
  #hud #cmd .act:not(.round) > svg { width: 22px; height: 22px; margin-top: -11px; right: 10px; }
  .act.round { width: 64px; height: 64px; padding: 4px; }
  .act.round.small { width: 56px; height: 56px; }
  .act.round b { font-size: 13px; }
  .act.round.small b { font-size: 12px; }
  #hud .act.round > svg { width: 22px; height: 22px; }
  .rounds { gap: 12px; }
  #cmd .queue { margin-top: 6px; }
  .side-chip { font-size: 14px; padding-right: 12px; }
  #guide-next { font-size: 14px; }
  /* words never touch a button's edge: quick buttons size to their labels, goal text wraps to two lines */
  #quick { display: flex; }
  .qbtn { flex: 1 1 auto; padding: 4px 8px; }
  #guide-next { font-size: 13px; }
  .act.round.small { width: 64px; height: 64px; }
  #cmd.sheet .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #cmd.sheet .act { padding: 7px 8px; }
  #cmd.sheet .act b { font-size: 15px; }
  #cmd.sheet .cmd-top { position: sticky; top: -6px; z-index: 1; background: var(--sheet); margin: -6px -6px 0; padding: 6px; }
  /* short screens: the side chips pack two to a row, the goals and chest chips drop their words */
  #side { flex-flow: row wrap; justify-content: flex-end; gap: 10px; }
  /* while an action panel is open the side chips would sit on top of it: keep only the raid warning */
  #hud:has(#cmd:not(:empty)) #side > :not(#raid-chip) { display: none; }
  #side > #guide { flex-basis: 100%; }
  .side-chip.goals .st, .side-chip.chest .st { display: none; }
  .side-chip.chest { padding: 4px 6px; }
  .stat .stext { display: none; }
}
@media (min-width: 900px) and (min-height: 600px) {
  .stat .stext { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .btn:active, .act:active, .qbtn:active, .pill:active, .chip:active, .qi:active, .nation:active, .seg button:active, .desel:active { transform: none; filter: brightness(.94); }
}

/* ================= account sheet ================= */
.acct-btn { position: absolute; z-index: 2; top: calc(var(--sa-t) + 12px); right: calc(var(--sa-r) + 12px); display: inline-flex; align-items: center; gap: 8px; min-height: 48px; padding: 6px 16px 6px 12px; font-size: 17px; max-width: min(240px, 42vw); }
.acct-btn svg { width: 22px; height: 22px; color: var(--blue); }
.acct-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#account { display: grid; place-items: center; z-index: 45; }
#account.dim { background: rgba(22, 56, 110, 0.55); }
.acct-sheet { width: min(500px, calc(100vw - 32px)); display: block; }
.acct-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.acct-top h2 { margin: 0; }
.sq-x { width: 48px; min-height: 48px; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.sq-x svg { width: 22px; height: 22px; }
.acct-lede { margin: 0 0 14px; line-height: 1.5; }
.acct-tabs { background: var(--sheet-3); margin-bottom: 14px; }
.seg.acct-tabs button { flex: 1; min-height: 48px; }
.acct-form { display: grid; gap: 12px; }
.acct-field { display: grid; gap: 6px; }
.acct-field label { font-family: var(--display); font-weight: 600; font-size: 17px; }
.acct-input { display: flex; gap: 8px; }
.acct-input input {
  flex: 1; min-width: 0; min-height: 54px; padding: 0 16px; border-radius: 16px; background: #fff; color: var(--ink);
  border: 2px solid var(--hair); font: 600 18px/1.2 var(--font); user-select: text; -webkit-user-select: text;
}
.acct-input input:focus { border-color: var(--blue-hi); outline: 3px solid var(--blue-hi); outline-offset: 1px; }
.acct-input input[aria-invalid="true"] { border-color: var(--red-hi); background: #fff8f7; }
.pw-show { min-width: 84px; min-height: 54px; }
.acct-hint { margin: 0; font-size: 13px; color: var(--muted); }
.acct-err, .acct-ok, .acct-note { margin: 0; padding: 10px 14px; border-radius: 14px; line-height: 1.45; }
.acct-err { background: var(--bad-tint); color: var(--bad); font-weight: 600; }
.acct-ok { background: var(--good-tint); color: #17592a; font-weight: 600; margin-bottom: 12px; }
.acct-note { background: var(--sheet-2); font-size: 14px; }
.acct-form .btn.big, .acct-sheet > #acct-body > .btn.big { width: 100%; }
.acct-card { display: flex; align-items: center; gap: 16px; padding: 14px 16px; margin: 4px 0 14px; background: #fff; border: 2px solid var(--hair); border-radius: 22px; }
.acct-disc { flex: none; width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-family: var(--display); font-weight: 700; font-size: 32px; }
.acct-who { min-width: 0; }
.acct-who p { margin: 0; }
.acct-as { font-size: 15px; color: var(--muted); }
.acct-as b { display: block; color: var(--ink); font-family: var(--display); font-size: 24px; font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.acct-sync, .sync-line { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; margin-top: 4px; }
.acct-sync::before, .sync-line::before { content: ''; flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--grey); }
[data-s="synced"]::before { background: var(--go-hi); }
[data-s="saving"]::before { background: var(--blue-hi); }
[data-s="pending"]::before, [data-s="conflict"]::before { background: var(--amber-hi); }
#modal-body .sync-line { margin: 0 0 10px; color: var(--muted); }
.acct-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.acct-actions .btn { min-height: 52px; }
.acct-actions .btn.primary { grid-column: 1 / -1; }
.acct-choice { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.empire-card { display: flex; flex-direction: column; gap: 10px; padding: 14px; background: #fff; border: 2px solid var(--hair); border-radius: 20px; }
.empire-card h3 { margin: 0; font-family: var(--display); font-size: 20px; font-weight: 700; }
.empire-card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.empire-card dt { color: var(--muted); font-weight: 600; }
.empire-card dd { margin: 0; text-align: right; font-family: var(--display); font-weight: 700; font-size: 17px; font-variant-numeric: tabular-nums; }
.empire-card .btn { margin-top: auto; width: 100%; font-size: 16px; min-height: 56px; line-height: 1.2; }
@media (min-width: 900px) and (min-height: 600px) { .acct-sheet { width: 540px; } }
/* phones: the sheet fills the screen and scrolls */
@media (max-width: 760px), (max-height: 520px) {
  #account { place-items: stretch; }
  .acct-sheet { width: 100%; height: 100%; display: block; overflow-y: auto; overscroll-behavior: contain; }
}
/* short landscape phones: everything on one screen without scrolling */
@media (max-height: 520px) and (orientation: landscape) {
  .acct-sheet { display: block; padding-top: calc(var(--sa-t) + 10px); padding-bottom: calc(var(--sa-b) + 10px); }
  .acct-top { margin-bottom: 4px; }
  .acct-top h2 { font-size: 24px; }
  .sq-x { width: 44px; min-height: 44px; }
  .acct-lede { font-size: 14px; margin-bottom: 8px; line-height: 1.4; }
  .acct-intro { display: none; }
  .acct-tabs { margin-bottom: 8px; }
  .seg.acct-tabs button { min-height: 44px; }
  .acct-form { grid-template-columns: 1fr 1fr; align-items: start; gap: 8px 16px; }
  .acct-form .acct-err, .acct-form .acct-note, .acct-form .btn.big { grid-column: 1 / -1; }
  .acct-field label { font-size: 15px; }
  .acct-input input, .pw-show { min-height: 48px; }
  .acct-note { font-size: 13px; padding: 8px 12px; }
  .acct-form .btn.big { min-height: 50px; }
  .acct-card { margin: 0 0 8px; padding: 8px 12px; }
  .acct-disc { width: 52px; height: 52px; font-size: 26px; }
  .acct-as b { font-size: 21px; }
  .acct-ok { margin-bottom: 8px; padding: 8px 12px; }
  .acct-actions { grid-template-columns: 1.3fr 1fr 1fr; }
  .acct-actions .btn.primary { grid-column: auto; }
  .acct-choice .empire-card { padding: 10px 12px; gap: 6px; }
  .empire-card .btn { min-height: 50px; }
}
@media (max-width: 520px) { .acct-choice, .acct-actions { grid-template-columns: 1fr; } }

/* the Account button sits inside the preview window's corner */
.acct-btn { top: calc(var(--sa-t) + 22px); right: calc(var(--sa-r) + 22px); }
@media (max-height: 500px) and (orientation: landscape) { .acct-btn { top: calc(var(--sa-t) + 16px); right: calc(var(--sa-r) + 16px); min-height: 44px; } }
@media (max-width: 760px) and (orientation: portrait), (max-width: 560px) { .acct-btn { top: calc(var(--sa-t) + 12px); right: calc(var(--sa-r) + 12px); } }
@media (min-width: 900px) and (min-height: 560px) { .acct-btn { top: 36px; right: 36px; } }

/* ---- title on phones: more of the choices above the fold ---- */
@media (max-width: 760px) and (orientation: portrait), (max-width: 560px) {
  .wordmark { font-size: 32px; }
  .title-head { padding-right: calc(150px + var(--sa-r)); }
  .acct-btn { min-height: 44px; padding: 4px 12px 4px 10px; font-size: 15px; }
  #nations { grid-template-columns: 1fr 1fr; gap: 8px; }
  .nation { grid-template-columns: 12px 1fr; padding: 6px 10px; min-height: 54px; gap: 0 8px; align-content: center; }
  .nation .sw { width: 12px; height: 12px; }
  .nation b { font-size: 15px; line-height: 1.15; }
  .nation span { font-size: 12px; }
  .pick-h { margin: 4px 0 8px; font-size: 17px; }
  #nation-card { padding: 5px 10px; }
  #nation-card h2 { font-size: 16px; gap: 8px; }
  #nation-card h2::before { width: 12px; height: 12px; }
  #nation-card p { font-size: 12px; margin-top: 1px; }
  .seg button { padding: 0 12px; min-height: 44px; font-size: 15px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #title { grid-template-columns: minmax(0, 1.75fr) minmax(0, 1fr); }
  .pick-h { margin: 2px 0 6px; font-size: 16px; }
  #setup { gap: 6px 14px; padding-top: 4px; }
  .seg button { padding: 0 11px; min-height: 44px; font-size: 15px; }
  .stepper { gap: 6px; }
  #setup .btn.sq { width: 44px; min-height: 44px; }
  .stepper output { min-width: 30px; font-size: 22px; }
  #nation-card dl { display: none; }
  #nation-card { right: auto; }
}
@media (max-height: 500px) and (orientation: landscape) {
  #nations { grid-template-columns: 1fr 1fr; gap: 6px 8px; }
  .nation { min-height: 44px; padding: 4px 10px; }
  .nation span { display: none; }
  .pick-h { display: none; }
}
/* wide but short windows (small laptops): drop the tagline so more nations fit */
@media (min-width: 900px) and (min-height: 560px) and (max-height: 720px) {
  .lede { display: none; }
  .title-head { padding-top: 22px; }
  .wordmark { font-size: clamp(48px, 5vw, 72px); }
}

/* ---------- store: gems (magenta, used for nothing else), power-ups, skins ---------- */
.stat.gems .si { background: var(--gem); }
.stat.gems { border-color: var(--gem-hair); }
.stat.gems.guest b { font-size: 15px; }
.side-chip.boost { background: #fff; }
.side-chip.boost .si { background: var(--go); }
.side-chip.pw-shield .si { background: var(--violet); }
.side-chip.pw-builder .si { background: var(--amber); }
.gem-ic { width: 18px; height: 18px; color: var(--gem); }

#store { display: grid; place-items: center; z-index: 44; }
#store.dim { background: rgba(22, 56, 110, 0.55); }
.store-sheet { width: min(640px, calc(100vw - 32px)); display: flex; flex-direction: column; max-height: calc(100dvh - 32px); overflow: hidden; padding: 20px 22px; }
.store-top { display: grid; grid-template-columns: auto 1fr auto; grid-template-areas: "h bal x" "tabs tabs tabs"; align-items: center; gap: 10px 12px; }
.store-top h2 { grid-area: h; margin: 0; }
.store-bal { grid-area: bal; justify-self: start; margin: 0; display: inline-flex; align-items: center; gap: 6px; padding: 4px 14px 4px 10px; min-height: 40px; border-radius: 99px; background: var(--gem-tint); border: 2px solid var(--gem-hair); color: var(--gem); font-family: var(--display); font-weight: 600; }
.store-bal b { font-size: 20px; font-variant-numeric: tabular-nums; }
.store-bal .gem-ic { width: 20px; height: 20px; }
.store-top .sq-x { grid-area: x; }
.seg.store-tabs { grid-area: tabs; background: var(--sheet-3); }
.seg.store-tabs button { flex: 1; min-height: 48px; }
.seg.store-tabs button[aria-selected="true"] { background: linear-gradient(var(--go-hi) 0 8px, var(--go) 8px 100%); color: var(--on); }
#store-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; margin: 12px -6px 0; padding: 0 6px 4px; }
#store-body h3 { margin: 0; font-family: var(--display); font-size: 18px; font-weight: 700; line-height: 1.2; }
#store-body p { margin: 0; }
.shop-lede, .shop-free { margin-bottom: 12px !important; line-height: 1.45; color: var(--muted); }
.shop-free { padding: 10px 14px; border-radius: 16px; background: var(--gem-tint); color: var(--ink); }
.shop-free b { color: var(--gem); font-family: var(--display); }
.shop-msg { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 12px; padding: 10px 14px; border-radius: 14px; background: var(--good-tint); color: #17592a; font-weight: 600; line-height: 1.4; }
.shop-msg.bad { background: var(--bad-tint); color: var(--bad); }
.shop-msg .btn { flex: none; min-height: 44px; }
.shop-guest { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; padding: 12px 14px; border-radius: 18px; background: #fff; border: 2px solid var(--hair); line-height: 1.45; }
.shop-guest .btn { flex: none; min-height: 48px; }

/* gem bundles: one ladder, the gem count is the headline of each rung */
.shop-ladder { display: grid; background: #fff; border: 2px solid var(--hair); border-radius: 20px; padding: 2px 14px; margin-top: 12px; }
.shop-rung { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; min-height: 64px; }
.shop-rung + .shop-rung { border-top: 1px solid var(--sheet-3); }
.rung-what { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; min-width: 0; }
.rung-what .gem-ic { align-self: center; width: 24px; height: 24px; }
.rung-what b { font-family: var(--display); font-size: 24px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.rung-what span { color: var(--muted); font-weight: 600; }
.rung-extra { font-style: normal; font-size: 13px; font-weight: 700; color: var(--gem); background: var(--gem-tint); border-radius: 99px; padding: 2px 10px; }
.shop-usd { flex: none; min-width: 150px; min-height: 48px; line-height: 1.2; }
.shop-usd:disabled { --hi: var(--sheet-2); --c: var(--sheet-2); --t: var(--muted); border-color: var(--hair); font-size: 14px; max-width: 200px; white-space: normal; padding: 6px 14px; cursor: default; }
/* the two card items: a little colour, what you get, one button */
.shop-packs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.shop-pack { display: grid; grid-template-rows: auto 1fr auto; gap: 8px; padding: 14px; background: #fff; border: 2px solid var(--hair); border-radius: 20px; }
.shop-pack p { font-size: 14px; color: var(--muted); line-height: 1.4; margin-top: 3px !important; }
.pack-art { display: flex; gap: 6px; }
.swatch { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff; outline: 2px solid var(--hair); }
.shop-pack .shop-usd { width: 100%; }
.shop-foot { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 13px; color: var(--muted); }

/* power-ups: one row each */
.shop-list { display: grid; background: #fff; border: 2px solid var(--hair); border-radius: 20px; padding: 2px 14px; }
.shop-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; padding: 10px 0; }
.shop-row + .shop-row { border-top: 1px solid var(--sheet-3); }
.row-ic { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; color: var(--on); background: var(--rc, var(--blue)); }
.row-ic svg { width: 24px; height: 24px; }
.row-ic.pw-prod { --rc: var(--go); } .row-ic.pw-builder { --rc: var(--amber); } .row-ic.pw-shield { --rc: var(--violet); }
.row-txt p { font-size: 14px; color: var(--muted); line-height: 1.4; margin-top: 2px !important; }
.row-txt .row-on { color: #17592a; font-weight: 600; }
.shop-gem { --hi: var(--gem-hi); --c: var(--gem); flex: none; min-width: 150px; min-height: 56px; display: grid; justify-items: center; gap: 1px; padding: 6px 14px; line-height: 1.15; }
.shop-gem > b { font-size: 16px; }
.shop-gem.armed { --hi: var(--go-hi); --c: var(--go); }
.shop-price { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; }
.shop-price .gem-ic { width: 14px; height: 14px; color: currentColor; }
.shop-price small { font-family: var(--font); font-size: 12px; font-weight: 600; opacity: .9; margin-left: 4px; }
.shop-gem:disabled .shop-price { display: none; }
/* skins: the colour itself is the picture */
.shop-skins { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.shop-skin { display: grid; grid-template-rows: auto auto 1fr auto; justify-items: center; text-align: center; gap: 4px; padding: 12px 10px; background: #fff; border: 2px solid var(--hair); border-radius: 20px; }
.shop-skin.on { border-color: var(--go-hi); background: #f3fcf4; }
.shop-skin p { font-size: 13px; color: var(--muted); line-height: 1.35; }
.skin-art { width: 64px; height: 64px; border-radius: 18px; background: linear-gradient(var(--sk) 0 0) 0 0 / 100% 62% no-repeat, color-mix(in srgb, var(--sk) 55%, #ffffff); }
.shop-skin .btn { width: 100%; min-width: 0; margin-top: 4px; }

/* Finish now, on a running upgrade */
.act.finish { --hi: var(--gem-hi); --c: var(--gem); --t: var(--on); border-color: var(--gem-hi); flex: none; min-width: 112px; justify-items: center; text-align: center; padding: 6px 10px; }
.act.finish .cost { display: inline-flex; align-items: center; gap: 3px; color: var(--on); font-weight: 700; }
.act.finish .cost svg { width: 13px; height: 13px; color: var(--on); }

/* phones: the store fills the screen */
@media (max-width: 760px), (max-height: 520px) {
  #store { place-items: stretch; }
  .store-sheet { width: 100%; height: 100%; max-height: none; padding: calc(var(--sa-t) + 12px) calc(var(--sa-r) + 16px) calc(var(--sa-b) + 10px) calc(var(--sa-l) + 16px); }
  .shop-skins { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 520px) {
  .shop-packs { grid-template-columns: 1fr; }
  .shop-row { grid-template-columns: 44px 1fr; }
  .shop-row .shop-gem { grid-column: 1 / -1; width: 100%; }
  .shop-guest { flex-direction: column; align-items: stretch; }
}
/* short landscape phones: title, balance, tabs and close share one row */
@media (max-height: 520px) and (orientation: landscape) {
  .store-sheet { padding-top: calc(var(--sa-t) + 8px); }
  .store-top { grid-template-columns: auto auto 1fr auto; grid-template-areas: "h bal tabs x"; }
  .store-top h2 { font-size: 24px; }
  .store-bal { min-height: 36px; padding: 2px 12px 2px 8px; }
  .store-bal b { font-size: 17px; }
  .seg.store-tabs button { min-height: 44px; padding: 0 10px; font-size: 15px; }
  #store-body { margin-top: 8px; }
  .shop-skins { grid-template-columns: repeat(4, 1fr); }
  .shop-skin { padding: 8px; }
  .skin-art { width: 48px; height: 48px; }
  .shop-skin p { display: none; }
  .shop-lede, .shop-free { font-size: 14px; margin-bottom: 8px !important; padding-top: 6px; padding-bottom: 6px; }
  .shop-rung { min-height: 56px; padding: 4px 0; }
  .shop-row { padding: 6px 0; }
}
.act.finish.armed { --hi: var(--go-hi); --c: var(--go); border-color: var(--go-hi); }
