/* ==========================================================================
   A game controller runs the site (draft 10, batch 9): the fairy cursor, the tag beside it, the glow on
   whatever it is over, the button pictures, the guide dialog and the settings controls. assets/js/pad.mjs.
   The fairy's colour follows the page's accent when there is one (--pad-c), else a warm gold.
   ========================================================================== */
:root { --pad-c: #ffd23f; --pad-c2: #fff7cf; --pad-ink: #23180f; }
:root[data-world="ocean"], :root[data-drawer-mood="ocean"] { --pad-c: #7be0ff; --pad-c2: #e6fbff; }
:root[data-world="meadow"], :root[data-drawer-mood="meadow"] { --pad-c: #c9ff6b; --pad-c2: #f3ffd6; }
:root[data-world="dusk"], :root[data-drawer-mood="dusk"], :root[data-world="aurora"], :root[data-drawer-mood="aurora"] { --pad-c: #d9a6ff; --pad-c2: #f7eaff; }
:root[data-world="calm"], :root[data-drawer-mood="calm"] { --pad-c: #ffffff; --pad-c2: #e9f0ff; }

/* ---------- the layer: a popover in the top layer, so the fairy paints above modal dialogs ---------- */
#pad-layer { position: fixed; inset: 0 auto auto 0; width: 0; height: 0; margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; pointer-events: none; z-index: 2147483000; color: inherit; }
#pad-layer:popover-open { display: block; }
#pad-layer::backdrop { display: none; }

/* ---------- the fairy ---------- */
#pad-fairy { position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 2147483000; pointer-events: none; will-change: transform; transition: opacity .25s; }
#pad-fairy.is-away { opacity: 0; }
#pad-fairy > * { position: absolute; pointer-events: none; }
#pad-fairy .pf-star { width: 38px; height: 38px; max-width: none; left: -19px; top: -19px; fill: var(--pad-c); stroke: var(--pad-ink); stroke-width: 2.2; stroke-linejoin: round; filter: drop-shadow(0 0 7px var(--pad-c)) drop-shadow(0 0 2px #fff) drop-shadow(0 2px 2px rgba(0, 0, 0, .4)); animation: pf-twinkle 1.8s ease-in-out infinite; }
#pad-fairy .pf-star circle { fill: #fff; stroke: var(--pad-ink); stroke-width: 1.4; }
#pad-fairy .pf-halo { left: -30px; top: -30px; width: 60px; height: 60px; border-radius: 50%; background: radial-gradient(circle, color-mix(in srgb, var(--pad-c) 70%, #fff), color-mix(in srgb, var(--pad-c) 35%, transparent) 40%, transparent 70%); animation: pf-breathe 2.2s ease-in-out infinite; }
#pad-fairy .pf-wing { width: 14px; height: 18px; top: -16px; border-radius: 80% 20% 70% 30% / 60% 40% 60% 40%; background: linear-gradient(160deg, rgba(255, 255, 255, .85), color-mix(in srgb, var(--pad-c) 45%, transparent)); border: 1px solid rgba(255, 255, 255, .7); filter: drop-shadow(0 0 3px var(--pad-c)); transform-origin: 100% 100%; animation: pf-flap .5s ease-in-out infinite alternate; }
#pad-fairy .pf-wing-l { left: -24px; }
#pad-fairy .pf-wing-r { left: 10px; transform: scaleX(-1); transform-origin: 0 100%; animation-name: pf-flap-r; }
#pad-fairy .pf-trail { width: 8px; height: 8px; left: -4px; top: -4px; border-radius: 50%; background: var(--pad-c); box-shadow: 0 0 8px var(--pad-c); opacity: calc(.55 - var(--i) * .1); scale: calc(1 - var(--i) * .15); }
#pad-fairy.no-glow .pf-halo { display: none; }
#pad-fairy.no-glow .pf-star { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, .35)); }
#pad-fairy.no-trail .pf-trail { display: none; }
@keyframes pf-twinkle { 0%, 100% { transform: rotate(0deg) scale(1); } 50% { transform: rotate(18deg) scale(1.1); } }
@keyframes pf-breathe { 50% { transform: scale(1.25); opacity: .75; } }
@keyframes pf-flap { from { transform: rotate(-12deg); } to { transform: rotate(14deg); } }
@keyframes pf-flap-r { from { transform: scaleX(-1) rotate(-12deg); } to { transform: scaleX(-1) rotate(14deg); } }
:root[data-motion="reduce"] #pad-fairy :is(.pf-star, .pf-halo, .pf-wing) { animation: none; }
@media (prefers-reduced-motion: reduce) { #pad-fairy :is(.pf-star, .pf-halo, .pf-wing) { animation: none; } }

/* ---------- the tag beside the fairy ---------- */
#pad-prompt { position: fixed; left: 0; top: 0; z-index: 2147482999; pointer-events: none; display: flex; flex-direction: column; gap: 3px; padding: 5px 9px 5px 7px; border-radius: 12px; background: rgba(35, 24, 15, .92); color: #fffdf7; font: 700 13px/1.25 system-ui, sans-serif; border: 2px solid var(--pad-c); box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 8px 20px -8px rgba(0, 0, 0, .6), 0 0 14px color-mix(in srgb, var(--pad-c) 40%, transparent); white-space: nowrap; max-width: 60vw; will-change: transform; }
#pad-prompt[hidden] { display: none; }
#pad-prompt .pp-main, #pad-prompt .pp-more { display: flex; align-items: center; gap: 6px; }
#pad-prompt .pp-more { font-weight: 600; font-size: 12px; color: #e8dcc6; }
#pad-prompt .pg { width: 18px; height: 18px; flex: none; max-width: none; }

/* ---------- what the fairy is over ---------- */
:root[data-pad="on"] .pad-target { outline: 3px solid var(--pad-c) !important; outline-offset: 3px; box-shadow: 0 0 0 7px color-mix(in srgb, var(--pad-c) 30%, transparent), 0 0 22px color-mix(in srgb, var(--pad-c) 70%, transparent) !important; transition: box-shadow .15s, outline-color .15s; }
:root[data-pad="on"] .w.pad-target, :root[data-pad="on"] .w:has(.pad-target) { --w-pad: 1; }
:root[data-pad="on"] .w.pad-target > .ob, :root[data-pad="on"] .w:has(.pad-target) > .ob { outline: none; }
:root[data-pad="on"] .w.pad-target .w-menu, :root[data-pad="on"] .w:has(.pad-target) .w-menu { opacity: 1; } /* the ⋯ shows for Triangle */
:root[data-pad="on"] .w.pad-target { outline-offset: -2px; border-radius: 14px; }
:root[data-pad="on"] .pad-target:is(input, select, textarea) { outline-offset: 1px; }
:root[data-pad="on"] body { cursor: none; } /* the fairy is the pointer while the stick drives */
:root[data-contrast="high"] .pad-target { outline-color: currentColor !important; }

/* ---------- the button pictures ---------- */
.pg { width: 20px; height: 20px; display: inline-block; vertical-align: middle; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.pg circle:first-child, .pg > rect:first-child, .pg > path:first-child { fill: #2b2b33; stroke: #d9d9e4; }
.pg .pg-in { stroke-width: 1.9; }
.pg-cross path { stroke: #7fb5ff; }  .pg-cross path.pg-bar { stroke: #fff; stroke-width: 2.4; }
.pg-circle .pg-in { stroke: #ff6b6b; }
.pg-square .pg-in { stroke: #ff8fcf; }
.pg-triangle .pg-in { stroke: #5ee09a; }
.pg-dpad .pg-in { fill: #fff; stroke: none; }
.pg-stick .pg-in { fill: #d9d9e4; stroke: none; }
.pg-txt { font: 700 8px/1 system-ui, sans-serif; fill: #fff; text-anchor: middle; stroke: none; }
.pg-shoulder text { fill: #fff; }
.pg-small .pg-lines { stroke: #fff; stroke-width: 1.6; }
.pg-small .pg-in { fill: #fff; stroke: none; }
.pg-hold { position: relative; }

/* ---------- the guide (Options) ---------- */
.pad-guide { border: 3px solid var(--pad-ink); border-radius: 18px; padding: 0; width: min(100% - 24px, 36rem); max-height: min(92vh, 48rem); background: #fffdf7; color: #23180f; box-shadow: 0 10px 0 var(--pad-ink), 0 30px 60px -20px rgba(0, 0, 0, .6); }
.pad-guide::backdrop { background: rgba(20, 12, 30, .55); backdrop-filter: blur(3px); }
.pad-guide-in { padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 12px; max-height: inherit; overflow: auto; }
.pad-guide h2 { margin: 0; font-size: 1.35rem; display: flex; align-items: center; gap: .45em; }
.pad-guide h2 .pg { width: 26px; height: 26px; }
.pad-guide-lead { margin: 0; color: #47372a; }
.pad-map { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.pad-map li { display: grid; grid-template-columns: 30px 7.5rem 1fr; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 10px; background: #f6efe0; }
.pad-map .pg { width: 26px; height: 26px; }
.pad-map b { font-size: .95rem; }
.pad-map span { font-size: .9rem; color: #3a2d20; }
.pad-guide-foot { margin: 0; font-size: .9rem; }
.pad-guide-btns { display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 540px) { .pad-map li { grid-template-columns: 26px 1fr; } .pad-map span { grid-column: 1 / -1; } }

/* ---------- the settings controls (Accessibility panel) ---------- */
.pref-pad .link-btn { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--link, #1b5ca2); text-decoration: underline; cursor: pointer; }
.pad-speed { display: flex; align-items: center; gap: 10px; }
.pad-speed-label { font-weight: 700; font-size: var(--step--1); }
.pad-speed input[type=range] { flex: 1; min-width: 0; accent-color: var(--pad-ink, #23180f); }
.pad-speed output { font-weight: 700; font-size: var(--step--1); min-width: 9ch; }
.pad-toggles { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.pad-toggles button[aria-pressed="true"]::before, .pad-toggles button[aria-pressed="false"]::before { content: ""; width: .8em; height: .8em; border-radius: 50%; border: 2px solid currentColor; margin-right: .4em; flex: none; }
.pad-toggles button[aria-pressed="true"]::before { background: currentColor; }
.pad-audio { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px dashed var(--line, #dcc8a6); }
.pad-audio select { font: inherit; font-size: var(--step--1); padding: 6px 8px; border-radius: 8px; border: 2px solid var(--line-strong, #a3865c); background: var(--surface, #fffdf7); color: inherit; max-width: 100%; }
.pad-map-mini { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 6px 12px; font-size: var(--step--1); }
.pad-map-mini li { display: flex; align-items: center; gap: 6px; }

/* ---------- the written guide on the Accessibility page ---------- */
.pad-table { width: 100%; border-collapse: collapse; }
.pad-table th, .pad-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line, #dcc8a6); vertical-align: middle; }
.pad-table th { width: 11rem; white-space: nowrap; }
.pad-table .pg { width: 24px; height: 24px; margin-right: 6px; }
.pad-figure { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: var(--space-4); align-items: start; }
.pad-art { width: 100%; height: auto; display: block; }

/* ---------- a drop-down's choices, all at once (draft 11, A8) ---------- */
.pad-list { position: fixed; z-index: 2147482998; pointer-events: auto; display: flex; flex-direction: column; min-height: 0; overflow: hidden; border-radius: 16px; border: 3px solid var(--pad-ink); background: #fffdf7; color: #23180f; box-shadow: 0 8px 0 var(--pad-ink), 0 0 0 4px color-mix(in srgb, var(--pad-c) 55%, transparent), 0 24px 50px -16px rgba(0, 0, 0, .6); font: 600 15px/1.25 var(--font-body, system-ui), sans-serif; }
.pad-list-h { margin: 0; padding: 10px 12px 6px; font-weight: 800; display: flex; align-items: center; gap: 6px; border-bottom: 2px dashed #e2cfa6; }
.pad-list-scroll { overflow: auto; min-height: 0; flex: 1; padding: 6px; display: flex; flex-direction: column; gap: 3px; scrollbar-width: thin; }
.pad-list-g { margin: 6px 6px 2px; font-size: 12px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; color: #6b5a45; }
.pad-list-o { display: block; width: 100%; text-align: left; font: inherit; padding: 8px 10px; border-radius: 10px; border: 2px solid transparent; background: transparent; color: inherit; cursor: pointer; }
.pad-list-o.is-on { font-weight: 800; }
.pad-list-o:hover { background: #f6efe0; }
.pad-list-o.is-hi { background: #fff3c4; border-color: var(--pad-ink); box-shadow: 0 0 0 3px color-mix(in srgb, var(--pad-c) 50%, transparent); }
.pad-list-foot { margin: 0; padding: 6px 12px 8px; font-size: 12px; font-weight: 700; color: #47372a; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; border-top: 2px dashed #e2cfa6; }
.pad-list .pg { width: 18px; height: 18px; max-width: none; }
