/* Shared desktop/WebView shop. RAN ivory panels and the original atlas button face. */
#shop-app, .shop-header, .shop-tabs, .product-detail-dialog, .purchase-dialog {
  color-scheme: light;
  --shop-ink: #29343a; --shop-muted: #696b60; --shop-faint: #82775e;
  --shop-gold: #89682e; --shop-gold-bright: #805b20; --shop-line: #d8cfbb;
  --shop-line-strong: #c2b596; --shop-surface: #fcfaf5; --shop-surface-raised: #fcfaf5;
  --shop-surface-soft: #eee6d5; --shop-danger: #a72f2f;
  color: var(--shop-ink);
}
:root .shop-header, :root .shop-tabs { background: linear-gradient(#fcfcf8,#e5e5dd); backdrop-filter: none; }
#shop-app { background: #f4f0e6; border: 1px solid #c5bdac; border-radius: 8px; padding: 12px; }
#shop-app .shop-sidebar, #shop-app .shop-toolbar, #shop-app .category-toggle,
#shop-app .shop-search, #shop-app .shop-sort select { color: var(--shop-ink); background: var(--shop-surface); }
#shop-app .category-button { color: var(--shop-ink); }
#shop-app .category-button.is-active { color: #795823; background: #f2e4c6; }
#shop-app .product-card { background: linear-gradient(#fffdf6,#f0e7d4); border-radius: 7px; box-shadow: inset 0 1px #fff; }
#shop-app .product-image { background: radial-gradient(#fffdf4,#e9ddc1); }
#shop-app .product-stock, #shop-app .product-badge { background: #f4e8cd; color: #73521e; }
#shop-app .product-body h2, #shop-app .shop-search input, #shop-app .shop-sort select { color: var(--shop-ink); }
#shop-app .product-body p { display: -webkit-box; }
#shop-app .product-card:hover { transform: none; }
#shop-app .product-image img { filter: none; }
#shop-app .product-card.is-featured::after { display: none; }

/* Three-piece atlas faces preserve the authored cap proportions at any width. */
.product-detail-dialog .button, .purchase-dialog .button, #shop-app .product-buy {
  position: relative; isolation: isolate; min-height: 44px; border: 1px solid #a58e5f;
  border-radius: 5px; background: #e5d6b1; color: #503b1a; box-shadow: inset 0 1px #fff5d8;
  font: 600 13px/1.2 "Segoe UI", sans-serif; text-shadow: 0 1px #fff5db;
  padding: 0 14px; transition: transform 120ms cubic-bezier(.23,1,.32,1); overflow: hidden;
}
.product-detail-dialog .button::before, .purchase-dialog .button::before, #shop-app .product-buy::before {
  content: ""; position: absolute; z-index: -1; inset: 0; pointer-events: none;
  border-image-source: url('/assets/item-shop-button-normal.svg');
  border-image-slice: 0 7 fill; border-image-width: 0 17px;
  /* The strip is the same source used by RanGuiAtlas.OuterTextButton18. */
  opacity: .35; filter: sepia(.8) saturate(.7) brightness(1.9);
}
.product-detail-dialog .button.secondary, .purchase-dialog .button.secondary { background: #eeece2; border-color: #b6ae98; color: #595a50; }
.product-detail-dialog .button:active:not(:disabled), .purchase-dialog .button:active:not(:disabled), #shop-app .product-buy:active:not(:disabled) { transform: translate(1px,1px); }
.product-detail-dialog .button:disabled, .purchase-dialog .button:disabled { opacity: .45; cursor: default; }
.product-detail-dialog :focus-visible, .purchase-dialog :focus-visible { outline: 2px solid #99702c; outline-offset: -3px; }
@media (hover: hover) and (pointer: fine) {
  .product-detail-dialog .button:hover:not(:disabled), .purchase-dialog .button:hover:not(:disabled), #shop-app .product-buy:hover:not(:disabled) { box-shadow: inset 0 0 0 1px #c19c50; }
  .product-detail-dialog .button:hover:not(:disabled)::before, .purchase-dialog .button:hover:not(:disabled)::before, #shop-app .product-buy:hover:not(:disabled)::before { border-image-source: url('/assets/item-shop-button-focused.svg'); }
}

/* Only the information panes scroll; the header and checkout never join that scroll. */
#product-detail-dialog, #purchase-dialog {
  --shop-available-height: calc(var(--shop-viewport-height, 100dvh) - max(12px, env(safe-area-inset-top)) - max(12px, env(safe-area-inset-bottom)));
  position: fixed; top: var(--shop-viewport-top, 0px); bottom: auto;
  margin: max(6px, env(safe-area-inset-top)) auto; padding: 0;
  max-height: var(--shop-available-height); overflow: hidden;
  border: 1px solid #ac9d7e; border-radius: 9px; background: #fcfaf5;
  box-shadow: 0 14px 50px #17202855;
}
#product-detail-dialog { width: min(880px, calc(100% - max(16px, env(safe-area-inset-left)) - max(16px, env(safe-area-inset-right)))); }
#product-detail-dialog > section {
  display: flex; flex-direction: column; height: min(560px, var(--shop-available-height));
  max-height: calc(var(--shop-available-height) - 2px); overflow: hidden; padding: 0;
}
.item-detail-header { display: flex; align-items: center; gap: 16px; flex: none; min-height: 62px; padding: 6px 14px; border-bottom: 1px solid #c5bdac; background: linear-gradient(#fcfcf8,#e5e5dd); }
.item-detail-header h2 { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; min-width: 0; flex: 1; margin: 0; font: 600 20px/1.2 "Segoe UI",sans-serif; overflow-wrap: anywhere; }
.item-detail-header small { flex: none; max-width: 140px; font-size: 12px; color: #80602a; font-variant-numeric: tabular-nums; }
.item-detail-body { display: grid; grid-template-columns: 210px minmax(0,1fr); flex: 1; min-height: 0; overflow: hidden; }
#product-detail-dialog .product-detail-preview { display: flex; height: auto; min-height: 0; max-height: none; align-items: center; flex-direction: column; padding: 22px 16px; gap: 12px; overflow-y: auto; background: radial-gradient(ellipse at top,#fffdf3,#f0e8d5); border-right: 1px solid #ded4be; border-bottom: 0; }
#product-detail-image { width: 150px; height: 150px; max-width: 100%; flex: none; object-fit: contain; border: 1px solid #c4b28a; border-radius: 6px; background: #f7efdc; padding: 8px; }
#product-detail-dialog .product-detail-meta { justify-content: center; text-align: center; }
#product-detail-dialog .product-detail-meta span { padding: 0; border: 0; font-size: 13px; line-height: 1.4; font-weight: 600; background: none; color: #6c5d39; }
#product-detail-storage { margin: 0; text-align: center; color: #827252; font-size: 12px; line-height: 1.5; }
#product-detail-dialog .product-detail-content { min-height: 0; padding: 0; overflow: hidden; }
.item-detail-tabs { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); flex: none; padding: 4px 8px 0; gap: 4px; border-bottom: 1px solid #d4c7ac; background: linear-gradient(#f9f8f2,#eeeadf); }
.item-detail-tabs button { min-height: 44px; padding: 4px; border: 1px solid transparent; border-bottom: 3px solid transparent; border-radius: 5px 5px 0 0; color: #68695f; background: transparent; font-size: 13px; }
.item-detail-tabs button[aria-selected=true] { color: #795823; background: linear-gradient(#fffdf5,#f4e8ce); border-color: #d0ba8b; border-bottom-color: #ad8743; font-weight: 600; }
.item-detail-panel { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; padding: 20px 24px; font-size: 14px; line-height: 1.55; }
.item-detail-panel h3 { margin: 0 0 8px; color: #886025; font: 600 24px/1.2 "Segoe UI",sans-serif; }
#product-detail-description { margin: 0 0 16px; font-size: 14px; line-height: 1.55; white-space: pre-line; }
.item-detail-panel h4 { margin: 0 0 4px; font-size: 11px; color: #877650; text-transform: uppercase; letter-spacing: .05em; }
#product-detail-contents { margin: 0 0 16px; }
.item-warning { margin: 0; border-left: 2px solid #b39455; padding: 8px 10px; background: #f8efd9; color: #786035; font-size: 12px; line-height: 1.5; }
.item-detail-panel ul, .item-detail-panel ol, #purchase-requirements { padding-left: 20px; margin: 0 0 12px; }
.item-detail-panel li { margin-bottom: 8px; }
.item-requirement-note { border-top: 1px solid #e1d8c7; padding-top: 10px; color: #827152; font-size: 12px; }
#product-detail-dialog .product-detail-purchase { display: flex; align-items: center; gap: 16px; flex: none; margin: 0; padding: 10px 14px; border-top: 1px solid #bfb18f; background: linear-gradient(#f8f3e8,#eadebf); }
.detail-quantity { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.purchase-quantity-control { display: flex; align-items: center; gap: 4px; }
.product-detail-purchase .purchase-quantity-control .button { width: 44px; min-width: 44px; padding: 0; font-size: 20px; }
.product-detail-dialog .purchase-quantity-control input, .purchase-dialog .purchase-quantity-control input { width: 44px; height: 44px; padding: 0; background: #fffdf5; border-radius: 4px; appearance: textfield; font-size: 16px; }
.purchase-quantity-control input::-webkit-inner-spin-button, .purchase-quantity-control input::-webkit-outer-spin-button { appearance: none; margin: 0; }
#product-detail-dialog .detail-unit { display: grid; min-width: 0; flex: 1; text-align: right; gap: 3px; font-size: 13px; }
#product-detail-dialog #product-detail-buy { width: 174px; min-width: 130px; flex: none; }

#purchase-dialog { width: min(510px, calc(100% - max(14px, env(safe-area-inset-left)) - max(14px, env(safe-area-inset-right)))); }
#purchase-dialog form { max-height: calc(var(--shop-available-height) - 2px); grid-template-rows: auto minmax(0,1fr) auto; }
#purchase-dialog .purchase-dialog-product { grid-template-columns: 40px minmax(0,1fr); gap: 10px; padding: 10px 52px 10px 14px; background: linear-gradient(#fcfcf8,#e5e5dd); border-bottom: 1px solid #d8cfbb; }
#purchase-dialog .purchase-dialog-product img { width: 40px; height: 40px; }
#purchase-dialog h2 { font: 600 16px/1.25 "Segoe UI",sans-serif; -webkit-line-clamp: 2; }
#purchase-order-summary { margin: 4px 0 0; font-size: 12px; color: #746642; }
#purchase-dialog .dialog-close { top: 6px; right: 5px; width: 44px; height: 44px; }
#purchase-dialog .purchase-dialog-body { gap: 8px; padding: 10px 14px; }
#purchase-dialog #purchase-description { display: block; overflow: visible; -webkit-line-clamp: unset; margin: 8px 0; white-space: pre-line; font-size: 13px; line-height: 1.5; }
.purchase-item-info { color: #59624f; font-size: 13px; }
.purchase-item-info summary { min-height: 44px; display: flex; align-items: center; gap: 8px; cursor: pointer; color: #795823; font-weight: 600; }
.purchase-item-info summary::before { content: "+"; font-size: 20px; }
.purchase-item-info[open] summary::before { content: "−"; }
#purchase-dialog .purchase-summary { display: grid; grid-template-columns: 1fr 1.4fr; gap: 6px; }
#purchase-dialog .purchase-summary > div { min-width: 0; padding: 4px 8px; border-radius: 5px; gap: 6px; flex-wrap: wrap; }
#purchase-dialog .purchase-summary dt { letter-spacing: 0; text-transform: none; font-size: 12px; }
#purchase-dialog .purchase-quantity-control { gap: 4px; }
#purchase-dialog .purchase-quantity-control .button { width: 44px; min-width: 44px; padding: 0; }
.purchase-balance { display: flex; align-items: center; justify-content: space-between; margin: 0; font-size: 12px; gap: 8px; }
#purchase-dialog .purchase-mail-count { font-size: 12px; }
#purchase-dialog .purchase-dialog-footer { padding: 8px 12px; gap: 6px; background: #f3ebda; }
#purchase-dialog .purchase-checkout-row { grid-template-columns: auto minmax(0,1fr); gap: 10px; }
#purchase-dialog .purchase-total { display: grid; gap: 2px; justify-content: start; }
#purchase-dialog .purchase-total strong { font-size: 20px; }
#purchase-dialog .dialog-actions { display: flex; gap: 6px; }
#purchase-dialog .dialog-actions .button { min-width: 0; flex: 1; padding: 0 8px; }
#purchase-dialog .dialog-message { max-height: 50px; overflow-y: auto; }
#purchase-dialog.is-processing #purchase-confirm::before { position: static; width: 14px; height: 14px; background: none; border-image: none; opacity: 1; filter: none; }

@media (max-width: 900px), (max-height: 500px) {
  .item-detail-header { min-height: 52px; gap: 8px; padding: 3px 8px; }
  .item-detail-header h2 { font-size: 16px; }
  .item-detail-header small { max-width: 110px; font-size: 11px; }
  .item-detail-header .button { font-size: 12px; padding: 0 8px; }
  .item-detail-body { grid-template-columns: 126px minmax(0,1fr); }
  #product-detail-dialog .product-detail-preview { padding: 12px 8px; gap: 9px; }
  #product-detail-image { width: 74px; height: 74px; }
  #product-detail-dialog .product-detail-meta span, #product-detail-storage { font-size: 11px; }
  .item-detail-panel { padding: 12px 14px; font-size: 13px; }
  .item-detail-panel h3 { font-size: 21px; }
  #product-detail-description { font-size: 13px; margin-bottom: 12px; }
  .item-detail-tabs button { font-size: 12px; }
  #product-detail-dialog .product-detail-purchase { padding: 8px 10px; gap: 10px; }
  .detail-quantity { gap: 6px; }
}
@media (max-width: 900px) {
  main { padding: 4px max(6px,env(safe-area-inset-left)) max(6px,env(safe-area-inset-bottom)); }
  :root .shop-header { min-height: 48px; height: auto; gap: 6px; padding: max(2px,env(safe-area-inset-top)) max(6px,env(safe-area-inset-right)) 2px max(6px,env(safe-area-inset-left)); }
  .shop-brand img { width: 30px; height: 30px; }
  .shop-brand small, .shop-wallet-balance > span, .shop-topup-trigger { display: none; }
  .shop-brand strong { font-size: 16px; }
  .shop-wallet strong::after { content: " PP"; font-size: 10px; font-weight: 500; }
  .shop-close { width: 44px; height: 44px; }
  :root .shop-tabs { position: relative; top: auto; min-height: 44px; padding: 0 6px; }
  .shop-tabs button { min-height: 44px; }
  #shop-app { padding: 4px; border-radius: 5px; }
  #shop-app .shop-layout { display: block; }
  #shop-app .shop-toolbar { display: flex; gap: 4px; min-height: 44px; padding: 0; margin: 0 0 4px; border: 0; }
  #shop-app .catalog-heading { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #shop-app .catalog-actions { display: flex; flex-wrap: nowrap; width: 100%; gap: 5px; }
  #shop-app .shop-search { flex: 1; min-width: 0; width: auto; height: 44px; }
  #shop-app .shop-search input { font-size: 16px; }
  #shop-app .category-toggle, #shop-app .shop-sort select { min-height: 44px; font-size: 12px; }
  #shop-app .shop-sort select { width: 150px; font-size: 11px; }
  #shop-app .shop-sort { flex: none; }
  #shop-app .shop-highlights, #shop-app .recently-viewed { display: none; }
  #shop-app .product-grid { grid-template-columns: repeat(4,minmax(0,1fr)); gap: 5px; }
  #shop-app .product-card { min-height: 64px; height: 64px; display: block; border-radius: 5px; content-visibility: visible; }
  #shop-app .product-image { position: static; display: block; min-height: 0; padding: 0; border: 0; background: none; }
  #shop-app .product-detail-trigger { position: absolute; z-index: 5; inset: 0; min-height: 44px; border-radius: 5px; }
  #shop-app .product-image img { position: absolute; left: 6px; top: 7px; width: 28px; height: 28px; max-width: none; max-height: none; }
  #shop-app .product-badges, #shop-app .product-stock, #shop-app .product-buy, #shop-app .product-details { display: none; }
  #shop-app .product-body { padding: 5px 5px 4px 40px; height: 100%; pointer-events: none; }
  #shop-app .product-body h2 { font-size: 11px; min-height: 27px; line-height: 1.2; font-weight: 600; }
  #shop-app .product-body p { display: -webkit-box; margin: 2px 0; min-height: 12px; font-size: 10px; line-height: 1.2; -webkit-line-clamp: 1; }
  #shop-app .product-price { justify-content: start; gap: 3px; }
  #shop-app .product-price strong { font-size: 12px; }
  #shop-app .product-price span { font-size: 10px; }
}
@media (max-width: 500px) {
  #shop-app .product-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  #shop-app .shop-sort { display: none; }
  .item-detail-header { flex-wrap: wrap; }
  .item-detail-header h2 { order: 2; flex-basis: 100%; font-size: 15px; }
  .item-detail-header small { margin-left: auto; }
  .item-detail-body { grid-template-columns: 78px minmax(0,1fr); }
  #product-detail-dialog .product-detail-preview { padding: 10px 4px; }
  #product-detail-image { width: 56px; height: 56px; padding: 3px; }
  #product-detail-storage { font-size: 10px; }
  .item-detail-tabs { grid-template-columns: 1fr 1.3fr .85fr; padding: 2px 2px 0; gap: 0; }
  .item-detail-tabs button { font-size: 11px; padding-inline: 1px; }
  .item-detail-panel { padding: 10px; }
  .item-detail-panel h3 { font-size: 18px; }
  #product-detail-dialog .product-detail-purchase { flex-wrap: wrap; gap: 4px 8px; padding: 6px; }
  .detail-quantity > label { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }
  #product-detail-dialog .detail-unit { order: -1; flex-basis: 100%; display: flex; justify-content: space-between; font-size: 11px; }
  #product-detail-dialog #product-detail-buy { width: auto; min-width: 0; flex: 1; padding: 0 5px; font-size: 12px; }
  #purchase-dialog .purchase-summary { grid-template-columns: 1fr; }
  #purchase-dialog .purchase-checkout-row { grid-template-columns: 1fr; gap: 5px; }
  #purchase-dialog .purchase-total { display: flex; justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) {
  .product-detail-dialog .button, .purchase-dialog .button { transition: none; }
  .product-detail-dialog .button:active:not(:disabled), .purchase-dialog .button:active:not(:disabled) { transform: none; }
}
