[hidden] { display: none !important; }
:root {
  --ck-ink: #222d23;
  --ck-panel: #2e392c;
  --ck-line: #8d7951;
  --ck-gold: #f3d599;
  --ck-paper: #eee8d7;
}
.ck-surface, dialog.ck-dialog {
  background: var(--ck-ink) !important;
  border: 1px solid var(--ck-line) !important;
  color: var(--ck-paper) !important;
  border-radius: 9px !important;
  box-shadow: 0 6px 26px #101910a6 !important;
  font: 14px/1.4 system-ui, sans-serif !important;
  overflow-wrap: anywhere;
}
.ck-atlas .ck-surface strong, .ck-dialog h2, .management-panel h2 {
  color: var(--ck-gold) !important;
  font-family: Georgia, serif !important;
  font-size: 19px !important;
  line-height: 1.15;
  text-shadow: none !important;
}
/* One set of interactive states for the HUD and its surfaces. */
body button {
  appearance: none;
  box-sizing: border-box;
  max-width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--ck-line);
  border-radius: 6px;
  background: var(--ck-panel);
  color: var(--ck-gold);
  font: 600 13px/1.25 system-ui, sans-serif;
  overflow-wrap: anywhere;
  cursor: pointer;
  touch-action: manipulation;
}
:is(#header,#sidebar,.ck-town-bar,.ck-atlas,.ck-dock,dialog,.ck-header-drawer) button:not(.ck-sheet-slot,.ck-inventory-cell,.ck-traveler-portrait) {
  border: 1px solid var(--ck-line) !important;
  border-radius: 6px !important;
  background: var(--ck-panel) !important;
  color: var(--ck-gold) !important;
  font: 600 13px/1.25 system-ui, sans-serif !important;
  padding: 6px 9px !important;
  text-shadow: none;
  text-decoration: none;
  transform: none;
  box-shadow: none;
}
body button:enabled:hover {
  border-color: var(--ck-gold);
  background-color: #455441;
}
:is(#header,#sidebar,.ck-town-bar,.ck-atlas,.ck-dock,dialog,.ck-header-drawer) button:enabled:hover:not(.ck-sheet-slot,.ck-inventory-cell,.ck-traveler-portrait) {
  border-color: var(--ck-gold) !important;
  background: #455441 !important;
}
body button:focus-visible {
  outline: 2px solid var(--ck-gold);
  outline-offset: -3px;
}
:is(#header,#sidebar,.ck-town-bar,.ck-atlas,.ck-dock,dialog,.ck-header-drawer) button:is(.ck-primary,.selected,[aria-pressed=true],[aria-expanded=true],[aria-selected=true]):enabled:not(.ck-sheet-slot,.ck-inventory-cell,.ck-traveler-portrait) {
  background: #e8c787 !important;
  border-color: var(--ck-gold) !important;
  color: #29251c !important;
}
body button:is(:disabled,[aria-disabled=true],.disabled) {
  cursor: not-allowed;
  opacity: 1;
}
:is(#header,#sidebar,.ck-town-bar,.ck-atlas,.ck-dock,dialog,.ck-header-drawer) button:is(:disabled,[aria-disabled=true],.disabled):not(.ck-sheet-slot,.ck-inventory-cell,.ck-traveler-portrait) {
  border-color: #657162 !important;
  background: var(--ck-ink) !important;
  color: #b4b7a8 !important;
}
.ck-dialog {
  margin: auto;
  inset: 0;
  width: min(480px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 20px;
  overflow: auto;
  z-index: 11000;
}
.ck-dialog::backdrop { background: #0d160ed0; }
.ck-dialog h2 { margin: 0 0 12px; }
.ck-dialog p { margin: 8px 0 16px; white-space: pre-line; }
.ck-dialog footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; }
.ck-castle-name { margin-block: 12px 16px; }
.ck-castle-name-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-top: 4px; }
.ck-castle-name-row input { min-width: 0; min-height: 44px; font-size: 16px; box-sizing: border-box; }
.ck-castle-name-roll { min-width: 44px; }
.ck-castle-name[hidden], .ck-castle-name-skip[hidden] { display: none !important; }
#ck-crowned-title, .ck-keep-castle-name, .ck-atlas-card strong, .ck-depth-board li { overflow-wrap: anywhere; }
.ck-guide-step { color: #cbc9b4; font-size: 12px; }
.ck-dialog kbd { padding: 2px 5px; border: 1px solid var(--ck-line); border-radius: 3px; }
#gameArea { position: relative; }
.ck-segments { display: inline-flex; align-items: center; }
#gameArea.ck-map-open {
  --ck-atlas-panel-width: 0px;
  --ck-atlas-mini-width: 96px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, min(42vw, 276px)) var(--ck-atlas-mini-width) var(--ck-atlas-panel-width);
  grid-template-rows: auto minmax(0, 1fr) auto;
  column-gap: 0;
  row-gap: 4px;
  padding-inline: max(6px, env(safe-area-inset-left)) max(6px, env(safe-area-inset-right));
  padding-bottom: max(6px, env(safe-area-inset-bottom));
}
#gameArea.ck-map-open #canvas {
  grid-area: 2 / 1 / 3 / 4;
  box-sizing: border-box;
  min-height: 0;
}
.ck-atlas { display: contents; }
.ck-atlas-top {
  grid-area: 2 / 1 / 3 / 4;
  align-self: start;
  display: grid;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2fr) minmax(0, 1fr);
  align-items: start;
  gap: 6px;
  margin: 8px;
  min-width: 0;
  z-index: 8;
  pointer-events: none;
}
#ck-map-loading {
  grid-column: 2;
  grid-row: 2;
  justify-self: center;
  width: min(210px, 100%);
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--ck-line);
  border-radius: 6px;
  background: #18231dee;
}
.ck-atlas-prompts {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}
.ck-atlas-prompts[hidden], .ck-atlas-prompts button[hidden], .ck-atlas-legend span[hidden] { display: none; }
.ck-atlas-prompts button {
  box-sizing: border-box;
  max-width: 100%;
  min-height: 44px;
  padding: 5px 9px;
  background: #151d1a;
  border: 1px solid #c7a657;
  color: #ffe5a6;
  font: 600 13px/1.2 system-ui, sans-serif;
  white-space: normal;
  overflow-wrap: anywhere;
  pointer-events: auto;
  cursor: pointer;
}
.ck-atlas-top .ck-atlas-prompts button { box-shadow: 0 3px 12px #0008; }
.ck-atlas-prompts small { display: block; color: #e8d9a8; }
.ck-atlas-prompts .ck-primary { order: -1; }
.ck-atlas-top > .ck-notifications {
  position: static;
  grid-column: 2;
  grid-row: 3;
}
.ck-atlas-top > .ck-notifications:empty { display: none; }
#gameArea .ck-atlas-top > .ck-traveler-hud {
  grid-column: 3;
  grid-row: 1;
  justify-self: end;
  position: static;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 3px 6px;
  width: auto;
  min-width: 0;
}
.ck-atlas-top .ck-traveler-vitals {
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 4px;
  padding: 2px 5px;
  min-width: clamp(124px, 20vw, 178px);
}
.ck-atlas-top .ck-traveler-portrait { width: 44px; height: 44px; }
.ck-atlas-top .ck-traveler-portrait:enabled:hover { filter: brightness(1.15); }
.ck-atlas-top .ck-vitals-name { flex-wrap: wrap; gap: 2px 5px; }
.ck-atlas-top .ck-vitals-bar span { min-width: 0; }
.ck-atlas-top .ck-traveler-track, .ck-atlas-top .ck-traveler-services { grid-column: 1 / -1; }
.ck-atlas-top .ck-traveler-track { padding: 2px 5px; }
.ck-atlas-top [data-traveler-gold]:empty { display: none; }
#gameArea.ck-map-open > #chat-ui {
  grid-area: 4 / 1 / 5 / 4;
  position: static !important;
  justify-self: end;
  align-self: start;
  box-sizing: border-box;
  width: min(100%, 320px) !important;
  max-height: min(21dvh, 156px) !important;
  overflow: auto;
}
.ck-map-open #chat-header, .ck-map-open #chat-input-container {
  flex-shrink: 0;
  padding: 4px !important;
}
.ck-map-open #chat-header { gap: 4px; flex-wrap: wrap; }
.ck-map-open #chat-messages {
  min-height: 24px !important;
  padding: 4px !important;
  overflow-wrap: anywhere;
}
.ck-map-open #chat-input, .ck-map-open #chat-send-btn { padding: 4px !important; }
.ck-map-open #chat-input { min-width: 0; }
.ck-atlas-tools {
  grid-area: 3 / 1 / 4 / 3;
  align-self: center;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ck-atlas-tools button, .ck-atlas-card button { min-width: 44px; min-height: 44px !important; }
.ck-atlas-mini {
  grid-area: 3 / 3 / 4 / 4;
  align-self: center;
  display: grid;
  place-items: center;
  width: 90px;
  margin-inline-start: 6px;
  padding: 2px !important;
}
.ck-atlas-mini canvas { display: block; width: 100%; height: auto; }
.ck-map-open :is(.ck-atlas-card, .ck-atlas-legend, .ck-road-planner) {
  position: absolute;
  z-index: 10;
  top: 6px;
  right: max(6px, env(safe-area-inset-right));
  box-sizing: border-box;
  width: min(32%, 320px);
  min-width: 0;
  max-height: calc(100% - 12px);
  margin: 0;
  padding: 6px 10px;
  overflow: auto;
  box-shadow: 0 4px 18px #000a;
}
.ck-atlas-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.ck-atlas-card-heading strong { min-width: 0; overflow-wrap: anywhere; }
.ck-atlas-details { display: block; white-space: pre-line; margin-top: 3px; }
.ck-atlas-card .ck-atlas-site-action {
  display: block;
  margin-top: 8px;
  padding: 6px 10px;
  border-color: #e2bd73;
  background: #4d3d23;
  color: #fff2cc;
  font-weight: 700;
}
.ck-atlas-card .ck-atlas-site-action[hidden] { display: none; }
.ck-atlas-card .ck-atlas-site-action:hover { background: #654f2c; }
.ck-map-open .ck-atlas-legend { display: flex; flex-direction: column; gap: 6px; overflow: hidden; font-size: 12px !important; }
.ck-legend-entries {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 12px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.ck-legend-scroll-cue { display: block; visibility: hidden; color: #e8d9a8; }
.ck-legend-has-more .ck-legend-scroll-cue { visibility: visible; }
.ck-atlas-legend span { display: flex; align-items: center; gap: 7px; overflow-wrap: anywhere; }
.ck-atlas-legend i { flex: 0 0 auto; width: 10px; height: 10px; border-radius: 2px; border: 1px solid #b8b497; }
.ck-town-bar {
  order: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 8px max(5px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--ck-line);
  background: #222b22;
}
.ck-town-bar button { min-width: 68px; min-height: 44px !important; }
@media (orientation: landscape) and (max-height: 520px) {
  .ck-town-bar { padding-block-start: 3px; }
}
#gameContainer:has(.ck-town-bar:not([hidden])) #footer { display: none; }
#gameContainer:has(.ck-map-open) :is(#footer,.ck-town-bar) { display: none; }
#infoPanel .ck-inspector-action { margin: 8px 0 12px; display: grid; gap: 6px; }
#infoPanel .ck-action-cost { color: #d9d5bd; margin: 0; }
#infoPanel .ck-action-note { color: #f0b292; margin: 0; min-height: 2.5em; line-height: 1.25; }
#infoPanel .ck-upgrade-builders { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; }
#infoPanel .ck-builder-chip { padding: 1px 8px; border-radius: 999px; background: rgba(120, 170, 90, .22); color: #cfe8b8; white-space: nowrap; font-variant-numeric: tabular-nums; }
#infoPanel #upgrade-btn[aria-disabled=true] { border-color: #657162 !important; background: var(--ck-ink) !important; color: #b4b7a8 !important; box-shadow: none !important; }
#infoPanel .ck-builder-chip.is-busy { background: rgba(205, 110, 80, .24); color: #f0b292; }
.ck-build-summary { display: block; text-align: left; min-width: 0; }
.ck-build-note { display: block; margin-top: 3px; font-size: 11px; color: #f0cdae; }
.management-panel { max-width: min(680px, calc(100% - 20px)) !important; }
.management-panel > .ck-panel-heading { border-color: var(--ck-line) !important; gap: 12px; padding-bottom: 8px !important; }
.management-panel .panel-content { min-width: 0; overflow: auto; }
.management-panel table { max-width: 100%; }
.management-panel td, .management-panel th { overflow-wrap: anywhere; }
.management-panel input, .management-panel select, #infoPanel select, .ck-dialog input {
  color: var(--ck-paper); background: #1d261e; border: 1px solid var(--ck-line); padding: 6px; border-radius: 5px;
}
@media (max-width: 680px), (pointer: coarse) and (max-width: 1100px) {
  #ck-sign-in, .ck-town-bar button, .ck-dialog button, .management-panel button,
  .management-panel input, .management-panel select, #infoPanel select, #infoPanel button { min-height: 44px !important; min-width: 44px; }
  .ck-town-bar { gap: 4px; }
  .ck-town-bar button { flex: 1 1 auto; min-width: 44px; padding-inline: 4px !important; white-space: nowrap; }
}
@media (max-width: 690px) and (orientation: portrait), (max-width: 600px) {
  #gameArea.ck-map-open {
    --ck-atlas-mini-width: 64px;
    grid-template-columns: minmax(0, 1fr) minmax(0, calc(50% - var(--ck-atlas-mini-width))) var(--ck-atlas-mini-width) 0px;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    row-gap: 0;
  }
  #gameArea.ck-map-open:has(:is(.ck-atlas-card, .ck-atlas-legend, .ck-road-planner):not([hidden])) {
    --ck-atlas-panel-width: 0px;
  }
  .ck-atlas-top { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ck-atlas-top .ck-atlas-prompts { grid-column: 1; justify-content: start; }
  #gameArea .ck-atlas-top > .ck-traveler-hud { grid-column: 2; }
  #ck-map-loading { grid-column: 1 / -1; }
  .ck-map-open :is(.ck-atlas-card, .ck-atlas-legend, .ck-road-planner) {
    top: auto;
    right: max(6px, env(safe-area-inset-right));
    bottom: max(58px, env(safe-area-inset-bottom));
    left: max(6px, env(safe-area-inset-left));
    width: auto;
    max-height: min(21dvh, 156px);
  }
  .ck-atlas-tools, .ck-atlas-mini { grid-row: 4; margin-top: 4px; }
  #gameArea.ck-map-open > #chat-ui { grid-row: 5; margin-top: 4px; }
  .ck-atlas-tools { gap: 2px; }
  .ck-atlas-tools button { flex: 1 0 auto; padding-inline: 4px !important; }
  .ck-atlas-mini { width: 58px; }
}
@media (orientation: portrait) and (max-width: 360px) and (max-height: 700px) {
  .ck-map-open :is(.ck-atlas-card, .ck-atlas-legend, .ck-road-planner) {
    max-height: min(17dvh, 120px);
  }
  .ck-map-open #chat-header, .ck-map-open #chat-input-container { padding-block: 0 !important; }
}
@media (orientation: landscape) and (max-height: 420px) and (min-width: 601px) {
  #gameArea.ck-map-open:has(> #chat-ui[style*="display: flex"]) {
    grid-template-columns: min(21%, 158px) minmax(0, 1fr) var(--ck-atlas-mini-width) var(--ck-atlas-panel-width);
  }
  #gameArea.ck-map-open:has(> #chat-ui[style*="display: flex"]) #canvas,
  #gameArea.ck-map-open:has(> #chat-ui[style*="display: flex"]) .ck-atlas-top,
  #gameArea.ck-map-open:has(> #chat-ui[style*="display: flex"]) .ck-atlas-tools {
    grid-column-start: 2;
  }
  #gameArea.ck-map-open > #chat-ui {
    grid-area: 2 / 1 / 4 / 2;
    justify-self: start;
    width: calc(100% - 6px) !important;
    max-height: 100% !important;
  }
}

/* Hunter's Shack target picker */
#infoPanel .ck-hunting {
  margin: 12px 0;
  padding-top: 10px;
  border-top: 1px solid var(--ck-line);
  color: var(--ck-paper);
}
.ck-hunting h4,
.ck-hunting h5 {
  margin: 0;
  color: var(--ck-gold);
}
.ck-hunting h4 { font: 600 17px Georgia, serif; }
.ck-hunting h5 {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 8px;
  margin-bottom: 4px;
  font-size: 13px;
}
#infoPanel .ck-hunting-summary { margin: 3px 0; color: var(--ck-paper); font-weight: 700; }
#infoPanel .ck-hunting-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 0;
}
.ck-hunting-legend span { display: inline-flex; align-items: center; gap: 4px; }
.ck-hunting .ck-icon { width: 14px; height: 14px; stroke-width: 2; }
.ck-hunting-group { margin-top: 8px; }
.ck-hunting-count { color: var(--ck-paper); font-variant-numeric: tabular-nums; }
.ck-hunting-chips,
.ck-hunting-actions { display: flex; flex-wrap: wrap; gap: 4px; }
.ck-hunting-actions { margin-top: 10px; }
.ck-hunting-actions button { flex: 1 1 auto; }

#infoPanel .ck-hunting .hunting-target-btn {
  display: inline-grid;
  grid-template-columns: 14px auto;
  align-items: center;
  gap: 4px;
  text-align: left;
  background: #222d23 !important;
  color: #ddd7c7 !important;
  border-color: #a89570 !important;
}
#infoPanel .ck-hunting .hunting-target-btn:enabled:hover { border-color: var(--ck-gold) !important; }
#infoPanel .ck-hunting .hunting-target-btn.is-hunted {
  background: #e8c787 !important;
  color: #29251c !important;
  border-color: var(--ck-gold) !important;
}
#infoPanel .ck-hunting .hunting-target-btn.is-hunted:focus-visible { outline-color: #29251c; }
.hunting-target-btn .ck-icon { grid-area: 1 / 1; }
.hunting-target-btn span { grid-area: 1 / 2; }
.hunting-target-btn:not(.is-hunted) .ck-hunting-check,
.hunting-target-btn.is-hunted .ck-hunting-shield { display: none; }

/* Castle HUD */
.ck-icon-definitions, .ck-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.ck-icon {
  width: 17px;
  height: 17px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.65;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#gameContainer #header {
  position: relative;
  display: grid;
  box-sizing: border-box;
  min-height: 46px;
  grid-template-columns: auto auto minmax(0,1fr) auto;
  align-items: center;
  gap: 4px clamp(5px, 1vw, 14px);
  flex: none;
  padding: 5px clamp(6px, 1.2vw, 16px);
  border-bottom: 1px solid var(--ck-line);
  background: linear-gradient(180deg, var(--ck-panel), var(--ck-ink));
  box-shadow: 0 3px 14px #0005;
  z-index: 2;
}
#gameContainer #header:has(.ck-atlas-status:not([hidden])) {
  grid-template-columns: auto auto minmax(0, 1fr) auto auto;
}
#gameContainer #header:has(.ck-header-drawer:not([hidden])) { z-index: 21; }
#header:has(.ck-atlas-status:not([hidden])) .ck-header-tools { grid-column: -2; }
#header .ck-atlas-status {
  display: grid;
  min-width: 0;
  color: var(--ck-gold);
  font: 600 15px/1.15 Georgia, serif;
}
#header .ck-atlas-status > * {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#header .ck-atlas-status span {
  color: #ddd8c1;
  font: 12px/1.3 system-ui, sans-serif;
}
#header #ck-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--ck-gold);
  font: 600 clamp(16px, 1.6vw, 23px)/1.1 Georgia, serif;
  letter-spacing: .02em;
}
#ck-title .ck-icon { width: 24px; height: 24px; }
#header #header-stats, .ck-header-tools, #header .ck-view-bar {
  display: flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
}
#header #header-stats {
  justify-content: flex-end;
  flex-wrap: wrap;
  overflow: visible;
}
#header #header-stats > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: max-content;
  padding-inline: clamp(3px, .55vw, 9px) !important;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
#header #header-stats .ck-icon { flex-shrink: 0; }
#header .ck-resource .ck-icon { color: var(--ck-gold); }
#header .ck-resource:is(#stat-food,#stat-population) .ck-icon { color: #b8dba0; }
#header .ck-view-bar {
  padding: 0;
  background: transparent;
  border: 0;
}
#header .ck-segments { padding: 0; gap: 2px; background: transparent; border: 0; }
#header .ck-segments button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; }
#ck-save-status {
  position: fixed; z-index: 10001;
  inset-inline-end: max(10px, env(safe-area-inset-right));
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 76px));
  display: inline-flex; align-items: center; gap: 5px;
  animation: ck-save-status-in .2s ease-out;
  min-height: 30px; padding: 0 8px; white-space: nowrap;
  border: 1px solid var(--danger); border-inline-start-width: 3px; border-radius: 5px;
  color: var(--text-primary); background: #252b21; font: 600 12px 'Segoe UI', Arial, sans-serif;
}
@keyframes ck-save-status-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { #ck-save-status { animation: none; } }
#ck-save-status[hidden] { display: none; }
#ck-save-status:is([data-state=saving], [data-state=saved]) { border-color: #7f9a5c; font-weight: 500; }
#ck-save-status:is([data-state=reconnecting], [data-state=paused]) { border-color: #d9a441; }
#ck-save-status a { color: #f1d59a; }
#ck-save-status button { padding: 2px 6px; font: inherit; }
@media (max-width: 520px) { #ck-save-status { padding: 0 5px; font-size: 11px; } #ck-save-status a span { display: none; } }
#ck-guest-banner {
  position: fixed; bottom: max(64px, calc(env(safe-area-inset-bottom) + 56px)); inset-inline-start: 10px;
  width: fit-content; max-width: calc(100vw - 20px); display: flex; align-items: center; gap: 10px;
  pointer-events: auto; z-index: 9999;
}
#ck-guest-banner a { color: #f1d59a; white-space: nowrap; }
#ck-guest-banner button { min-width: 32px; min-height: 32px; }
#header .ck-icon-button { display: grid; place-items: center; min-width: 34px; padding-inline: 6px !important; }
#ck-switch-character {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0 !important;
  flex: none;
}
#ck-sound:not([aria-pressed=true]) .ck-sound-on,
#ck-sound[aria-pressed=true] .ck-icon:not(.ck-sound-on) { display: none; }
.ck-header-drawer {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  padding-top: 5px;
  border-top: 1px solid #8d795188;
}
.ck-header-drawer :is(button,.stat) { display: inline-flex; align-items: center; gap: 6px; }
#header > .ck-header-drawer {
  position: absolute;
  inset: 100% 0 auto;
  grid-column: auto;
  padding: 5px clamp(6px, 1.2vw, 16px);
  background: var(--ck-ink);
  box-shadow: 0 4px 12px #0005;
}
#online-indicator { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.ck-header-account {
  position: relative;
  flex: none;
}
.ck-header-account:has(#ck-sign-in[hidden] + #ck-account-toggle[hidden]) { display: none; }
#header .ck-account-control {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--ck-line);
  border-radius: 6px;
  background: var(--ck-panel);
  color: var(--ck-gold);
  font: 600 13px/1.25 system-ui, sans-serif;
  text-decoration: none;
  white-space: nowrap;
}
#header a.ck-account-control:is(:hover, :focus-visible) {
  background: #455441;
  border-color: var(--ck-gold);
}
#ck-account-toggle span {
  max-width: clamp(56px, 12vw, 160px);
  overflow: hidden;
  text-overflow: ellipsis;
}
#ck-account-menu {
  position: absolute;
  inset: calc(100% + 5px) 0 auto auto;
  z-index: 1;
  flex-wrap: nowrap;
  flex-direction: column;
  align-items: stretch;
  min-width: 112px;
  padding: 5px;
}
#ck-status .stat {
  min-height: 32px;
  padding: 4px 8px;
  font: 600 13px/1.25 system-ui, sans-serif;
}
.ck-town-bar button { text-decoration: none; }
@media (max-width: 1160px) {
  #header .ck-segments button > span { display: none; }
}
@media (max-width: 760px) {
  #gameContainer #header { grid-template-columns: minmax(0, 1fr) auto auto; }
  #gameContainer #header:has(.ck-atlas-status:not([hidden])) {
    grid-template-columns: auto auto minmax(0, 1fr) auto;
  }
  #header #header-stats {
    grid-row: 2;
    grid-column: 1 / -1;
    justify-content: flex-start;
  }
  #header #header-stats > button {
    flex: 1 0 auto;
    padding-inline: 2px !important;
    min-height: 35px;
    font-size: clamp(9px, 2.8vw, 13px) !important;
  }
  #header .ck-resource .ck-icon { width: clamp(11px, 3.5vw, 16px); }
}
@media (max-width: 600px) {
  #gameContainer #header:has(.ck-atlas-status:not([hidden])) {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }
  #header .ck-atlas-status { grid-area: 2 / 1 / 3 / -1; }
  #header:has(.ck-atlas-status:not([hidden])) #header-stats { grid-row: 3; }
  #ck-account-toggle span { display: none; }
}
@media (max-width: 420px) {
  #header #ck-title { font-size: 0; }
  #header #ck-title .ck-icon { width: 25px; height: 25px; }
  #header .ck-segments button { padding-inline: 5px !important; }
  #header .ck-icon-button { min-width: 32px; }
}
@media (pointer: coarse) {
  #header .ck-segments button, #header .ck-icon-button { min-width: clamp(32px, 10vw, 44px); min-height: 44px; }
}

/* Keep all surfaces in the playable viewport, below the header and above the town bar. */
:root {
  --ck-play-top: 62px;
  --ck-play-bottom: 0px;
  --ck-play-right: 0px;
  --ck-dock-width: clamp(286px, 38vw, 572px);
  --ck-dock-height: min(46dvh, 440px);
}
body :is(dialog,.ck-dock,.ck-header-drawer) {
  box-sizing: border-box;
  color: var(--ck-paper);
  font: 14px/1.4 system-ui, sans-serif;
}
body :is(dialog,.ck-dock) {
  background: var(--ck-ink) !important;
  border: 1px solid var(--ck-line) !important;
  border-radius: 8px !important;
  box-shadow: 0 6px 24px #101910a6 !important;
  overflow-wrap: anywhere;
  scrollbar-color: var(--ck-line) var(--ck-ink);
  overscroll-behavior: contain;
}
body dialog[open], body .ck-dock:not([hidden]) {
  position: fixed !important;
  inset: calc(var(--ck-play-top) + 6px) max(6px, env(safe-area-inset-right)) calc(var(--ck-play-bottom) + 6px) max(6px, env(safe-area-inset-left)) !important;
  width: min(620px, calc(100% - 18px));
  min-width: 0 !important;
  max-width: none !important;
  height: max-content;
  min-height: 0 !important;
  max-height: calc(100dvh - var(--ck-play-top) - var(--ck-play-bottom) - 12px) !important;
  margin: auto !important;
  transform: none !important;
  padding: 12px !important;
  overflow: auto !important;
}
body .ck-dock:not([hidden]) { z-index: 20; }
body dialog::backdrop { background: #0d160e8f; }
body[data-player-role="king"] dialog::backdrop { background: transparent; }
/* Town panels overlay the playfield so opening them leaves the canvas bitmap intact. */
body #ck-confirm[open] { z-index: 14010; }
body #ck-confirm::backdrop { background: #0d160e8f; }
body[data-player-role="king"]:has(dialog[open]:not(#ck-confirm), .ck-dock:not([hidden])) #sidebar { display: none !important; }
body[data-player-role="king"] :is(dialog[open]:not(#ck-confirm),.ck-dock:not([hidden])) {
  inset: calc(var(--ck-play-top) + 6px) calc(var(--ck-play-right) + 6px) calc(var(--ck-play-bottom) + 6px) auto !important;
  width: var(--ck-dock-width) !important;
  margin: 0 !important;
}
body[data-player-role] #character-info-popup.ck-dock:not([hidden]) {
  width: min(320px, calc(100% - 18px)) !important;
}
body[data-player-role="king"]:has(dialog[open]:not(#ck-confirm)) .ck-dock,
.ck-dock:not([hidden]):has(~ .ck-dock:not([hidden])) { visibility: hidden; pointer-events: none; }
body :is(dialog,.ck-dock) :is(.ck-panel-heading,header,footer) {
  min-width: 0;
}
.ck-panel-heading, body dialog > header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin: 0 0 10px;
  border-bottom: 1px solid var(--ck-line);
}
.ck-panel-heading :is(h2,h3), body dialog :is(h2,header h3) {
  color: var(--ck-gold);
  font: 600 20px/1.2 Georgia, serif;
  margin: 0;
}
.ck-panel-heading button { flex: 0 0 auto; }

.ck-close, .ck-panel-toggle { touch-action: manipulation; }
button.ck-close, button.ck-follow {
  display: grid;
  place-items: center;
  box-sizing: border-box;
  flex: none;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
  padding: 0 !important;
  margin: 0;
  border: 1px solid #ab9568;
  border-radius: 6px;
  background: #252d24;
  color: #fae9c5;
  cursor: pointer;
}
button.ck-close::before,
button.ck-close::after {
  content: '';
  grid-area: 1 / 1;
  width: 17px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
  transform: rotate(45deg);
  forced-color-adjust: none;
}
button.ck-close::after { transform: rotate(-45deg); }
button.ck-close[hidden] { display: none !important; }
button:is(.ck-close,.ck-follow):enabled:hover { background: #455039; }
button:is(.ck-close,.ck-follow):focus-visible { outline: 2px solid #f2c97b; outline-offset: -4px; }
@media (forced-colors: active) {
  button.ck-close::before, button.ck-close::after { background: ButtonText; }
}

.ck-build-menu-header,
:is(header, .ck-routes-heading, .ck-atlas-card-heading):has(> .ck-close, > form > .ck-close) {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 6px 10px;
}
:is(header, .ck-routes-heading, .ck-atlas-card-heading) > :is(.ck-close, form:has(> .ck-close)) {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  margin: 0;
}
#character-info-popup .ck-panel-heading {
  grid-template-columns: minmax(0, 1fr) auto auto;
  column-gap: 6px;
}
#character-info-popup .ck-panel-heading h2 { overflow-wrap: anywhere; }
#character-info-popup .ck-close { grid-column: 3; }
button.ck-follow { grid-column: 2; grid-row: 1; touch-action: manipulation; }
button.ck-follow[aria-pressed="true"] {
  background: var(--ck-gold);
  color: var(--ck-ink);
  box-shadow: inset 0 0 0 2px currentColor;
}
@media (min-width: 761px) and (pointer: fine) {
  button.ck-follow { width: 36px !important; min-width: 36px !important; }
}
.ck-sheet-header-actions, .ck-routes-heading > [data-castle-watch] {
  grid-column: 1 / -1;
  justify-self: start;
  flex-wrap: wrap;
}
.ck-traveler-portrait[aria-pressed=true] { outline: 2px solid #f2c97b; outline-offset: -3px; }
body dialog.ck-hud-dialog[open] { z-index: var(--ck-panel-z, 11000); }
body dialog.ck-site-dialog[open] { z-index: var(--ck-panel-z, 14002); }
body:has(dialog.ck-hud-dialog[open]) :is(#canvas, .ck-location-stage) { pointer-events: none; }
body[data-player-role] dialog.ck-play-dialog[open] {
  top: var(--ck-dialog-top, calc(var(--ck-play-top) + 6px)) !important;
  bottom: var(--ck-dialog-bottom, calc(var(--ck-play-bottom) + 6px)) !important;
  max-height: calc(100dvh - var(--ck-dialog-top, 62px) - var(--ck-dialog-bottom, 6px)) !important;
}

.ck-panel-body { min-width: 0; }
.ck-panel-actions, body dialog footer {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.ck-panel-actions { padding-top: 9px; border-top: 1px solid var(--ck-line); }
.ck-panel-actions:empty { display: none; }
.ck-stat-rows { margin: 0; }
.ck-stat-row {
  display: grid;
  grid-template-columns: minmax(0, 6.5rem) minmax(0, 1fr);
  align-items: center;
  gap: 4px 12px;
  padding: 5px 0;
  border-bottom: 1px solid #8d795140;
}
.ck-stat-row dd { margin: 0; color: var(--ck-gold); font-variant-numeric: tabular-nums; }
.ck-stat-row progress { grid-column: 1 / -1; }
.ck-age-requirements {
  width: min(100%, 22rem);
  padding: 4px 12px;
  box-sizing: border-box;
  border: 1px solid var(--ck-line);
  border-radius: 4px;
  background: #2d1f1f99;
}
.ck-age-requirements .ck-stat-row { grid-template-columns: minmax(0, 7rem) minmax(0, 1fr); }
.ck-age-requirements dd { text-align: left; overflow-wrap: anywhere; }
.ck-age-requirements .ck-stat-row:last-child { border-bottom: 0; }
.ck-company-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
:is(.ck-dock, dialog, #sidebar) progress {
  width: 100%;
  height: .55rem;
  accent-color: #a3c48b;
}
.ck-tag {
  display: inline-flex;
  padding: 2px 7px;
  border: 1px solid var(--ck-line);
  border-radius: 6px;
  color: var(--ck-gold);
  font-size: 12px;
}
.ck-pane-subheading { font-size: 13px; margin: 12px 0 4px; color: var(--ck-gold); }
.ck-dock input, .ck-dock select, dialog :is(input,select,textarea) {
  max-width: 100%;
  font: inherit;
  color: var(--ck-paper);
  background: #1d261e;
  border: 1px solid var(--ck-line);
  border-radius: 6px;
}
.ck-dock input[type=checkbox], dialog input[type=checkbox] { accent-color: var(--ck-gold); }
@media (max-width: 760px) and (orientation: portrait) {
  body[data-player-role="king"] :is(dialog[open]:not(#ck-confirm),.ck-dock:not([hidden])) {
    inset: auto max(6px, env(safe-area-inset-right)) calc(var(--ck-play-bottom) + 6px) max(6px, env(safe-area-inset-left)) !important;
    width: auto !important;
    max-height: min(var(--ck-dock-height), calc(100dvh - var(--ck-play-top) - var(--ck-play-bottom) - 12px)) !important;
  }
  body[data-player-role="king"] .ck-routes.ck-hud-dialog:not(.ck-play-dialog)[open] {
    /* Keep the close target in place while Kingdom records load. */
    height: var(--ck-dock-height);
  }
  body[data-player-role="king"] #character-info-popup.ck-dock:not([hidden]) {
    margin-inline: auto !important;
  }
}
@media (orientation: landscape) and (max-height: 520px) {
  :root { --ck-dock-width: clamp(250px, 43vw, 445px); }
}
#game-log-panel.ck-dock .game-log-content { min-height: 60px; max-height: 30dvh; }
body .ck-notifications { top: calc(var(--ck-play-top) + 8px); }
body:has(dialog[open]) #ck-notifications { display: none; }
#ck-update-required {
  grid-column: 1 / -1;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px 10px;
  padding: 6px 8px; color: var(--ck-paper); background: var(--ck-panel);
  font: 600 13px/1.25 system-ui, sans-serif;
}
#ck-update-required button {
  min-height: 44px; padding: 0 12px; cursor: pointer;
  font: inherit; color: var(--ck-ink); background: var(--ck-gold);
  border: 1px solid var(--ck-line); border-radius: 6px;
}
#ck-update-required button:disabled { opacity: 0.75; cursor: progress; }
#ck-update-required button:focus-visible { outline: 2px solid var(--ck-paper); outline-offset: 2px; }
#ck-navigation .ck-build-version { opacity: 0.65; font-size: 11px; padding: 0 6px; white-space: nowrap; }
#ck-build-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  max-width: 100%; box-sizing: border-box;
  padding: 2px 4px; font: 11px/1.2 system-ui, sans-serif; color: var(--ck-paper);
}
@media (max-width: 760px), (pointer: coarse) {
  #header > #ck-notifications {
    grid-column: 1 / -1; position: static; align-items: center; gap: 0;
  }
  #header > #ck-notifications:empty { display: none; }
  #header > #ck-notifications .ck-notification {
    box-sizing: border-box; margin: 2px 4px; padding: 3px 6px;
    font-size: 12px; overflow-wrap: anywhere; box-shadow: none;
  }
}
#ck-build-bar .ck-build-label { font-variant-numeric: tabular-nums; opacity: 0.85; }
#ck-build-bar .ck-build-state { font-weight: 600; }
#ck-build-bar[data-state="current"] .ck-build-state { color: #9fd39a; }
#ck-build-bar[data-state="update"] .ck-build-state { color: #f3a65a; }
#ck-build-bar[data-state="unknown"] .ck-build-state,
#ck-build-bar[data-state="checking"] .ck-build-state,
#ck-build-bar[data-state="dev"] .ck-build-state { color: #c9c0a8; font-weight: 400; }
#ck-build-bar button {
  min-height: 26px; padding: 2px 10px; cursor: pointer;
  font: 600 11px/1.2 system-ui, sans-serif; color: var(--ck-ink);
  background: var(--ck-gold); border: 1px solid var(--ck-line); border-radius: 10px;
}
#ck-build-bar button:disabled { opacity: 0.7; cursor: progress; }
@media (max-width: 760px), (pointer: coarse) { #ck-build-bar button { min-height: 44px; } }
@media (min-width: 761px), (orientation: landscape) {
  body[data-player-role="king"]:has(.ck-dock:not([hidden])) > .ck-notifications {
    inset-inline-end: calc(var(--ck-play-right) + var(--ck-dock-width) + 14px);
  }
  body > .ck-notifications .ck-notification { box-sizing: border-box; overflow-wrap: anywhere; }
}
.ck-network-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }

#buildMenu .build-button {
  display: grid;
  grid-template-columns: 32px minmax(0,1fr);
  gap: 3px 7px;
  align-items: center;
  min-height: 44px;
  text-align: left;
}
#buildMenu .build-button > :first-child { grid-column: 2; grid-row: 1; }
#buildMenu .build-button > img {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 32px;
  height: 32px;
  object-fit: contain;
}
#buildMenu .build-button > .build-cost { grid-column: 2; grid-row: 2; min-width: 0; }
.ck-costs, .ck-tooltip .build-cost {
  display: flex;
  align-items: center;
  gap: clamp(3px, .5vw, 7px);
  color: #e3d5b2;
  font: 600 11px/1.2 system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
}
.ck-cost-item { display: inline-flex; gap: 2px; align-items: center; white-space: nowrap; }
.ck-cost-item .ck-icon { width: 13px; height: 13px; color: var(--ck-gold); }
@media (max-width: 680px) and (orientation: portrait) {
  #sidebar:has(#action-mode-hud:not([style*="display: none"])) #infoPanel:has(.action-mode-character-name) { display: none; }
  #sidebar #action-mode-hud > .ck-action-mode-heading {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-block: 4px;
    background: #252d24;
  }
  #sidebar #buildMenu { flex-direction: column; }
  #buildMenu .menu-category { flex: none; min-width: 0; overflow: visible; }
  #buildMenu .build-button { overflow-wrap: anywhere; }
  #buildMenu .ck-costs { flex-wrap: wrap; }
  #buildMenu .ck-works-build-tools { flex: none; }
}
@media (max-width: 680px) and (orientation: portrait),
       (pointer: coarse) and (orientation: landscape) and (max-height: 360px) {
  #sidebar:has(#buildMenu:not([style*="display: none"])) #infoPanel:is(:has(.ck-empty-inspector), :has(#current-mode)) { display: none; }
}
.ck-tooltip {
  position: fixed;
  z-index: 25;
  box-sizing: border-box;
  width: max-content;
  max-width: min(260px, calc(100% - 16px));
  padding: 9px 11px;
  border: 1px solid var(--ck-line);
  border-radius: 6px;
  background: var(--ck-ink);
  color: var(--ck-paper);
  box-shadow: 0 4px 14px #0007;
  font: 13px/1.4 system-ui, sans-serif;
  pointer-events: none;
}
.ck-tooltip > strong { color: var(--ck-gold); }
.ck-tooltip p { margin: 3px 0 6px; }

/* Keep the sidebar out of the canvas layout in both the build and inspector views. */
#gameArea > #sidebar {
  position: absolute;
  z-index: 8;
  inset: 10px 10px 10px auto;
}
@media (max-width: 680px) {
  #gameArea > #sidebar { inset: 6px 6px 6px auto; }
}
@media (max-width: 680px) and (orientation: portrait) {
  #gameArea > #sidebar {
    inset: auto 6px 6px;
    width: auto;
  }
}
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  #gameArea > #sidebar { inset: 4px 4px 4px auto; }
}
#sidebar.ck-build-collapsed #buildMenu { display: none !important; }
#sidebar.ck-build-collapsed:has(#buildMenu:not([style*="display: none"])) { display: none !important; }
#sidebar.ck-build-collapsed #infoPanel { flex: 1 1 auto !important; max-height: none !important; border-top: 0; }
#ck-build-toggle[aria-expanded=false] { opacity: .75; }
/* One more header button (build menu) on a phone: keep the whole header row on screen */
@media (max-width: 420px) {
  #header .ck-header-tools .ck-icon-button { min-width: 30px; padding-inline: 3px !important; }
  #header .ck-segments button { min-width: 32px; padding-inline: 4px !important; }
}

.ck-atlas-bottom, .ck-atlas-actions { display: contents; }
.ck-atlas-bottom .ck-notifications {
  position: absolute;
  grid-area: 2 / 1 / 3 / 4;
  top: 8px;
}
.ck-atlas-tool-icon { display: none; }

@media (pointer: coarse) and (max-width: 1100px) {
  body #gameContainer:has(.ck-map-open) { padding-bottom: 0; }
  #gameArea.ck-map-open { display: block; padding: 0; }
  #gameArea.ck-map-open #canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 0;
  }
  #gameArea .ck-atlas-top {
    position: absolute;
    inset: 6px 6px auto;
    margin: 0;
  }
  #gameArea .ck-atlas-top > .ck-traveler-hud {
    grid-column: 1 / -1;
    justify-self: start;
    display: flex;
    flex-wrap: wrap;
    align-items: start;
    gap: 4px;
    font-size: 14px;
  }
  #gameArea .ck-atlas-top .ck-traveler-vitals {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    padding: 0 8px 0 0;
  }
  .ck-atlas-top .ck-vitals-details { flex: 1; min-width: 0; }
  .ck-atlas-top .ck-vitals-name strong { max-width: 32vw; }
  .ck-atlas-top .ck-vitals-bar { font-size: 14px; line-height: 1.2; }
  .ck-atlas-top .ck-vitals-bar progress { min-width: 32px; }
  .ck-atlas-top .ck-traveler-track { flex-basis: 100%; width: fit-content; }

  #gameArea.ck-map-open > #chat-ui {
    position: absolute !important;
    z-index: 9 !important;
    top: 70px !important;
    right: 6px !important;
    bottom: auto !important;
    width: min(calc(100% - 12px), 300px) !important;
    margin: 0;
  }
  #chat-ui :is(button, input) { min-height: 44px !important; }
  .ck-map-open .ck-atlas-bottom {
    position: absolute;
    z-index: 10;
    inset: auto 6px max(6px, env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: min(100% - 12px, 500px);
    margin-inline: auto;
    pointer-events: none;
  }
  .ck-map-open .ck-atlas-actions {
    order: 2;
    display: flex;
    align-items: center;
    gap: 3px;
    padding: 3px;
    border: 1px solid var(--ck-line);
    border-radius: 8px;
    background: var(--ck-ink);
    box-shadow: 0 3px 14px #0008;
    pointer-events: auto;
  }
  .ck-atlas-actions :is(.ck-atlas-tools, .ck-atlas-prompts) {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: nowrap;
    gap: 3px;
    margin: 0;
  }
  .ck-atlas-actions .ck-atlas-tools [data-atlas="in"],
  .ck-atlas-actions .ck-atlas-tools [data-atlas="out"],
  .ck-atlas-actions :is(.ck-atlas-tools button, .ck-atlas-prompts button) > span { display: none; }
  .ck-atlas-actions :is(.ck-atlas-tools button, .ck-atlas-prompts button, .ck-atlas-mini) {
    display: grid;
    place-items: center;
    flex: 1 0 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 2px !important;
  }
  .ck-atlas-actions .ck-atlas-prompts button { background: #48432a; border-color: #bd9c58; color: #ffedbc; }
  .ck-atlas-actions .ck-atlas-prompts .ck-primary {
    flex: 1 1 auto;
    min-width: 72px;
  }
  .ck-atlas-actions .ck-atlas-prompts .ck-primary .ck-atlas-tool-icon { display: none; }
  .ck-atlas-actions .ck-atlas-prompts .ck-primary .ck-atlas-prompt-label {
    display: block;
    font-size: 14px;
    line-height: 1.15;
    min-width: 0;
  }
  .ck-atlas-prompt-label small { font-size: inherit; }
  .ck-atlas-actions .ck-atlas-tool-icon { display: block; width: 21px; height: 21px; }
  .ck-atlas-actions .ck-atlas-mini { width: 50px; flex: 0 1 50px; margin: 0; }

  .ck-map-open .ck-atlas-bottom :is(.ck-atlas-card, .ck-atlas-legend, .ck-road-planner) {
    position: relative;
    inset: auto;
    order: 1;
    align-self: stretch;
    width: auto;
    max-height: 24dvh;
    margin: 0;
    padding: 6px 10px;
    background: var(--ck-ink);
    font-size: 14px !important;
    overscroll-behavior: contain;
    pointer-events: auto;
  }
  .ck-map-open .ck-atlas-bottom .ck-atlas-legend { max-height: 33dvh; }
  .ck-atlas-card-heading strong { font-size: 17px; }
  .ck-atlas-bottom .ck-notifications { position: static; align-items: start; gap: 3px; }
  .ck-atlas-bottom .ck-notifications:empty { display: none; }
  .ck-atlas-bottom .ck-notification { padding: 4px 8px; overflow-wrap: anywhere; }
  .ck-atlas-bottom #ck-guest-banner { position: static; max-width: 100%; padding: 0 4px 0 8px; }
  #ck-guest-banner a { display: inline-flex; align-items: center; min-height: 44px; min-width: 44px; }
  #ck-guest-banner button { min-width: 44px; min-height: 44px; }

  #header .ck-segments button, #header .ck-header-tools .ck-icon-button,
  #header .ck-header-drawer :is(button, a), .ck-town-bar button {
    min-width: 44px;
    min-height: 44px;
  }
  #header .ck-view-bar, #header .ck-header-tools { flex-wrap: wrap; }
  #header .ck-header-tools { justify-content: end; }
  #header .ck-account-control { min-width: 44px; min-height: 44px; }
  #header #header-stats > button { min-width: 44px; min-height: 44px; font-size: 14px !important; }
  #header #ck-save-status { font-size: 14px; }
  #header #ck-save-status :is(a, button) { display: inline-flex; align-items: center; min-height: 44px; }
  #sidebar :is(.build-cost, .category-title, .ck-build-note), #infoPanel :is(p, button, .hire-btn),
  #header .ck-header-drawer :is(button, a), #header #ck-status .stat,
  .ck-town-bar button { font-size: 14px !important; }
  #infoPanel { overflow-wrap: anywhere; }
  #infoPanel label:has(#allow-visitors-toggle) { min-width: 44px; min-height: 44px; font-size: 14px !important; }
  .ck-scene-exit { min-height: 44px; }
  body :is(dialog, .ck-dock) :is(button, input:not([type=hidden]), select),
  #sidebar :is(button, select) { min-width: 44px; min-height: 44px !important; }
  body :is(dialog, .ck-dock) :is(input:not([type=hidden]), textarea, select) { max-width: 100%; font-size: 16px; }
  body :is(dialog, .ck-dock) :is(button, p, label, summary) { font-size: 14px; }
  #ck-confirm[open] { display: flex; flex-direction: column; }
  #ck-confirm > :is(header, form) { flex: none; }
  #ck-confirm > .ck-panel-body { min-height: 0; overflow-y: auto; }
  #ck-confirm footer { display: flex; flex-wrap: wrap; gap: 6px; }
  .ck-keyboard-only { display: none; }
}

@media (pointer: coarse) and (max-width: 600px) {
  #gameContainer #header,
  #gameContainer #header:has(.ck-atlas-status:not([hidden])) {
    grid-template-columns: minmax(0, 1fr) max-content;
  }
  #header #ck-title { display: none; }
  #ck-navigation .ck-icon-button { display: inline-flex; gap: 5px; }
  #ck-navigation .ck-icon-button::after { content: attr(aria-label); }
}

@media (pointer: coarse) and (max-width: 600px),
       (pointer: coarse) and (orientation: landscape) and (max-width: 1100px) {
  #header #header-stats > button { flex-direction: column; gap: 1px; line-height: 1.1; }
  #header #header-stats .ck-icon { width: 13px; height: 13px; }
}

@media (pointer: coarse) and (orientation: landscape) and (min-width: 761px) and (max-width: 950px) {
  #header #ck-title { font-size: 0; }
  #ck-account-toggle span { display: none; }
  #header #header-stats { flex-wrap: wrap; }
  #header #header-stats > button { flex-shrink: 0; }
}

@media (pointer: coarse) and (orientation: landscape) and (min-width: 601px) and (max-width: 1100px) {
  #gameArea.ck-map-open > #chat-ui { width: min(33%, 300px) !important; }
  #gameArea.ck-map-open:has(> #chat-ui[style*="display: flex"]) .ck-atlas-bottom {
    inset-inline-end: calc(min(33%, 300px) + 12px);
    width: auto;
    max-width: 500px;
  }
}


#war-panel .ck-field-order, #war-panel .ck-field-supply {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 4px 10px;
  overflow-wrap: anywhere;
}
#war-panel .ck-field-supply {
  padding: 4px 0 8px;
  color: #ead3aa;
  font-size: 12px;
}
#war-panel [data-scroll] { overscroll-behavior: contain; }
#war-incoming-banner {
  width: max-content;
  max-width: calc(100% - 20px);
  overflow-wrap: anywhere;
}
@media (pointer: coarse) {
  #war-panel button { min-height: 44px; }
  #war-incoming-banner { bottom: calc(55px + env(safe-area-inset-bottom)) !important; }
}


#war-panel .ck-field-kit {
  margin: 3px 0 3px 22px;
  color: #d3c3a5;
  font-size: 12px;
  overflow-wrap: anywhere;
}

#ck-placement:not([hidden]) {
  display: flex;
  flex: 0 0 auto;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-inline: clamp(4px, 1vw, 10px);
  padding: 4px 6px 4px 10px;
  border: 1px solid #9e885d;
  border-radius: 8px;
  background: #232b22;
  color: #f2e7c9;
}
#ck-placement [role="status"] { min-width: 0; line-height: 1.25; }
#ck-placement :is(strong, small) { display: block; }
/* A price held by a plan still waiting for the server (castleWorks.place) */
.stat-value.ck-reserved { font-style: italic; opacity: .78; }
#ck-placement small { color: #d5c7a7; font-size: 12px; }
.ck-player-camp button[aria-pressed="true"] { outline: 2px solid #c0a373; outline-offset: -2px; }

.ck-volume-controls { display: grid; gap: 10px; margin-top: 12px; }
.ck-voice-subtitle {
  position: fixed;
  z-index: 9999;
  inset: auto 12px max(112px, calc(env(safe-area-inset-bottom) + 88px));
  margin-inline: auto;
  max-width: 42ch;
  width: fit-content;
  padding: 6px 12px;
  border-radius: 5px;
  background: #171b16f5;
  color: #f5e4b7;
  text-align: center;
  pointer-events: none;
  font-size: 14px;
}
@media (max-width: 760px), (pointer: coarse) {
  body[data-player-role="king"]:has(.ck-dock:not([hidden]), #infoPanel[data-inspected-building]) > .ck-voice-subtitle {
    inset-block: calc(var(--ck-play-top) + 8px) auto;
  }
}
.ck-atlas-bottom .ck-voice-subtitle {
  position: static;
  box-sizing: border-box;
  max-width: min(100%, 42ch);
  overflow-wrap: anywhere;
}
.ck-volume-controls label { display: grid; grid-template-columns: minmax(0, 1fr) 3.5em; align-items: center; gap: 4px 10px; }
.ck-volume-controls label > span { grid-column: 1 / -1; }
.ck-volume-controls input[type=range] { width: 100%; min-height: 44px; margin: 0; accent-color: #d8b36a; }
.ck-volume-controls output { text-align: right; font-variant-numeric: tabular-nums; }
#ck-sound-settings { width: min(360px, calc(100% - 24px)); }
#ck-sound-settings footer { margin-top: 16px; }
.ck-volcano-notice {
  grid-column: 1 / -1;
  justify-self: center;
  max-inline-size: 100%;
  padding: 7px 14px;
  border: 1px solid #bd8054;
  border-radius: 6px;
  background: #2d2425;
  color: #ffe5bc;
  font: 600 13px/1.35 system-ui, sans-serif;
  text-align: center;
}
/* Buildings use the compact character card width at every viewport. */
#gameArea > #sidebar:has(.ck-building-inspector) {
  width: min(320px, calc(100% - 18px));
  min-width: 0;
  height: auto;
  top: 10px;
  bottom: auto;
  max-height: calc(100% - 20px);
}

#sidebar #infoPanel:has(.ck-building-inspector) {
  min-height: 0;
  padding: 12px;
  border: 0;
  overflow-y: auto;
}

.ck-building-inspector {
  display: grid;
  gap: 9px;
  min-width: 0;
  overflow-wrap: anywhere;
}

#infoPanel .ck-building-inspector :is(h3, h4, p) { margin: 0; }
.ck-building-inspector .ck-panel-heading { padding: 0; }
.ck-building-inspector .ck-panel-heading h3 { display: flex; align-items: center; gap: 8px; }
.ck-inspector-building-art { width: 42px; height: 42px; object-fit: contain; flex: none; }
.ck-building-inspector .ck-building-meta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 9px;
  color: var(--ck-paper);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.ck-building-status { color: #cfe8b8; }
.ck-building-status[data-attention=true] { color: #f0b292; }
.ck-building-health { color: #d1d1bd; }

.ck-building-stats,
.ck-building-controls,
.ck-building-details,
.ck-building-danger {
  display: grid;
  gap: 5px;
}
.ck-building-stats {
  padding: 8px 9px;
  border: 1px solid #80755866;
  border-radius: 6px;
  background: #10181170;
}
.ck-building-inspector .ck-production { margin: 0; }
.ck-building-inspector .ck-production > strong { font-size: 14px; }
#infoPanel .ck-building-inspector .ck-inspector-action { margin: 0; gap: 4px; }
#infoPanel .ck-building-inspector .ck-action-note { min-height: 2.5em; }
.ck-building-inspector :is(.ck-inspector-action, .ck-building-stats, .ck-building-controls, .ck-building-details, .ck-building-danger):empty {
  display: none;
}
.ck-building-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}
.ck-building-actions > button { flex: 1 1 auto; }
.ck-building-controls > :is(hr:first-child, hr:last-child) { display: none; }
.ck-building-controls > h4 { color: var(--ck-gold); }
.ck-building-controls > hr {
  width: 100%;
  margin: 3px 0;
  border: 0;
  border-top: 1px solid #9b8c66;
}
.ck-building-details { padding-top: 7px; border-top: 1px solid #80755866; }
.ck-building-danger { padding-top: 8px; border-top: 1px solid #a977695e; }
#sidebar .ck-building-danger > button {
  border-color: #b47b70 !important;
  color: #ffd1c4 !important;
  background: #4c2e27 !important;
}
#sidebar .ck-building-danger > button:enabled:hover { background: #634037 !important; }

@media (max-width: 680px) and (orientation: portrait) {
  #gameArea > #sidebar:has(.ck-building-inspector) {
    inset: auto 9px 6px auto;
    max-height: min(56dvh, calc(100% - 12px));
  }
}
.ck-building-action-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}
.ck-building-action-row > button { flex: 1 1 auto; }
.ck-building-detail-row {
  padding: 6px 8px;
  border: 1px solid #80755866;
  border-radius: 5px;
}
.ck-building-inspector small { color: #c7c4ad; }
.ck-building-inspector .ck-works-recruit { margin-top: 4px; }

/* Citizen Manager uses the game dock, with a fixed heading and a scrolling roster. */
#header #stat-population:is([aria-pressed="true"], [aria-expanded="true"]) :is(.ck-icon, .stat-value) {
  color: inherit;
}
body #population-panel.ck-dock:not([hidden]) {
  display: flex;
  flex-direction: column;
  width: min(690px, calc(100% - 12px));
  height: min(650px, 74dvh);
  overflow: hidden !important;
}
#population-panel > .ck-panel-heading { flex: none; }
#population-panel > .ck-panel-body,
.ck-citizen-roster {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.ck-citizen-filters {
  display: flex;
  flex: none;
  gap: 6px;
  margin-bottom: 10px;
}
#population-panel .ck-citizen-filters button {
  white-space: nowrap;
  padding-inline: clamp(6px, 2vw, 13px);
  border-radius: 24px;
}
.ck-citizen-filters strong { font-variant-numeric: tabular-nums; }
.ck-citizen-layout {
  display: grid;
  flex: 1;
  min-height: 0;
  grid-template-columns: minmax(0, 3fr) minmax(180px, 2fr);
  grid-template-areas: "roster trend";
  gap: 12px;
}
.ck-citizen-trend, .ck-citizen-roster {
  border: 1px solid var(--ck-line);
  border-radius: 6px;
  background: #141e19;
}
.ck-citizen-trend {
  grid-area: trend;
  align-self: start;
  min-width: 0;
  padding: 8px;
}
.ck-citizen-trend-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: 0 0 5px;
}
.ck-citizen-trend-heading h3 {
  margin: 0;
  color: var(--ck-gold);
  font: 600 16px/1.2 Georgia, serif;
}
#population-panel .ck-citizen-range {
  box-sizing: border-box;
  min-width: 0;
  padding: 4px 6px;
}
.ck-citizen-chart { position: relative; }
.ck-citizen-chart canvas {
  display: block;
  width: 100%;
  height: 156px;
  touch-action: pan-y;
}
.ck-citizen-chart canvas[hidden] { display: none; }
.ck-citizen-chart-empty, .ck-citizen-empty {
  color: #b9bcaa;
  padding: 12px;
  margin: 0;
}
.ck-citizen-chart-point {
  position: absolute;
  padding: 2px 6px;
  border: 1px solid var(--ck-line);
  border-radius: 4px;
  background: var(--ck-ink);
  font-size: 11px;
  white-space: nowrap;
  pointer-events: none;
}
.ck-citizen-roster { grid-area: roster; overflow: hidden; }
.ck-citizen-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(70px, 33%) 55px;
  gap: 6px;
  align-items: center;
  text-align: start;
}
.ck-citizen-sort {
  flex: none;
  padding: 3px 8px;
  border-bottom: 1px solid var(--ck-line);
  scrollbar-gutter: stable;
  overflow-y: hidden;
}
#population-panel.ck-dock .ck-citizen-sort button {
  padding: 3px 4px !important;
  border: 1px solid transparent !important;
  background: transparent !important;
  color: var(--ck-paper) !important;
  text-align: start;
  white-space: nowrap;
}
#population-panel.ck-dock .ck-citizen-sort button[aria-pressed=true] {
  background: var(--ck-panel) !important;
  color: var(--ck-gold) !important;
}
#population-panel.ck-dock .ck-citizen-sort button:hover { border-color: var(--ck-line) !important; }
.ck-citizen-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 0;
  margin: 0;
  list-style: none;
}
#population-panel.ck-dock .ck-citizen-row {
  width: 100%;
  min-height: 48px;
  padding: 5px 8px !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: 0 !important;
  border-bottom: 1px solid #aba48132 !important;
  color: var(--ck-paper) !important;
  font-weight: 400 !important;
}
#population-panel.ck-dock .ck-citizen-row:hover { background: #2a382c !important; }
.ck-citizen-identity, .ck-citizen-job, .ck-citizen-mood {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 0;
}
.ck-citizen-portrait {
  width: 36px;
  height: 36px;
  flex: none;
  border-radius: 6px;
  background: #303d31;
}
.ck-citizen-name-block, .ck-citizen-job > span { min-width: 0; }
.ck-citizen-name, .ck-citizen-job-name {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ck-citizen-row small {
  display: block;
  font-size: 11px;
  color: #b9bcaa;
}
.ck-citizen-row small[data-status=working] { color: #a8d6ae; }
.ck-citizen-row small[data-status=visiting] { color: #8bc6dd; }
.ck-citizen-job .ck-icon { flex: none; width: 15px; height: 15px; color: var(--ck-gold); }
.ck-citizen-mood { font-variant-numeric: tabular-nums; }
.ck-citizen-mood svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-linecap: round; }
.ck-citizen-mood[data-mood=good] { color: #a8d6ae; }
.ck-citizen-mood[data-mood=fair] { color: #ebc781; }
.ck-citizen-mood[data-mood=low] { color: #f1a69a; }

@media (min-width: 1024px) {
  body[data-player-role="king"]:has(#population-panel:not([hidden])):not(:has(
    #population-panel ~ .ck-dock:not([hidden]), dialog[open]:not(#ck-confirm)
  )) {
    --ck-dock-width: clamp(590px, 48vw, 690px);
  }
}
@media (max-width: 1023px) {
  .ck-citizen-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "trend" "roster";
    gap: 8px;
  }
  .ck-citizen-chart canvas { height: clamp(80px, 16dvh, 132px); }
}
@media (max-width: 760px) and (orientation: portrait) {
  body[data-player-role="king"] #population-panel.ck-dock:not([hidden]) {
    max-height: calc(100dvh - var(--ck-play-top) - var(--ck-play-bottom) - 102px) !important;
    height: min(670px, 78dvh);
  }
}
@media (orientation: landscape) and (max-height: 520px) {
  .ck-citizen-layout {
    grid-template-columns: minmax(0, 3fr) minmax(158px, 2fr);
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "roster trend";
  }
  body[data-player-role="king"]:has(#population-panel:not([hidden])):not(:has(
    #population-panel ~ .ck-dock:not([hidden]), dialog[open]:not(#ck-confirm)
  )) {
    --ck-dock-width: min(630px, 84vw);
  }
}
