/* docs/features/game-engine/production/ */

/* --- Shell hooks (production-root lives inside the fixed-ratio stage) --- */

/* SPA + SSR: `.surface-page` wraps the shell — keep selector resilient and tint lighter than base stub 0.72. */
.town-field.game-stage.town-field--stub:has(.production-root)::after,
.town-field.game-stage.town-field--stub:has(.surface-page .production-root)::after {
  background: linear-gradient(
    165deg,
    rgba(12, 8, 22, 0.12) 0%,
    rgba(8, 6, 16, 0.09) 45%,
    rgba(14, 10, 26, 0.13) 100%
  );
}

/* Overrides `.town-field--stub .workbench-root` padding from formation-builder.css for this surface */
.town-field--stub .workbench-root.production-root {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: calc(var(--gs-u-h) * 0.45) calc(var(--gs-u-w) * 0.85)
    max(calc(var(--gs-u-h) * 1.35), calc(var(--gs-u-h) * 6));
  box-sizing: border-box;
}

.town-field--stub:has(.game-wallet-hud) .production-root .game-mode-bar__inner {
  padding-right: clamp(calc(var(--gs-u-w) * 10), calc(var(--gs-u-w) * 20), calc(var(--gs-u-w) * 14));
}

.town-field--stub:has(.production-root) .player-meta-dock {
  background: rgba(22, 16, 36, 0.52);
  border: 1px solid var(--gs-border-gold-panel);
  box-shadow: 0 calc(var(--gs-u-w) * 0.9) calc(var(--gs-u-h) * 2.9) rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(8px);
}

/* --- Feature tokens --- */

.production-root {
  --prod-radius: calc(var(--gs-u-h) * 1.33);
  /* Slot icons ~20% larger than prior 6.9 to fill card chrome. */
  --prod-worker-icon-size: calc(var(--gs-u-h) * 8.28);
  /* Sidebar pool icons ~50% larger than slot icons. */
  --prod-pool-icon-size: calc(var(--gs-u-h) * 12.42);
  --prod-collect-btn-min-h: calc(var(--gs-u-h) * 5.85);
  --prod-storage-row-h: calc(var(--gs-u-h) * 3.2);
  /* Chrome: .ornate-panel on line cards; .brass-panel on sidebar tray. */
}

.production-tab--off {
  opacity: 0.45;
  cursor: not-allowed;
}

.production-layout {
  display: grid;
  grid-template-columns: 1fr minmax(calc(var(--gs-u-w) * 14), calc(var(--gs-u-w) * 18));
  gap: calc(var(--gs-u-h) * 0.85);
  align-items: stretch;
}

.production-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: calc(var(--gs-u-h) * 1.15);
  padding: calc(var(--gs-u-h) * 0.45);
  align-items: start;
  justify-items: start;
}

/* Facility heraldry left of card; card ~70% of cell — leftover space stays empty. */
.production-line-row {
  display: grid;
  grid-template-columns: minmax(0, 26%) minmax(0, 70%);
  column-gap: 0;
  align-items: start;
  justify-content: start;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.production-facility-mark {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
  /* Match card padding-block-start so the banner lines up with the headline. */
  padding-top: calc(var(--gs-u-h) * 0.85);
  /* Nudge into the card so the banner sits partly behind the panel. */
  position: relative;
  z-index: 0;
  transform: translateX(5%);
}

.production-facility-icon {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  object-position: top center;
  user-select: none;
}

.production-card {
  position: relative;
  z-index: 1;
  min-width: 0;
  box-sizing: border-box;
  overflow: visible;
  padding-block: calc(var(--gs-u-h) * 0.85) calc(var(--gs-u-h) * 0.95);
  padding-inline: calc(var(--gs-u-w) * 1.55);
  transition: filter 0.2s ease, opacity 0.2s ease;
}

.production-card--ready {
  filter: brightness(1.05);
}

.production-card--active:not(.production-card--ready) {
  filter: saturate(1.05);
}

.production-card--idle {
  opacity: 0.94;
}

.production-card--drag-over {
  outline: var(--gs-stroke) solid rgba(120, 200, 255, 0.55);
  outline-offset: calc(var(--gs-u-h) * 0.22);
}

.production-card__title {
  position: relative;
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  margin: 0 0 calc(var(--gs-u-h) * 0.28);
  padding-inline-end: calc(var(--gs-u-h) * 1.4);
}

.production-card__title h3 {
  margin: 0;
  font-size: calc(var(--gs-u-h) * 2.65);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff6eb;
  text-shadow: 0 calc(var(--gs-u-h) * 0.12) calc(var(--gs-u-h) * 0.35) rgba(0, 0, 0, 0.45);
}

.production-card__title .action-notify-dot {
  top: 0;
  right: 0;
}

.production-slots {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  margin: calc(var(--gs-u-h) * 0.75) 0 calc(var(--gs-u-h) * 0.5);
  flex-wrap: nowrap;
  gap: 0;
}

.production-slot {
  width: var(--prod-worker-icon-size);
  height: var(--prod-worker-icon-size);
  box-sizing: border-box;
  flex: 0 0 var(--prod-worker-icon-size);
  border-radius: var(--gs-radius-md);
  border: var(--gs-hairline) dashed rgba(190, 175, 215, 0.4);
  background: rgba(10, 9, 14, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
}

.production-slot--filled {
  border-style: solid;
  border-color: rgba(255, 210, 120, 0.55);
  background: transparent;
  padding: 0;
  overflow: hidden;
  cursor: grab;
}

.production-slot--rental {
  border-color: rgba(120, 200, 255, 0.55);
  outline: none;
}

.production-slot--expired {
  cursor: pointer;
  overflow: visible;
}

.production-slot--expired .production-worker-icon {
  opacity: 0.45;
  filter: grayscale(0.9);
}

.production-slot--empty.production-slot--droppable {
  border-color: rgba(140, 200, 255, 0.48);
}

.production-slot--drop-hover {
  background: rgba(60, 100, 140, 0.38);
}

.production-slot .production-worker-icon {
  width: 100%;
  height: 100%;
  border-radius: 0;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  filter: drop-shadow(0 calc(var(--gs-u-h) * 0.22) calc(var(--gs-u-h) * 0.45) rgba(0, 0, 0, 0.45));
}

.production-recipe {
  display: flex;
  align-items: center;
  gap: calc(var(--gs-u-h) * 0.5);
  flex-wrap: wrap;
  font-size: calc(var(--gs-u-h) * 2.05);
  color: #c9baa8;
  margin: 0 0 calc(var(--gs-u-h) * 0.22);
  margin-inline-start: 0;
  padding-inline-start: 0;
  min-height: calc(var(--gs-u-h) * 6);
}

.production-input {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: calc(var(--gs-u-w) * 3.5);
}

/* Flush the first recipe chip to the card content edge (no leading dead space). */
.production-recipe > .production-input:first-child,
.production-recipe > .production-output:first-child {
  margin-inline-start: 0;
  min-width: 0;
  justify-content: flex-start;
}

.production-input__icon-wrap {
  position: relative;
  width: calc(var(--gs-u-h) * 5);
  height: calc(var(--gs-u-h) * 5);
  flex-shrink: 0;
}

.production-input__icon-wrap img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 100%;
  background: rgba(10, 8, 14, 0.72);
  box-shadow: 0 calc(var(--gs-u-w) * 0.22) calc(var(--gs-u-h) * 0.9) rgba(0, 0, 0, 0.25);
  display: block;
}

/* Qty > 1 only — bottom-right bubble (inventory-tile pattern). */
.production-input__qty {
  position: absolute;
  right: calc(var(--gs-u-w) * -0.35);
  bottom: calc(var(--gs-u-h) * -0.2);
  z-index: 1;
  min-width: calc(var(--gs-u-h) * 2.4);
  padding: calc(var(--gs-u-h) * 0.14) calc(var(--gs-u-w) * 0.38);
  border-radius: var(--gs-radius-xs, calc(var(--gs-u-h) * 0.45));
  border: var(--gs-hairline) solid rgba(255, 200, 120, 0.35);
  background: rgba(36, 25, 49, 0.92);
  color: #ffe4b8;
  font-size: calc(var(--gs-u-h) * 1.65);
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  text-align: center;
  box-sizing: border-box;
  pointer-events: none;
}

.production-arrow {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  color: #e8c45a;
  opacity: 0.5;
}

.production-arrow__svg {
  width: calc(var(--gs-u-w) * 5.5);
  height: calc(var(--gs-u-h) * 2.4);
  display: block;
  overflow: visible;
}

.production-output {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: calc(var(--gs-u-w) * 6);
}

.production-output img {
  width: calc(var(--gs-u-h) * 6);
  height: calc(var(--gs-u-h) * 6);
  object-fit: contain;
  border-radius: 33%;
  background: rgba(10, 8, 14, 0.72);
  box-shadow: 0 calc(var(--gs-u-w) * 0.22) calc(var(--gs-u-h) * 0.9) rgba(0, 0, 0, 0.25);
  display: block;
}

/* Storage: output icon + guild-tinted fill bar (no stored/cap numerals — Collect shows amount).
   Always mounts at fixed height so idle / ready cards share the same footprint. */
.production-storage {
  margin-top: calc(var(--gs-u-h) * 0.28);
  min-height: var(--prod-storage-row-h);
  display: flex;
  align-items: center;
  width: 100%;
}

.production-storage--placeholder {
  visibility: hidden;
  pointer-events: none;
}

.production-storage__meter {
  display: flex;
  align-items: center;
  gap: 0;
  width: 100%;
  min-width: 0;
}

.production-storage__icon-wrap {
  position: relative;
  z-index: 2;
  flex-shrink: 0;
  /* Sit the produced unit slightly over the fill bar. */
  margin-inline-end: calc(var(--gs-u-w) * -1.1);
}

.production-storage__icon {
  width: calc(var(--gs-u-h) * 3.6);
  height: calc(var(--gs-u-h) * 3.6);
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 calc(var(--gs-u-h) * 0.12) calc(var(--gs-u-h) * 0.28) rgba(0, 0, 0, 0.45));
}

.production-storage__bar {
  position: relative;
  z-index: 1;
  flex: 1 1 auto;
  min-width: 0;
  height: calc(var(--gs-u-h) * 2.55);
  border-radius: calc(var(--gs-u-h) * 0.55);
  border: var(--gs-hairline) solid rgba(190, 200, 220, 0.42);
  background: rgba(8, 7, 12, 0.78);
  box-shadow:
    inset 0 calc(var(--gs-hairline)) 0 rgba(255, 255, 255, 0.08),
    inset 0 calc(var(--gs-hairline) * -1) 0 rgba(0, 0, 0, 0.45);
  overflow: hidden;
}

.production-storage__bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--fill, 0%);
  height: 100%;
  pointer-events: none;
  transition: width 0.35s ease;
}

/* Guild fill tints — match facility heraldry (wood / stone / tile / glass). */
.production-storage--wood .production-storage__bar-fill {
  background: linear-gradient(90deg, #1e4d2b 0%, #3d8f52 45%, #6bc47f 100%);
  box-shadow: 0 0 calc(var(--gs-u-h) * 0.7) rgba(70, 160, 90, 0.35);
}

.production-storage--stone .production-storage__bar-fill {
  background: linear-gradient(90deg, #3a3d42 0%, #6a6e76 45%, #9aa0a8 100%);
  box-shadow: 0 0 calc(var(--gs-u-h) * 0.7) rgba(150, 155, 165, 0.3);
}

.production-storage--tile .production-storage__bar-fill {
  background: linear-gradient(90deg, #6b1c1c 0%, #b43a32 45%, #e07058 100%);
  box-shadow: 0 0 calc(var(--gs-u-h) * 0.7) rgba(200, 70, 55, 0.35);
}

.production-storage--glass .production-storage__bar-fill {
  background: linear-gradient(90deg, #163a6b 0%, #2f6fbf 45%, #6eb0ef 100%);
  box-shadow: 0 0 calc(var(--gs-u-h) * 0.7) rgba(70, 140, 220, 0.35);
}

.production-storage--military .production-storage__bar-fill {
  background: linear-gradient(90deg, #4a1a1a 0%, #8b2e2e 45%, #c45a4a 100%);
  box-shadow: 0 0 calc(var(--gs-u-h) * 0.7) rgba(180, 70, 60, 0.32);
}

.production-storage--magic .production-storage__bar-fill {
  background: linear-gradient(90deg, #3a1a5c 0%, #6b3a9e 45%, #a878d8 100%);
  box-shadow: 0 0 calc(var(--gs-u-h) * 0.7) rgba(140, 90, 200, 0.35);
}

.production-storage__full-label {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-inline: calc(var(--gs-u-w) * 1.2);
  font-size: calc(var(--gs-u-h) * 1.95);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1;
  pointer-events: none;
  /* Readable on all guild fills: light glyph + dark outline. */
  color: #fff8ec;
  text-shadow:
    0 0 calc(var(--gs-u-h) * 0.35) rgba(0, 0, 0, 0.85),
    calc(var(--gs-hairline)) calc(var(--gs-hairline)) 0 rgba(0, 0, 0, 0.9),
    calc(var(--gs-hairline) * -1) calc(var(--gs-hairline)) 0 rgba(0, 0, 0, 0.9),
    calc(var(--gs-hairline)) calc(var(--gs-hairline) * -1) 0 rgba(0, 0, 0, 0.9),
    calc(var(--gs-hairline) * -1) calc(var(--gs-hairline) * -1) 0 rgba(0, 0, 0, 0.9);
}

.production-storage--full .production-storage__bar {
  border-color: rgba(255, 220, 140, 0.55);
}

.production-collect-wrap {
  margin-top: calc(var(--gs-u-h) * 0.55);
  min-height: var(--prod-collect-btn-min-h);
}

.production-collect-wrap--placeholder {
  visibility: hidden;
  pointer-events: none;
}

/* Gold collect CTA — feature-local (draft L&F experiment). */
.production-collect-btn {
  width: 100%;
  min-height: var(--prod-collect-btn-min-h);
  border-radius: calc(var(--gs-u-h) * 1.15);
  border: var(--gs-hairline) solid rgba(245, 210, 120, 0.55);
  background:
    linear-gradient(180deg, rgba(255, 245, 200, 0.35), transparent 42%),
    linear-gradient(180deg, #d4a84a 0%, #b8862e 48%, #8f6420 100%);
  box-shadow:
    inset 0 calc(var(--gs-hairline)) 0 rgba(255, 248, 220, 0.45),
    inset 0 calc(var(--gs-hairline) * -1) 0 rgba(70, 45, 10, 0.55),
    0 calc(var(--gs-u-h) * 0.28) calc(var(--gs-u-h) * 1.1) rgba(0, 0, 0, 0.35);
  color: #fff8ec;
  font-size: calc(var(--gs-u-h) * 2.45);
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 calc(var(--gs-hairline)) calc(var(--gs-u-h) * 0.28) rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: calc(var(--gs-u-w) * 0.55);
  padding: calc(var(--gs-u-h) * 0.35) calc(var(--gs-u-h) * 0.95);
  cursor: pointer;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease, transform 0.12s ease;
}

.production-collect-btn__icon {
  width: calc(var(--gs-u-h) * 3.85);
  height: calc(var(--gs-u-h) * 3.85);
  object-fit: contain;
  flex-shrink: 0;
  pointer-events: none;
  filter: drop-shadow(0 calc(var(--gs-u-h) * 0.12) calc(var(--gs-u-h) * 0.28) rgba(0, 0, 0, 0.4));
}

.production-collect-btn__label {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.production-collect-btn:not([disabled]):hover {
  border-color: rgba(255, 230, 150, 0.75);
  filter: brightness(1.06);
  box-shadow:
    inset 0 calc(var(--gs-hairline)) 0 rgba(255, 248, 220, 0.55),
    inset 0 calc(var(--gs-hairline) * -1) 0 rgba(70, 45, 10, 0.55),
    0 0 calc(var(--gs-u-h) * 1.55) rgba(222, 165, 58, 0.28);
}

.production-collect-btn:not([disabled]):active {
  transform: translateY(calc(var(--gs-hairline)));
  filter: brightness(0.96);
}

.production-collect-btn:focus-visible {
  outline: var(--gs-stroke) solid rgba(255, 220, 140, 0.95);
  outline-offset: calc(var(--gs-u-h) * 0.22);
}

.production-collect-btn[disabled] {
  cursor: default;
  opacity: 0.55;
  filter: grayscale(0.25) brightness(0.88);
}

.production-collect-btn--ready:not([disabled]) {
  border-color: rgba(255, 225, 140, 0.72);
}

.production-side {
  border-radius: var(--prod-radius);
  padding: calc(var(--gs-u-h) * 0.62) calc(var(--gs-u-h) * 0.65);
  font-size: calc(var(--gs-u-h) * 2.15);
  color: #e8dcc8;
  display: flex;
  flex-direction: column;
  gap: calc(var(--gs-u-h) * 0.15);
}

.production-side h3 {
  margin: 0 0 calc(var(--gs-u-h) * 0.4);
  font-size: calc(var(--gs-u-h) * 2.5);
  font-weight: 700;
  letter-spacing: 0.03em;
  color: #fff6eb;
}

.production-side h4 {
  margin: calc(var(--gs-u-h) * 0.35) 0 calc(var(--gs-u-h) * 0.3);
  font-size: calc(var(--gs-u-h) * 2.2);
  font-weight: 600;
  color: rgba(255, 235, 210, 0.78);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.production-side form {
  margin: calc(var(--gs-u-h) * 0.25) 0;
}

.production-side .town-nav-btn {
  font-size: calc(var(--gs-u-h) * 2.05);
  font-weight: 600;
  padding: calc(var(--gs-u-h) * 0.36) calc(var(--gs-u-h) * 0.55);
  width: 100%;
  box-sizing: border-box;
}

.production-side .town-nav-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.production-banner {
  margin: calc(var(--gs-u-h) * 0.35) 0;
  padding: calc(var(--gs-u-h) * 0.35) calc(var(--gs-u-h) * 0.5);
  border-radius: var(--gs-radius-sm);
  font-size: calc(var(--gs-u-h) * 2.25);
}

.production-banner--err {
  background: rgba(120, 30, 30, 0.35);
  border: var(--gs-hairline) solid rgba(255, 140, 140, 0.35);
  color: #ffd4d4;
}

.production-price {
  display: inline-flex;
  align-items: center;
  gap: calc(var(--gs-u-h) * 0.35);
  justify-content: center;
  width: 100%;
}

.production-pool-dock {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: calc(var(--gs-u-h) * 15.5);
  border-radius: var(--gs-radius-md);
  border: var(--gs-hairline) dashed rgba(200, 175, 230, 0.35);
  background: rgba(9, 8, 13, 0.55);
  margin: calc(var(--gs-u-h) * 0.28) 0;
  padding: calc(var(--gs-u-h) * 0.4) 0;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.production-pool-dock .production-worker-icon {
  width: var(--prod-pool-icon-size);
  height: var(--prod-pool-icon-size);
  border-radius: var(--gs-radius-md);
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-user-drag: none;
  user-select: none;
  filter: drop-shadow(0 calc(var(--gs-u-h) * 0.22) calc(var(--gs-u-h) * 0.67) rgba(0, 0, 0, 0.4));
}

.production-worker-icon.dnd-dragging {
  opacity: 0.45;
}

.production-pool-dock__count {
  font-size: calc(var(--gs-u-h) * 2.65);
  font-weight: 800;
  color: #fff4e6;
  margin-top: calc(var(--gs-u-h) * 0.12);
  font-variant-numeric: tabular-nums;
}

.production-pool-dock--inactive {
  opacity: 0.42;
  filter: grayscale(1);
}

.production-pool-dock[draggable="true"] {
  cursor: grab;
}

.production-pool-dock.production-drop-hover {
  border-color: rgba(120, 200, 255, 0.7);
  background: rgba(40, 70, 100, 0.38);
}

.production-hire-gap {
  margin: calc(var(--gs-u-h) * 0.5) 0;
  padding-top: calc(var(--gs-u-h) * 0.4);
  border-top: var(--gs-hairline) solid rgba(180, 160, 200, 0.2);
}

.production-pool {
  margin: calc(var(--gs-u-h) * 0.2) 0 calc(var(--gs-u-h) * 0.35);
  font-size: calc(var(--gs-u-h) * 2);
  color: #9a8d7c;
  line-height: 1.35;
}

.production-sidebar-vip-hint {
  margin: calc(var(--gs-u-h) * 0.28) 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .production-collect-btn:not([disabled]):hover,
  .production-collect-btn:not([disabled]):active {
    transform: none;
  }

  .production-storage__bar-fill {
    transition: none;
  }
}
