/* ------------------------------------------------------------------ */
/* Uniform game UI                                                    */
/* ------------------------------------------------------------------ */
/* One source of truth for every category box: the title box and every */
/* content box share the same paper, border, shadow, padding, heading  */
/* font and body copy. Change a token here and every section follows.  */
/* This file loads after the per-tab stylesheets and before mobile.css,*/
/* so section-specific rules cannot drift the shared box again.        */

:root {
  --ui-box-padding: 22px;
  --ui-box-gap: 18px;
  --ui-box-border: 1px solid #b4935c;
  --ui-box-background:
    linear-gradient(160deg, rgba(255, 252, 242, .35), rgba(255, 251, 235, 0) 60%),
    repeating-linear-gradient(0deg, #f0e0bd 0 3px, #f4e7c9 3px 6px);
  --ui-box-shadow:
    0 0 0 3px #213632,
    0 0 0 4px #634f32,
    0 12px 28px rgba(4, 12, 11, .25);
  --ui-box-heading-size: 30px;
  --ui-box-title-size: 42px;
  --ui-box-copy-size: 12.5px;
  --ui-box-copy-line: 1.5;
  --ui-box-text: #705c3f;
  --ui-box-accent: #8a3a27;
}

/* Every content box keeps the same paper-and-brass frame. The per-tab
   padding overrides are intentionally superseded here. */
.panel {
  padding: var(--ui-box-padding);
  border: var(--ui-box-border);
  background: var(--ui-box-background);
  box-shadow: var(--ui-box-shadow);
}

/* The section head is the first category box on every screen. It is the old
   screen header and hall banner merged: the tab's name, its poetic kicker, its
   explanatory copy and villager slots, with no statistics. */
.title-box {
  display: flex;
  align-items: center;
  gap: 20px;
  min-height: 191px;
  padding: var(--ui-box-padding);
  color: var(--ink);
  background:
    radial-gradient(circle at 84% 4%, rgba(201, 74, 49, .13), transparent 30%),
    var(--ui-box-background);
}
.title-box > * {
  position: relative;
  z-index: 1;
}
.title-box-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border: 1px solid #8f703f;
  background: #c94a31;
  color: #ffefd0;
  font-family: serif;
  font-size: 31px;
  line-height: 1;
  box-shadow: inset 0 0 0 4px #ead8b0, inset 0 0 0 5px #a63928;
  transform: rotate(-2deg);
}
.title-box-copy {
  flex: 1 1 auto;
  min-width: 0;
}
.title-box .eyebrow {
  margin: 0 0 6px;
  color: var(--ui-box-accent);
  font-size: 10px;
  letter-spacing: .12em;
}
.title-box-title {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: var(--ui-box-title-size);
  font-weight: 700;
  line-height: .92;
  letter-spacing: -.02em;
}
.title-box-subtitle {
  max-width: 780px;
  margin: 9px 0 0;
  color: var(--ui-box-text);
  font-size: 13px;
  line-height: 1.5;
}
.title-box-aside {
  flex: 0 0 auto;
  margin-left: auto;
  min-width: 0;
  max-width: 360px;
}
.title-box-aside .hall-slots {
  min-width: 0;
  max-width: none;
}
.title-box-aside .hall-slots-kicker {
  margin: 0 0 6px;
  color: #7d6644;
  font-size: 10px;
  letter-spacing: .06em;
  text-align: right;
}
.title-box-aside .hall-worker-grid {
  justify-content: flex-end;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
  margin-top: 0;
}
.title-box-aside .hall-worker-grid .worker-slot {
  width: 100%;
  min-width: 0;
}

/* The category heading is one size on every page. This deliberately beats the
   per-tab sizes that had drifted between 21px and 33px. */
.panel > .panel-head h3,
.panel .panel-head h3,
.panel > .market-board-head h2,
.panel > .warehouse-top h2,
.panel > .ranking-board-head h2,
.panel > .adventure-stage-head h3,
.panel > h2,
.panel > h3 {
  font-family: var(--font-display);
  font-size: var(--ui-box-heading-size);
  font-weight: 700;
  line-height: 1;
}
/* The heading elements above also need the ink colour, not a tinted tab
   variant. Inner cards are excluded because they are not direct children. */
.panel > .panel-head h3,
.panel > .market-board-head h2,
.panel > .warehouse-top h2,
.panel > .ranking-board-head h2,
.panel > h2,
.panel > h3 {
  color: var(--ink);
}

/* The explanatory line under each category heading is the same size and
   colour throughout, including the per-tab heads that styled it locally. */
.panel > .panel-head p,
.panel > .market-board-head p,
.panel > .warehouse-top > div > p,
.panel > .ranking-board-head p,
.panel > .adventure-stage-head p {
  color: var(--ui-box-text);
  font-size: var(--ui-box-copy-size);
  line-height: var(--ui-box-copy-line);
}

/* Section notes that were written for the teal page background become ink
   when their section becomes a paper box. */
.panel .production-note {
  color: var(--ui-box-text);
}

/* The single spacing rhythm between all category boxes. Margins on the
   sections themselves are neutralised so the gap owns the spacing. */
.tab-inner {
  gap: var(--ui-box-gap);
}
.tab-inner > :not(.tab-footer) {
  margin-top: 0;
  margin-bottom: 0;
}

/* Two-column and stacked section layouts use the same gap token. */
.market-layout,
.resource-layout,
.food-layout,
.settings-layout,
.villager-layout,
.inventory-stack,
.ranking-boards,
.combat-attack-grid {
  gap: var(--ui-box-gap);
}

/* The section's corner controls: the red close cross, the upgrade/reassign
   icon and the shared filter button. They form one vertical stack on desktop
   and one row on a phone, always in the title box. */
.panel.has-page-fabs { position: relative; }
.page-fab-stack {
  position: absolute;
  z-index: 4;
  display: flex;
  align-items: center;
}
/* All three controls are the same square. The upgrade button has no bottom
   shadow bar, so it no longer reads a few pixels taller than the cross. */
.page-fab-stack > .villager-fab,
.page-fab-stack > .cross-close {
  width: 33px;
  height: 33px;
  flex: 0 0 auto;
  box-shadow: none;
}
.page-fab-stack > .cross-close {
  font-size: 20px;
}
/* A missing control keeps its slot so the remaining buttons never move. The
   ghost is hidden on a phone, where the row simply packs the buttons it has. */
.page-fab-ghost { display: none; }
/* The info control only exists in the phone frame; desktop keeps the section's
   explanatory copy inline in the title box. */
.page-info-pop { display: none; }
/* Desktop: a fixed three-row grid. The first slot is the close, the second the
   upgrade, the third the filter. The stack is the same height as the villager
   board, so the first button's top and the third button's bottom line up with
   it. The buttons grow to fill that height while the gap stays 11.5px. */
@media (min-width: 861px) {
  .page-fab-stack {
    top: 22px;
    right: 22px;
    bottom: 22px;
    width: 40.67px;
    display: grid;
    grid-template-rows: repeat(3, minmax(0, 1fr));
    gap: 11.5px;
  }
  .page-fab-stack > .villager-fab,
  .page-fab-stack > .cross-close,
  .page-fab-stack > .page-fab-ghost {
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
  }
  .page-fab-stack > .cross-close { font-size: 24px; }
  .page-fab-stack > .villager-fab svg { width: 25px; height: 25px; }
  .page-fab-stack > .page-fab-ghost { display: block; order: 2; }
  .page-fab-stack > .building-close-fab,
  .page-fab-stack > .page-close-fab { order: 1; }
  .page-fab-stack > .building-fab { order: 2; }
  .page-fab-stack > .page-filter-fab { order: 3; }
  /* Match the space on the right of the stack with the same space on its left:
     the stack sits on the title box's content edge, so the villager board's
     margin is the button plus the 23px visual inset. */
  .title-box.has-page-fabs .title-box-aside { margin-right: calc(40.67px + 23px); }
}

/* Phone: the buttons line up with the first box's heading in a two-by-two
   grid. The upgrade and close cross sit on the first row, the filter and info
   on the second, so the cross keeps the far-right corner it always had. */
@media (max-width: 860px) {
  .page-fab-stack {
    top: 14px;
    right: 14px;
    display: grid;
    grid-template-columns: repeat(2, 33px);
    grid-auto-rows: 33px;
    gap: 8px;
  }
  .page-fab-stack > .building-fab { order: 1; }
  .page-fab-stack > .building-close-fab { order: 2; }
  .page-fab-stack > .page-filter-fab { order: 3; }
  .page-fab-stack > .page-info-fab { order: 4; display: grid; }
  /* An info-only head (Premium) sits alone in the far-right column. */
  .page-fab-stack--info > .page-info-fab { grid-column: 2; grid-row: 1; }
  /* A section without a building has no upgrade control beside the cross, so
     place the cross in the same far-right corner the building sections use and
     let the filter and info fill the second row. */
  .page-fab-stack > .page-close-fab {
    order: 1;
    grid-column: 2;
    grid-row: 1;
  }
  .page-fab-stack > .page-close-fab ~ .page-filter-fab {
    grid-column: 1;
    grid-row: 2;
  }
  .page-fab-stack > .page-close-fab ~ .page-info-fab {
    grid-column: 2;
    grid-row: 2;
  }
  /* The open [i] keeps the paper face but presses into the page. */
  .page-info-fab[aria-expanded="true"] {
    border-color: #8a3a27;
    color: #6b2b1c;
    background: #e8d3a8;
    box-shadow: inset 0 0 0 1px #c9a86a;
  }
  .panel.has-page-fabs:not(.title-box) > :first-child { padding-right: 52px; }
  .panel.has-info-fab:not(.title-box) > :first-child,
  .panel.has-building-fabs:not(.title-box) > :first-child { padding-right: 96px; }
  /* The explanatory copy the title box carries on desktop is moved into the
     info sheet over the box's own content on a phone. ui.mountVillagerFab()
     sets the offset from the real head height; 96px is the fallback. */
  .page-info-pop {
    position: absolute;
    z-index: 5;
    top: 96px;
    right: 14px;
    left: 14px;
    max-height: calc(100vh - 190px);
    overflow-y: auto;
    color: var(--ui-box-text);
    box-shadow: 0 10px 22px rgba(4, 12, 11, .22);
  }
  .page-info-pop.is-open { display: block; }
  .page-info-copy {
    margin: 0;
    color: var(--ui-box-text);
    font-size: var(--ui-box-copy-size);
    line-height: var(--ui-box-copy-line);
  }
}

.villager-fab {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 33px;
  height: 33px;
  padding: 0;
  border: 1px solid #b4935c;
  border-radius: 2px;
  color: #8a3a27;
  background:
    linear-gradient(160deg, rgba(255, 252, 242, .35), rgba(255, 251, 235, 0) 60%),
    repeating-linear-gradient(0deg, #f0e0bd 0 3px, #f4e7c9 3px 6px);
  cursor: pointer;
}
.villager-fab svg {
  width: 21px;
  height: 21px;
}
.villager-fab:active { transform: translateY(1px); }
/* The filter button wears the register's blue when any filter is active, and
   the same paper-and-ink as the upgrade button when none is. */
.page-filter-fab.is-active {
  border-color: #234a66;
  color: #f4f8fb;
  background: #365f7d;
  box-shadow: inset 0 0 0 1px #6d93b0;
}
/* The City and World already own a toolbar, so their lone filter button keeps
   that row's compact rhythm instead of becoming a panel stack. */
.page-fab-stack--map {
  position: static;
  inset: auto;
  /* Never let a tall neighbour (the World's coordinate panel) stretch the
     stack: the toolbar buttons stay on the same top edge as the row. */
  align-self: flex-start;
  display: flex;
  width: auto;
  height: auto;
  flex-direction: row;
  gap: 6px;
}
/* Match the map toolbar's square and glyph so the filter reads as one more
   control in that row rather than a larger button sitting beside it. */
.page-fab-stack--map > .villager-fab {
  width: 34px;
  height: 34px;
}
.page-fab-stack--map > .villager-fab svg { width: 16px; height: 16px; }
@media (max-width: 860px) {
  .page-fab-stack--map > .villager-fab {
    width: 30px;
    height: 30px;
  }
}
/* The phone frame is the only place the info control appears; the desktop
   title box already prints the same copy under its heading. */
@media (min-width: 861px) {
  .page-info-fab,
  .page-info-pop { display: none !important; }
}
.mobile-only { display: none; }

/* The phone staffing sheet uses the same worker tiles as the old hall
   banners, grouped by hall and ordered with the open section first. */
.staff-board {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.staff-board-hall {
  padding: 12px;
  border: 1px solid #c0a46e;
  background: rgba(255, 252, 242, .5);
}
.staff-board-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
  padding-bottom: 7px;
  border-bottom: 1px solid #c3aa78;
}
.staff-board-head h3 {
  margin: 3px 0 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
}
.staff-board-level {
  color: #8a7049;
  font-family: var(--font-pixel);
  font-size: 9px;
  letter-spacing: .06em;
  white-space: nowrap;
}
.staff-board-grid {
  justify-content: flex-start;
  grid-template-columns: repeat(auto-fill, minmax(58px, 1fr));
  gap: 5px;
}
.staff-board-grid .worker-slot {
  width: 100%;
  min-width: 0;
}
.staff-board-note {
  margin: 0;
  color: #7b6645;
  font-size: 11.5px;
  line-height: 1.45;
  text-align: center;
}

/* ------------------------------------------------------------------ */
/* Shared per-page filter sheet                                       */
/* ------------------------------------------------------------------ */
/* A card hidden by its section's own filter. The class is used rather than
   [hidden] so tab code that already toggles hidden for other reasons keeps
   working independently. */
.is-filtered-out { display: none !important; }

.page-filter-overlay {
  position: fixed;
  inset: 64px 0 144px;
  z-index: 60;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  overflow-y: auto;
  padding: 24px 22px;
  background: rgba(13, 29, 27, .55);
  backdrop-filter: blur(1.5px);
}
.page-filter-sheet {
  width: min(760px, 100%);
  max-height: max(260px, calc(100dvh - 256px));
  display: flex;
  flex-direction: column;
  margin: 0;
}
.page-filter-groups {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: #9d804f rgba(8, 17, 17, .2);
}
.page-filter-groups::-webkit-scrollbar { width: 8px; }
.page-filter-groups::-webkit-scrollbar-thumb { background: #ae925f; border: 2px solid #f0e0bd; }
.page-filter-groups::-webkit-scrollbar-track { background: rgba(147, 111, 60, .12); }
.page-filter-group {
  padding: 12px 0;
  border-bottom: 1px solid #c3aa78;
}
.page-filter-group:last-child { border-bottom: 0; }
.page-filter-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.page-filter-group-head h3 {
  margin: 0;
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}
.page-filter-group-head span {
  color: #806a46;
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: .03em;
  white-space: nowrap;
}
.page-filter-chips { margin-top: 9px; }
.page-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-color: #b59b6c;
  background: rgba(255, 252, 239, .55);
  color: #5b4730;
  font-size: 12px;
}
.page-filter-chip strong { color: #8a7553; font-size: 10px; font-weight: 400; }
.page-filter-chip:hover { border-color: #caa45e; background: #f6e7c5; }
.page-filter-chip.is-on {
  border-color: #365f7d;
  background: #e2edf6;
  color: #264b65;
  box-shadow: inset 0 0 0 1px #6d93b0;
}
.page-filter-chip.is-on strong { color: #365f7d; }
.page-filter-empty-note {
  margin: 0;
  color: #806a46;
  font-family: var(--font-pixel);
  font-size: 9.5px;
  letter-spacing: .02em;
}
/* The sheet is fixed; stop the tab enter animation transforming its wrapper. */
.tab-inner.page-filter-open { animation: none; }

@media (max-width: 860px) {
  .page-filter-overlay {
    inset: var(--app-chrome-top, 0px) 0 var(--app-chrome-bottom, 0px);
    padding: 12px;
  }
  .page-filter-sheet {
    width: 100%;
    max-height: 100%;
  }
  .page-filter-group-head h3 { font-size: 18px; }
  .page-filter-chip { padding: 6px 8px; font-size: 11px; }
}
