:root {
  color-scheme: dark;
  --forest: #11251f;
  --ink: #f4e9ca;
  --gold: #dabc83;
  --muted: #d1c9ad;
  --paper: #f0e6d0;
  --paper-ink: #202d25;
  --serif: "Grenze", Georgia, serif;
  --sans: "Barlow Semi Condensed", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(ellipse at 48% 0,#28473a 0,transparent 48rem), var(--forest); font: 500 1rem/1.3 var(--sans); }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid #d8ac63; outline-offset: 3px; }
.wrap { width: min(960px, calc(100% - 36px)); margin-inline: auto; }
main.wrap { padding-bottom: max(11px, env(safe-area-inset-bottom)); }
.site-header { position: sticky; top: 0; z-index: 5; background: #11251ff7; border-bottom: 1px solid #c9ae7559; }
.header-inner { min-height: 52px; display: flex; align-items: center; justify-content: space-between; }
.header-inner img { width: 80px; height: auto; }
.back { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.back span { color: var(--gold); font-size: 1.24rem; }
.back:hover { color: var(--gold); }
.intro { display: flex; align-items: end; justify-content: space-between; gap: 12px; margin-block: 15px 17px; }
.intro p { margin: 0 0 2px; color: var(--gold); text-transform: uppercase; letter-spacing: .15em; font-weight: 700; font-size: .78rem; }
h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 600; line-height: 1; }
h1 { font-size: clamp(2.6rem, 6.5vw, 4.75rem); letter-spacing: -.025em; }
h2 { font-size: 1.5rem; }
.layout { display: grid; grid-template-columns: minmax(0, 1.07fr) minmax(0, 1fr); gap: 12px; }
.controls { color-scheme: light; padding: 14px 17px; border: 1px solid #cab485; border-radius: 11px; color: var(--paper-ink); background: linear-gradient(155deg, #f8efdc, var(--paper) 75%, #e6d8b8); box-shadow: 0 8px 25px #08181055; }
.setup-preview {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid #bc9b6387;
  border-radius: 11px;
  background:
    radial-gradient(ellipse at 43% 46%, #356053 0, #1d3b35 42%, #102622 79%),
    #0f251f;
  box-shadow: inset 0 0 38px #071611b8, 0 8px 25px #08181055;
}
.section-heading, .board-heading, .setup-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.section-heading { margin-bottom: 4px; }
.plain { color: inherit; min-height: 34px; border: 0; padding: 0 4px; text-decoration: underline; text-underline-offset: 3px; background: transparent; }
.counter-row { min-width: 0; display: grid; grid-template-columns: 17px minmax(0, 1fr) 36px 21px 36px; align-items: center; gap: 4px; min-height: 42px; border-top: 1px solid #8273543d; }
.counter-row button { width: 100%; height: 36px; border: 1px solid #b7ad91; border-radius: 6px; color: #213429; background: #fff9ea; padding: 0; font: 700 1.19rem/1 var(--sans); }
.swatch { width: 13px; height: 13px; border: 1px solid #16231d78; border-radius: 4px; background: linear-gradient(145deg,var(--light),var(--die),var(--shade)); transform: rotate(-12deg); }
.color-name { font-weight: 700; line-height: 1; overflow-wrap: anywhere; }
.color-name small { display: block; margin-top: 3px; color: #495b4b; font-size: .77rem; font-weight: 500; }
.quantity { text-align: center; font-variant-numeric: tabular-nums; font-weight: 700; }
.setup-foot { min-height: 41px; border-top: 1px solid #8273543d; margin: 3px 0 7px; }
.setup-foot select { background: #fff9ea; color: #213429; border: 1px solid #b7ad91; border-radius: 5px; min-height: 33px; padding-inline: 6px; }
.primary, .secondary, .quiet, dialog button, .fold button:not(.plain) { border: 1px solid #a49a73; border-radius: 7px; min-height: 40px; padding: 5px 11px; font-weight: 700; background: #243d31; color: var(--ink); }
.primary { background: linear-gradient(#e3c995,#c5a46b); border-color: #efce8e; color: #212b22; }
.controls .primary { background: linear-gradient(#38634b,#234334); border-color: #1c392b; color: #fff1d0; }
.primary:hover:not(:disabled) { filter: brightness(1.1); }
.quiet { min-height: 36px; font-size: .89rem; white-space: nowrap; }
.wide { width: 100%; }
.board { border: 1px solid #ac925e8c; border-radius: 11px; background: #142b24; box-shadow: 0 8px 25px #08181072; min-width: 0; }
.board-heading { padding: 9px 13px; }
.board-heading h2 { font-size: 1.42rem; }
#progress { color: var(--gold); text-align: right; font-size: .9rem; }
.tray { position: relative; isolation: isolate; display: grid; align-items: center; overflow: hidden; margin: 0 7px; min-block-size: clamp(179px, 36vh, 306px); border: 5px solid #5c4e34; border-radius: 7px; background: radial-gradient(ellipse at 48% 36%,#39645070,#132b24e8), repeating-linear-gradient(137deg,#31513f 0 1px,#2f503f 1px 3px); box-shadow: inset 0 0 0 1px #dbc29177,inset 0 0 14px 5px #04140f99; }
.tray::before { content: ""; position: absolute; inset: 6px; border: 1px solid #edce8731; pointer-events: none; }
.dice { position: relative; display: grid; grid-template-columns: repeat(var(--columns, 4), minmax(0,1fr)); gap: 3px; width: min(100%, 680px); margin: auto; padding: 7px; }
.die-button { min-width: 0; min-height: 47px; display: grid; justify-items: center; gap: 1px; padding: 1px 2px 4px; color: var(--ink); background: transparent; border: 1px solid transparent; border-radius: 7px; line-height: 1; }
.die-button:disabled { opacity: 1; }
.die-button[aria-pressed="true"] { border-color: #ffdc8d; background: #d5ad5a2e; box-shadow: inset 0 0 0 1px #392c11; }
.die-button[data-effect] .die-label { color: #ffe598; }
.die-render { position: relative; isolation: isolate; display: grid; place-items: center; width: min(100%, var(--die-size, 82px)); aspect-ratio: 1; touch-action: manipulation; }
.die-render::before { content: ""; position: absolute; z-index: -1; width: 63%; height: 24%; bottom: 11%; background: #050b08; filter: blur(5px); border-radius: 50%; opacity: .73; }
.die-render canvas { width: 100%; height: 100%; position: absolute; inset: 0; }
.die-art { flex: 0 0 auto; display: inline-grid; place-items: center; width: 29px; height: 29px; border-radius: 20%; background-color: var(--die); color: var(--face-ink); overflow: hidden; }
.die-render .die-art { width: 71%; height: 71%; box-shadow: inset 2px 2px 5px #fff4, inset -3px -3px 5px #0005; }
.face-art { background: var(--die) url("./caras.webp") var(--face-column) var(--face-row) / 600% 700% no-repeat; }
.custom-result { position: absolute; inset: 0; display: grid; place-items: center; margin: 16%; color: var(--face-ink); font-size: .62rem; overflow-wrap: anywhere; }
.die-label { font-weight: 700; font-size: .89rem; line-height: 1.05; overflow-wrap: anywhere; }
.die-type { color: #d9cfb5; font-size: .75rem; line-height: 1.12; overflow-wrap: anywhere; }
.reserved-row { display: flex; gap: 8px; align-items: center; padding: 6px 11px 0; }
.reserved-row h3 { font-size: 1.05rem; }
#reserved { display: flex; gap: 4px; flex-wrap: wrap; }
.reserve-chip, .history-die { display: inline-flex; gap: 5px; align-items: center; min-height: 34px; padding: 2px 6px 2px 2px; color: var(--ink); background: #244035; border: 1px solid #958460; border-radius: 6px; font-size: .83rem; }
.reserve-chip[aria-pressed="true"] { border-color: #ffdc8d; background: #52482e; }
.reserve-chip .die-art, .history-die .die-art { width: 25px; height: 25px; }
.move-panel { padding: 7px 10px 8px; }
#instruction { min-height: 1.3em; margin: 0 0 6px; color: #eee2bd; }
.actions { display: flex; flex-wrap: wrap; gap: 5px; align-items: stretch; }
.actions button { flex: 1 1 auto; }
.extras { margin-top: 4px; }
.extras summary, .fold summary { color: var(--gold); min-height: 31px; padding: 5px 1px; cursor: pointer; font-weight: 600; }
.extras[open] .actions { padding-block: 3px; }
.fold { margin-top: 6px; padding: 0 9px; border: 1px solid #c3ac755c; border-radius: 6px; background: #152b23; }
.fold p, dialog p { color: var(--muted); margin-block: 8px; }
.fold form { margin: 8px 0; }
.fold input, .fold select, dialog input { border: 1px solid #9b9476; background: #23382c; color: var(--ink); border-radius: 5px; min-height: 37px; padding: 5px 8px; }
.face-fields { display: grid; grid-template-columns: repeat(auto-fit,minmax(125px,1fr)); gap: 6px; margin: 8px 0; }
.face-fields label { display: grid; gap: 2px; }
.face-fields input { width: 100%; }
#history-content { display: grid; gap: 6px; padding-bottom: 8px; }
.history-group { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.history-group strong { padding-right: 5px; }
dialog { width: min(calc(100% - 26px), 380px); color: var(--ink); background: #193126; border: 1px solid var(--gold); border-radius: 10px; padding: 17px; }
dialog::backdrop { background: #091611c9; }
dialog label, dialog input { display: block; width: 100%; }
dialog .actions { margin-top: 8px; }
#helper-error:empty, #settings-status:empty { display: none; }
@media (max-width: 620px) {
  .wrap { width: calc(100% - 16px); }
  .header-inner { min-height: 44px; }
  .header-inner img { width: 65px; }
  .back { font-size: .88rem; }
  .intro { margin-block: 7px 8px; align-items: center; gap: 5px; }
  .intro p { font-size: .68rem; letter-spacing: .12em; }
  h1 { font-size: clamp(1.8rem, 8.1vw, 2.55rem); }
  .quiet { font-size: .77rem; padding-inline: 6px; }
  .layout { grid-template-columns: 1fr; gap: 6px; }
  .controls { padding: 7px 8px 8px; }
  .setup-preview { min-height: clamp(85px, 24dvh, 200px); }
  #dice-controls { display: grid; grid-template-columns: 1fr 1fr; column-gap: 8px; }
  .counter-row { grid-template-columns: 10px minmax(0,1fr) 26px 15px 26px; gap: 2px; min-height: 40px; }
  .counter-row button { height: 34px; }
  .swatch { width: 9px; height: 9px; }
  .color-name { font-size: clamp(.76rem,3.7vw,.94rem); }
  .board-heading { padding: 7px 8px; }
  .board-heading h2 { font-size: 1.26rem; }
  #progress { font-size: .82rem; }
  .tray { margin-inline: 4px; min-block-size: clamp(160px, 35dvh, 270px); border-width: 4px; }
  .dice { padding: 4px; --die-size: 64px; }
  .dice[data-dense] { --die-size: 49px; }
  .die-type { font-size: .66rem; }
  .die-label { font-size: .76rem; }
  .move-panel { padding: 5px 6px 6px; }
  #instruction { font-size: .92rem; }
  .actions button { min-height: 38px; padding: 4px 6px; font-size: .9rem; }
  .reserved-row { padding: 4px 6px 0; }
  .fold { margin-top: 4px; }
}
@media (max-width: 370px) {
  .counter-row { grid-template-columns: minmax(0,1fr) 28px 14px 28px; }
  .swatch { display: none; }
}
@media (max-width: 620px) and (max-height: 630px) {
  .setup-preview { min-height: 83px; }
  .tray { min-block-size: 152px; }
  .dice { --die-size: 51px; }
}

.counter-row button[aria-disabled="true"] { opacity: .45; cursor: default; }
.empty-tray { margin: auto; color: var(--muted); text-align: center; }
#instruction:focus:not(:focus-visible) { outline: none; }


main.wrap { position: relative; z-index: 1; }
body { overflow-x: clip; }
.arcane-scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  isolation: isolate;
}
.arcane-scene::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 48% 48%, #75c5a535 0, #4b8a7333 27%, transparent 62%),
    radial-gradient(ellipse at 67% 33%, #8e7cab26, transparent 56%);
  opacity: .76;
}
.relic-image, .relic-motes { position: absolute; inset: 0; }
.relic-image {
  inset: 5% 6%;
  background: url("./reliquia.webp") center / contain no-repeat;
  filter: drop-shadow(0 12px 22px #05140fbb) drop-shadow(0 0 13px #77dfb34a);
  transform: perspective(780px) rotateX(2deg) rotateZ(-2deg);
}
.relic-motes {
  background:
    radial-gradient(circle at 18% 35%, #a3d0ac8c 0 1px, transparent 2.1px),
    radial-gradient(circle at 26% 64%, #f3d49a75 0 1px, transparent 2px),
    radial-gradient(circle at 75% 27%, #9cdfbcb3 0 1.25px, transparent 2.5px),
    radial-gradient(circle at 85% 42%, #a3d0ac91 0 1px, transparent 2.1px),
    radial-gradient(circle at 67% 74%, #d5dbad91 0 1px, transparent 2.3px),
    radial-gradient(ellipse at 48% 54%, #70b79813, transparent 44%);
  opacity: .66;
}
.tray-scene {
  opacity: .53;
  mask-image: radial-gradient(ellipse at center, #000 31%, #000c 63%, transparent 93%);
}
.tray-scene .relic-image { inset: 8% 8%; }
.tray-scene::before { opacity: .64; }
@media (prefers-reduced-motion: no-preference) {
  .relic-image { animation: relic-drift 14s ease-in-out infinite alternate; }
  .relic-motes { animation: relic-motes-drift 18s ease-in-out infinite alternate; }
}
@keyframes relic-drift {
  0% { transform: perspective(780px) translate3d(-4px, 2px, 0) rotateX(2deg) rotateY(-5deg) rotateZ(-2deg); }
  100% { transform: perspective(780px) translate3d(4px, -6px, 0) rotateX(-3deg) rotateY(5deg) rotateZ(1deg); }
}
@keyframes relic-motes-drift {
  0% { opacity: .42; transform: translate3d(-4px, 4px, 0); }
  100% { opacity: .8; transform: translate3d(5px, -6px, 0); }
}
@media (max-width: 620px) {
  .setup-scene .relic-image { inset: 1% 19%; }
  .tray-scene .relic-image { inset: 8% 5%; }
}
.header-end { display: flex; align-items: center; gap: 11px; }
.music-control { position: relative; display: flex; align-items: center; }
#music-toggle, #music-menu summary {
  display: flex;
  min-height: 35px;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid #ae925b8a;
  padding: 0 7px;
  color: var(--ink);
  background: #223b2f;
  font-size: .9rem;
  font-weight: 700;
}
#music-toggle { border-radius: 6px 0 0 6px; }
#music-toggle span:first-child { color: var(--gold); font-size: 1.13rem; }
#music-toggle[aria-pressed="true"] { background: #4c452b; border-color: #c8a96e; }
#music-toggle:hover, #music-menu summary:hover { background: #334b38; }
#music-menu summary {
  width: 31px;
  border-left: 0;
  border-radius: 0 6px 6px 0;
  cursor: pointer;
  list-style: none;
}
#music-menu summary::-webkit-details-marker { display: none; }
#music-menu summary span {
  width: 7px;
  height: 7px;
  transform: translateY(-2px) rotate(45deg);
  border-right: 2px solid var(--gold);
  border-bottom: 2px solid var(--gold);
}
#music-menu[open] summary span { transform: translateY(2px) rotate(225deg); }
.music-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(252px, calc(100vw - 18px));
  max-height: min(285px, calc(100dvh - 58px));
  overflow: auto;
  padding: 12px;
  border: 1px solid #b59b65;
  border-radius: 8px;
  background: #193126;
  box-shadow: 0 10px 27px #060f0abf;
}
.music-panel label { display: block; margin-bottom: 6px; font-weight: 700; color: var(--gold); }
.music-panel select {
  width: 100%;
  min-height: 38px;
  padding: 3px 7px;
  color: var(--ink);
  background: #254337;
  border: 1px solid #9b9476;
  border-radius: 5px;
}
.music-panel p { margin: 7px 0 0; color: var(--muted); font-size: .86rem; }
@media (max-width: 620px) {
  .header-end { gap: 6px; }
  #music-toggle, #music-menu summary { min-height: 34px; }
}
@media (max-width: 359px) {
  .header-end img { display: none; }
}
