/* =========================================================================
   Steal a Dragon Egg — panel chrome (SE.UI.registerPanel): carved wood frame,
   gold rim + rivets, red ribbon title, round close button, gem-shaped tabs,
   warm parchment body that scrolls inside, footer slot, confirm layer.
   Sizes: .panel-s (≤ 460 px), .panel-m (≤ 720 px), .panel-l (≤ 1100 × 760 px,
   fixed height so big layouts can use height:100%).
   Shared kit for any panel: .pn-section, .pn-h, .pn-card, .pn-grid, .pn-row,
   .pn-bar, .pn-empty, .pn-note, .pn-tag.
   ========================================================================= */

#modals { position: absolute; inset: 0; pointer-events: none; z-index: 50; }
.modal {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: calc(30px + var(--sat)) calc(22px + var(--sar)) calc(16px + var(--sab)) calc(22px + var(--sal));
  pointer-events: auto;
}
.modal-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, rgba(30, 14, 4, .35), rgba(14, 6, 1, .72));
  opacity: 0; transition: opacity .18s ease;
}
.modal.in .modal-bg { opacity: 1; }
.modal.out .modal-bg { opacity: 0; }
.modal > .panel { transform: scale(.88) translateY(18px); opacity: 0; }
.modal.in > .panel { animation: panel-in .3s cubic-bezier(.2, 1.35, .4, 1) both; }
.modal.out > .panel { animation: panel-out .18s ease both; }
@keyframes panel-in { from { transform: scale(.88) translateY(18px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes panel-out { from { transform: none; opacity: 1; } to { transform: scale(.94) translateY(10px); opacity: 0; } }
.confirm-layer { z-index: 5; }

/* ---------- the frame ---------- */
.panel {
  position: relative;
  display: flex; flex-direction: column;
  max-width: 100%; max-height: 100%;
  padding: 30px 12px 12px;
  border: 3px solid var(--ink);
  border-radius: 24px;
  color: var(--parch-ink);
  background:
    repeating-linear-gradient(180deg, rgba(255, 255, 255, .055) 0 2px, rgba(0, 0, 0, 0) 2px 10px, rgba(0, 0, 0, .075) 10px 12px, rgba(0, 0, 0, 0) 12px 19px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0) 0 140px, rgba(0, 0, 0, .12) 140px 143px, rgba(255, 220, 160, .08) 143px 145px),
    linear-gradient(180deg, var(--wood-1), var(--wood-2) 50%, var(--wood-3));
  box-shadow: inset 0 3px 0 rgba(255, 220, 160, .35), inset 0 -5px 0 rgba(0, 0, 0, .32), 0 8px 0 var(--ink), 0 22px 50px rgba(0, 0, 0, .5);
}
.panel::before {           /* gold inlay */
  content: ''; position: absolute; inset: 5px;
  border: 2px solid rgba(255, 211, 77, .55); border-radius: 19px;
  pointer-events: none;
}
.panel .rivet {
  position: absolute; width: 13px; height: 13px; border-radius: 50%; z-index: 1;
  background: radial-gradient(circle at 35% 30%, #fff6c0, #f5c02a 45%, #8a5a00);
  box-shadow: 0 1px 0 rgba(0, 0, 0, .55);
  pointer-events: none;
}
.panel .rivet.r1 { left: 9px; top: 9px; }
.panel .rivet.r2 { right: 9px; top: 9px; }
.panel .rivet.r3 { left: 9px; bottom: 9px; }
.panel .rivet.r4 { right: 9px; bottom: 9px; }

.panel-s { width: min(460px, 100%); }
.panel-m { width: min(720px, 100%); }
.panel-l { width: min(1100px, 100%); height: min(760px, 100%); }

/* ---------- ribbon title ---------- */
.panel-head { position: absolute; left: 0; right: 0; top: 0; height: 0; z-index: 3; }
.panel-ribbon {
  position: absolute; left: 50%; top: -24px; transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  max-width: calc(100% - 120px);
  padding: 6px 30px 8px;
  border: 3px solid var(--ink); border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, .3) 0 42%, rgba(255, 255, 255, 0) 43%),
    linear-gradient(180deg, #ef5b3c, #c22a1d);
  box-shadow: inset 0 -4px 0 #861a10, 0 4px 0 var(--ink), 0 8px 14px rgba(0, 0, 0, .3);
}
.panel-ribbon::before, .panel-ribbon::after {    /* folded tails */
  content: ''; position: absolute; top: 10px; width: 26px; height: calc(100% - 4px); z-index: -1;
  background: linear-gradient(180deg, #b42418, #7d150c);
  border: 3px solid var(--ink);
}
.panel-ribbon::before { left: -18px; border-radius: 6px 0 0 6px; clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 40% 50%); }
.panel-ribbon::after { right: -18px; border-radius: 0 6px 6px 0; clip-path: polygon(0 0, 100% 0, 60% 50%, 100% 100%, 0 100%); }
.panel-ribbon.danger { background: linear-gradient(180deg, rgba(255, 255, 255, .25) 0 42%, rgba(255, 255, 255, 0) 43%), linear-gradient(180deg, #ff6a3a, #d03010); }
.pr-ic { display: inline-flex; width: 38px; height: 38px; margin: -10px 0 -8px -12px; }
.pr-ic .ic { width: 100%; height: 100%; filter: drop-shadow(0 2px 0 rgba(42, 20, 7, .7)); }
.pr-title { margin: 0; font: 900 27px/1.1 var(--font); color: #fff; text-shadow: var(--ts); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* core.js fitTitle: a title that does not fit at 15 px takes two lines */
.panel-ribbon.is-two { padding-left: 10px; padding-right: 10px; }
.panel-ribbon.is-two .pr-title { white-space: normal; text-overflow: clip; font-size: 15px; line-height: 1.05; text-align: center; overflow-wrap: anywhere; }

.panel-close {
  position: absolute; right: -14px; top: -16px; z-index: 4;
  width: 50px; height: 50px; padding: 9px;
  border-radius: 50%; border: 3px solid var(--ink);
  background: radial-gradient(circle at 50% 30%, #ff8a72, #e0321f 60%, #a3200f);
  color: #fff; cursor: pointer;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .5), inset 0 -4px 0 #7a150a, 0 4px 0 var(--ink);
  transition: transform .08s ease;
}
.panel-close .ic { width: 100%; height: 100%; filter: drop-shadow(0 2px 0 rgba(42, 20, 7, .8)); }
.panel-close:hover { transform: rotate(8deg) scale(1.05); }
.panel-close:active { transform: translateY(2px) scale(.95); }

/* ---------- gem tabs ---------- */
.panel-tabs {
  position: relative; z-index: 2;
  display: flex; justify-content: flex-start; gap: 6px;
  padding: 0 6px 10px;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  flex: 0 0 auto;
}
.panel-tabs::-webkit-scrollbar { display: none; }
.panel-tabs > :first-child { margin-left: auto; }
.panel-tabs > :last-child { margin-right: auto; }
.gem-tab {
  --tab-c: #39a6ff;
  position: relative; flex: 0 0 auto;
  min-width: 96px; height: 50px; padding: 3px;
  border: 0; background: var(--ink); cursor: pointer;
  clip-path: polygon(14px 0, calc(100% - 14px) 0, 100% 50%, calc(100% - 14px) 100%, 14px 100%, 0 50%);
  filter: saturate(.45) brightness(.88);
  transition: filter .15s ease, transform .1s ease;
}
.gem-tab .gt-face {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  width: 100%; height: 100%; padding: 0 18px 2px;
  clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 50%, calc(100% - 12px) 100%, 12px 100%, 0 50%);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, .55) 0 22%, rgba(255, 255, 255, .12) 23% 48%, rgba(0, 0, 0, .0) 49% 70%, rgba(0, 0, 0, .18) 71%),
    var(--tab-c);
  color: #fff; font: 900 16px/1 var(--font); text-shadow: var(--ts-sm); white-space: nowrap;
}
.gem-tab .gt-ic { width: 30px; height: 30px; margin-left: -6px; filter: drop-shadow(0 2px 0 rgba(42, 20, 7, .6)); }
.gem-tab .gt-count { font-size: 12px; opacity: .95; margin-left: 2px; }
.gem-tab .badge { top: 0; right: 10px; }
.gem-tab:hover { filter: saturate(.8) brightness(.98); }
.gem-tab.on { filter: none; transform: translateY(-2px) scale(1.04); }
.gem-tab.on .gt-face { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .55); }

/* ---------- parchment body + footer ---------- */
.panel-body {
  position: relative; z-index: 1;
  flex: 1 1 auto; min-height: 0;
  overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 14px;
  border: 3px solid #4a250b; border-radius: 14px;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 45%),
    radial-gradient(ellipse at 100% 100%, rgba(170, 110, 40, .22), rgba(170, 110, 40, 0) 50%),
    radial-gradient(ellipse at 0% 100%, rgba(170, 110, 40, .16), rgba(170, 110, 40, 0) 40%),
    linear-gradient(180deg, var(--parch-1), var(--parch-2) 70%, var(--parch-3));
  box-shadow: inset 0 3px 8px rgba(90, 50, 10, .35), inset 0 0 0 2px rgba(255, 255, 255, .35);
  color: var(--parch-ink);
  font: 800 16px/1.35 var(--font);
  user-select: none;
  scrollbar-width: thin; scrollbar-color: #a86d2a rgba(120, 70, 20, .15);
}
.panel-body::-webkit-scrollbar { width: 10px; }
.panel-body::-webkit-scrollbar-track { background: rgba(120, 70, 20, .12); border-radius: 6px; }
.panel-body::-webkit-scrollbar-thumb { background: linear-gradient(#c58337, #8a4b1f); border-radius: 6px; border: 2px solid rgba(255, 243, 214, .7); }
.panel.flush .panel-body { padding: 0; overflow: hidden; }
.panel-foot {
  position: relative; z-index: 2;
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px;
  padding: 12px 4px 4px;
  flex: 0 0 auto;
}

/* confirm layer */
.panel-confirm .panel-body { text-align: center; }
.cf-box { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 4px; }
.cf-ic { width: 72px; height: 72px; }
.cf-text { margin: 0; font: 800 18px/1.35 var(--font); white-space: pre-line; }
.cf-foot .ui-btn { min-width: 130px; }

/* ---------- shared kit ---------- */
.pn-section { margin: 0 0 14px; }
.pn-h { margin: 0 0 8px; font: 900 19px/1.15 var(--font); color: var(--parch-ink); display: flex; align-items: center; gap: 8px; }
.pn-h .ic { width: 28px; height: 28px; }
.pn-card {
  position: relative;
  padding: 10px;
  border-radius: 14px; border: 3px solid #7a4a1c;
  background: linear-gradient(180deg, #fffaf0, #f7e6bd);
  box-shadow: inset 0 2px 0 #fff, 0 3px 0 #7a4a1c;
}
.pn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pn-row { display: flex; align-items: center; gap: 10px; }
.pn-bar { position: relative; height: 16px; border-radius: 9px; background: rgba(90, 50, 10, .2); border: 2px solid #7a4a1c; overflow: hidden; }
.pn-bar > i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(180deg, #8bf04f, #3fae1f); border-radius: 7px; }
.pn-empty { padding: 28px 12px; text-align: center; font: 900 18px/1.35 var(--font); color: rgba(74, 42, 16, .75); }
.pn-note { font: 800 14px/1.3 var(--font); color: rgba(74, 42, 16, .8); }
.pn-tag { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 8px; font: 900 12px/1.2 var(--font); color: #fff; text-shadow: var(--ts-sm); background: #7a4a1c; border: 2px solid var(--ink); }

/* ---------- responsive frame ---------- */
@media (max-height: 520px) {
  .modal { padding: calc(22px + var(--sat)) calc(12px + var(--sar)) calc(6px + var(--sab)) calc(12px + var(--sal)); }
  .panel { padding: 22px 8px 8px; border-radius: 18px; }
  .panel::before { inset: 4px; border-radius: 14px; }
  .panel .rivet { width: 10px; height: 10px; }
  .panel-l { height: 100%; }
  .panel-ribbon { top: -20px; padding: 3px 22px 5px; }
  .pr-title { font-size: 21px; }
  .pr-ic { width: 30px; height: 30px; margin: -6px 0 -6px -10px; }
  .panel-close { width: 44px; height: 44px; padding: 8px; top: -14px; right: -8px; }
  .panel-tabs { padding-bottom: 6px; }
  .gem-tab { height: 42px; min-width: 80px; }
  .gem-tab .gt-face { font-size: 14px; padding: 0 14px 2px; }
  .gem-tab .gt-ic { width: 26px; height: 26px; }
  .panel-body { padding: 10px; border-radius: 11px; }
  .panel-foot { padding-top: 8px; }
  .cf-ic { width: 52px; height: 52px; }
  .cf-text { font-size: 16px; }
}
@media (max-width: 600px) {
  .modal { padding: calc(28px + var(--sat)) calc(8px + var(--sar)) calc(8px + var(--sab)) calc(8px + var(--sal)); }
  .panel { padding: 26px 8px 8px; border-radius: 18px; }
  .panel::before { inset: 4px; border-radius: 14px; }
  .panel-l { height: 100%; }
  .panel-ribbon { max-width: calc(100% - 128px); padding: 4px 14px 6px; gap: 6px; }   /* the tails stay clear of the close button */
  .pr-title { font-size: 20px; }
  .pr-ic { width: 30px; height: 30px; margin: -6px 0 -6px -6px; }
  .panel-close { width: 46px; height: 46px; right: -6px; }
  .gem-tab { min-width: 64px; }
  .gem-tab .gt-face { padding: 0 12px 2px; }
  .panel-body { padding: 10px; }
  .pn-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
}
