:root, :root[data-theme='dark'] {
  --preferences-surface: #111b32;
  --preferences-subtle: #16233f;
  --preferences-ink: #eaf0ff;
  --preferences-muted: #a7b6ce;
  --preferences-line: #344563;
  --preferences-accent: #7c9cff;
  --preferences-accent-ink: #0b1224;
  --preferences-hover: #1f3155;
  --preferences-shadow: 0 18px 65px rgba(0, 0, 0, .35);
}

:root[data-theme='light'] {
  --preferences-surface: #ffffff;
  --preferences-subtle: #f8fafc;
  --preferences-ink: #17253d;
  --preferences-muted: #5f6e82;
  --preferences-line: #dce4ee;
  --preferences-accent: #2563eb;
  --preferences-accent-ink: #ffffff;
  --preferences-hover: #eff6ff;
  --preferences-shadow: 0 12px 48px rgba(25, 44, 76, .17);
}

.preferences-toolbar { position: absolute; top: 3px; right: 0; display: flex; justify-content: flex-end; }
.preferences-trigger {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 38px; padding: 7px 13px; border: 1px solid var(--preferences-line); border-radius: 10px;
  background: var(--preferences-surface); color: var(--preferences-muted); cursor: pointer; font-size: 13px; font-weight: 600;
}
.preferences-trigger-icon { font-size: 18px; line-height: 1; }
.preferences-trigger:hover { color: var(--preferences-accent); background: var(--preferences-hover); }
.preferences-dialog {
  position: fixed; inset: 0; margin: auto; width: min(440px, calc(100vw - 32px));
  max-width: calc(100vw - 32px); max-height: min(720px, calc(100vh - 32px)); overflow-y: auto;
  padding: 23px; border: 1px solid var(--preferences-line); border-radius: 18px;
  background: var(--preferences-surface); color: var(--preferences-ink); box-shadow: var(--preferences-shadow);
}
.preferences-dialog::backdrop { background: rgba(4, 12, 27, .48); }
.preferences-heading, .preferences-recent-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.preferences-heading h2 { margin: 0; font-size: 21px; line-height: 1.4; letter-spacing: -.02em; }
.preferences-close {
  display: grid; place-items: center; flex: 0 0 auto; width: 34px; height: 34px;
  border: 1px solid var(--preferences-line); border-radius: 9px;
  background: var(--preferences-subtle); color: var(--preferences-muted); font-size: 24px; line-height: 1; cursor: pointer;
}
.preferences-close:hover { color: var(--preferences-ink); background: var(--preferences-hover); }
.preferences-description { margin: 12px 0 23px; color: var(--preferences-muted); font-size: 12px; line-height: 1.7; }
.preferences-section-title { margin: 0; color: var(--preferences-ink); font-size: 14px; line-height: 1.5; font-weight: 700; }
.preferences-theme-choices { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 10px; }
.preferences-theme-button {
  min-height: 42px; padding: 10px; border: 1px solid var(--preferences-line); border-radius: 10px;
  background: var(--preferences-subtle); color: var(--preferences-ink); cursor: pointer; font-size: 13px; font-weight: 600;
}
.preferences-theme-button:hover { background: var(--preferences-hover); }
.preferences-theme-button[aria-pressed='true'] { border-color: var(--preferences-accent); background: var(--preferences-accent); color: var(--preferences-accent-ink); }
.preferences-recent { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--preferences-line); }
.preferences-clear {
  padding: 5px 0 5px 8px; border: 0; border-radius: 5px; background: transparent;
  color: var(--preferences-accent); cursor: pointer; font-size: 12px; white-space: nowrap;
}
.preferences-clear:disabled { color: var(--preferences-muted); opacity: .6; cursor: not-allowed; }
.preferences-privacy { margin: 7px 0 13px; color: var(--preferences-muted); font-size: 11px; line-height: 1.6; }
.preferences-history { display: grid; gap: 7px; list-style: none; padding: 0; margin: 0; }
.preferences-history li { min-width: 0; }
.preferences-history-button {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 11px 12px; border: 1px solid var(--preferences-line); border-radius: 10px;
  background: var(--preferences-subtle); color: var(--preferences-ink); text-align: left; cursor: pointer;
}
.preferences-history-button:hover { background: var(--preferences-hover); border-color: var(--preferences-accent); }
.preferences-history-label { min-width: 0; overflow-wrap: anywhere; font-size: 12px; font-weight: 600; }
.preferences-history-time { flex: 0 0 auto; color: var(--preferences-muted); font-size: 10px; white-space: nowrap; }
.preferences-history-empty { margin: 0; padding: 17px 12px; border: 1px dashed var(--preferences-line); border-radius: 10px; color: var(--preferences-muted); text-align: center; font-size: 12px; line-height: 1.7; }
.preferences-history-status { min-height: 0; margin: 9px 0 0; color: var(--preferences-muted); font-size: 11px; }
.preferences-history-status:empty { display: none; }
.preferences-trigger:focus-visible, .preferences-close:focus-visible, .preferences-theme-button:focus-visible, .preferences-clear:focus-visible, .preferences-history-button:focus-visible { outline: 2px solid var(--preferences-accent); outline-offset: 3px; }

@media (max-width: 620px) {
  .preferences-toolbar { position: static; margin-bottom: 15px; }
  .preferences-trigger { min-height: 36px; padding: 6px 11px; font-size: 12px; }
  .preferences-dialog { padding: 19px; }
}
@media (max-width: 360px) {
  .preferences-history-button { align-items: flex-start; flex-direction: column; gap: 4px; }
}
