/* The selected page hue also colours the working panels. Keep the shared
   --panel/--line tokens unchanged: Skills and the Battle sculpture use them.
   Grey keeps the original panel surfaces from before theme colouring. */
:root {
  /* Grey's ground is #0b0b0b, its panels #1b1a18 / #1d1c19.
     Apply that same +16/+15/+13 (nested +18/+17/+14) shade step
     to every coloured theme's base, rather than reusing its dark ground. */
  --theme-panel: rgb(from var(--page-ground, var(--bg)) calc(r + 16) calc(g + 15) calc(b + 13));
  --theme-panel-inset: rgb(from var(--page-ground, var(--bg)) calc(r + 18) calc(g + 17) calc(b + 14));
  --theme-background: color-mix(in srgb, var(--page-ground, var(--bg)) 82%, #000);
  --theme-panel-edge: color-mix(in srgb, var(--page-ground, var(--bg)) 35%, var(--line));
}

/* Retain the chosen page grounds; panels now use Grey's lighter shade step. */
html[data-background-theme="brown"],
html[data-background-theme="green"] {
  --theme-background: color-mix(in srgb, var(--page-ground, var(--bg)) 94%, #000);
}
html[data-background-theme]:where(:not([data-background-theme="grey"])) body {
  background: var(--theme-background);
}

/* Explicit outer surfaces exclude the entire skill tree and every piece of
   the Battle canvas, including its transparent portrait/stone apertures. */
html[data-background-theme]:where(:not([data-background-theme="grey"])) .shell > .grid > .panel,
html[data-background-theme]:where(:not([data-background-theme="grey"])) :is(#huntView, #campView, #charactersView, #statsView, #dungeonsView) > .panel:not(.battleStonePanel):not(.battleStoneSkills),
html[data-background-theme]:where(:not([data-background-theme="grey"])) #equipmentColumn > .panel,
html[data-background-theme]:where(:not([data-background-theme="grey"])) #campView > .campGrid > .panel,
html[data-background-theme]:where(:not([data-background-theme="grey"])) #creation > .creation {
  background: var(--theme-panel);
  border-color: var(--theme-panel-edge);
}

/* Plain nested panels follow the same hue. Equipment, loot rarity surfaces,
   inventory cells, art backdrops and active-state colours retain their rules. */
html[data-background-theme]:where(:not([data-background-theme="grey"])) #campView :is(.craftRecipe, .resourceItem, .farmWellPanel, .planterWater),
html[data-background-theme]:where(:not([data-background-theme="grey"])) #charactersView .characterCard,
html[data-background-theme]:where(:not([data-background-theme="grey"])) #creation .classChoice,
html[data-background-theme]:where(:not([data-background-theme="grey"])) #monsterAffixPanel .monsterAffixList details {
  background-color: var(--theme-panel-inset);
  border-color: var(--theme-panel-edge);
}

html[data-background-theme]:where(:not([data-background-theme="grey"])) #headerSupplies.supplyBelt,
html[data-background-theme]:where(:not([data-background-theme="grey"])) .siteToolbar .topAccountFrame,
html[data-background-theme]:where(:not([data-background-theme="grey"])) .siteToolbar .backgroundPicker,
html[data-background-theme]:where(:not([data-background-theme="grey"])) .siteToolbar .backgroundChoices,
html[data-background-theme]:where(:not([data-background-theme="grey"])) .mobileHud,
html[data-background-theme]:where(:not([data-background-theme="grey"])) #mobileHudToggle,
html[data-background-theme]:where(:not([data-background-theme="grey"])) .idleSummaryPanel,
html[data-background-theme]:where(:not([data-background-theme="grey"])) .gameAccountDialog {
  background: var(--theme-panel);
  border-color: var(--theme-panel-edge);
}

/* Selection is an interaction cue, not another panel colour. */
html[data-background-theme]:where(:not([data-background-theme="grey"])) #creation .classChoice.selected,
html[data-background-theme]:where(:not([data-background-theme="grey"])) #charactersView .characterCard.active:not(.selectedElsewhere) {
  border-color: var(--gold);
}
