/* Reference Panel — reusable overlay modal
   Include this CSS on any page that includes scripts/refpanel.js */

#ref-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 600;
}
#ref-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.82);
}
#ref-card {
  position: relative;
  width: min(640px, 96vw);
  max-height: 92vh;
  border: 3px solid #8a6a2a;
  border-radius: 8px;
  box-shadow: 0 0 50px rgba(0,0,0,0.95);
  background: #0e0c06;
  font-family: 'Skranji', serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}
#ref-card.hero-layout {
  width: min(640px, 96vw);
}
#ref-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 34px;
  height: 34px;
  padding: 0;
  font-family: verdana, sans-serif;
  font-size: 24px;
  line-height: 30px;
  text-align: center;
  background: rgba(28,22,10,0.92);
  color: #c8a84b;
  border: 1px solid rgba(106,82,40,0.92);
  border-radius: 50%;
  cursor: pointer;
  z-index: 5;
  box-shadow: 0 2px 10px rgba(0,0,0,0.32);
}
#ref-close:hover { background: rgba(42,32,16,0.96); border-color: #c8a84b; }

/* Tab row — styled like party portrait slots */
#ref-tabs {
  display: flex;
  justify-content: center;
  gap: 10px;
  padding: 12px 56px 8px 12px;
  background: linear-gradient(to bottom, rgba(184,136,42,0.25), transparent);
  border-bottom: 2px solid #5a4010;
  flex-shrink: 0;
}
.ref-tab {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid #5a4010;
  background: #110e04;
  box-shadow: inset 0 0 10px rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
  padding: 0;
  position: relative;
  overflow: hidden;
}
.ref-tab img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  opacity: 0.82;
  transition: opacity 0.2s, transform 0.2s;
}
.ref-tab span {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 5px;
  z-index: 1;
  font-size: 9px;
  color: #d8bf7a;
  font-family: 'Skranji', serif;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  transition: color 0.2s;
  text-align: center;
  text-shadow: 0 1px 2px rgba(0,0,0,0.95);
  line-height: 1.1;
  pointer-events: none;
}
.ref-tab:hover {
  border-color: #9a7830;
  box-shadow: 0 0 10px rgba(200,168,75,0.3), inset 0 0 10px rgba(0,0,0,0.6);
}
.ref-tab:hover img {
  opacity: 0.98;
  transform: scale(1.03);
}
.ref-tab:hover span { color: #c8a84b; }
.ref-tab.active {
  border-color: #c8a84b;
  box-shadow: 0 0 14px rgba(200,168,75,0.55), inset 0 0 10px rgba(0,0,0,0.6);
}
.ref-tab.active img { opacity: 1; }
.ref-tab.active span { color: #e8d090; }

/* Select dropdown bar */
#ref-select-bar {
  padding: 8px 14px;
  background: rgba(42,26,8,0.85);
  border-bottom: 1px solid #3a2e10;
  flex-shrink: 0;
}
#ref-select {
  width: 100%;
  background: #1a1206;
  border: 1px solid #6a5228;
  color: #e0c070;
  font-family: 'Skranji', serif;
  font-size: 14px;
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  outline: none;
}
#ref-select option { background: #1a1206; color: #e0c070; }

/* Content area */
#ref-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}
#ref-content.is-treasure {
  display: block;
}
#ref-portrait-wrap {
  width: 160px;
  flex-shrink: 0;
  background: #080604;
  border-right: 1px solid #3a2e10;
  overflow: hidden;
  align-self: stretch;
}
#ref-portrait-wrap.is-monster {
  width: 240px;
  height: 240px;
  align-self: flex-start;
}
#ref-portrait-wrap.is-treasure {
  width: auto;
  height: auto;
  border-right: none;
  border-bottom: 1px solid #3a2e10;
  background: #120d05;
}
#ref-portrait {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
}
#ref-portrait-wrap.is-monster #ref-portrait {
  object-position: center center;
}
#ref-portrait-wrap.is-treasure #ref-portrait {
  width: 100%;
  height: auto;
  max-height: 420px;
  object-fit: contain;
  object-position: center center;
}
#ref-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  color: #c8b878;
  font-size: 13px;
  font-family: verdana, sans-serif;
  line-height: 1.55;
  background: #0e0c06;
  min-width: 0;
}
#ref-card.hero-layout #ref-body {
  padding: 18px 20px;
}
#ref-card.monster-layout #ref-body {
  padding: 0;
  min-height: 520px;
  display: block;
}
#ref-body p { margin: 0 0 8px; }
#ref-body h1, #ref-body h2, #ref-body h3 { font-family: 'Skranji', serif; color: #e8d090; margin: 8px 0 6px; }
#ref-body ul { margin: 4px 0 8px 18px; padding: 0; }
#ref-body table { border-collapse: collapse; font-size: 12px; margin: 6px 0; }
#ref-body td, #ref-body th { border: 1px solid #4a3a18; padding: 4px 8px; color: #b8a868; }

.ref-item-title {
  font-family: 'Skranji', serif;
  font-size: 18px;
  color: #e8d090;
  border-bottom: 1px solid #5a4010;
  padding-bottom: 5px;
  margin-bottom: 10px !important;
}
.ref-loading { color: #8a7040; font-style: italic; }
.ref-mono-meta { color: #9a8040; font-size: 12px; margin-bottom: 6px !important; }
.ref-top-layout {
  display: flex;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 12px;
}
.ref-top-media {
  width: min(260px, 32%);
  flex: 0 0 min(260px, 32%);
  background: #080604;
  border: 1px solid #3a2e10;
  border-radius: 6px;
  padding: 8px;
}
.ref-top-image {
  width: 100%;
  height: auto;
  max-height: 280px;
  object-fit: contain;
  object-position: top left;
  display: block;
}
.ref-top-image-skill {
  max-height: 220px;
  object-position: center center;
}
.ref-top-copy {
  flex: 1 1 auto;
  min-width: 0;
}

/* Cast table (skills / lore) */
.ref-cast-table { margin: 8px 0; border-top: 1px solid #3a2e10; padding-top: 6px; }
.ref-cast-row { margin-bottom: 4px; font-size: 12px; }
.ref-cast-label { color: #cc6060; font-weight: bold; }

/* Stone results row */
.ref-stones {
  display: flex;
  gap: 4px;
  flex-wrap: nowrap;
  margin-top: 8px;
  border-top: 1px solid #3a2e10;
  padding-top: 8px;
}
.ref-stone {
  flex: 1;
  min-width: 0;
  padding: 5px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: #fff8e0;
  line-height: 1.4;
  text-shadow: 1px 1px 2px #000;
  word-break: break-word;
}
.ref-stone.red   { background: rgba(140,40,40,0.7);  border: 1px solid #cc4444; }
.ref-stone.green { background: rgba(40,100,40,0.7);  border: 1px solid #44aa44; }
.ref-stone.blue  { background: rgba(40,60,140,0.7);  border: 1px solid #4466cc; }
.ref-stone.black { background: rgba(40,40,40,0.75);  border: 1px solid #888; }
.ref-stone-icon  { height: 30px; width: auto; vertical-align: middle; margin: 1px; }
.ref-skill-stone-title {
  font-family: 'Skranji', serif;
  font-size: 12px;
  color: #fff8e0;
  margin-bottom: 0;
  text-transform: uppercase;
}
.ref-skill-stone {
  position: relative;
}
.ref-skill-stone-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  min-height: 32px;
}
.ref-skill-stone-icon {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(0,0,0,0.45);
}
.ref-skill-row {
  margin-bottom: 8px;
}
.ref-skill-row:last-child {
  margin-bottom: 0;
}
.ref-skill-row-label {
  display: inline-block;
  min-width: 52px;
  color: #ffe8a8;
  font-weight: bold;
}
.ref-skill-row p,
.ref-skill-row ul {
  margin-top: 4px;
  margin-bottom: 4px;
}
.ref-skill-inline-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ref-skill-inline-row {
  align-items: flex-start;
}
.ref-skill-inline-outcomes {
  flex: 1;
  min-width: 0;
  color: #e8d8a8;
  line-height: 1.45;
}
.ref-skill-inline-item {
  display: inline;
  margin-right: 12px;
}
.ref-skill-inline-label {
  color: #ffe8a8;
  font-weight: bold;
}
.ref-skill-inline-item p,
.ref-skill-inline-item ul,
.ref-skill-inline-item li {
  display: inline;
  margin: 0;
  padding: 0;
}
.ref-monster-panel {
  min-height: 520px;
  display: block;
}
.ref-monster-stage {
  min-height: 520px;
  display: block;
  width: 100%;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}
.ref-monster-topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  z-index: 3;
}
.ref-monster-common {
  display: flex;
  align-items: flex-start;
  gap: 0;
  min-width: 0;
  flex-wrap: wrap;
}
.ref-monster-common .ref-stone-icon {
  height: 34px;
  margin-right: 0;
}
.ref-monster-desc-link {
  position: relative;
  background: rgba(12, 9, 5, 0.58);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.34);
  flex-shrink: 0;
}
.ref-monster-strips {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: row;
  gap: 2px;
  padding: 8px 8px 10px;
  background: linear-gradient(180deg, rgba(12, 9, 5, 0) 0%, rgba(12, 9, 5, 0.18) 16%, rgba(12, 9, 5, 0.52) 42%, rgba(12, 9, 5, 0.86) 100%);
  pointer-events: none;
}
.ref-monster-strip {
  display: flex;
  flex: 1 1 0;
  min-width: 0;
  padding: 1px 2px;
  pointer-events: auto;
  border-radius: 2px;
  font-size: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.32);
  opacity: 1;
  flex-wrap: wrap;
  align-content: flex-start;
}
.ref-monster-strip.red   { background: rgba(140,40,40,0.35); }
.ref-monster-strip.green { background: rgba(40,100,40,0.35); }
.ref-monster-strip.blue  { background: rgba(40,60,140,0.35); }
.ref-monster-strip.black { background: rgba(40,40,40,0.38); }
.ref-monster-strip .ref-stone-icon {
  height: 34px;
  margin-right: 0;
}

.ref-hero-header {
  margin-bottom: 14px;
}
.ref-hero-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ref-hero-title-row .ref-item-title {
  flex: 1;
  margin-bottom: 0 !important;
}
.ref-hero-title-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  opacity: 0.95;
}
.ref-hero-title-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.ref-hero-overlay {
  background: transparent;
  border: 1px solid rgba(58, 46, 16, 0.38);
  border-radius: 8px;
  padding: 12px;
  box-shadow: none;
}
.ref-hero-skill-list {
  padding-top: 6px;
}
.ref-battle-roster {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ref-battle-roster-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(90, 64, 16, 0.7);
  border-radius: 8px;
  background: rgba(180,140,80,0.1);
}
.ref-battle-roster-name {
  color: #e8d090;
  font-family: 'Skranji', serif;
  font-size: 15px;
  line-height: 1.2;
  flex: 0 0 180px;
}
.ref-battle-roster-icons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex: 1 1 auto;
  flex-wrap: wrap;
}
.ref-battle-roster-icon {
  width: 30px;
  height: 30px;
  object-fit: contain;
  display: block;
}
.ref-hero-skill-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,200,80,0.2);
  background: rgba(0,0,0,0.1);
  border-radius: 4px;
  margin-bottom: 4px;
}
.ref-hero-skill-icon {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  cursor: pointer;
}
.ref-hero-skill-name {
  flex: 1;
  font-weight: bold;
  font-size: 13px;
  color: #fff8e0;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.78), 0 0 5px rgba(0,0,0,0.55);
}
.ref-hero-skill-val {
  min-width: 28px;
  text-align: center;
  font-family: 'Skranji', serif;
  font-size: 20px;
  color: #ffe080;
  text-shadow: 1px 1px 2px rgba(0,0,0,0.78), 0 0 5px rgba(0,0,0,0.55);
}
#ref-desc-pop {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(0,0,0,0.68);
  display: flex;
  justify-content: center;
  align-items: center;
}
#ref-desc-card {
  width: min(420px, 88vw);
  max-height: 72vh;
  background: rgba(20,14,8,0.96);
  border: 2px solid #8a6a2a;
  border-radius: 8px;
  box-shadow: 0 0 40px rgba(0,0,0,0.85);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#ref-desc-title {
  padding: 10px 14px;
  background: linear-gradient(to bottom, rgba(184,136,42,0.35), rgba(42,26,8,0.92));
  border-bottom: 1px solid #5a4010;
  color: #e8d090;
  font-family: 'Skranji', serif;
  font-size: 18px;
}
#ref-desc-text {
  padding: 14px;
  color: #d8c88f;
  font-size: 14px;
  line-height: 1.6;
  overflow-y: auto;
  white-space: pre-wrap;
}
#ref-desc-footer {
  padding: 10px;
  border-top: 1px solid #3a2e10;
  background: rgba(42,26,8,0.9);
  text-align: center;
}
#ref-desc-close {
  font-family: 'Skranji', serif;
  background: #1c160a;
  color: #c8a84b;
  border: 1px solid #6a5228;
  border-radius: 6px;
  padding: 8px 28px;
  font-size: 0.95em;
  cursor: pointer;
}
#ref-desc-close:hover {
  background: #2a2010;
  border-color: #c8a84b;
}

@media (max-width: 760px) {
  #ref-card.hero-layout {
    width: min(640px, 96vw);
  }
  .ref-top-layout {
    display: block;
  }
  .ref-top-media {
    width: 100%;
    max-width: 260px;
    margin: 0 auto 12px;
  }
  .ref-stones {
    flex-wrap: wrap;
  }
  .ref-battle-roster-row {
    align-items: flex-start;
    flex-direction: column;
  }
  .ref-battle-roster-name {
    flex-basis: auto;
  }
  .ref-battle-roster-icons {
    justify-content: flex-start;
  }
}
