.rune-widget[hidden] { display: none; }
[data-rune-open] { cursor: pointer; }

.rune-widget {
  --rune-bg: var(--form-surface-muted, #f0fafa);
  --rune-panel: var(--form-surface, #fff);
  --rune-text: var(--form-text, #1d2b2a);
  --rune-muted: var(--form-muted, #4a524d);
  --rune-line: var(--form-line, rgba(43, 179, 177, .12));
  --rune-accent: var(--wd-teal-deep, #0f6f73);
  --rune-focus: rgba(15, 111, 115, .28);
  position: fixed;
  inset: 0;
  z-index: 10000;
  color: var(--rune-text);
}

.rune-widget__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(8, 47, 50, .54);
  cursor: pointer;
}

.rune-widget__dialog {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(760px, calc(100% - 32px));
  max-height: min(88dvh, 900px);
  margin: 6dvh auto;
  overflow: hidden;
  outline: 0;
  background:
    radial-gradient(circle at 88% 8%, var(--form-bg-glow, rgba(100, 207, 202, .12)), transparent 30%),
    linear-gradient(180deg, var(--form-paper, #f4fffe), var(--rune-panel) 34%);
  border: 1px solid var(--form-rim, rgba(43, 179, 177, .26));
  border-radius: 16px;
  box-shadow: var(--wd-surface-shadow, 0 18px 46px rgba(29, 43, 42, .14));
}

.rune-widget__header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--rune-line);
  background: var(--form-paper, #f4fffe);
}

.rune-widget__title { margin: 0; color: var(--form-heading, #0a4d52); font-size: 1.5rem; }
.rune-widget__intro { margin: 6px 0 0; color: var(--rune-muted); line-height: 1.5; }
.rune-widget__close { flex: 0 0 44px; width: 44px; height: 44px; border: 1px solid var(--rune-line); border-radius: 50%; background: transparent; color: inherit; font-size: 28px; cursor: pointer; }
.rune-widget__body { padding: 24px; overflow: auto; overscroll-behavior: contain; scroll-padding-top: 16px; }
.rune-widget__controls { display: grid; gap: 20px; }
.rune-widget__label, .rune-widget__legend { display: block; margin-bottom: 8px; font-weight: 700; }
.rune-widget__select { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid var(--wd-input-border, rgba(15, 111, 115, .18)); border-radius: 8px; background: var(--wd-input-bg, var(--rune-panel)); color: var(--rune-text); font: inherit; cursor: pointer; }
.rune-widget__fieldset { margin: 0; padding: 0; border: 0; scroll-margin-top: 16px; }
.rune-widget__segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.rune-widget__choice { position: relative; min-height: 48px; }
.rune-widget__choice input { position: absolute; opacity: 0; pointer-events: none; }
.rune-widget__choice span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 8px 12px; border: 1px solid var(--wd-input-border, rgba(15, 111, 115, .18)); border-radius: 8px; background: var(--wd-input-bg, var(--rune-panel)); cursor: pointer; }
.rune-widget__choice input:checked + span { border-color: var(--rune-accent); background: var(--form-primary-soft, rgba(174, 230, 229, .52)); box-shadow: inset 0 0 0 1px var(--rune-accent); color: var(--form-heading, #0a4d52); font-weight: 700; }
.rune-widget__choice.is-disabled span { opacity: .48; cursor: not-allowed; }
.rune-widget__helper, .rune-widget__status, .rune-widget__note { color: var(--rune-muted); line-height: 1.55; }
.rune-widget__helper { margin: 8px 0 0; }
.rune-widget__result { margin-top: 24px; scroll-margin-top: 16px; }
.rune-widget__result h3 { color: var(--form-heading, #0a4d52); font-size: 1.3rem; line-height: 1.35; }
.rune-widget__section { padding: 16px 0; border-top: 1px solid var(--rune-line); }
.rune-widget__section h4 { margin: 0 0 8px; color: var(--form-heading, #0a4d52); font-size: 1rem; }
.rune-widget__section p, .rune-widget__section ul { margin: 0; line-height: 1.65; }
.rune-widget__section ul { padding-left: 22px; }
.rune-widget__section li + li { margin-top: 7px; }
.rune-widget__sources { list-style: none; padding: 0 !important; }
.rune-widget__sources a { color: var(--rune-accent); font-weight: 700; text-underline-offset: 3px; }
.rune-widget__sources small { display: block; margin-top: 2px; color: var(--rune-muted); }
.rune-widget__choice input:focus-visible + span, .rune-widget__select:focus-visible, .rune-widget__close:focus-visible, .rune-widget__sources a:focus-visible { outline: 3px solid var(--rune-focus); outline-offset: 3px; }

:root:not([data-wd-theme="dark"]) .rune-widget__close:hover {
  border-color: var(--wd-input-border-focus, rgba(15, 111, 115, .46));
  color: var(--wd-teal-deep, #0f6f73);
  background: rgba(43, 179, 177, .10);
}

:root[data-wd-theme="dark"] .rune-widget {
  --rune-bg: var(--form-surface-muted, #17292b);
  --rune-panel: var(--form-surface, #101c1f);
  --rune-text: var(--wd-ink, #f3e8c8);
  --rune-muted: var(--wd-muted, rgba(243, 232, 200, .76));
  --rune-line: var(--panel-border, rgba(228, 191, 99, .16));
  --rune-accent: var(--wd-teal-light, #73dad4);
  --rune-focus: rgba(115, 218, 212, .34);
  color-scheme: dark;
}

:root[data-wd-theme="dark"] .rune-widget__backdrop { background: rgba(5, 8, 10, .76); }
:root[data-wd-theme="dark"] .rune-widget__dialog { background: radial-gradient(circle at 88% 8%, rgba(47, 104, 183, .10), transparent 30%), linear-gradient(180deg, rgba(22, 33, 34, .99), rgba(11, 18, 21, .98)); border-color: var(--panel-border, rgba(228, 191, 99, .16)); box-shadow: var(--panel-shadow, 0 18px 46px rgba(0, 0, 0, .34)), inset 0 1px rgba(255, 249, 238, .06); scrollbar-color: rgba(201, 168, 91, .55) transparent; }
:root[data-wd-theme="dark"] .rune-widget__header { background: var(--form-surface, #101c1f); border-color: var(--panel-border, rgba(228, 191, 99, .16)); }
:root[data-wd-theme="dark"] .rune-widget__title, :root[data-wd-theme="dark"] .rune-widget__result h3, :root[data-wd-theme="dark"] .rune-widget__section h4 { color: var(--wd-gold-pale, #f1d57e); }
:root[data-wd-theme="dark"] .rune-widget__select, :root[data-wd-theme="dark"] .rune-widget__choice span { color: var(--wd-ink, #f3e8c8); border-color: var(--wd-input-border, rgba(228, 191, 99, .20)); background: var(--wd-input-bg, rgba(9, 15, 18, .58)); }
:root[data-wd-theme="dark"] .rune-widget__choice input:checked + span { color: var(--wd-teal-light, #73dad4); border-color: var(--wd-teal-light, #73dad4); background: rgba(43, 179, 177, .10); box-shadow: inset 0 0 0 1px var(--wd-teal-light, #73dad4); }
:root[data-wd-theme="dark"] .rune-widget__sources a { color: var(--wd-teal-light, #73dad4); }
:root[data-wd-theme="dark"] .rune-widget__close:hover { color: var(--wd-teal-light, #73dad4); border-color: rgba(115, 218, 212, .44); background: rgba(43, 179, 177, .10); }

body.rune-widget-open { overflow: hidden; }
.rune-widget__glyph { display: inline-block; margin-right: .32em; transform: rotate(0deg); transform-origin: center; }
.rune-widget__glyph.is-reversed { transform: rotate(180deg); }

@media (max-width: 600px) {
  .rune-widget__dialog { width: 100%; height: 100dvh; max-height: none; margin: 0; border-radius: 0; border-inline: 0; }
  .rune-widget__header, .rune-widget__body { padding: 16px; }
  .rune-widget__title { font-size: 1.25rem; }
  .rune-widget__segmented { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
  .rune-widget__dialog { animation: rune-in .2s ease-out; }
  .rune-widget__glyph { transition: transform .2s ease-out; }
  @keyframes rune-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
}
