:root {
  color-scheme: dark;
  --bg: #091a20;
  --recess: #0b2025;
  --surface: #1a353a;
  --line: #39595c;
  --ink: #f6eee0;
  --muted: #adc5bb;
  --mint: #88e1c5;
  --gold: #f2c27e;
  --display: ui-monospace, Consolas, "Microsoft YaHei", monospace;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

body {
  background: linear-gradient(#07191b40, #07191b60), url("assets/factory-ui/cabinet.webp") center / cover no-repeat;
  user-select: none;
}

button { font: inherit; }
button:focus-visible { outline: 2px solid var(--mint); outline-offset: 3px; }
[hidden] { display: none !important; }

.factory-app {
  width: 100%;
  height: 100dvh;
  max-width: 1136px;
  margin-inline: auto;
  padding: clamp(10px, 2.3vh, 24px);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(300px, 0.88fr);
  gap: clamp(14px, 2.4vw, 28px);
  align-items: center;
}

.board-column {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  container-type: size;
}

.canvas-wrap {
  position: relative;
  width: min(100%, calc((100dvh - 48px) * 0.75));
  aspect-ratio: 3 / 4;
  overflow: hidden;
  border: 2px solid #a77e4d;
  border-radius: 14px;
  background: #0a2029;
  box-shadow: 0 0 0 4px #102328, 0 0 0 5px #3c5148, 0 20px 50px #010e12a6;
}

#nubby-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.toast-banner {
  position: absolute;
  top: 13.5%;
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: 90%;
  padding: 7px 13px;
  border: 1px solid #659487;
  border-radius: 7px;
  background: #142e33f5;
  color: var(--ink);
  box-shadow: 0 4px 18px #020c10c2;
  font-size: 12px;
  font-weight: 750;
  text-align: center;
  pointer-events: none;
  z-index: 4;
}

.toast-banner[data-tone="good"] { border-color: #63bc9d; color: #c7f7e2; }
.toast-banner[data-tone="warn"] { border-color: #ed947d; color: #ffd3c3; }

.console-column {
  min-width: 0;
  min-height: min(560px, calc(100dvh - 48px));
  max-height: calc(100dvh - 48px);
  padding: clamp(13px, 1.4vw, 19px);
  display: flex;
  flex-direction: column;
  gap: 13px;
  overflow-y: auto;
  border: 1px solid #52766d;
  border-top: 3px solid #b89962;
  border-radius: 15px;
  background: linear-gradient(148deg, #213e42, #10292e 40%, #0e252a);
  box-shadow: inset 0 0 0 3px #142b2e, 0 18px 48px #020d1080;
}

.console-top {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.brand-lockup {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  width: 42px;
  height: 46px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 3px 5px #020b10a6);
}

.brand-lockup h1 {
  margin: 0;
  font-size: clamp(19px, 2vw, 24px);
  line-height: 1.13;
  font-weight: 850;
}

.brand-lockup small {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font: 700 10px/1.3 var(--display);
  letter-spacing: 0.09em;
}

.toolbar-btns {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.tool-btn, .btn-secondary, .btn-shop-buy {
  border: 1px solid #547670;
  color: var(--ink);
  background: linear-gradient(#24464a, #193438);
  box-shadow: inset 0 1px #c9e3cf18, 0 2px #071a1e;
  cursor: pointer;
}

.tool-btn, .btn-launch, .btn-secondary, .btn-shop-buy, .price {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
}

.tool-btn {
  min-height: 30px;
  padding: 4px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.tool-btn:hover, .btn-secondary:hover, .btn-shop-buy:hover:not(:disabled) {
  border-color: var(--mint);
  background: #2c5151;
}

.ui-icon {
  width: 1.1em;
  height: 1.1em;
  display: inline-block;
  flex: none;
  object-fit: contain;
  vertical-align: middle;
  pointer-events: none;
}

.tool-btn .ui-icon { width: 13px; height: 13px; }

.hud-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.hud-cell {
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid #385456;
  border-radius: 7px;
  background: linear-gradient(#0d2328, #102a2d);
  box-shadow: inset 0 2px 5px #020f14a6;
}

.hud-cell > span {
  display: block;
  color: var(--muted);
  font: 700 10px/1.2 var(--display);
  text-transform: uppercase;
}

.hud-cell > b {
  display: flex;
  align-items: center;
  min-height: 1.2em;
  margin-top: 4px;
  font: 800 clamp(14px, 1.8vw, 20px)/1.05 var(--display);
  font-variant-numeric: tabular-nums;
}

.hud-cell .hearts { gap: 2px; }
.hearts .ui-icon { width: min(15%, 15px); height: 15px; }
.hud-wallet { gap: 4px; }
.hud-wallet .ui-icon { width: 0.8em; height: 0.8em; }
.gold { color: var(--gold); }
.cyan { color: var(--mint); }

.status-badges, .perks-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge-pill, .perk-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border: 1px solid #52716b;
  border-radius: 6px;
  color: #d9e9df;
  background: #183637;
  font-size: 11px;
  font-weight: 700;
}

.badge-pill .ui-icon, .perk-chip .ui-icon { width: 16px; height: 16px; }
.boss-pill { border-color: #a86550; color: #ffd2c1; background: #402c2b; }
.perk-chip { border-color: #7c6b87; color: #f1dff1; background: #342b3d; }

.panel-box {
  min-width: 0;
  padding: 9px;
  border: 1px solid #3b5656;
  border-radius: 9px;
  background: var(--recess);
  box-shadow: inset 0 2px 5px #06191f;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
}

.panel-head small { font-family: var(--display); }
.items-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.item-slot {
  position: relative;
  min-height: 59px;
  padding: 6px 4px;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  border: 1px solid #4b6461;
  border-radius: 7px;
  background: radial-gradient(ellipse at 50% 15%, #27484b, #152e33 75%);
  color: var(--ink);
  cursor: pointer;
}

.item-slot.is-empty {
  opacity: 0.68;
  border-color: #3f5551;
  background: #10262b;
  cursor: default;
}

.item-slot.has-item:hover, .item-slot.is-selected {
  background: #2a4c49;
  box-shadow: inset 0 0 0 1px #9dcdb4;
}

.slot-ico {
  width: 27px;
  height: 27px;
  filter: drop-shadow(0 2px 3px #010b0e91);
}

.slot-lbl { font-size: 10px; font-weight: 700; text-align: center; line-height: 1.16; }
.slot-prog {
  position: absolute;
  top: 3px;
  right: 4px;
  color: var(--mint);
  font: 750 9px var(--display);
}

.item-inspector {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding: 8px;
  border: 1px solid #598273;
  border-radius: 7px;
  background: var(--surface);
  font-size: 11px;
  line-height: 1.5;
}

.btn-sell-item {
  flex-shrink: 0;
  padding: 5px 8px;
  border: 1px solid #b27062;
  border-radius: 6px;
  background: #512f2a;
  color: #ffd8ca;
  font-size: 11px;
  font-weight: 750;
  cursor: pointer;
}

.perks-row { min-height: 15px; }
.action-footer { margin-top: auto; padding-top: 4px; }

.btn-launch {
  width: 100%;
  min-height: 47px;
  padding: 9px 16px;
  gap: 8px;
  border: 1px solid #ffba88;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffb486, #ee805e);
  color: #352018;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 1px #ffe1ae, 0 3px #9c4d39, 0 7px 15px #0a1416a6;
}

.btn-launch .ui-icon { width: 20px; height: 20px; }
.btn-launch:hover:not(:disabled) { filter: brightness(1.1); }
.btn-launch:active:not(:disabled) { transform: translateY(2px); }
.btn-launch:disabled { opacity: 0.55; cursor: not-allowed; }

.modal-mask {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  background: #051416b0;
  backdrop-filter: blur(5px);
  z-index: 30;
}

.modal-card {
  width: 100%;
  max-width: 705px;
  max-height: 91dvh;
  overflow-y: auto;
  padding: clamp(15px, 2.8vw, 27px);
  border: 1px solid #759184;
  border-top: 3px solid #c6a777;
  border-radius: 15px;
  background: linear-gradient(154deg, #28464a, #142c31 46%, #11272c);
  box-shadow: inset 0 0 0 4px #1a3437, 0 20px 65px #000d12d9;
}

.supervisor-modal-card {
  background:
    url("assets/factory-ui/nubby.webp") right 25px top 14px / auto 72px no-repeat,
    linear-gradient(154deg, #28464a, #142c31 46%, #11272c);
}

.supervisor-modal-card h2, .supervisor-modal-card .modal-lead { padding-right: 78px; }

.modal-card h2 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: clamp(18px, 3vw, 28px);
  font-weight: 850;
  line-height: 1.22;
}

.modal-lead {
  margin: 0 0 17px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.continue-wrap { margin-bottom: 12px; }
.btn-primary-wide { width: 100%; margin-bottom: 2px; }

.sup-grid, .perk-grid, .shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 178px), 1fr));
  gap: 9px;
}

.sup-card, .perk-card, .shop-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 12px;
  border: 1px solid #58746d;
  border-radius: 9px;
  background: linear-gradient(145deg, #28464a, #173035 80%);
  box-shadow: inset 0 1px #e6d6b81a, 0 2px #0a1d21;
  color: var(--ink);
  text-align: left;
}

.sup-card, .perk-card { cursor: pointer; }
.sup-card:hover, .perk-card:hover { border-color: var(--gold); background: #2b4947; }
.sup-head, .shop-card-top { display: flex; align-items: center; gap: 9px; }

.sup-icon, .shop-icon, .perk-icon {
  width: 49px;
  height: 49px;
  filter: drop-shadow(0 3px 4px #020b11a6);
}

.sup-head strong, .perk-card > strong { font-size: 14px; }
.sup-head small { display: block; margin-top: 3px; color: var(--mint); font-size: 10px; }
.sup-card p, .perk-card p, .shop-desc {
  flex: 1;
  margin: 0;
  color: #d0ded4;
  font-size: 12px;
  line-height: 1.5;
}

.sup-go, .perk-cta {
  padding-top: 7px;
  border-top: 1px solid #547168;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
}

.shop-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.shop-wallet {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  border: 1px solid #aa8958;
  border-radius: 7px;
  background: #3a3325;
  color: var(--gold);
  font: 800 17px var(--display);
  white-space: nowrap;
}

.shop-wallet .ui-icon { width: 20px; height: 20px; }
.shop-section-title {
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.shop-card.is-sold { opacity: 0.62; }
.shop-name { font-size: 13px; font-weight: 800; }
.rarity-pill { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 750; }
.rarity-uncommon { border-color: #69a9a2; }
.rarity-rare { border-color: #a587bc; }
.rarity-legendary { border-color: #c6a06a; }
.rarity-uncommon .rarity-pill { color: var(--mint); }
.rarity-rare .rarity-pill { color: #e4c6fb; }
.rarity-legendary .rarity-pill { color: var(--gold); }

.btn-shop-buy {
  width: 100%;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.price { gap: 3px; white-space: nowrap; color: var(--gold); }
.price .ui-icon { width: 13px; height: 13px; }
.btn-shop-buy:disabled, .btn-secondary:disabled { opacity: 0.5; cursor: not-allowed; }

.shop-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 15px; }

.btn-primary, .btn-primary-wide, .btn-secondary {
  min-height: 35px;
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 800;
}

.btn-primary, .btn-primary-wide {
  border: 1px solid #b4e7c5;
  background: linear-gradient(#a4e9c9, #71c7a8);
  color: #112f2c;
  box-shadow: inset 0 1px #d2f5da, 0 2px #396f60;
  cursor: pointer;
}

.btn-primary:hover, .btn-primary-wide:hover { filter: brightness(1.1); }
.end-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.end-stats div { padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--recess); }
.end-stats span { display: block; color: var(--muted); font-size: 11px; }
.end-stats b { color: var(--gold); font: 800 16px var(--display); }
.help-body p { margin: 0 0 9px; color: #e0eadd; font-size: 13px; line-height: 1.6; }

@media (max-width: 859px) {
  .factory-app {
    padding: 7px max(7px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(7px, env(safe-area-inset-left));
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, calc((100vw - 14px) * 4 / 3));
    align-content: center;
    gap: 10px;
  }

  .console-column {
    order: -1;
    min-height: 0;
    max-height: none;
    padding: 6px 7px;
    gap: 6px;
    overflow: visible;
    border-radius: 9px;
    border-top-width: 2px;
  }

  .console-top { justify-content: space-between; align-items: center; gap: 4px; padding: 0; border: 0; }
  .brand-lockup { width: auto; gap: 5px; }
  .brand-mark { width: 25px; height: 29px; }
  .brand-lockup h1 { font-size: 14px; }
  .brand-lockup small { display: none; }
  .tool-btn { min-height: 25px; padding: 3px 5px; font-size: 10px; gap: 3px; }
  .tool-btn .ui-icon { width: 11px; height: 11px; }
  .hud-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 3px; }
  .hud-cell { padding: 3px 2px; text-align: center; }
  .hud-cell > span { font-size: 8px; }
  .hud-cell > b { justify-content: center; margin-top: 2px; font-size: clamp(9px, 2.7vw, 13px); }
  .hud-cell .hearts { gap: 1px; }
  .hearts .ui-icon { width: min(16%, 10px); height: 10px; }
  .hud-wallet { gap: 2px; }
  .status-badges, .perks-panel, .panel-head, .slot-lbl, .action-footer { display: none; }
  .items-panel { padding: 3px; }
  .items-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .item-slot { min-height: 32px; padding: 2px; }
  .slot-ico { width: 21px; height: 21px; }
  .slot-prog { top: 1px; right: 2px; font-size: 8px; }
  .canvas-wrap { border-radius: 9px; border-width: 1px; box-shadow: 0 0 0 2px #183539, 0 10px 30px #0111149c; }
}

@media (max-width: 480px) {
  .sup-grid, .perk-grid, .shop-grid { grid-template-columns: 1fr; }
  .supervisor-modal-card { background-size: auto 51px, auto; background-position: right 16px top 19px, center; }
  .supervisor-modal-card h2, .supervisor-modal-card .modal-lead { padding-right: 48px; }
  .sup-icon, .shop-icon, .perk-icon { width: 41px; height: 41px; }
}

@supports (width: 100cqh) {
  .canvas-wrap { width: min(100cqw, calc(100cqh * 0.75)); }
}
