/* UI-03 r06. The three tabs share this frame, palette and control set. */
#gift-workshop[hidden] { display: none !important; }

#gift-workshop:where(:not([data-screen="RUNE"])) {
  --gw-ink: #542c19;
  --gw-gold: #bd843c;
  --gw-edge: #d1a163;
  --gw-paper: linear-gradient(#fff5dd, #f1d5a7);
  --gw-button: linear-gradient(#fff6de, #eac183);
  --gw-green: linear-gradient(#54863c, #185329 52%, #124422);
  --gw-wood:
    repeating-linear-gradient(178deg, #ffc17016 0 1px, transparent 2px 6px, #28100926 7px 9px),
    linear-gradient(#8c4826, #613016 56%, #422012);
  --gw-gap: 8px;
  --gw-radius: 12px;
  --gw-shadow: inset 0 1px #fff7df, 0 1px 2px #55270b46;
  --gw-heading: clamp(16px, 2vw, 22px);
  position: fixed;
  inset: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right))
    max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
  margin: auto;
  max-width: 1180px;
  max-height: 750px;
  z-index: 60000;
  isolation: isolate;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 2px solid #e1aa56;
  border-radius: 17px;
  background: var(--gw-wood);
  color: var(--gw-ink);
  box-shadow: 0 0 0 100vmax #081725cd, 0 12px 40px #190c06c0;
  font: 14px/1.28 Georgia, 'Times New Roman', serif;

  & *, & *::before, & *::after { box-sizing: border-box; }
  & :is(h2,h3,h4,h5,p) { margin: 0; }
  & :is(button,summary):focus-visible { outline: 2px solid #168c9b; outline-offset: -2px; }
  & .gw-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    min-height: 30px;
    padding: 4px 10px;
    border: 1px solid var(--gw-gold);
    border-radius: 8px;
    background: var(--gw-button);
    color: var(--gw-ink);
    box-shadow: var(--gw-shadow);
    font-family: inherit;
    font-size: inherit;
    font-weight: bold;
    line-height: 1.15;
    cursor: pointer;
    touch-action: manipulation;
  }
  & .gw-button:hover:not(:disabled) { filter: brightness(1.09); }
  & .gw-button:disabled { opacity: .65; cursor: default; }
  & :is(.gw-primary,.gw-tab[aria-pressed="true"],.gw-station-label[aria-pressed="true"]) {
    background: var(--gw-green);
    color: #fff9db;
    border-color: #e7af42;
    box-shadow: inset 0 0 0 1px #acc47a87, 0 1px 2px #4c2b19a3;
  }
  & :is(.gw-close,.gw-back) {
    flex: none;
    width: 34px;
    height: 34px;
    padding: 0;
    border: 2px solid #f2c46a;
    border-radius: 50%;
    color: #fff4d1;
    font-size: 23px;
  }
  & .gw-back { font-size: 0; background: #78401e; }
  & .gw-back::before { content: '←'; font-size: 20px; }
  & .gw-close { background: linear-gradient(#d94a29,#942015); }
  & .gw-head {
    flex: none;
    height: 42px;
    display: flex;
    align-items: center;
    gap: var(--gw-gap);
    padding: 3px 9px;
    color: #ffedba;
  }
  & .gw-brand { flex: 1; min-width: 0; }
  & .gw-brand h2 {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: clamp(19px, 3.1vw, 31px);
    line-height: 1;
    color: inherit;
    text-shadow: 0 2px #381709;
  }
  & .gw-brand h2::before {
    content: '❄';
    display: grid;
    place-items: center;
    flex: none;
    width: 1.45em;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 2px solid #f4c25f;
    background: #a24e1e;
    color: #ffe8a4;
    font-size: .73em;
  }
  & :is(.gw-overline,.gw-wallet-item small) { display: none; }
  & .gw-wallet, & .gw-wallet-item { display: flex; align-items: center; gap: 5px; }
  & .gw-wallet-item {
    padding: 3px 6px;
    border: 1px solid var(--gw-gold);
    border-radius: 999px;
    background: #3f1c0f;
    color: #fff2cc;
    white-space: nowrap;
    font: bold 12px/1 system-ui, sans-serif;
  }
  & .gw-wallet-icon { width: 15px; height: 15px; object-fit: contain; }
  & .gw-tabs {
    flex: none;
    display: grid;
    grid-template-columns: repeat(3,minmax(0,1fr));
    align-items: end;
    gap: 5px;
    padding: 0 6% 0;
    border-bottom: 2px solid #e7ae64;
  }
  & .gw-tab {
    min-width: 0;
    min-height: 38px;
    padding: 4px;
    border-radius: 11px 11px 0 0;
    font-size: clamp(12px,1.8vw,17px);
  }
  & .gw-content {
    flex: 1;
    min-height: 0;
    padding: var(--gw-gap);
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: #bc854d #f5e3c7;
    background: var(--gw-paper);
  }
  & .gw-production-content { position: relative; }
  & .gw-factory-content { padding: 4px; overflow: hidden; background: #482417; }

  /* Factory */
  & :is(.gw-factory,.gw-production-space,.gw-stage-viewport) { position: relative; height: 100%; }
  & .gw-stage-viewport {
    display: grid;
    grid-template-rows: minmax(0,1fr) auto;
    overflow: hidden;
    border: 1px solid #d39a52;
    border-radius: var(--gw-radius);
    background: #6e432c url('assets/workshop-r03/room.png') center / var(--gw-room-size, 100% 100%) no-repeat;
  }
  & .gw-stage-viewport > .gw-scene {
    min-width: 0;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
  }
  & .gw-station-captions {
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(4,minmax(0,1fr));
    justify-items: center;
    gap: 4px;
    padding: 0 2% 5px;
  }
  & .gw-station-label { min-height: 26px; min-width: 68%; padding: 3px 6px; border-radius: 999px; }
  & .gw-station-label.gw-stage-current { box-shadow: 0 0 0 1px #ffdc6a, 0 0 11px #ffbe4a; }
  & .gw-mobile-rune {
    position: absolute;
    z-index: 12;
    top: 5px;
    right: 5px;
    min-height: 24px;
    background: #4b2516e8;
    color: #fff0bd;
    font-size: 12px;
  }

  /* Shift and energy */
  & :is(.gw-progress-area,.gw-team-save,.gw-status) {
    flex: none;
    padding: 6px var(--gw-gap);
    border-top: 1px solid var(--gw-gold);
    background: var(--gw-paper);
  }
  & .gw-progress-area { display: grid; align-content: center; gap: 4px var(--gw-gap); }
  & > .gw-progress-area {
    grid-template-columns: minmax(0,1fr) auto;
    grid-template-rows: auto auto;
    align-content: center;
    min-height: var(--gw-shift-min-height, 61px);
  }
  & > .gw-progress-area .gw-progress-controls { grid-area: 1 / 2 / 3 / 3; }
  & :is(.gw-progress-heading,.gw-progress-controls,.gw-queue-choices,.gw-status) {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 8px;
    min-width: 0;
  }
  & .gw-progress-heading { justify-content: space-between; }
  & :is(.gw-production-clock,.gw-idle-quote,.gw-running-note,.gw-queue-note,.gw-progress-num) { font-size: 11px; }
  & > .gw-progress-area .gw-idle-quote { display: none; }
  & .gw-progress-num { display: none; }
  & :is(.gw-progress,.gw-energy-shop-meter) {
    height: 8px;
    overflow: hidden;
    border: 1px solid #a67c4c;
    border-radius: 999px;
    background: #e4c494;
  }
  & :is(.gw-progress-fill,.gw-energy-shop-meter > span) {
    display: block;
    height: 100%;
    background: linear-gradient(#a8db64, #468b27);
    border-radius: inherit;
  }
  & .gw-progress-fill { width: 0; transition: width .5s; }
  & .gw-queue-choices { gap: 4px; font-size: 12px; }
  & .gw-queue-choice { min-width: 30px; min-height: 26px; padding: 2px 5px; }
  & .gw-queue-choice[aria-pressed="true"] { background: #d4e89e; border-color: #6c9142; }
  & .gw-start, & .gw-claim-button { min-width: 126px; }
  & .gw-status { justify-content: space-between; max-height: 70px; overflow: auto; font-size: 12px; }

  /* Shared panels */
  & :is(.gw-setup-team,.gw-prod-recipes,.gw-prod-sidebar,.gw-team-board,.gw-team-side,
        .gw-ready-card,.gw-work-dock,.gw-info-card,.gw-first-visit,.gw-v42-upgrade,.gw-shift-receipt) {
    min-width: 0;
    padding: var(--gw-gap);
    border: 1px solid var(--gw-edge);
    border-radius: var(--gw-radius);
    background: var(--gw-paper);
    box-shadow: var(--gw-shadow);
  }
  & :is(.gw-info-card,.gw-ready-card,.gw-work-dock,.gw-v42-upgrade,.gw-first-visit[open]) {
    display: grid;
    align-content: start;
    gap: 5px;
  }
  & .gw-info-card {
    position: absolute;
    z-index: 25;
    top: 5px;
    right: 5px;
    max-height: calc(100% - 10px);
    width: min(350px, 70%);
    padding: 10px 36px 10px 10px;
    overflow: auto;
  }
  & .gw-sheet-close { position: absolute; right: 4px; top: 4px; padding: 0; width: 28px; min-height: 28px; font-size: 19px; }
  & .gw-info-card > .gw-portrait { height: 82px; width: 70px; }
  & .gw-first-visit summary { cursor: pointer; }
  & .gw-field-label { color: #784b27; font-weight: bold; }
  & .gw-warning, & .gw-energy-warning { color: #8d2916; }
  & .gw-loading { margin: auto; padding: 16px; text-align: center; color: #fff1cf; }
  & .gw-loading > * { margin: 5px; }

  /* Production */
  & .gw-production { display: grid; gap: var(--gw-gap); }
  & .gw-prod-layout { display: grid; grid-template-columns: minmax(0,58fr) minmax(0,42fr); gap: var(--gw-gap); }
  & .gw-prod-recipes, & .gw-prod-sidebar { display: flex; flex-direction: column; gap: var(--gw-gap); }
  & .gw-prod-sidebar .gw-progress-area {
    margin-top: auto;
    padding: var(--gw-gap) 0 0;
    background: none;
    gap: 5px;
  }
  & .gw-prod-sidebar .gw-progress { display: none; }
  & .gw-prod-sidebar .gw-progress-controls > :is(.gw-idle-quote,.gw-start) { flex: 1 0 100%; }
  & .gw-setup-team { display: flex; align-items: center; flex-wrap: wrap; gap: var(--gw-gap); padding-block: 3px; }
  & .gw-mini-team { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
  & .gw-mini-elf { width: 33px; height: 32px; padding: 0; border-radius: 50%; overflow: hidden; }
  & .gw-mini-elf .gw-portrait { width: 28px; height: 30px; }
  & .gw-recipe-options { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: var(--gw-gap); margin-top: 5px; }
  & .gw-recipe { flex-direction: column; justify-content: flex-start; padding: 5px; border-radius: var(--gw-radius); text-align: center; }
  & .gw-recipe[aria-pressed="true"] {
    border-color: #c98620;
    background: linear-gradient(#ffeab4,#f6d486);
    box-shadow: inset 0 0 0 2px #ffedb2, 0 1px 2px #88542173;
  }
  & .gw-product-label { display: grid; justify-items: center; gap: 3px; width: 100%; font-size: 16px; }
  & .gw-product-icon {
    display: block;
    width: 100%;
    height: clamp(39px, 13vh, 105px);
    padding: 3px;
    border-radius: 8px;
    background: radial-gradient(ellipse,#fff4bf,#eac183);
    object-fit: contain;
  }
  & .gw-energy-shop { display: grid; align-content: start; gap: 5px; min-width: 0; }
  & .gw-energy-shop-heading { display: flex; align-items: center; gap: 5px; }
  & .gw-energy-shop-heading > div { display: flex; justify-content: space-between; gap: 5px; flex: 1; }
  & .gw-energy-shop-heading span { white-space: nowrap; }
  & .gw-energy-shop-icon { width: 17px; height: 17px; }
  & .gw-energy-regeneration, & .gw-energy-warning { font-size: 12px; }
  & .gw-shift-receipt { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12px; }
  & .gw-stage-checklist { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; margin: 4px 0; padding: 0; list-style: none; }
  & .gw-stage-checklist li { display: flex; align-items: center; gap: 5px; padding: 5px; border: 1px solid var(--gw-edge); border-radius: 8px; }
  & .gw-stage-checklist .is-current { background: #fff0a9; }
  & .gw-stage-checklist .is-done { background: #e3ecc0; }
  & .gw-legacy-choice { display: flex; flex-wrap: wrap; gap: 6px; }
  & .gw-legacy-choice .gw-selected { background: #dbe7ac; }

  /* Team */
  & :is(.gw-elves-screen,.gw-team-layout) { height: 100%; }
  & .gw-team-layout { min-height: 0; display: grid; grid-template-rows: minmax(0,1fr); grid-template-columns: minmax(0,53fr) minmax(0,47fr); gap: var(--gw-gap); }
  & .gw-team-board { min-height: 0; display: flex; flex-direction: column; gap: 5px; }
  & .gw-team-board-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 3px var(--gw-gap); }
  & .gw-team-board-head span { color: #6e451e; font-size: 12px; }
  & :is(.gw-team-board h3,.gw-setup-recipes h3) { font-size: var(--gw-heading); }
  & .gw-assign-grid { min-height: 0; flex: 1; display: grid; grid-template: repeat(2,1fr) / repeat(2,minmax(0,1fr)); gap: 6px; }
  & .gw-team-position { position: relative; min-height: 0; }
  & .gw-assign-item {
    display: grid;
    grid-template-columns: 22px minmax(0,1fr);
    grid-template-rows: auto 1fr;
    align-items: center;
    gap: 3px 5px;
    width: 100%;
    height: 100%;
    padding: 5px;
    text-align: left;
    border-radius: var(--gw-radius);
  }
  & .gw-assign-item:disabled { opacity: 1; }
  & .gw-position-filled .gw-assign-item { background: linear-gradient(#fff3cc,#f4d798); }
  & .gw-position-choosing .gw-assign-item:not(:disabled) { border-color: #719c40; }
  & .gw-position-filled .gw-assign-item { padding-bottom: 24px; }
  & .gw-position-number {
    display: grid;
    place-items: center;
    width: 22px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: linear-gradient(#af6529,#7a3f16);
    color: #fff2cb;
  }
  & .gw-position-worker { grid-column: 1 / -1; display: flex; align-items: center; gap: 4px; font-weight: normal; }
  & .gw-position-worker .gw-portrait { width: 25px; height: 27px; }
  & .gw-position-auto { color: #9d622a; font-size: 20px; }
  & .gw-position-remove { position: absolute; right: 5px; bottom: 4px; min-height: 20px; padding: 2px 5px; font-size: 11px; }
  & .gw-team-side { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
  & .gw-team-inspector { flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; }
  & .gw-elf-card { display: grid; grid-template-columns: minmax(64px,26%) minmax(0,1fr); gap: 4px 6px; align-items: start; padding: 1px; }
  & .gw-elf-status { grid-column: 1 / -1; font-size: 11px; color: #45612b; }
  & .gw-elf-visual {
    position: relative;
    grid-column: 1;
    align-self: stretch;
    min-height: 80px;
    border: 1px solid var(--gw-gold);
    border-radius: 9px;
    background: radial-gradient(ellipse at 50% 45%,#ffedbe,#dba963);
  }
  & .gw-elf-visual .gw-portrait { position: absolute; inset: 0; }
  & .gw-elf-frost { position: absolute; top: 3px; right: 4px; color: #fff; }
  & .gw-elf-copy { grid-column: 2 / -1; display: grid; align-content: start; gap: 2px; font-size: 12px; overflow-wrap: anywhere; }
  & .gw-elf-copy h5 { font-size: var(--gw-heading); }
  & .gw-elf-details summary { cursor: pointer; }
  & .gw-elf-details p { margin: 3px 0; }
  & .gw-elf-actions { display: flex; flex-wrap: wrap; gap: 4px; flex: none; }
  & .gw-elf-actions:empty { display: none; }
  & .gw-elf-actions .gw-button { flex: 1; }
  & .gw-elf-actions .gw-lock-note { flex-basis: 100%; }
  & :is(.gw-elf-hire,.gw-lock-note,.gw-rank-max) { grid-column: 2 / -1; }
  & :is(.gw-elf-pick,.gw-elf-upgrade,.gw-elf-hire) { font-size: 11px; min-height: 25px; padding: 3px; }
  & .gw-elf-pick { background: var(--gw-green); color: #fff5d4; }
  & .gw-team-elf-selector { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 4px; flex: none; }
  & .gw-team-elf-thumb { position: relative; display: grid; justify-items: center; gap: 2px; min-width: 0; padding: 2px; font-size: 10px; }
  & .gw-team-elf-thumb .gw-portrait { width: 100%; height: clamp(26px,6vh,47px); }
  & .gw-team-elf-thumb[aria-pressed="true"] { background: #ffdc8a; border-color: #a96511; box-shadow: inset 0 0 0 1px #fff1af; }
  & .gw-unowned-thumb .gw-portrait { filter: saturate(.6); }
  & .gw-team-elf-thumb small { position: absolute; top: 2px; right: 2px; border-radius: 99px; padding: 1px 3px; background: #416f2e; color: #fff; }
  & .gw-portrait { position: relative; }
  & .gw-portrait img { display: block; width: 100%; height: 100%; object-fit: contain; }
  & .gw-team-save { display: flex; align-items: center; gap: var(--gw-gap); }
  & .gw-save-team { flex: 1; }
  & .gw-team-change-state { font-size: 12px; }

  @media (min-height: 560px) and (min-width: 761px) {
    --gw-gap: 12px;
    &[data-tab="production"], &[data-tab="elves"] { max-height: 600px; }
    :where(html:not([data-window-layout="compact"])) &[data-tab="factory"] {
      max-width: 900px;
      max-height: 510px;
      --gw-room-size: cover;
      --gw-shift-min-height: 0px;
      --gw-sprite-height: auto;
      --gw-machine-width: min(66%, 55cqh);
      --gw-worker-width: min(61%, 54cqh);

      & .gw-scene { container-type: size; }
    }
    & .gw-head { height: 54px; }
    & .gw-tab { min-height: 44px; }
    & .gw-station-label, & .gw-save-team { min-height: 39px; }
    & .gw-production { min-height: 100%; grid-template-rows: auto 1fr; align-content: start; }
    & .gw-production:has(.gw-ready-card,.gw-work-dock) { grid-template-rows: 1fr; }
    & .gw-setup-recipes { display: flex; flex-direction: column; flex: 1; }
    & .gw-recipe-options { flex: 1; }
    & .gw-recipe { min-height: 154px; justify-content: center; }
    & .gw-elf-visual { min-height: 155px; }
    & .gw-team-elf-thumb { font-size: 12px; }
  }

  @media (max-height: 450px) {
    --gw-gap: 6px;
    & .gw-elf-copy { font-size: 11px; }
    & .gw-team-side { gap: 4px; }
    & .gw-recipe { font-size: 12px; }
    & .gw-prod-sidebar .gw-idle-quote { font-size: 10px; }
  }

  @media (max-width: 540px) {
    & .gw-back, & .gw-brand h2::before { display: none; }
    & .gw-head { padding-inline: 4px; gap: 4px; }
    & .gw-wallet, & .gw-wallet-item { gap: 2px; }
    & .gw-wallet-item { padding: 3px; font-size: 10px; }
    & .gw-wallet-icon { width: 12px; height: 12px; }
    & .gw-brand h2 { font-size: 16px; }
    & .gw-tabs { padding-inline: 4px; }
    & .gw-prod-layout, & .gw-team-layout { grid-template-columns: minmax(0,1fr); }
    & .gw-team-layout { height: auto; grid-template-rows: auto; }
    & .gw-team-position { min-height: 76px; }
    & .gw-team-inspector { max-height: 265px; }
    & > .gw-progress-area { grid-template-columns: minmax(0,1fr); grid-template-rows: auto; }
    & > .gw-progress-area .gw-progress-controls { grid-area: auto; }
    & .gw-station-label { min-width: 0; font-size: 11px; }
  }
}

@media (prefers-reduced-motion: reduce) {
  #gift-workshop .gw-progress-fill { transition: none; }
}