/* Frames, parchment and crest from Wildbound UI by lucco2912.
   Navigation and heading icons from Free Medieval Fantasy UI Pack. */
:root {
  --base: #0e0c16;
  --panel: #191422;
  --line: #483653;
  --text: #f2eafa;
  --muted: #bdb0ce;
  --gold: #d7b7ff;
  --darkgold: #2d2041;
  --rpg-accent: #d7b7ff;
  --rpg-text: #f2eafa;
  --rpg-edge: #68517e;
  --rpg-surface: linear-gradient(130deg, #1c1527ed, #0e0c16f5),
    url("theme/walnut.png") left top / 64px 64px, #211a30;
  --rpg-frame: url("theme/carved-frame.png") 33 / 11px round;
  --rpg-paper: url("theme/book-page.png") 19 fill / 9px stretch;
}

body {
  background: radial-gradient(ellipse at 40% 0, #251936, #14111d 45%, #0c0b12 90%);
}

body > header {
  background: var(--rpg-surface);
  border-color: var(--rpg-edge);
  box-shadow: 0 3px 0 #08060b66;
}

.brand { color: var(--rpg-text); }
.brand .logo {
  background: url("theme/crest.png") center / 42px 42px no-repeat;
  border: 0;
  image-rendering: pixelated;
}

body > header nav button {
  color: #cec1e2;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  gap: 5px;
}

body > header nav .current,
body > header nav button:hover,
.view-buttons button[aria-pressed="true"] {
  background: #3e2958;
  border-color: #8d64b8;
  color: var(--rpg-text);
}

body > header nav button::before,
.dock-heading h2::before,
#initiativeDrawer summary strong::before {
  content: "";
  display: inline-block;
  width: 22px;
  height: 22px;
  flex: none;
  vertical-align: -.15em;
  background: var(--rpg-icon) center / contain no-repeat;
  image-rendering: pixelated;
}

[data-tab="table"] { --rpg-icon: url("theme/map.png"); }
[data-tab="characters"] { --rpg-icon: url("theme/character.png"); }
[data-tab="library"] { --rpg-icon: url("theme/book.png"); }
[data-tab="macros"],
.dock-macros { --rpg-icon: url("theme/wand.png"); }
[data-tab="tokenLibrary"] { --rpg-icon: url("theme/helmet.png"); }
.dock-actions { --rpg-icon: url("theme/quill.png"); }
#initiativeDrawer { --rpg-icon: url("theme/sword.png"); }

.dock-heading h2::before,
#initiativeDrawer summary strong::before { margin-right: 5px; }

.heading h1 {
  color: var(--rpg-text);
  text-shadow: 0 2px 7px #090611b0;
}

.heading .eyebrow {
  color: var(--rpg-accent);
  font-family: Cinzel, Georgia, serif;
}

.view-buttons button,
.map-foot button,
.table-dock :is(button, select),
.combat-drawers button {
  background-color: #251c35;
  border-color: #584269;
}

.view-buttons button:hover,
.map-foot button:hover,
.table-dock :is(button, select):hover,
.combat-drawers button:hover {
  border-color: #aa84d0;
}

.map-panel {
  background: var(--rpg-surface);
  border: 7px solid #4a5140;
  border-radius: 0;
  border-image: url("theme/stone-frame.png") 14 / 7px round;
  box-shadow: 0 12px 26px #08060390;
}

.map-head {
  border-bottom: 1px solid #5c4774;
  color: var(--rpg-text);
}

.map-head strong { font: 21px 'Instrument Serif', Georgia, serif; }
.map-foot { border-top: 1px solid #5c4774; }
.map-head span, .map-foot { color: #c9bdd8; }

.maptools {
  background: linear-gradient(#2a203aee, #120e1eea);
  border-color: #8d70a4;
  border-radius: 5px;
}

.maptools .active {
  background: #493061;
  border-color: #8d64b8;
}

.panel,
body > dialog {
  background: var(--rpg-surface);
  color: var(--rpg-text);
  border: 1px solid var(--rpg-edge);
  border-radius: 0;
  border-image: var(--rpg-frame);
  box-shadow: 0 7px 17px #08060370;
}

.table-dock { padding: 13px; }
.table-dock > .dock-actions { border-color: #4d3b63; }
.combat-drawers > details { padding: 13px; }

#rolls, .party-card, #collections .record {
  background: #171222;
  border: 1px solid #514166;
  border-radius: 4px;
}

.table-dock .primary,
.combat-drawers .primary,
#collections .primary,
body > dialog .primary,
#primeButton {
  color: #1b1228;
  background: #c8a2f3;
  border-color: #dcc0ff;
}

.table-dock .primary:hover,
.combat-drawers .primary:hover,
#collections .primary:hover,
body > dialog .primary:hover,
#primeButton:hover {
  color: #1b1228;
  background: #dbbbff;
}

/* The page uses the book sprite as a nine-slice to preserve its edges. */
#characterDialog {
  background: var(--rpg-surface);
  border-color: var(--rpg-edge);
}

.character-header h2 { color: var(--rpg-text); }

#sheetTabs {
  border-bottom-color: var(--rpg-edge);
  background: url("theme/divider.png") right bottom / 128px 8px no-repeat;
}

#sheetTabs button {
  color: #e0d2f0;
  background: #211a30;
  border-color: var(--rpg-edge);
}

#sheetTabs button:hover { color: #fbf4ff; }

#sheetTabs [aria-pressed="true"] {
  color: #1b1228;
  background: #c8a2f3;
  border-color: #dcc0ff;
}

#characterIdentity,
#characterDialog .sheet-card {
  --rpg-ink: #321e13;
  --rpg-ink-muted: #5c4028;
  --rpg-paper-edge: #a47f4b;
  color: var(--rpg-ink);
  color-scheme: light;
  background: #e9cf9c;
  border: 1px solid var(--rpg-paper-edge);
  border-radius: 0;
  border-image: var(--rpg-paper);
  padding: 11px;
}

#characterDialog .sheet-card h3 {
  color: #502a19;
  border-bottom: 1px solid #a47f4b99;
  padding-bottom: 3px;
}

#characterDialog :is(.sheet-card, #characterIdentity) :is(label, .muted) {
  color: var(--rpg-ink-muted);
}

#characterDialog :is(.sheet-card, #characterIdentity) :is(input, select, textarea) {
  color: var(--rpg-ink);
  background: #f7e5c0;
  border-color: var(--rpg-paper-edge);
  accent-color: #794629;
}

#characterDialog :is(.sheet-card, #characterIdentity) :is(input, textarea)::placeholder {
  color: #70573d;
}

#characterDialog .sheet-card :is(.sheet-ability, .sheet-list-row, .sheet-action-row) {
  border-color: #a47f4b99;
}

#characterDialog .sheet-card :is(.sheet-computed output, .sheet-skill button, .sheet-action-row button, .sheet-list-row button, .outline) {
  color: var(--rpg-ink);
  background: #dfbd84;
  border-color: var(--rpg-paper-edge);
}

#characterDialog .sheet-card .sheet-check output { color: #70381c; }

#characterDialog .sheet-card :is(button:hover, .sheet-expertise[aria-pressed="true"]) {
  color: #fff1ce;
  background: #754325;
  border-color: #69391f;
}

#characterDialog :is(.sheet-card, #characterIdentity) :focus-visible {
  outline: 2px solid #754325;
  outline-offset: 1px;
}

@media (max-width: 550px) {
  body > header nav button::before { display: none; }
  .map-panel { border-width: 5px; border-image-width: 5px; }
  .table-dock { padding: 11px; }
  #sheetTabs { background-image: none; }
}

.spell-catalog-picker,
#spellCastForm {
  display: grid;
  gap: 8px;
}
.spell-search-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(115px, auto);
  gap: 7px;
  align-items: end;
}
.spell-matches {
  display: grid;
  gap: 4px;
  max-height: 190px;
  overflow: auto;
}
.spell-matches:empty { display: none; }
.spell-match {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  text-align: left;
  gap: 3px 12px;
  padding: 6px 8px;
}
.spell-match small { color: #cec1e2; }
#spellCastForm select {
  background: #171222;
  border: 1px solid var(--rpg-edge);
  border-radius: 5px;
  color: inherit;
  font: inherit;
  padding: 7px;
}
#spellCastPreview { color: var(--rpg-accent); }
#spellCastRules { margin: 0; white-space: pre-line; }
@media (max-width: 380px) {
  .spell-search-fields { grid-template-columns: minmax(0, 1fr); }
}

.collection-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 6px;
}
.popout-window { padding: 10px; }
.popout-window #characterDialog {
  position: static;
  margin: 0;
  width: 100%;
  max-height: none;
}
.popout-library,
.popout-reader { padding: 16px; }
.popout-books {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}
.popout-books .record { flex-wrap: wrap; }
.popout-reader {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  height: calc(100dvh - 20px);
}
.popout-reader iframe {
  display: block;
  height: 100%;
  margin: 0;
  background: #171222;
}
#reader .panel-head,
.popout-reader .panel-head { flex-wrap: wrap; }
#reader h2,
.popout-reader h2 { overflow-wrap: anywhere; }

/* Campaign menu */
.campaign-menu {
  --menu-image: url("map.webp");
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr;
  align-items: center;
  padding: clamp(18px, 4vw, 60px) clamp(20px, 7vw, 110px);
  background-color: #130f20;
  background-image: linear-gradient(90deg, #0c0815fa, #140e2080 56%, #120f2060),
    linear-gradient(0deg, #0c0916d9 0%, transparent 55%), var(--menu-image);
  background-size: cover;
  background-position: center;
}
.menu-tools {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  align-self: start;
}
.menu-tools button {
  background: #1c1429df;
  border-color: #72578b;
  color: #f2eafa;
}
.menu-inner {
  width: min(100%, 560px);
  padding: clamp(24px, 4.5vw, 80px) 0;
}
.menu-brand img {
  display: block;
  image-rendering: pixelated;
  margin: 0 0 12px -4px;
}
.menu-brand h1 {
  color: #fbf3ff;
  font: 700 clamp(2.4rem, 6vw, 5rem)/.98 Cinzel, Georgia, serif;
  text-shadow: 0 3px 18px #0a0613;
  margin: 0 0 28px;
}
.menu-brand h1 span {
  display: block;
  font-size: .43em;
  letter-spacing: .08em;
  margin-bottom: .35em;
  color: #dbc0fb;
}
.campaign-panel {
  padding: clamp(16px, 3vw, 24px);
  box-shadow: 0 13px 40px #06030dcc;
}
.campaign-panel h2 { font-size: 2rem; }
.campaign-list {
  display: grid;
  gap: 7px;
  margin: 12px 0 18px;
  max-height: 36vh;
  overflow: auto;
  padding: 3px;
}
.campaign-list .muted { margin: 6px; }
.campaign-link {
  min-width: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  text-decoration: none;
  background: #241a37;
  border: 1px solid #60467a;
  border-radius: 5px;
}
.campaign-link:hover { background: #33234a; }
.campaign-link strong { overflow-wrap: anywhere; }
.campaign-link span { color: #dfc5ff; font-size: .875rem; }
.new-campaign-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  align-items: end;
  border-top: 1px solid #4e3d62;
  padding-top: 14px;
}
.new-campaign-form input { background: #110d1b; }
.campaign-panel .primary {
  background: #c8a2f3;
  border-color: #dcc0ff;
  color: #1b1228;
  padding: 9px 12px;
}
.campaign-panel .primary:hover { background: #dbbbff; }
#campaignMenuStatus { color: #e2c9ff; margin: 12px 0 0; }
.menu-local { font-size: .875rem; color: #ddd0e9; margin: 12px 0 0; }
#campaignMenuLink { color: #e5ccff; white-space: nowrap; }
#campaignHeader { flex-wrap: wrap; height: auto; min-height: 73px; padding-block: 9px; }
#campaignHeader .brand { font-size: clamp(1.1rem, 2vw, 1.6rem); max-width: 100%; white-space: normal; }
#campaignHeader nav { max-width: 100%; overflow: auto; }
#board.blank-board { background-color: #20172e; }
.outline:not(.token-stat-button) { background-color: #241a33; }
@media (max-width: 550px) {
  .campaign-menu { background-position: 61% center; }
  .new-campaign-form { grid-template-columns: minmax(0, 1fr); }
  .campaign-list { max-height: 40vh; }
}

#characterDialog .magic-item-picker {
  margin-bottom: 5px;
}
#characterDialog .magic-item-picker summary {
  cursor: pointer;
}
#characterDialog .magic-item-picker > label,
#characterDialog .magic-item-picker > .spell-matches,
#characterDialog .magic-item-credit {
  margin-top: 7px;
}
#characterDialog .magic-item-credit {
  display: block;
}
#characterDialog .magic-item-picker .spell-match {
  align-items: start;
  color: var(--rpg-ink);
  background: #f7e5c0;
  border-color: var(--rpg-paper-edge);
}
#characterDialog .magic-item-picker .spell-match:hover,
#characterDialog .magic-item-picker .spell-match:focus-visible {
  background: #fdf0d4;
}
#characterDialog .magic-item-picker .spell-match small {
  color: var(--rpg-ink-muted);
}
#characterDialog .sheet-item-details {
  flex: 1 0 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2px 8px;
}
#characterDialog :is(.sheet-item-details, .magic-item-credit) a {
  color: #512f70;
}

#characterDialog .item-search-result .spell-match {
  width: 100%;
}
#characterDialog .item-description {
  min-width: 0;
  flex-basis: 100%;
  padding: 4px 6px;
  border: 1px solid var(--rpg-paper-edge);
  border-radius: 4px;
}
#characterDialog .item-search-result .item-description {
  margin: 3px 0;
}
#characterDialog .item-description summary {
  color: #512f70;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}
#characterDialog .item-description-panel {
  max-height: 36vh;
  overflow: auto;
  margin: 5px 0;
}
#characterDialog .item-description-panel p {
  margin: 0 0 5px;
}
#characterDialog .item-description-text {
  font-size: .9rem;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.dock-dice .dock-heading h2::before { display: none; }
.dice-visual-toggle {
  white-space: nowrap;
}
.dice-visual-toggle input {
  width: auto;
  accent-color: var(--rpg-accent);
}
body:has(#campaignWorkspace:not([hidden])) {
  background: linear-gradient(#120b19a0, #100a16dc), url("theme/tavern-table.webp") center top / cover fixed;
}
.tavern-table-layout:has(#table[hidden]) { display: none; }
.tavern-roll-rail { display: none; }
.tavern-roll-rail,
.tavern-tray-pop {
  background-image: url("theme/tavern-table.webp");
  background-repeat: no-repeat;
}
@media (min-width: 1100px) {
  #campaignWorkspace:has(#table:not([hidden])) { max-width: 1760px; }
  .tavern-table-layout {
    display: grid;
    grid-template-columns: clamp(150px, 16vw, 245px) minmax(0, 1fr);
    gap: 14px;
    align-items: start;
  }
  .tavern-roll-rail {
    display: block;
    position: sticky;
    top: 10px;
    aspect-ratio: 430 / 1024;
    background-size: 357.2093% 100%;
    background-position: left top;
    border-radius: 6px;
    overflow: hidden;
  }
}
.tavern-dice-bed {
  position: absolute;
  inset: 35.5% 17.5% 28% 12.5%;
  display: grid;
  place-items: center;
  overflow: hidden;
  pointer-events: none;
}
.tavern-tray-pop {
  position: fixed;
  z-index: 25;
  inset: auto auto 12px 12px;
  width: min(55vw, 252px);
  aspect-ratio: 392 / 490;
  background-size: 391.8367% 208.9796%;
  background-position: .8741% 56.7416%;
  border-radius: 10%;
  clip-path: polygon(7% 0, 93% 0, 100% 8%, 100% 92%, 93% 100%, 7% 100%, 0 92%, 0 8%);
  pointer-events: none;
}
.tavern-tray-pop .tavern-dice-bed { inset: 11% 11% 12%; }
.dice-visual-layer {
  display: grid;
  grid-template-columns: repeat(var(--dice-columns), minmax(0, 1fr));
  justify-items: center;
  align-items: end;
  gap: 2px;
  width: 100%;
  color: #f6ebff;
  text-shadow: 0 1px 2px #110714, 0 0 6px #110714;
  pointer-events: none;
}
.dice-visual-tile { min-width: 0; width: 100%; text-align: center; }
.dice-visual-models { display: flex; justify-content: center; }
.dice-visual-models canvas {
  display: block;
  width: 100%;
  max-width: 72px;
  min-width: 0;
  height: auto;
  filter: drop-shadow(0 4px 4px #0b0514);
}
.dice-visual-models:has(canvas + canvas) canvas { width: 50%; }
.dice-visual-layer:not(.settled) canvas {
  animation: dice-bounce 1.05s ease-out both;
}
@keyframes dice-bounce {
  0% { transform: translate(-14px, -22px) scale(.82); }
  40% { transform: translate(5px, 7px) scale(1.05); }
  62% { transform: translate(-2px, -5px); }
  82% { transform: translate(1px, 2px); }
  100% { transform: translate(0, 0); }
}
.dice-visual-tile span {
  display: inline-block;
  padding: 1px 0;
  font-size: clamp(.6rem, .8vw, .8rem);
  font-weight: 700;
  color: #e1c6ff;
  overflow-wrap: anywhere;
}
.dice-visual-layer:not(.settled) .dice-visual-tile span { visibility: hidden; }
.dice-visual-layer.settled .dice-visual-tile span { color: #fff2ff; }
.dice-visual-layer > p {
  grid-column: 1 / -1;
  margin: 3px 0 0;
  color: #e1c6ff;
  text-align: center;
  font-size: .85rem;
}
@media (prefers-reduced-motion: reduce) {
  .dice-visual-layer canvas { animation: none; }
}

#diceStyleButton { margin: 0 0 8px; }
#diceStyleDialog { max-height: 92vh; overflow: auto; }
#diceStyleDialog .dice-style-preview {
  display: flex;
  justify-content: center;
  gap: 12px;
}
#diceStyleDialog canvas {
  width: 96px;
  height: 96px;
  filter: drop-shadow(0 4px 4px #0b0514);
}
.dice-style-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.dice-style-fields input[type="color"] {
  min-height: 38px;
  padding: 2px;
  cursor: pointer;
}
.dice-style-help { margin: 5px 0 12px; }
.dice-style-actions { margin-top: 10px; flex-wrap: wrap; }
