.town-service-surface .ro-subtabs {
  display: flex;
  overflow-x: auto;
  /* Size from the parent so eight tabs scroll instead of widening the page. */
  contain: inline-size;
  min-width: 0;
  scrollbar-width: thin;
  border: 1px solid #748394;
  background: #cbd2d6;
}
.town-service-surface .ro-subtabs button {
  flex: 0 0 auto;
  min-width: 64px;
  min-height: 32px;
  padding: 4px 14px;
  border: 0;
  border-right: 1px solid #91a0aa;
  border-bottom: 2px solid transparent;
  background: linear-gradient(#eef1f2, #c4ccd1);
  color: #24394d;
  font-size: 13px;
  cursor: pointer;
}
.town-service-surface .ro-subtabs button.active {
  border-bottom-color: #356da3;
  background: #fff;
  color: #173f70;
  font-weight: bold;
}

@media (max-width: 520px) { .town-service-surface .ro-subtabs button { min-width: 48px; padding: 4px 6px; } }
/* Frozen handoff rules, retained verbatim by bounded selector extraction. */
.town-service-cancel,
.town-service-close {
  min-width: 24px;
  height: 22px;
  border: 1px solid #405b79;
  background: linear-gradient(#fff, #cbd4dc);
  color: #1f3954;
  font-weight: bold;
  line-height: 1;
  cursor: pointer;
}

.minimap-wrap.town-service-open { height: clamp(460px, 60vh, 720px); overflow: hidden; }
.minimap-wrap.town-service-open > canvas,
.minimap-wrap.town-service-open > .map-legend,
.minimap-wrap.town-service-open > .town-service-markers { display: none; }
.town-service-surface {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: #0b100c;
  overflow: hidden;
}
.town-service-scene { position: relative; width: 100%; height: 100%; }
.shop-scene { background: #d7dcda; }
.kafra-scene { background: #5d7067; }
.town-service-window {
  position: absolute;
  top: 12px;
  left: 12px;
  width: min(440px, 58%);
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}
.town-service-window > .titlebar { align-items: center; }
.town-service-window > .titlebar > .town-service-close { margin-left: 8px; }
.town-service-preview-tag { font-weight: normal; font-size: 12px; }
.town-service-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  border-top: 1px solid #a0a9ad;
  font-size: 12px;
}
.town-service-notice { margin: 0; padding: 0 8px 6px; font-size: 12px; color: #8a3b12; }
.town-service-notice:empty { display: none; }
.town-service-item-icon { display: inline-grid; place-items: center; width: 24px; height: 24px; flex: 0 0 24px; }
.town-service-item-icon img { max-width: 24px; max-height: 24px; image-rendering: pixelated; }

.town-service-empty { display: block; padding: 12px 8px; color: #677381; font-size: 12px; }
.town-service-bag-window {
  left: 278px;
  top: 12px;
  width: min(356px, calc(100% - 290px));
  min-width: 218px;
  height: 232px;
}
.town-service-bag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 40px);
  align-content: start;
  gap: 3px;
  padding: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  background: #f4f5f1;
}
.town-service-slot {
  position: relative;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid #b7bfc3;
  background: #fff;
  padding: 0;
  cursor: pointer;
}
.town-service-slot:hover,
.town-service-slot:focus-visible { border-color: #2f6ea5; background: #e8f1fb; }
/* G8L-211 U3: multi-sell picks and the trade confirm window. */
.town-service-slot.selected { border-color: #2f6ea5; background: #cfe2f6; box-shadow: inset 0 0 0 2px #2f6ea5; }
.town-service-multi { justify-content: flex-end; gap: 6px; }
.town-service-multi[hidden] { display: none; }
.town-service-trade-confirm .town-service-quantity-body { flex-direction: column; align-items: stretch; max-height: 260px; overflow-y: auto; }
.town-service-confirm-row { display: flex; align-items: center; gap: 8px; }
.town-service-confirm-row span:nth-child(2) { flex: 1; }
.town-service-trade-confirm .town-service-total { margin: 4px 0 0; text-align: right; }
.shop-scene .town-service-trade-confirm .town-service-price,
.shop-scene .town-service-trade-confirm .town-service-total b { color: #234765; } /* the confirm window is white, not glass */
.town-service-slot b {
  position: absolute;
  right: 2px;
  bottom: 0;
  font-size: 11px;
  color: #1f3954;
  text-shadow: 0 0 2px #fff, 0 0 2px #fff;
}

/* Shop: L layout (list down the left, bag along the bottom) around the merchant film. */
.shop-scene { --shop-list-w: min(340px, 34%); background: #2a1c10; }
.merchant-film {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 70% 30%;
  pointer-events: none;
}
.shop-scene > .town-service-window:not(.town-service-bag-window) {
  top: 8px;
  bottom: auto;
  left: 8px;
  width: var(--shop-list-w);
  max-height: calc(100% - 16px);
}
.shop-scene .town-service-bag-window {
  top: auto;
  bottom: 8px;
  left: calc(var(--shop-list-w) + 16px);
  width: min(430px, calc(100% - var(--shop-list-w) - 24px));
  min-width: 0;
  height: min(340px, calc(100% - 16px));
}
.shop-scene .town-service-bag-window > .titlebar,
.shop-scene .town-service-bag-window > .town-service-tabs,
.shop-scene .town-service-bag-window > .town-service-foot { flex-shrink: 0; }
.shop-scene .town-service-bag-grid > .town-service-empty { grid-column: 1 / -1; }
/* Glass theme: the merchant film shows through every panel. */
.shop-scene .town-service-window {
  border: 1px solid rgb(255 214 150 / 45%);
  border-radius: 8px;
  background: rgb(28 16 8 / 38%);
  backdrop-filter: blur(7px) saturate(1.15);
  box-shadow: 0 6px 22px rgb(0 0 0 / 35%), inset 0 1px 0 rgb(255 240 210 / 25%);
  color: #fbeed4;
}
.shop-scene .town-service-window > .titlebar {
  background: linear-gradient(rgb(255 225 170 / 28%), rgb(120 70 30 / 22%));
  border-bottom: 1px solid rgb(255 214 150 / 35%);
  color: #fff3dc;
  text-shadow: 0 1px 2px rgb(0 0 0 / 70%);
}
.shop-scene .town-service-preview-tag { color: #f5d9a6; }
.shop-scene .town-service-close {
  border: 1px solid rgb(255 220 160 / 55%);
  border-radius: 4px;
  background: rgb(255 255 255 / 12%);
  color: #fff3dc;
}
.shop-scene .town-service-bag-grid,
.shop-scene .town-service-trade-list { background: transparent; }
.shop-scene .town-service-window [role='tablist'],
.shop-scene .town-service-window .tabs { background: rgb(0 0 0 / 18%); border-color: rgb(255 214 150 / 30%); }
.shop-scene .town-service-window [role='tab'] {
  border-color: rgb(255 214 150 / 30%);
  background: rgb(255 255 255 / 8%);
  color: #f1dfbf;
}
.shop-scene .town-service-window [role='tab'][aria-selected='true'] {
  background: rgb(255 200 110 / 28%);
  color: #fff6e4;
  font-weight: bold;
}
.shop-scene .town-service-trade-row {
  border-bottom-color: rgb(255 214 150 / 16%);
  color: #fbeed4;
  text-shadow: 0 1px 2px rgb(0 0 0 / 60%);
}
.shop-scene .town-service-trade-row:hover { background: rgb(255 210 140 / 14%); }
.shop-scene .town-service-price,
.shop-scene .town-service-total b { color: #ffd98a; }
.shop-scene .town-service-trade-row small { color: #e0c9a2; }
.shop-scene .town-service-trade-row input {
  border: 1px solid rgb(255 214 150 / 50%);
  border-radius: 4px;
  background: rgb(0 0 0 / 30%);
  color: #fff6e4;
}
.shop-scene .town-service-foot { border-top-color: rgb(255 214 150 / 30%); color: #f1dfbf; }
.shop-scene .town-service-foot .primary {
  border: 1px solid rgb(255 220 150 / 70%);
  border-radius: 4px;
  background: linear-gradient(rgb(255 214 130 / 55%), rgb(190 120 40 / 55%));
  color: #fff;
  font-weight: bold;
  text-shadow: 0 1px 2px rgb(0 0 0 / 60%);
}
.shop-scene .town-service-notice { color: #ffcf9a; }
.shop-scene .town-service-slot {
  border: 1px solid rgb(255 214 150 / 40%);
  border-radius: 4px;
  background: rgb(255 255 255 / 14%);
}
.shop-scene .town-service-slot:hover,
.shop-scene .town-service-slot:focus-visible { border-color: #ffd98a; background: rgb(255 210 140 / 26%); }
.shop-scene .town-service-slot b { color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.town-service-trade-list { flex: 1; min-height: 0; overflow-y: auto; background: #f4f5f1; }
.town-service-trade-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-bottom: 1px solid #dde1e3;
  font-size: 13px;
}
.town-service-trade-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.town-service-trade-row small { color: #5f6870; }
.town-service-price { color: #234765; white-space: nowrap; }
.town-service-trade-row input { width: 56px; min-height: 26px; }
.town-service-total b { color: #234765; }

.town-service-quantity {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: #14223699;
}
.town-service-quantity-window { width: min(270px, calc(100% - 32px)); background: #fff; }
.town-service-quantity-body { display: flex; align-items: center; gap: 8px; padding: 14px 10px; font-size: 13px; }
.town-service-quantity-body span:nth-child(2) { flex: 1; }
.town-service-quantity-body input { width: 66px; min-height: 30px; }
.town-service-quantity-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 0 10px 10px; }
.refine-options-body { flex-direction: column; align-items: stretch; max-height: 320px; overflow-y: auto; }
.refine-options-body .refine-option-row, .refine-options-body .refine-blessing-choice { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.refine-options-body input { width: 16px; flex: 0 0 16px; }
.refine-option-warning { margin: 0; }

.refine-button {
  position: absolute;
  left: 31.7%;
  top: 81.1%;
  width: 36.6%;
  height: 15.9%;
  /* The value sits in the button's dark field, right of the Zeny coin. */
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 10% 12% 0 30%;
  border: 0;
  background: url('/ro/client/town-service/bt_refining_normal.6952289ef4672d32.png') center / 100% 100% no-repeat;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  text-align: right;
  cursor: pointer;
}
.refine-button[data-state='press'] { background-image: url('/ro/client/town-service/bt_refining_press.bb695a5d5a171225.png'); }
.refine-button[data-state='disable'] { background-image: url('/ro/client/town-service/bt_refining_disable.a853341f7777db75.png'); cursor: default; }

/* Refinery: Sindri & Brok forge stage replaces the original refine board.
   Slot boxes use percentages of the 16:9 film frame (see town-service-ui.js). */
.refine-scene { container-type: size; background: #140c08; }
.refine-scene .town-service-window.forge-window {
  top: 8px;
  left: 50%;
  translate: -50% 0;
  width: min(calc(100cqw - 16px), calc((100cqh - 16px - 30px) * 16 / 9));
  max-height: calc(100% - 16px);
  background: #120a06;
}
.forge-refine { position: relative; flex: 1 1 auto; min-height: 0; }
.forge-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #120a06 url('/assets/ui-themes/forge-brothers/forge-poster.3f190afe4397ad8f.jpg') center / cover no-repeat;
  user-select: none;
}
.forge-film,
.forge-reaction {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}
.forge-reaction { opacity: 0; transition: opacity 0.28s ease-out; }
.forge-stage[data-phase^='result'] .forge-reaction { opacity: 1; animation: forge-reaction-in 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2); }
.forge-stage[data-phase='result-fail'] .forge-reaction { animation-name: forge-reaction-sink; }
@keyframes forge-reaction-in { from { scale: 1.07; filter: brightness(2.2); } to { scale: 1; filter: none; } }
@keyframes forge-reaction-sink { from { scale: 1.02; filter: brightness(0.35) saturate(0); } to { scale: 1; filter: none; } }

/* Glow on the anvil: builds during the three blows, bursts on the result. */
.forge-flash {
  position: absolute;
  left: 49.6%;
  top: 66%;
  width: 60%;
  aspect-ratio: 1;
  translate: -50% -50%;
  border-radius: 50%;
  background: radial-gradient(circle, rgb(255 236 170 / 95%), rgb(255 170 60 / 45%) 28%, transparent 62%);
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
}
.forge-stage[data-phase='process'] .forge-flash { animation: forge-charge 1.4s ease-in forwards; }
.forge-stage[data-phase='result-success'] .forge-flash { animation: forge-burst 1.1s ease-out forwards; }
.forge-stage[data-phase='result-fail'] .forge-flash {
  background: radial-gradient(circle, rgb(120 120 130 / 70%), rgb(40 40 50 / 40%) 30%, transparent 62%);
  mix-blend-mode: normal;
  animation: forge-burst 0.9s ease-out forwards;
}
@keyframes forge-charge {
  0% { opacity: 0; scale: 0.3; }
  30% { opacity: 0.55; scale: 0.45; }
  33% { opacity: 0.2; }
  60% { opacity: 0.75; scale: 0.6; }
  63% { opacity: 0.3; }
  100% { opacity: 1; scale: 0.8; }
}
@keyframes forge-burst { 0% { opacity: 1; scale: 0.8; } 100% { opacity: 0; scale: 1.8; } }

.forge-sparks { position: absolute; left: 49.6%; top: 66%; pointer-events: none; }
.forge-sparks i {
  position: absolute;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff3c4;
  box-shadow: 0 0 6px 2px #ffb640;
  animation: forge-spark 1.1s ease-out forwards;
}
@keyframes forge-spark {
  0% { translate: 0 0; opacity: 1; }
  100% { translate: var(--dx) var(--dy); opacity: 0; scale: 0.3; }
}

.forge-plate {
  position: absolute;
  left: 50%;
  top: 3%;
  translate: -50% 0;
  max-width: 44%;
  padding: 3px 16px;
  border: 1px solid rgb(246 217 160 / 55%);
  border-radius: 4px;
  background: rgb(20 12 6 / 62%);
  color: #fbe7bb;
  font-size: 14px;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 2px #000;
}
.forge-plate.empty { color: #d9c7a4; font-weight: normal; font-size: 13px; }
.forge-stage[data-phase^='result'] .forge-plate { visibility: hidden; }
.forge-risk {
  position: absolute;
  left: 50%;
  top: calc(3% + 30px);
  translate: -50% 0;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 10px;
  border-radius: 4px;
  background: rgb(60 8 8 / 70%);
  color: #ffd2c4;
  font-size: 12px;
  white-space: nowrap;
}
.forge-risk[hidden] { display: none; }

.forge-slot { position: absolute; display: grid; place-items: center; }
.forge-slot .town-service-item-icon { width: 60%; height: 60%; flex: none; }
.forge-slot .town-service-item-icon img { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; }
/* Anvil face: the refined item (original slot_item_off). */
.forge-slot-item {
  left: 45.9%;
  top: 72.4%;
  width: 7.4%;
  aspect-ratio: 1;
  background: url('/ro/client/town-service/slot_item_off.b63c1181400fd8eb.png') center / 100% 100% no-repeat;
  clip-path: inset(2px round 6px);
  opacity: 0.9;
  filter: drop-shadow(0 0 4px rgb(0 0 0 / 70%));
}
.forge-stage[data-phase='process'] .forge-slot-item { animation: forge-slot-heat 0.42s ease-in-out 3 alternate; }
@keyframes forge-slot-heat { to { filter: drop-shadow(0 0 10px #ffb640) brightness(1.5); } }
.forge-stage[data-phase='result-success'] .forge-slot-item { filter: drop-shadow(0 0 10px #ffe07a); }
/* Hexagon slots flank the item slot on the anvil: material (blue) and blessing (red). */
.forge-slot-material,
.forge-slot-blessing {
  width: 5.2%;
  aspect-ratio: 46 / 53;
  translate: -50% -50%;
  clip-path: polygon(50% 1%, 99% 26%, 99% 74%, 50% 99%, 1% 74%, 1% 26%);
  opacity: 0.55;
  transition: opacity 0.2s;
}
.forge-slot-material { left: 38.4%; top: 79%; background: url('/ro/client/town-service/slot_select_blue0.12608397dcb3c6a0.png') center / 100% 100% no-repeat; }
.forge-slot-material.filled { opacity: 0.95; }
.forge-slot-blessing { left: 60.8%; top: 79%; background: url('/ro/client/town-service/slot_select_red.e0c56d11a04e3f20.png') center / 100% 100% no-repeat; opacity: 0.45; }

.forge-result {
  position: absolute;
  left: 50%;
  top: 14%;
  translate: -50% 0;
  color: #fff1c2;
  font-size: clamp(16px, 2.6cqw, 28px);
  font-weight: bold;
  letter-spacing: 0.06em;
  white-space: nowrap;
  text-shadow: 0 0 10px #ff9d1c, 0 2px 3px #000;
  opacity: 0;
  pointer-events: none;
}
.forge-stage[data-phase^='result'] .forge-result { opacity: 1; animation: forge-result-in 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.4); }
.forge-stage[data-phase='result-fail'] .forge-result { color: #d9dde6; text-shadow: 0 0 8px #3b4660, 0 2px 3px #000; }
@keyframes forge-result-in { from { scale: 0.4; opacity: 0; } to { scale: 1; opacity: 1; } }

/* Actions sit under the item slot; .forge-refine matches the stage on desktop. */
.forge-actions {
  position: absolute;
  z-index: 1;
  left: 49.6%;
  top: 87%;
  translate: -50% 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 6px;
  width: 27%;
}
.forge-actions .refine-button {
  position: relative;
  left: auto;
  top: auto;
  width: 48%;
  flex: none;
  height: auto;
  aspect-ratio: 96 / 48;
  clip-path: inset(3px round 5px);
}
.forge-result-button {
  display: none;
  width: 48%;
  flex: none;
  aspect-ratio: 101 / 50;
  border: 0;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgb(0 0 0 / 70%);
  clip-path: inset(3px round 5px);
  cursor: pointer;
}
.forge-return { aspect-ratio: 101 / 38; }
.forge-again { background: url('/ro/client/town-service/bt_refining_again_success_normal.8c34852f13eb24d8.png') center / 100% 100% no-repeat; }
.forge-again:active { background-image: url('/ro/client/town-service/bt_refining_again_success_press.3a6f9fab74c258b8.png'); }
.forge-return { background: url('/ro/client/town-service/bt_refining_return_success_normal.8085ff2f5683b533.png') center / 100% 100% no-repeat; }
.forge-return:active { background-image: url('/ro/client/town-service/bt_refining_return_success_press.e6a69a51fa464ac6.png'); }
.forge-refine[data-phase='result-fail'] .forge-return { background-image: url('/ro/client/town-service/bt_refining_return_fail_normal.c2958829114e39c1.png'); }
.forge-refine[data-phase='result-fail'] .forge-return:active { background-image: url('/ro/client/town-service/bt_refining_return_fail_press.6f1bf6d4172bf856.png'); }
.forge-refine[data-phase^='result'] .refine-button { display: none; }
.forge-refine[data-phase='result-success'] .forge-again,
.forge-refine[data-phase^='result'] .forge-return { display: block; }

/* Equipment list: collapsible glass panel on the left edge of the forge. */
.forge-list {
  position: absolute;
  z-index: 2;
  left: 1.2%;
  top: 3%;
  max-height: 94%;
  width: 21%;
  display: flex;
  flex-direction: column;
  border: 1px solid rgb(246 217 160 / 35%);
  border-radius: 6px;
  background: rgb(18 10 6 / 48%);
  backdrop-filter: blur(6px);
  overflow: hidden;
}
.forge-list.collapsed { width: auto; }
.forge-list.collapsed .forge-list-rows { display: none; }
.forge-list-toggle {
  padding: 5px 10px;
  border: 0;
  border-bottom: 1px solid rgb(246 217 160 / 25%);
  background: transparent;
  color: #fbe7bb;
  font-size: 13px;
  font-weight: bold;
  text-align: left;
  cursor: pointer;
}
.forge-list-toggle::after { content: ' ◂'; }
.forge-list.collapsed .forge-list-toggle::after { content: ' ▸'; }
.forge-list-rows { display: flex; flex-direction: column; gap: 3px; padding: 5px; overflow-y: auto; }
.forge-list-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 2px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: rgb(255 255 255 / 8%);
  color: #f3e6cc;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.forge-list-row:hover:not(:disabled) { background: rgb(255 214 140 / 18%); }
.forge-list-row.selected { border-color: rgb(255 208 120 / 80%); background: rgb(255 190 90 / 24%); font-weight: bold; }
.forge-list-row:disabled { opacity: 0.55; cursor: default; }
.forge-list .town-service-empty { color: #d9c7a4; }

.forge-sound {
  position: absolute;
  z-index: 2;
  top: 3%;
  right: 1.5%;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid rgb(246 217 160 / 55%);
  border-radius: 50%;
  background: rgb(18 10 6 / 55%);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.forge-window .town-service-notice {
  position: absolute;
  left: 1.2%;
  bottom: 6px;
  z-index: 2;
  padding: 2px 10px;
  border-radius: 4px;
  background: rgb(18 10 6 / 70%);
  color: #f2d9a8;
}
.forge-stage.forge-quake { animation: forge-quake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
.forge-stage.forge-quake-strong { animation: forge-quake 0.6s cubic-bezier(0.36, 0.07, 0.19, 0.97); animation-name: forge-quake-strong; }
@keyframes forge-quake {
  10% { translate: -4px 2px; }
  22% { translate: 5px -3px; }
  36% { translate: -4px 3px; }
  52% { translate: 3px -2px; }
  70% { translate: -2px 1px; }
  86% { translate: 1px 0; }
  100% { translate: 0 0; }
}
@keyframes forge-quake-strong {
  8% { translate: -9px 4px; }
  18% { translate: 10px -6px; }
  30% { translate: -8px 6px; }
  44% { translate: 6px -4px; }
  60% { translate: -4px 2px; }
  78% { translate: 2px -1px; }
  100% { translate: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .forge-stage.forge-quake,
  .forge-stage.forge-quake-strong,
  .forge-stage[data-phase^='result'] .forge-reaction { animation: none; }
}
@media (max-width: 520px) {
  .refine-scene .town-service-window.forge-window {
    top: 8px;
    bottom: auto;
    left: 8px;
    translate: none;
    width: calc(100% - 16px);
    max-height: calc(100% - 16px);
    overflow-y: auto;
  }
  .forge-plate { top: 4%; font-size: 12px; padding: 2px 10px; max-width: 64%; }
  .forge-plate.empty { font-size: 11px; }
  .forge-risk { top: calc(4% + 22px); font-size: 10px; padding: 1px 6px; }
  .forge-risk img { width: 11px; }
  .forge-slot-material,
  .forge-slot-blessing { width: 7%; }
  .forge-slot-material { left: 37.2%; }
  .forge-slot-blessing { left: 62%; }
  .forge-slot-item { width: 9%; left: 45.1%; top: 71.6%; }
  /* Too little room under the anvil on a phone: the action bar follows the stage. */
  .forge-actions {
    position: static;
    translate: none;
    width: auto;
    padding: 6px 8px;
    background: #1d130c;
  }
  .forge-actions .refine-button,
  .forge-result-button { width: 120px; }
  .forge-sound { width: 24px; height: 24px; font-size: 12px; }
  .forge-list {
    position: static;
    width: auto;
    border-radius: 0;
    border-width: 1px 0 0;
    background: #1d130c;
    backdrop-filter: none;
  }
  .forge-list.collapsed { width: auto; }
  .forge-list-rows { max-height: 170px; }
  .forge-window .town-service-notice { position: static; translate: none; border-radius: 0; text-align: center; }
}


/* 系統設定 → 介面／主題 → 卡普拉主題 */
@media (max-width: 520px) {
  .town-service-surface { scroll-margin-bottom: 76px; }
  .minimap-wrap.town-service-open { height: 520px; }
  .town-service-window,
  .refine-scene .town-service-window { top: auto; bottom: 8px; left: 8px; width: calc(100% - 16px); max-height: 60%; }
  .shop-scene .town-service-window,
  .refine-scene .town-service-window { top: 8px; max-height: calc(100% - 16px); }
  .shop-scene > .town-service-window:not(.town-service-bag-window) {
    top: 8px;
    bottom: auto;
    width: calc(100% - 16px);
    height: 344px;
  }
  .shop-scene .town-service-bag-window {
    top: auto;
    bottom: 8px;
    left: 8px;
    width: calc(100% - 16px);
    height: 152px;
  }
  .town-service-refine { flex-direction: column-reverse; align-items: stretch; }
  .town-service-refine-board { width: min(262px, 100%); align-self: center; }
  .town-service-refine-list { flex: none; }
}

/* Shop on phones: the film fills the scene; merchant on top, list, then bag. */
@media (max-width: 520px) {
  .minimap-wrap.town-service-open:has(.shop-scene) { height: 768px; }
  .shop-scene {
    background: linear-gradient(rgb(27 15 7 / 45%), rgb(27 15 7 / 65%)),
      url('/assets/ui-themes/merchant-trump/merchant-poster.730388401eb4220e.jpg') 74% top / cover;
  }
  .shop-scene .merchant-film {
    inset: 0 auto auto 0;
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: contain;
    object-position: center;
    transform-origin: 74% 0;
    transform: scale(1);
    transition: transform 1000ms cubic-bezier(.22, .61, .36, 1);
  }
  .shop-scene .merchant-film.merchant-zoom {
    transform: scale(var(--merchant-closeup-scale, 3));
    transition-duration: 180ms;
  }
  .shop-scene > .town-service-window:not(.town-service-bag-window) {
    top: 214px;
    bottom: 278px;
    left: 8px;
    width: calc(100% - 16px);
    height: auto;
    max-height: none;
  }
  .shop-scene .town-service-bag-window {
    top: auto;
    bottom: 8px;
    left: 8px;
    width: calc(100% - 16px);
    height: 262px;
  }
}

@media (max-width: 520px) and (prefers-reduced-motion: reduce) {
  .shop-scene .merchant-film { transition: none; }
}

/* Refine forge glass: original button bitmaps kept, warm tint and glass layer on top. */
.forge-actions .refine-button {
  isolation: isolate;
  background: linear-gradient(rgb(255 196 110 / 22%), rgb(90 44 12 / 30%));
  border-radius: 9px;
  clip-path: none;
  box-shadow: inset 0 0 0 1px rgb(255 222 160 / 70%), inset 0 0 14px rgb(255 170 70 / 28%),
    0 4px 14px rgb(0 0 0 / 50%), 0 0 22px rgb(255 150 40 / 35%);
  backdrop-filter: blur(6px) saturate(1.2);
}
.forge-actions .refine-button::before {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: url('/ro/client/town-service/bt_refining_normal.6952289ef4672d32.png') center / 100% 100% no-repeat;
  filter: sepia(1) saturate(2.3) hue-rotate(-10deg) brightness(.95) contrast(1.05);
  opacity: .62;
}
.forge-actions .refine-button[data-state='press']::before { background-image: url('/ro/client/town-service/bt_refining_press.bb695a5d5a171225.png'); }
.forge-actions .refine-button[data-state='disable']::before {
  background-image: url('/ro/client/town-service/bt_refining_disable.a853341f7777db75.png');
  filter: grayscale(1) sepia(.5) brightness(.55); opacity: .5;
}
.forge-actions .refine-button::after {
  content: ''; position: absolute; inset: 1px 1px 52% 1px; pointer-events: none;
  border-radius: 8px 8px 50% 50% / 8px 8px 10px 10px;
  background: linear-gradient(rgb(255 238 205 / 34%), transparent);
}
.forge-actions .refine-cost { position: relative; }
/* Failure return button: smoke glass matching the dejected forge scene. */
.forge-refine[data-phase='result-fail'] .forge-return {
  position: relative; isolation: isolate; border-radius: 9px; clip-path: none;
  background: linear-gradient(rgb(190 200 215 / 20%), rgb(30 34 44 / 45%));
  box-shadow: inset 0 0 0 1px rgb(210 220 235 / 55%), 0 4px 14px rgb(0 0 0 / 50%);
  backdrop-filter: blur(6px);
}
.forge-refine[data-phase='result-fail'] .forge-return::before {
  content: ''; position: absolute; inset: 0; z-index: -1; border-radius: inherit;
  background: url('/ro/client/town-service/bt_refining_return_fail_normal.c2958829114e39c1.png') center / 100% 100% no-repeat;
  filter: grayscale(.85) brightness(.8); opacity: .55;
}
.forge-refine[data-phase='result-fail'] .forge-return:active::before {
  background-image: url('/ro/client/town-service/bt_refining_return_fail_press.6f1bf6d4172bf856.png');
}
/* Phone: square forge stage fills the service area; slots follow the cover crop
   (x' = 1.778x - 38.9% of the 16:9 frame). The button rests on the anvil base. */
@media (max-width: 520px) {
  .forge-stage { aspect-ratio: 1 / 1; }
  .forge-slot-material { left: 27.2%; width: 12.4%; }
  .forge-slot-blessing { left: 71.3%; width: 12.4%; }
  .forge-slot-item { left: 41.3%; width: 16%; }
  .forge-plate { max-width: 70%; }
  .forge-actions {
    position: relative; top: auto; left: auto; z-index: 3; margin-top: -30px;
    padding: 0 8px 10px; background: linear-gradient(transparent, #1d130c 70%);
  }
}
/* Phone: the forge floor reflects the stage and fills the rest of the refine window.
   The layer starts below titlebar + square stage (margin % = window width), then flips
   so the poster bottom meets the stage's lower edge. 177.8% matches the stage crop. */
@media (max-width: 520px) {
  .refine-scene .town-service-window.forge-window { height: calc(100% - 16px); isolation: isolate; }
  .refine-scene .town-service-window.forge-window::before {
    content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none;
    margin-top: calc(100% + 30px);
    background:
      linear-gradient(to bottom, rgb(18 10 6 / 94%), rgb(18 10 6 / 30%)),
      url('/assets/ui-themes/forge-brothers/forge-poster.3f190afe4397ad8f.jpg') center bottom / 177.8% auto no-repeat;
    transform: scaleY(-1);
    filter: blur(5px) saturate(1.15);
  }
  .forge-actions { background: linear-gradient(transparent, rgb(20 11 6 / 30%)); }
  .forge-list { background: rgb(22 12 6 / 55%); border-color: rgb(246 217 160 / 22%); }
  .forge-window .town-service-notice { background: rgb(18 10 6 / 70%); }
}
