:root {
  color-scheme: light;
  --page-bg: #fff;
  --surface: #f5f5f5;
  --text: #171717;
  --secondary-text: #555;
  --theme-line: #ddd;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page-bg: #151515;
  --surface: #222;
  --text: #ededed;
  --secondary-text: #bdbdbd;
  --theme-line: #454545;
  --accent: #ff995e;
  --ink: var(--text);
  --muted: var(--secondary-text);
  --panel: var(--surface);
  --line: var(--theme-line);
  --bg: var(--page-bg);
  --accent-soft: #3d2a1f;
}

.theme-control {
  position: fixed;
  z-index: 10000;
  left: 1rem;
  bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.65rem;
  margin: 0;
  border: 1px solid var(--theme-line);
  border-radius: 0.5rem;
  background: var(--page-bg);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.4;
  box-shadow: 0 2px 12px #0001;
}

.theme-control span,
.theme-control select {
  font-size: 0.75rem;
}

.theme-control select {
  appearance: auto;
  -webkit-appearance: menulist;
  padding: 0.2rem;
  border: 0;
  background: transparent;
  color: inherit;
}

.theme-control select:focus-visible { outline: 2px solid var(--accent, #b85d00); }

html[data-theme="dark"] body {
  background: var(--page-bg);
  color: var(--text);
}

html[data-theme="dark"] :is(input, textarea, select) {
  color: var(--text);
  background-color: var(--page-bg);
  border-color: var(--theme-line);
}

html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder {
  color: var(--secondary-text);
  opacity: 1;
}

html[data-theme="dark"] :is(.calendar-panel, .editor-tabs, .article, .card, .row, .chart-shell, .metric-switch, .nav) {
  background: var(--surface);
  color: var(--text);
  border-color: var(--theme-line);
}

html[data-theme="dark"] :is(.search, .articles, .slug, .date, .nav, label, .calendar-table-wrap, .calendar-table td) {
  border-color: var(--theme-line);
}

html[data-theme="dark"] .calendar-table th {
  background: #2b2b2b;
  color: var(--text);
}

html[data-theme="dark"] :is(.calendar-table th button, .editor-tabs button) {
  background: transparent;
  color: var(--text);
}

html[data-theme="dark"] .calendar-table th[aria-sort="ascending"],
html[data-theme="dark"] .calendar-table th[aria-sort="descending"] {
  color: var(--accent);
}

html[data-theme="dark"] :is(.calendar-table input:focus, .calendar-table textarea:focus, .calendar-table select:focus, .article.active, .article:hover) {
  background: #34291f;
}

html[data-theme="dark"] .calendar-table tr[data-error="true"] { background: #4b2424; }
html[data-theme="dark"] .calendar-table .delete-event { background: #472421; color: #ffb1a7; }
html[data-theme="dark"] .calendar-panel button:not(.delete-event),
html[data-theme="dark"] .nav > button,
html[data-theme="dark"] button.add { background: var(--accent); color: #161616; }
html[data-theme="dark"] .calendar-table th button { background: transparent !important; color: inherit !important; }

html[data-theme="dark"] .toast-pill {
  background: #222f;
  color: var(--text);
  border-color: var(--accent);
}

html[data-theme="dark"] .toast-close,
html[data-theme="dark"] .toast-decline {
  background: #333;
  color: var(--text);
  border-color: var(--theme-line);
}

html[data-theme="dark"] .search-container { border-color: var(--theme-line); }
html[data-theme="dark"] :is(.event-dot, .preview-event-dot) { box-shadow: 0 0 0 4px var(--page-bg); }
html[data-theme="dark"] .event-timeline::before,
html[data-theme="dark"] .timeline-day::before,
html[data-theme="dark"] .kulturkompass-preview-list li::before { background: #686868; }
html[data-theme="dark"] :is(.event-category, .preview-event-category) { color: color-mix(in srgb, var(--event-color), white 40%); }
html[data-theme="dark"] .timeline-hint { color: var(--secondary-text); }
html[data-theme="dark"] .timeline-scroll { scrollbar-color: var(--accent) #303030; }
html[data-theme="dark"] .timeline-scroll::-webkit-scrollbar-track { background: #303030; }
html[data-theme="dark"] .timeline-scroll::-webkit-scrollbar-thumb { background: var(--accent); }
html[data-theme="dark"] .bar-track { background: #414141; }
html[data-theme="dark"] .article-like { border-color: #76513c; }

/* TinyMCE chrome and its independently styled content iframe. */
html[data-theme="dark"] .tox :is(.tox-toolbar, .tox-toolbar__primary, .tox-toolbar-overlord, .tox-menubar, .tox-menu, .tox-dialog, .tox-dialog__header, .tox-dialog__footer, .tox-dialog__body, .tox-statusbar, .tox-collection__item) {
  background: var(--surface);
  color: var(--text);
  border-color: var(--theme-line);
}

html[data-theme="dark"] .tox :is(.tox-tbtn, .tox-mbtn, .tox-label, .tox-listboxfield .tox-listbox--select, .tox-dialog__title, .tox-statusbar a, .tox-statusbar__path-item) {
  color: var(--text);
}

html[data-theme="dark"] .tox :is(.tox-tbtn svg, .tox-icon svg) { fill: var(--text); }
html[data-theme="dark"] .tox :is(.tox-tbtn:hover, .tox-tbtn--enabled, .tox-collection__item--active, .tox-mbtn:hover) { background: #414141; }
html[data-theme="dark"] .tox :is(.tox-textfield, .tox-textarea, .tox-listboxfield .tox-listbox--select) { background: var(--page-bg); border-color: var(--theme-line); color: var(--text); }
html[data-theme="dark"] .tox .tox-edit-area__iframe { background: var(--page-bg); }

@media (max-width: 599px) {
  .theme-control { left: 0.5rem; bottom: 0.5rem; }
  .theme-control > span { display: none; }
}
.theme-animating :is(body, header, nav, main, footer, article, section, aside, dialog, input, textarea, .article-canvas, .article-workspace) { transition: background-color 280ms ease, color 280ms ease, border-color 280ms ease; }
vw-theme-toggle { display: inline-flex; align-items: center; flex-shrink: 0; }
body .theme-toggle { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; min-height: 44px; margin: 0; padding: 12px; border: 0; border-radius: 6px; background: transparent; color: var(--vw-muted, var(--secondary-text)); cursor: pointer; box-shadow: none; }
body .theme-toggle:hover { background: transparent; transform: none; }
body .theme-toggle:focus-visible { outline: 2px solid var(--vw-accent, #aa4c22); outline-offset: -2px; }
body .theme-toggle .theme-icon { display: block; width: 20px; height: 20px; margin: 0; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle :is(.theme-sun, .theme-moon) { transform-origin: 12px 12px; transition: opacity 220ms ease, transform 320ms cubic-bezier(.2,.8,.2,1); }
.theme-toggle .theme-moon { opacity: 0; transform: rotate(-60deg) scale(.6); }
.theme-toggle .theme-sun { opacity: 1; transform: rotate(0) scale(1); }
.theme-toggle[aria-checked="true"] .theme-sun { opacity: 0; transform: rotate(60deg) scale(.6); }
.theme-toggle[aria-checked="true"] .theme-moon { opacity: 1; transform: rotate(0) scale(1); }
.editor-tabs > vw-theme-toggle { margin-left: auto; }
@media (prefers-reduced-motion: reduce) {
  .theme-animating *, .theme-toggle :is(.theme-sun, .theme-moon) { transition: none !important; }
}
