/* Рамки в стиле baldursgate3.game (.frame / .frame__border / .frame__corner) */

:root {
    --bg3-frame-gold: #bf9875;
    --bg3-frame-brown: #604b38;
    --bg3-frame-light: #e1cbb7;
    --bg3-frame-inset: 10px;
    --bg3-frame-corner: 18px;
    --bg3-frame-corner-url: url("assets/bg3/svg/corner.svg");
    --bg3-frame-decor-url: url("assets/bg3/svg/frame-decor.svg");
    --bg3-frame-bar: linear-gradient(90deg, var(--bg3-frame-gold), var(--bg3-frame-brown) 50%, var(--bg3-frame-gold));
}

/* Хост: контент поверх декоративной рамки */
.bg3-frame-host {
    position: relative;
    isolation: isolate;
}

.bg3-frame-host > :not(.bg3-frame) {
    position: relative;
    z-index: 1;
}

/* Слой рамки (как .frame на сайте) */
.bg3-frame {
    position: absolute;
    left: var(--bg3-frame-inset);
    top: var(--bg3-frame-inset);
    width: calc(100% - var(--bg3-frame-inset) * 2);
    height: calc(100% - var(--bg3-frame-inset) * 2);
    pointer-events: none;
    z-index: 5;
}

/* Вертикали — .frame::before / ::after */
.bg3-frame__side {
    position: absolute;
    top: 8px;
    width: 1px;
    height: calc(100% - 16px);
    background: var(--bg3-frame-gold);
}

.bg3-frame__side--left {
    left: -10px;
}

.bg3-frame__side--right {
    right: -10px;
}

/* Горизонтали — .frame__border */
.bg3-frame__bar {
    position: absolute;
    left: 8px;
    width: calc(100% - 16px);
    height: 1px;
    background: var(--bg3-frame-bar);
}

.bg3-frame__bar--top {
    top: -10px;
}

.bg3-frame__bar--bottom {
    bottom: -10px;
    top: auto;
}

/* Углы — .frame__corner */
.bg3-frame__corner {
    position: absolute;
    width: var(--bg3-frame-corner);
    height: var(--bg3-frame-corner);
    background: var(--bg3-frame-corner-url) center / contain no-repeat;
}

.bg3-frame__corner--lt {
    left: -10px;
    top: -10px;
}

.bg3-frame__corner--rt {
    right: -10px;
    top: -10px;
    transform: scaleX(-1);
}

.bg3-frame__corner--lb {
    left: -10px;
    bottom: -10px;
    transform: scaleY(-1);
}

.bg3-frame__corner--rb {
    right: -10px;
    bottom: -10px;
    transform: scale(-1);
}

/* Декор сверху — .frame__decor */
.bg3-frame__decor {
    position: absolute;
    left: 50%;
    top: -20px;
    width: 120px;
    height: 18px;
    transform: translateX(-50%);
    background: var(--bg3-frame-decor-url) center / contain no-repeat;
    opacity: 0.95;
}

.bg3-frame__decor--bottom {
    top: auto;
    bottom: -20px;
    transform: translateX(-50%) scaleY(-1);
}

/* --- Главная форма: corner-small (FAQ) + рамка по периметру --- */
.foundry-app.bg3-frame-host {
  --bg3-card-corner-size: clamp(72px, 10vw, 94px);
  --bg3-card-border-width: 2px;
  --bg3-card-inset: 4px;
  --bg3-frame-gold: #b1906a;
  --bg3-frame-gold-mid: #c19976;
  --bg3-frame-gold-dark: #7a6952;
  padding: var(--bg3-card-inset);
  overflow: hidden;
  box-sizing: border-box;
  border: var(--bg3-card-border-width) solid var(--bg3-frame-gold-mid);
  border-radius: 0;
  box-shadow: 0 24px 80px var(--shadow);
  background: transparent;
}

.foundry-app.bg3-frame-host > .foundry-body {
  background:
    radial-gradient(ellipse at 50% 28%, rgba(122, 105, 82, 0.14), transparent 55%),
    radial-gradient(ellipse at 50% 80%, rgba(0, 0, 0, 0.35), transparent 50%),
    linear-gradient(168deg, #14110f 0%, #0a0908 42%, #100e0c 100%);
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.45);
}

/* inset: 0 — иначе при height:auto у .foundry-app слой height:100% схлопывается */
.foundry-app > .bg3-frame.bg3-frame--card {
  top: calc(-1 * var(--bg3-card-border-width));
  right: calc(-1 * var(--bg3-card-border-width));
  bottom: calc(-1 * var(--bg3-card-border-width));
  left: calc(-1 * var(--bg3-card-border-width));
  width: auto;
  height: auto;
  z-index: 8;
}

/* Прямые стороны — border на .foundry-app; здесь только уголки */
.bg3-frame--card .bg3-frame__edges,
.bg3-frame--card .bg3-frame__perimeter {
  display: none !important;
}

.bg3-frame.bg3-frame--card::before,
.bg3-frame.bg3-frame--card::after {
  content: none;
  display: none;
}

/* Углы — corner-small, привязка к вершине (как .box-frame__corner) */
.bg3-frame--card .bg3-frame__card-corner {
  position: absolute;
  width: var(--bg3-card-corner-size);
  height: var(--bg3-card-corner-size);
  background-repeat: no-repeat;
  background-size: var(--bg3-card-corner-size) var(--bg3-card-corner-size);
  pointer-events: none;
  z-index: 7;
}

.bg3-frame--card .bg3-frame__card-corner--tl {
  top: 0;
  left: 0;
  background-image: url("assets/bg3/svg/corner-small-left-top.svg");
  background-position: 0 0;
}

.bg3-frame--card .bg3-frame__card-corner--tr {
  top: 0;
  right: 0;
  background-image: url("assets/bg3/svg/corner-small-right-top.svg");
  background-position: 100% 0;
}

.bg3-frame--card .bg3-frame__card-corner--bl {
  bottom: 0;
  left: 0;
  background-image: url("assets/bg3/svg/corner-small-left-bottom.svg");
  background-position: 0 100%;
}

.bg3-frame--card .bg3-frame__card-corner--br {
  bottom: 0;
  right: 0;
  background-image: url("assets/bg3/svg/corner-small-right-bottom.svg");
  background-position: 100% 100%;
}

/* Простая рамка не используется на главной форме */
.bg3-frame--card .bg3-frame__side,
.bg3-frame--card .bg3-frame__bar,
.bg3-frame--card .bg3-frame__corner,
.bg3-frame--card .bg3-frame__decor {
    display: none !important;
}

/* --- Рамка секций: сайдбар, атрибуты, блоки внутри модалок (как «Класс брони») --- */
.sidebar .hitpoints.bg3-frame-host,
.sidebar .armor-class.bg3-frame-host,
.sidebar ul.saves.bg3-frame-host,
.sidebar .perception.bg3-frame-host,
.actions-section.bg3-frame-host,
.attributes-table-container.bg3-frame-host,
.item-details-modal .item-detail-description.bg3-frame-host,
.item-details-modal .item-detail-ancestry-mechanics.bg3-frame-host,
.item-details-modal .item-detail-activation.bg3-frame-host,
.item-details-modal .item-detail-stages.bg3-frame-host,
.item-details-modal .deity-lore-banner.bg3-frame-host,
.item-details-modal .deity-lore-stats.bg3-frame-host,
.item-details-modal .deity-detail-section.bg3-frame-host {
    --bg3-frame-inset: 8px;
    --bg3-frame-corner: 10px;
    --bg3-frame-edge-gap: 5px;
    padding: 14px 12px 12px;
    margin-top: 0;
    margin-bottom: 10px;
    border: none;
    border-radius: 0;
    background: rgba(0, 0, 0, 0.38);
    box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.35),
                inset 0 0 0 1px rgba(191, 152, 117, 0.38);
}

.item-details-modal .item-detail-description.bg3-frame-host,
.item-details-modal .item-detail-ancestry-mechanics.bg3-frame-host,
.item-details-modal .item-detail-activation.bg3-frame-host,
.item-details-modal .item-detail-stages.bg3-frame-host,
.item-details-modal .deity-lore-banner.bg3-frame-host,
.item-details-modal .deity-lore-stats.bg3-frame-host,
.item-details-modal .deity-detail-section.bg3-frame-host {
    margin-top: 12px;
    margin-bottom: 12px;
}

/* Без ветвистого декора сверху */
.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__decor,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__decor,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__decor,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__decor {
    display: none;
}

/* Компактные уголки и узкие границы */
.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__corner--lt,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__corner--lt,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__corner--lt,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__corner--lt {
    left: calc(-1 * var(--bg3-frame-edge-gap));
    top: calc(-1 * var(--bg3-frame-edge-gap));
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__corner--rt,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__corner--rt,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__corner--rt,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__corner--rt {
    right: calc(-1 * var(--bg3-frame-edge-gap));
    top: calc(-1 * var(--bg3-frame-edge-gap));
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__corner--lb,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__corner--lb,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__corner--lb,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__corner--lb {
    left: calc(-1 * var(--bg3-frame-edge-gap));
    bottom: calc(-1 * var(--bg3-frame-edge-gap));
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__corner--rb,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__corner--rb,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__corner--rb,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__corner--rb {
    right: calc(-1 * var(--bg3-frame-edge-gap));
    bottom: calc(-1 * var(--bg3-frame-edge-gap));
}

/* Узкие границы по периметру (без внутренней сетки) */
.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__side,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__side,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__side,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__side {
    top: var(--bg3-frame-edge-gap);
    height: calc(100% - var(--bg3-frame-edge-gap) * 2);
    width: 1px;
    opacity: 0.85;
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__side--left,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__side--left,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__side--left,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__side--left {
    left: calc(-1 * var(--bg3-frame-edge-gap));
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__side--right,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__side--right,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__side--right,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__side--right {
    right: calc(-1 * var(--bg3-frame-edge-gap));
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__bar,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__bar,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__bar,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__bar {
    left: var(--bg3-frame-edge-gap);
    width: calc(100% - var(--bg3-frame-edge-gap) * 2);
    height: 1px;
    opacity: 0.85;
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__bar--top,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__bar--top,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__bar--top,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__bar--top {
    top: calc(-1 * var(--bg3-frame-edge-gap));
}

.sidebar .bg3-frame-host > .bg3-frame .bg3-frame__bar--bottom,
.actions-section.bg3-frame-host > .bg3-frame .bg3-frame__bar--bottom,
.attributes-table-container.bg3-frame-host > .bg3-frame .bg3-frame__bar--bottom,
.item-details-modal .bg3-frame-host > .bg3-frame .bg3-frame__bar--bottom {
    bottom: calc(-1 * var(--bg3-frame-edge-gap));
}

/* --- Модальные окна: сплошная рамка, без декоративных уголков --- */
.attributes-details-modal-content,
.ability-details-modal-content,
.modifiers-modal-content,
.item-details-modal-content,
.detail-modal-content,
.modal-resizable-content.attributes-details-modal-content,
.modal-resizable-content.ability-details-modal-content,
.modal-resizable-content.spell-preparation-modal-content {
    box-sizing: border-box;
    border: var(--bg3-card-border-width, 2px) solid var(--bg3-frame-gold-mid, #c19976) !important;
    border-radius: 4px;
}

.attributes-details-modal-content.bg3-frame-host > .bg3-frame,
.ability-details-modal-content.bg3-frame-host > .bg3-frame,
.modifiers-modal-content.bg3-frame-host > .bg3-frame,
.item-details-modal-content.bg3-frame-host > .bg3-frame,
.detail-modal-content.bg3-frame-host > .bg3-frame {
    display: none !important;
}

.attributes-details-modal-content > .modal-resize-handle,
.ability-details-modal-content > .modal-resize-handle,
.item-details-modal-content > .modal-resize-handle,
.modifiers-modal-content > .modal-resize-handle {
    z-index: 40;
}

/* Вкладки — разделитель как .divider-body на сайте */
.foundry-tabs-container {
    border-bottom: none;
    position: relative;
}

.foundry-tabs-container::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, #896d51 20%, #553c22 50%, #896d51 80%, transparent);
    pointer-events: none;
}

/* Шапка — нижняя линия-градиент */
.foundry-header::after {
    content: "";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 0;
    height: 1px;
    background: var(--bg3-frame-bar);
}

.foundry-header {
    position: relative;
}

/* Портрет — рамка с углами */
.avatar-upload-label.bg3-frame-host {
    --bg3-frame-inset: 6px;
    --bg3-frame-corner: 14px;
    border: none;
}

.avatar-upload-label.bg3-frame-host .bg3-frame__decor {
    display: none;
}

/* Блок «Мод. атрибутов» — без скролла (рамка в общем блоке выше) */
.attributes-table-container.bg3-frame-host {
    overflow: hidden;
    box-sizing: border-box;
}

.actions-section.bg3-frame-host {
    margin-bottom: 14px;
    overflow: hidden;
    box-sizing: border-box;
}

@media (max-width: 900px) {
  .foundry-app.bg3-frame-host {
    --bg3-card-corner-size: 72px;
  }
}
