:root {
  color-scheme: dark;
  --bg: #101316;
  --ink: #f5f7fb;
  --muted: #a7b0bd;
  --line: rgba(255,255,255,.12);
  --panel: rgba(22,28,34,.88);
  --panel-2: rgba(27,34,42,.94);
  --mint: #35d0a7;
  --amber: #f4b24b;
  --blue: #7b8cff;
  --pink: #ff6f91;
  --danger: #ff5959;
  --shadow: 0 18px 54px rgba(0,0,0,.34);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(130deg, rgba(53,208,167,.08), transparent 34%),
    linear-gradient(230deg, rgba(244,178,75,.08), transparent 38%),
    #101316;
  display: flex;
  justify-content: center;
}

button {
  color: inherit;
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.factory-shell {
  position: relative;
  width: min(430px, 100%);
  height: 100dvh;
  margin: 0 auto;
  overflow-x: hidden;
  overflow-y: auto;
  padding: max(12px, env(safe-area-inset-top)) 10px calc(92px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 8% 0%, rgba(53,208,167,.16), transparent 30%),
    radial-gradient(circle at 100% 8%, rgba(244,178,75,.12), transparent 30%),
    #0b1115;
  box-shadow: 0 0 60px rgba(0,0,0,.76);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 1 1 auto;
  min-width: 0;
}

.brand-lockup > div {
  min-width: 0;
}

.brand-lockup > img {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  object-fit: cover;
  box-shadow: 0 10px 28px rgba(0,0,0,.34);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--mint);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }

h1 {
  max-width: 158px;
  overflow: hidden;
  font-size: 17px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

h2 {
  font-size: 15px;
  line-height: 1.1;
}

.wallet {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 5px;
  max-width: none;
  flex: 0 1 auto;
  min-width: 0;
}

.wallet span,
.status-strip > div {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 58px;
  min-height: 32px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.07);
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.wallet img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.energy-mark {
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 0 7px rgba(244,178,75,.45));
}

.energy { color: var(--amber); }

.energy small {
  color: rgba(255,255,255,.62);
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
}

.energy-icon,
.energy-shop-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(255,230,142,.78);
  border-radius: 7px;
  color: #fff4bb;
  background:
    radial-gradient(circle at 35% 22%, rgba(255,255,255,.42), transparent 27%),
    linear-gradient(145deg, #5b4214, #f0ad38 44%, #6b4515);
  clip-path: polygon(50% 0, 92% 23%, 92% 76%, 50% 100%, 8% 76%, 8% 23%);
  box-shadow:
    inset 0 1px 2px rgba(255,255,255,.35),
    inset 0 -2px 5px rgba(61,32,0,.55),
    0 0 12px rgba(244,178,75,.38);
  font-size: 14px;
  font-weight: 1000;
  text-shadow: 0 1px 3px rgba(0,0,0,.72);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 8px;
  margin-bottom: 12px;
}

.status-strip > div {
  justify-content: space-between;
  min-width: 0;
}

.label {
  color: var(--muted);
  font-size: 12px;
}

.screen {
  display: grid;
  gap: 10px;
  animation: slideIn .12s ease;
}

.screen[hidden] {
  display: none !important;
}

.screen-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px 10px;
}

.screen-heading span {
  color: var(--muted);
  font-size: 12px;
}

@keyframes slideIn {
  from { opacity: 1; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr);
  gap: 12px;
  align-items: start;
}

.workbench,
.orders-panel,
.insight-panel,
.event-panel,
.shop-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.workbench {
  padding: 10px;
}

.workshop-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.board {
  display: grid;
  grid-column: 1;
  justify-self: center;
  width: min(100%, 306px);
  grid-template-columns: repeat(5, minmax(0, 1fr));
  grid-template-rows: repeat(5, minmax(0, 1fr));
  gap: 6px;
  aspect-ratio: 1;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255,255,255,.055);
  cursor: pointer;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}

.cell:focus-visible,
button:focus-visible {
  outline: 2px solid var(--mint);
  outline-offset: 2px;
}

.cell:not(.locked):hover {
  transform: translateY(-1px);
  border-color: rgba(255,255,255,.28);
}

.cell.selected {
  border-color: var(--amber);
  background: rgba(244,178,75,.13);
}

.cell.locked {
  cursor: pointer;
  color: rgba(255,255,255,.35);
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.04) 0 8px, transparent 8px 16px),
    rgba(0,0,0,.18);
}

.cell.locked:not(.unlockable),
.dice-slot.locked:not(.unlockable) {
  cursor: default;
}

.cell.unlockable,
.dice-slot.unlockable {
  color: var(--ink);
  border-color: rgba(244,178,75,.42);
  background:
    linear-gradient(145deg, rgba(244,178,75,.14), transparent),
    rgba(255,255,255,.055);
}

.slot-price {
  display: grid;
  place-items: center;
  gap: 2px;
  max-width: 100%;
  padding: 3px;
  text-align: center;
  line-height: 1;
}

.slot-price b {
  color: var(--amber);
  font-size: 20px;
}

.slot-price small {
  max-width: 100%;
  overflow-wrap: normal;
  white-space: nowrap;
  color: var(--ink);
  font-size: 10px;
  font-weight: 900;
}

.cell.order-ready {
  border-color: rgba(53,208,167,.86);
  background:
    radial-gradient(circle at 50% 50%, rgba(53,208,167,.22), transparent 64%),
    rgba(53,208,167,.10);
  box-shadow: inset 0 0 0 1px rgba(53,208,167,.42), 0 0 18px rgba(53,208,167,.18);
}

.item {
  position: relative;
  width: 108%;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: visible;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.item img {
  width: 118%;
  height: 118%;
  object-fit: contain;
  filter: drop-shadow(0 10px 12px rgba(0,0,0,.5));
}

.item-level,
.rarity-badge {
  position: absolute;
  right: 0;
  top: 0;
  display: grid;
  place-items: center;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border: 1px solid rgba(255,255,255,.34);
  border-radius: 999px;
  color: #08100d;
  background: var(--item-color);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 6px rgba(0,0,0,.35);
}

.rarity-badge {
  background: var(--rarity-color);
}

.item small,
.die-token small {
  position: absolute;
  left: 50%;
  bottom: -13px;
  transform: translateX(-50%);
  color: var(--muted);
  font-size: 9px;
  text-align: center;
}

.stash-panel {
  grid-column: 1;
  display: grid;
  gap: 6px;
  margin-top: 9px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 8px;
  background: rgba(0,0,0,.14);
}

.stash-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stash-head strong {
  color: var(--mint);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.stash-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.stash-slots {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.stash-slot {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 58px;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% 40%, rgba(255,255,255,.06), transparent 62%),
    rgba(255,255,255,.045);
  cursor: pointer;
}

.stash-slot .item {
  width: 96%;
}

.stash-slot .item img {
  width: 108%;
  height: 108%;
}

.stash-empty {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px dashed rgba(255,255,255,.18);
  border-radius: 999px;
  color: rgba(255,255,255,.42);
  font-size: 18px;
  font-weight: 950;
}

.stash-slot.locked {
  color: rgba(255,255,255,.35);
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.035) 0 8px, transparent 8px 16px),
    rgba(0,0,0,.16);
}

.stash-slot.unlockable {
  border-color: rgba(244,178,75,.42);
  background:
    linear-gradient(145deg, rgba(244,178,75,.13), transparent),
    rgba(255,255,255,.052);
}

.action-row {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.workshop-actions {
  grid-column: 1;
  grid-template-columns: 1fr;
  margin-top: 0;
}

.create-button {
  width: 100%;
  grid-column: 1 / -1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.energy-cost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px 2px 3px;
  border-radius: 999px;
  color: #08100d;
  background: rgba(8,16,13,.13);
  font-size: 13px;
}

.energy-cost .energy-icon,
.energy-cost .energy-mark {
  width: 20px;
  height: 20px;
}

.primary-button,
.soft-button,
.ghost-button,
.order button,
.chest-button,
.shard-row button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  color: #08100d;
  border-color: transparent;
  background: var(--mint);
  font-weight: 900;
}

.soft-button,
.order button,
.shard-row button {
  background: rgba(255,255,255,.08);
}

.soft-button:disabled,
.order button:disabled,
.shard-row button:disabled {
  cursor: default;
  color: rgba(255,255,255,.36);
  background: rgba(255,255,255,.045);
}

.ghost-button {
  background: transparent;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-heading span {
  color: var(--muted);
  font-size: 12px;
}

.panel-heading h2,
.chest-button strong,
.shop-offer strong {
  color: var(--ink);
}

.orders {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.compact-orders {
  grid-column: 1;
  grid-row: auto;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.035);
}

.compact-orders-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 38px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.compact-orders-head strong {
  color: var(--mint);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.order-refresh-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 54px;
  min-height: 44px;
  padding: 0 8px;
  border: 1px dashed rgba(244,178,75,.46);
  border-radius: 8px;
  color: var(--amber);
  background: rgba(244,178,75,.08);
  font-size: 12px;
  font-weight: 950;
}

.order-refresh-mini:disabled {
  opacity: .46;
}

.economy-loop {
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr);
  gap: 12px;
  margin-top: 12px;
}

.order {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  min-height: 58px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.order.ready {
  border-color: rgba(53,208,167,.78);
  background:
    linear-gradient(145deg, rgba(53,208,167,.14), transparent),
    var(--panel-2);
  box-shadow: inset 0 0 0 1px rgba(53,208,167,.22);
}

.order-target {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.order-need {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.order-need img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 5px 7px rgba(0,0,0,.45));
}

.order-target b {
  color: var(--item-color);
}

.order-reward {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.order-actions {
  display: grid;
  grid-template-columns: 58px;
  gap: 5px;
}

.order-actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 36px;
  padding: 0 4px;
  font-size: 11px;
  font-weight: 900;
}

.order-soft-icon {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  object-fit: contain;
}

.order-refresh {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 7px 10px;
  border: 1px dashed rgba(244,178,75,.46);
  border-radius: 8px;
  color: var(--amber);
  background: rgba(244,178,75,.08);
  font-size: 12px;
  font-weight: 900;
}

.order-refresh:disabled {
  cursor: default;
  opacity: .48;
}

.order-refresh small {
  color: var(--muted);
}

.chest-panel,
.vault-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.chest-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 10px;
}

.chest-button {
  display: grid;
  grid-template-columns: 86px 1fr;
  align-items: center;
  gap: 12px;
  min-height: 86px;
  padding: 10px 12px;
  color: var(--ink);
  text-align: left;
  background:
    linear-gradient(145deg, rgba(53,208,167,.14), transparent),
    rgba(255,255,255,.08);
}

.chest-button img {
  width: 78px;
  height: 78px;
  object-fit: contain;
}

.grimoire-button {
  grid-template-columns: 88px 1fr;
}

.grimoire-button img {
  width: 84px;
  height: 84px;
  filter:
    drop-shadow(0 0 8px rgba(53,208,167,.65))
    drop-shadow(0 0 18px rgba(244,178,75,.22));
}

.chest-button strong,
.chest-button small {
  display: block;
}

.chest-button.premium {
  background:
    linear-gradient(145deg, rgba(244,178,75,.18), transparent),
    rgba(255,255,255,.08);
}

.chest-button small {
  color: var(--muted);
  font-size: 12px;
}

.chest-result {
  display: grid;
  gap: 8px;
  margin: 0 10px 10px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
}

.chest-math,
.drop-rates {
  display: grid;
  gap: 7px;
  margin: 0 10px 10px;
}

.chest-math {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.chest-math > div,
.drop-rates span {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
}

.chest-math span {
  display: block;
  color: var(--muted);
  font-size: 10px;
}

.chest-math strong {
  display: block;
  margin-top: 3px;
  overflow-wrap: anywhere;
  color: var(--amber);
  font-size: 12px;
  line-height: 1.05;
}

.drop-rates {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.drop-rates span {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.drop-rates b {
  color: var(--ink);
}

.chest-result[hidden] {
  display: none;
}

.chest-result strong {
  color: var(--amber);
  font-size: 12px;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.drop-strip {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.drop-chip {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 5px;
  min-height: 42px;
  padding: 5px 8px 5px 5px;
  border: 1px solid color-mix(in srgb, var(--rarity-color) 58%, transparent);
  border-radius: 8px;
  color: var(--ink);
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--rarity-color) 16%, transparent), transparent),
    rgba(255,255,255,.06);
  font-size: 13px;
  font-weight: 900;
}

.drop-chip img {
  width: 31px;
  height: 31px;
  object-fit: contain;
}

.shards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  padding: 0 10px 10px;
}

.shard-row {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) 88px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--rarity-color) 14%, transparent), transparent),
    var(--panel-2);
}

.shard-icon {
  width: 70px;
  height: 70px;
  border-radius: 7px;
  object-fit: cover;
}

.shard-icon.mage-icon {
  border: 1px solid color-mix(in srgb, var(--rarity-color) 60%, rgba(255,255,255,.18));
}

.shard-name {
  color: color-mix(in srgb, var(--rarity-color) 68%, #f5f7fb);
  font-weight: 800;
  line-height: 1.12;
  overflow-wrap: anywhere;
}

.shard-progress {
  overflow: hidden;
  height: 7px;
  margin-top: 5px;
  border-radius: 999px;
  background: rgba(255,255,255,.10);
}

.shard-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--rarity-color);
}

.shard-count {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.dice-vault {
  display: grid;
  grid-template-columns: repeat(var(--vault-cols, 3), minmax(0, 1fr));
  gap: 7px;
  padding: 10px;
}

.dice-slot {
  display: grid;
  place-items: center;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: rgba(255,255,255,.36);
  background: rgba(255,255,255,.045);
}

.dice-slot.locked {
  cursor: pointer;
  background:
    repeating-linear-gradient(135deg, rgba(255,255,255,.035) 0 8px, transparent 8px 16px),
    rgba(255,255,255,.035);
}

.dice-slot:not(.locked) {
  cursor: pointer;
}

.dice-slot.selected {
  border-color: var(--amber);
  background: rgba(244,178,75,.13);
}

.die-token {
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  width: calc(100% - 6px);
  height: calc(100% - 6px);
  border: 2px solid var(--rarity-color);
  border-radius: 8px;
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--rarity-color) 24%, transparent), transparent),
    #11171d;
  color: var(--ink);
  box-shadow: 0 8px 22px color-mix(in srgb, var(--rarity-color) 20%, transparent);
}

.die-token img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.die-token::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 48%, rgba(0,0,0,.62));
  pointer-events: none;
}

.mage-merge-strip {
  display: flex;
  align-items: center;
  gap: 7px;
  overflow-x: auto;
  padding: 9px 10px 0;
  color: var(--muted);
  font-size: 12px;
}

.mage-merge-strip span {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: color-mix(in srgb, var(--ink) 86%, var(--muted));
  background: rgba(255,255,255,.055);
}

.mage-merge-strip b {
  color: var(--amber);
}

.vault-actions {
  display: grid;
  grid-template-columns: 1.15fr .85fr;
  gap: 8px;
  padding: 0 10px 10px;
}

.vault-actions button {
  min-height: 44px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 950;
}

.vault-market-button {
  border: 1px solid rgba(244,178,75,.46);
  color: #110e05;
  background: linear-gradient(180deg, #ffd979, #c48b29);
}

.vault-market-button:disabled {
  color: rgba(255,255,255,.42);
  background: rgba(255,255,255,.08);
}

.vault-clear-button {
  border: 1px solid var(--line);
  color: var(--ink);
  background: rgba(255,255,255,.055);
}

.vault-clear-button:disabled {
  color: rgba(255,255,255,.34);
  background: rgba(255,255,255,.035);
}

.shop-grid {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.shop-sections {
  display: grid;
  gap: 12px;
  padding: 10px;
}

.shop-placement-section {
  display: grid;
  gap: 9px;
}

.shop-placement-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
  padding: 0 2px;
}

.shop-placement-head strong {
  color: var(--shop-accent, var(--ink));
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 2.4px;
}

.shop-placement-head span {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

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

.currency-shop {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.market-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 128px;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border-bottom: 1px solid var(--line);
}

.market-summary > div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.market-summary small,
.market-card span,
.empty-market span {
  color: var(--muted);
  font-size: 12px;
}

.market-summary strong {
  font-size: 20px;
  line-height: 1;
}

.market-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.market-closed {
  grid-template-columns: minmax(0, 1fr);
}

.market-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.market-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) 82px;
  gap: 9px;
  align-items: center;
  min-height: 76px;
  padding: 8px;
  border: 1px solid color-mix(in srgb, var(--rarity-color) 44%, var(--line));
  border-radius: 8px;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--rarity-color) 13%, transparent), transparent),
    rgba(255,255,255,.055);
}

.market-card img {
  width: 58px;
  height: 58px;
  border: 1px solid color-mix(in srgb, var(--rarity-color) 62%, rgba(255,255,255,.18));
  border-radius: 8px;
  object-fit: cover;
}

.market-card strong,
.market-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.market-card button {
  min-height: 44px;
  border: 1px solid color-mix(in srgb, var(--rarity-color) 52%, rgba(255,255,255,.18));
  border-radius: 8px;
  color: var(--ink);
  background: color-mix(in srgb, var(--rarity-color) 15%, rgba(255,255,255,.06));
  font-size: 12px;
  font-weight: 900;
}

.empty-market {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255,255,255,.045);
}

.shop-offer {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 66px;
  padding: 0;
  border: 1.5px solid color-mix(in srgb, var(--shop-accent) 42%, transparent);
  border-radius: 9px;
  color: var(--ink);
  text-align: left;
  background: var(--shop-bg);
  box-shadow: 0 0 10px color-mix(in srgb, var(--shop-accent) 10%, transparent);
  overflow: hidden;
}

.placement-offer {
  min-height: 148px;
  text-align: center;
}

.placement-offer > b {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  margin-top: auto;
  padding: 7px 4px;
  border-radius: 0;
  color: var(--shop-button-text);
  background: var(--shop-button);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: .2px;
}

.placement-offer:disabled > b {
  color: rgba(255,255,255,.42);
  background: rgba(255,255,255,.08);
}

.placement-offer em {
  max-width: 44px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 4px;
  border-radius: 4px;
  color: #fff;
  background: #ff2d78;
  font-size: 8px;
  font-style: normal;
  font-weight: 950;
  letter-spacing: .2px;
}

.placement-offer strong,
.placement-offer small {
  max-width: 100%;
  overflow-wrap: anywhere;
  line-height: 1.08;
}

.placement-offer strong {
  font-size: 10px;
  font-weight: 950;
  color: rgba(255,255,255,.88);
}

.shop-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  min-height: 24px;
  padding: 4px 5px 1px;
}

.shop-amount {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  min-width: 0;
  color: var(--shop-accent);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .2px;
  text-shadow: 0 0 10px color-mix(in srgb, var(--shop-accent) 55%, transparent);
}

.shop-amount img {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  object-fit: contain;
}

.shop-card-bonus {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 12px;
  padding: 0 5px;
  color: #50dc82;
  font-size: 8px;
  font-weight: 850;
}

.shop-card-art {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  padding: 0 2px;
}

.shop-card-name {
  display: grid;
  gap: 2px;
  min-height: 38px;
  padding: 1px 5px 6px;
  text-align: center;
}

.ad-icon {
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 1px solid rgba(53,208,167,.46);
  border-radius: 8px;
  color: var(--mint);
  background: rgba(53,208,167,.12);
  font-size: 16px;
  font-weight: 950;
}

.currency-shop .shop-offer {
  grid-template-columns: 1fr;
  justify-items: center;
  min-height: 110px;
  text-align: center;
}

.shop-offer img {
  width: 54px;
  height: 54px;
  object-fit: contain;
  filter: drop-shadow(0 0 9px color-mix(in srgb, var(--shop-accent) 45%, transparent));
}

.shop-offer .shop-amount img {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 0 5px color-mix(in srgb, var(--shop-accent) 35%, transparent));
}

.energy-shop-icon {
  width: 64px;
  height: 64px;
  font-size: 24px;
}

.shop-offer strong,
.shop-offer small {
  display: block;
}

.shop-offer small {
  color: var(--muted);
  font-size: 9px;
}

.placement-offer[data-offer-kind="ad"] .shop-card-art img {
  width: 62px;
  height: 62px;
  filter:
    drop-shadow(0 0 9px color-mix(in srgb, var(--shop-accent) 55%, transparent))
    drop-shadow(0 0 18px rgba(255,255,255,.12));
}

.placement-offer[data-offer-id="ad_grimoire"] .shop-card-art img {
  width: 68px;
  height: 68px;
}

.placement-offer[data-offer-kind="hard"] .shop-card-art img,
.placement-offer[data-offer-kind="soft"] .shop-card-art img,
.placement-offer[data-offer-kind="energy"] .shop-card-art img {
  width: 56px;
  height: 56px;
}

.info-grid {
  display: grid;
  grid-template-columns: .8fr 1.2fr;
  gap: 12px;
  margin-top: 12px;
}

.insight-panel {
  padding: 12px;
}

.insight-panel ul {
  margin: 9px 0 0;
  padding-left: 18px;
  color: var(--muted);
  line-height: 1.45;
}

.event-panel {
  overflow: hidden;
}

.events {
  display: grid;
  gap: 1px;
  max-height: 186px;
  overflow: auto;
  padding: 0 10px 10px;
}

.event-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
  color: var(--muted);
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(16px);
  width: min(460px, calc(100% - 28px));
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(18,24,30,.96);
  opacity: 0;
  pointer-events: none;
  transition: opacity .16s ease, transform .16s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 3px;
  width: min(420px, calc(100% - 10px));
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13,18,23,.96);
  box-shadow: 0 16px 44px rgba(0,0,0,.42);
  transform: translateX(-50%);
}

.bottom-nav button {
  padding: 2px;
  display: grid;
  place-items: center;
  gap: 1px;
  min-width: 0;
  min-height: 76px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
}

.bottom-nav button.active {
  color: var(--ink);
  border-color: rgba(53,208,167,.28);
  background: rgba(53,208,167,.12);
}

.bottom-nav img {
  max-width: 100%;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: contain;
}

.bottom-nav button.active img {
  width: 56px;
  height: 56px;
}

.bottom-nav span {
  max-width: 100%;
  overflow: visible;
  font-size: 9px;
  font-weight: 800;
  line-height: 1;
  text-align: center;
  white-space: normal;
}

@media (max-width: 820px) {
  .factory-shell {
    width: min(430px, 100%);
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .wallet {
    display: flex;
    width: auto;
    max-width: none;
    justify-content: flex-end;
  }

  .wallet span {
    justify-content: center;
    min-width: 0;
  }

  .status-strip,
  .main-grid,
  .economy-loop,
  .info-grid,
  .action-row,
  .workshop-layout {
    grid-template-columns: 1fr;
  }

  .board,
  .stash-panel,
  .compact-orders {
    grid-column: 1;
    grid-row: auto;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ghost-button {
    grid-column: span 2;
  }

  .workbench {
    padding: 10px;
  }

  .orders-panel {
    scroll-margin-top: 12px;
  }
}

@media (max-width: 440px) {
  .factory-shell {
    padding: max(10px, env(safe-area-inset-top)) 10px calc(112px + env(safe-area-inset-bottom));
  }

  h1 {
    max-width: 108px;
    overflow: hidden;
    font-size: 15px;
    line-height: 1.05;
    text-overflow: clip;
    white-space: normal;
  }

  .eyebrow {
    font-size: 11px;
  }

  .wallet {
    gap: 5px;
  }

  .wallet span {
    min-width: 48px;
    min-height: 30px;
    padding: 4px 5px;
    font-size: 11px;
  }

  .wallet img {
    width: 18px;
    height: 18px;
  }

  .energy {
    min-width: 58px;
  }

  .screen-heading {
    padding-bottom: 6px;
  }

  .status-strip {
    gap: 7px;
  }

  .status-strip > div {
    min-height: 38px;
    padding: 7px;
  }

  .board {
    gap: 5px;
  }

  .cell {
    min-height: 0;
  }

  .workbench {
    padding: 9px;
  }

  .workshop-layout {
    gap: 7px;
  }

  .compact-orders .orders {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 5px;
    padding: 6px 0 0;
  }

  .compact-orders-head {
    min-height: 30px;
    padding: 2px 0 5px;
  }

  .compact-orders-head strong {
    font-size: 11px;
  }

  .order-refresh-mini {
    min-width: 50px;
    min-height: 44px;
    padding: 0 7px;
    font-size: 11px;
  }

  .order {
    grid-template-columns: 1fr;
    min-height: 68px;
    gap: 4px;
    padding: 5px;
  }

  .order-target {
    gap: 2px;
  }

  .order-target > span:last-child {
    display: none;
  }

  .order-need {
    gap: 4px;
  }

  .order-need img {
    width: 22px;
    height: 22px;
  }

  .order-need span {
    font-size: 10px;
    line-height: 1.05;
  }

  .order-actions {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .order-actions button {
    min-height: 32px;
    border-color: rgba(53,208,167,.35);
    border-radius: 999px;
    background: rgba(53,208,167,.12);
    font-size: 10px;
  }

  .item { width: 98%; }

  .item small {
    display: none;
  }

  .die-token small {
    display: none;
  }

  .action-row {
    position: sticky;
    bottom: calc(108px + env(safe-area-inset-bottom));
    z-index: 10;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 8px 0 0;
    background: linear-gradient(180deg, transparent, rgba(16,19,22,.94) 22%);
  }

  .workshop-actions {
    grid-template-columns: 1fr;
    position: static;
    padding: 0;
    background: none;
  }

  .action-row button {
    padding-left: 5px;
    padding-right: 5px;
    font-size: 12px;
    line-height: 1.05;
  }

  .primary-button,
  .soft-button,
  .ghost-button,
  .order button,
  .chest-button,
  .shard-row button {
    min-height: 46px;
  }

  .order {
    padding: 5px;
  }

  .order-actions {
    gap: 4px;
  }

  .toast {
    bottom: calc(176px + env(safe-area-inset-bottom));
  }

  .chest-actions {
    grid-template-columns: 1fr;
  }

  .shards {
    grid-template-columns: 1fr;
  }

  .shard-row {
    grid-template-columns: 64px minmax(0, 1fr) 82px;
    gap: 8px;
    padding: 8px;
  }

  .shard-icon {
    width: 64px;
    height: 64px;
  }

  .shard-row button {
    width: 100%;
    min-height: 46px;
  }

  .dice-vault {
    gap: 6px;
  }

  .dice-slot {
    min-height: 94px;
  }

  .shop-placement-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .placement-offer {
    min-height: 148px;
  }

  .placement-offer strong {
    font-size: 11px;
  }

  .placement-offer > b {
    padding-left: 6px;
    padding-right: 6px;
    font-size: 10px;
  }

  .shop-offer img,
  .energy-shop-icon {
    width: 52px;
    height: 52px;
  }

  .placement-offer[data-offer-kind="ad"] .shop-card-art img {
    width: 60px;
    height: 60px;
  }

  .placement-offer[data-offer-id="ad_grimoire"] .shop-card-art img {
    width: 68px;
    height: 68px;
  }

  .shop-offer .shop-amount img {
    width: 18px;
    height: 18px;
  }

  .vault-actions {
    position: static;
    grid-template-columns: 1fr 1fr;
    padding: 0 10px 10px;
    background: transparent;
  }
}

.calendar-entry { width:44px; height:44px; padding:0; flex-shrink:0; background:transparent; border:0; border-radius:6px; cursor:pointer; }
.calendar-entry img { width:100%; height:100%; object-fit:contain; }
.calendar-days { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; padding:12px; }
.calendar-day { display:flex; flex-direction:column; align-items:center; gap:5px; padding:10px 4px; border:1px solid #45565a; border-radius:6px; background:#1e292b; min-width:0; }
.calendar-day img { width:72px; height:72px; object-fit:contain; }
.calendar-day span,.calendar-day strong,.calendar-day small { font-size:12px; text-align:center; overflow-wrap:anywhere; }
.calendar-day small { min-height:16px; color:#9bb5b7; }
.calendar-day:last-child { grid-column:1 / -1; }
.calendar-day.current { border-color:#35d0a7; background:#163c33; }
.calendar-day.claimed { opacity:.6; }
.calendar-claim { display:block; width:calc(100% - 24px); margin:0 12px; min-height:44px; }
.calendar-status { margin:12px; font-size:12px; text-align:center; }
.chest-actions { position:relative; }
.chest-actions .grimoire-button { padding-right:54px; }
.chest-preview-button { position:absolute; right:16px; top:16px; z-index:1; width:44px; height:44px; min-height:44px; padding:0; border-radius:50%; font-size:20px; }
.shard-row button.claim-ready { border-color:#e7c76c; color:#fff1b8; box-shadow:0 0 8px #e7c76c55; }
.reward-preview { width:min(430px,calc(100% - 24px)); max-height:85dvh; box-sizing:border-box; padding:12px; border:1px solid #526867; border-radius:8px; color:#edf5f3; background:#142123; overflow:auto; }
.reward-preview::backdrop { background:rgba(0,0,0,.75); }
.reward-preview h2 { font-size:18px; }
.reward-preview p { font-size:13px; }
.reward-preview .panel-heading { padding:0 0 12px; gap:8px; }
.reward-preview button { min-width:44px; min-height:44px; }
.preview-amounts { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:8px; padding:8px 0 16px; }
.preview-amounts span { display:flex; flex-direction:column; gap:6px; text-align:center; font-size:12px; }
.preview-mages { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.preview-mages div { display:flex; flex-direction:column; gap:5px; align-items:center; text-align:center; min-width:0; font-size:12px; }
.preview-mages img { width:76px; height:76px; object-fit:contain; }
.preview-mages small { color:#a9b8b7; }

@media (max-width: 360px) {
  .factory-shell {
    padding-left: 8px;
    padding-right: 8px;
  }

  h1 {
    max-width: 100px;
    font-size: 14px;
  }

  .wallet span {
    gap: 4px;
    padding-left: 5px;
    padding-right: 5px;
  }

  .wallet img {
    width: 18px;
    height: 18px;
  }

  .cell {
    min-height: 0;
  }

  .order-target,
  .order-actions {
    grid-template-columns: 1fr;
  }
}
.onboarding-chest { display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 44px; max-width: 160px; font-size: 12px; border: 1px solid #a78951; border-radius: 8px; color: var(--ink); background: #29332e; }
.onboarding-chest img { width: 48px; height: 48px; object-fit: contain; }
.bottom-nav [data-nav="vault"] { position: relative; }
.onboarding-badge { position: absolute; top: 3px; right: 4px; min-width: 20px; height: 20px; border-radius: 50%; background: #f4b24b; color: #161e21; font-size: 12px; line-height: 20px; text-align: center; }
.onboarding-badge[hidden] { display: none; }
.vault-actions [hidden] { display: none !important; }
.workshop-actions [hidden], .onboarding-chest[hidden], .vault-actions[hidden] { display: none !important; }
.slot-price { width: 100%; min-width: 0; padding: 2px; box-sizing: border-box; gap: 1px; }
.slot-price b { display: block; width: 20px; height: 20px; line-height: 20px; font-family: Arial, sans-serif; font-weight: 400; }
.slot-price small { font-size: 11px; line-height: 13px; }
.slot-price > span { font-size: 9px; line-height: 11px; color: var(--muted); }
.calendar-shop-entry { display: flex; align-items: center; gap: 7px; }
.reward-dot { display: block; width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #f4b24b; }
.reward-dot[hidden] { display: none; }
.shop-offer > b small { display:block; margin-top:2px; font-size:10px; font-weight:400; }
.shop-offer[data-offer-kind="hard"] > b { flex-direction:column; gap:2px; line-height:1.1; min-height:44px; }
/* Reward animation never performs settlement. */
.sale-currency-icon { width: 24px; height: 24px; object-fit: contain; flex: 0 0 24px; }
[data-sell-item] { display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
[data-sell-item][hidden] { display: none; }
.chest-opening { width: min(420px, calc(100vw - 32px)); box-sizing: border-box; padding: 20px 12px; border: 1px solid #b79650; border-radius: 8px; background: #152124; color: #fff; text-align: center; overflow: hidden; }
.chest-opening::backdrop { background: #000b; }
.chest-opening h2 { font-size: 20px; margin: 0 0 16px; }
.roulette-window { position: relative; overflow: hidden; height: 120px; }
.roulette-window::after { content: ''; position: absolute; left: calc(50% - 1px); top: 0; height: 100%; width: 2px; background: #ffd179; pointer-events: none; }
.roulette-track { display: flex; gap: 8px; width: max-content; }
.roulette-prize { flex: 0 0 80px; width: 80px; height: 112px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #223236; border-radius: 6px; }
.roulette-prize img { width: 72px; height: 80px; object-fit: contain; }
.roulette-result { min-height: 42px; margin: 16px 0; overflow-wrap: anywhere; }
.chest-opening button { min-height: 44px; min-width: 140px; }

@media (max-width: 350px) {
  .topbar, .brand-lockup { gap: 4px; }
  .brand-lockup { min-width: 98px; }
  .wallet { gap: 3px; }
  .wallet span { min-width: 0; padding: 4px 3px; gap: 3px; font-size: 10px; }
  .wallet img { width: 14px; height: 14px; }
}

@media (max-width: 440px) and (max-height: 700px) and (orientation: portrait) {
  .workshop-screen .board {
    width: min(100%, calc(100svh - 330px));
    justify-self: center;
    gap: 4px;
  }
  .workshop-screen .screen-heading .eyebrow { display: none; }
  .workshop-screen .stash-panel { padding: 5px; margin-top: 0; gap: 4px; }
  .workshop-screen .stash-slot { height: 44px; min-height: 44px; aspect-ratio: auto; }
  .workshop-screen .stash-slot .item img { max-height: 40px; }
  .workshop-screen .stash-head { margin-bottom: 3px; }
  .workshop-screen .workshop-layout { gap: 5px; }
  .workshop-screen .workshop-actions button { min-height: 44px; }
  .workshop-screen .slot-price { padding: 1px; }
  .workshop-screen .slot-price b { height: 12px; line-height: 12px; font-size: 16px; }
  .workshop-screen .slot-price small { line-height: 11px; }
  .workshop-screen .slot-price > span { line-height: 10px; }
}
