/*
 * Dark theme: html[data-theme="dark"], set before first paint by the script in layouts/head
 * (saved choice, otherwise the system preference). Same layout and accents as the light
 * theme; the landing's own dark parts keep their look.
 */

/* the light theme stays light on a device in dark mode: without this the browser's default
   text colour (inherited by headings and amounts) turns white on our white pages */
html[data-theme="light"] {
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #0f0e15;
  --surface: #17161f;
  --surface-2: #1f1e29;
  --line: rgba(255, 255, 255, 0.08);
  --line-soft: rgba(255, 255, 255, 0.06);
  --text: #ecebf5;
  --text-muted: rgba(236, 235, 245, 0.58);
  --card-shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 16px 40px -20px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 4px rgba(124, 102, 255, 0.28);
  --color-primary: #7c66ff;
  --color-primary--rgb: 124, 102, 255;
  /* "second" is the site's text / dark-button colour: flip it to light text */
  --color-second: #ecebf5;
  --color-second--rgb: 236, 235, 245;
}

html[data-theme="dark"] body,
html[data-theme="dark"] .main {
  background-color: var(--canvas);
  color: var(--text);
}

html[data-theme="dark"] h1,
html[data-theme="dark"] h2,
html[data-theme="dark"] h3,
html[data-theme="dark"] h4,
html[data-theme="dark"] h5,
html[data-theme="dark"] h6,
html[data-theme="dark"] .title2,
html[data-theme="dark"] .title3,
html[data-theme="dark"] .title6 {
  color: var(--text);
}

html[data-theme="dark"] .content {
  background:
    radial-gradient(1100px 420px at 50% -160px, rgba(124, 102, 255, 0.16), transparent 70%),
    var(--canvas);
}

/* header & menu: the site's own "black header" look */
html[data-theme="dark"] .header:not(.header--black) {
  background-color: #12111a;
  box-shadow: 0 1px 0 var(--line);
}

html[data-theme="dark"] .logo .logo__text-img {
  fill: #fff;
}

html[data-theme="dark"] .user-balance__text,
html[data-theme="dark"] .user-balance__text a {
  color: var(--text);
}

html[data-theme="dark"] .menu-toggle__lines,
html[data-theme="dark"] .menu-toggle__lines:before,
html[data-theme="dark"] .menu-toggle__lines:after {
  background-color: #fff;
}

html[data-theme="dark"] .lang-select__current {
  color: var(--text);
  background-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .lang-select__current:hover {
  background-color: rgba(255, 255, 255, 0.14);
}

html[data-theme="dark"] .lang-select__dropdown,
html[data-theme="dark"] .menu__list,
html[data-theme="dark"] .settings-menu {
  background-color: var(--surface);
  border-color: var(--line);
  box-shadow: var(--card-shadow);
}

html[data-theme="dark"] .menu__link,
html[data-theme="dark"] .settings-menu__link,
html[data-theme="dark"] .lang-select__option {
  color: var(--text);
}

html[data-theme="dark"] .menu__link:hover,
html[data-theme="dark"] .settings-menu__link:hover {
  background-color: rgba(255, 255, 255, 0.06);
}

html[data-theme="dark"] .menu__item:last-child {
  border-top-color: var(--line);
}

html[data-theme="dark"] .menu__link-icon svg {
  fill: rgba(255, 255, 255, 0.6);
}

/* surfaces */
html[data-theme="dark"] .box,
html[data-theme="dark"] .balance-up,
html[data-theme="dark"] .balance-withdraw,
html[data-theme="dark"] .create-form__sidebar,
html[data-theme="dark"] .create-form__images,
html[data-theme="dark"] .create-form__input-about,
html[data-theme="dark"] .comment,
html[data-theme="dark"] .popup__content,
html[data-theme="dark"] .project__history-empty,
html[data-theme="dark"] .chain-listing {
  background-color: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

/* comment text is hard-coded dark in styles.css */
html[data-theme="dark"] .comment__text {
  color: var(--text);
}

html[data-theme="dark"] .header__login {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

html[data-theme="dark"] .header__login:hover {
  background-color: rgba(255, 255, 255, 0.14);
}

html[data-theme="dark"] .table:not(.table--bright) .table__content {
  background-color: var(--surface);
  border-color: var(--line);
}

html[data-theme="dark"] .popup__close {
  background-color: var(--surface-2);
}

html[data-theme="dark"] .content__header,
html[data-theme="dark"] .project-round__header,
html[data-theme="dark"] .project__header,
html[data-theme="dark"] .create-form__input-name,
html[data-theme="dark"] .comment__line,
html[data-theme="dark"] .comments__main:not(:first-child),
html[data-theme="dark"] .articles__item:not(:first-child),
html[data-theme="dark"] .articles__title--small {
  border-color: var(--line);
}

html[data-theme="dark"] .footer:not(.footer--black) {
  background-color: var(--canvas);
}

/* text */
html[data-theme="dark"] .table th {
  color: var(--text-muted);
}

html[data-theme="dark"] .table td,
html[data-theme="dark"] .table__name,
html[data-theme="dark"] .table__link,
html[data-theme="dark"] .project-round__title,
html[data-theme="dark"] .project-round__detail,
html[data-theme="dark"] .form-field__label,
html[data-theme="dark"] .article__text-content,
html[data-theme="dark"] .article__text-content h2,
html[data-theme="dark"] .text--dark-gray {
  color: var(--text);
}

html[data-theme="dark"] .table:not(.table--bright) td {
  border-color: var(--line-soft);
}

html[data-theme="dark"] .table:not(.table--bright) tbody tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

html[data-theme="dark"] .article__text-content a,
html[data-theme="dark"] .content a.chain-link {
  color: #a898ff;
}

/* controls */
html[data-theme="dark"] .input,
html[data-theme="dark"] .select__field,
html[data-theme="dark"] .comment-form__field,
html[data-theme="dark"] .comment-form__field--filled {
  background-color: #13121b;
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text);
}

html[data-theme="dark"] .input:hover,
html[data-theme="dark"] .select__field:hover {
  border-color: rgba(255, 255, 255, 0.2);
}

html[data-theme="dark"] .input:focus {
  border-color: var(--color-primary);
}

html[data-theme="dark"] .input--gray,
html[data-theme="dark"] .input[readonly] {
  background-color: #1a1924;
  color: var(--text-muted);
}

html[data-theme="dark"] .input::placeholder {
  color: rgba(236, 235, 245, 0.35);
}

html[data-theme="dark"] .select__list {
  background-color: var(--surface);
  border-color: var(--line);
}

html[data-theme="dark"] .select__item {
  color: var(--text);
}

html[data-theme="dark"] .select__item--hover {
  background-color: rgba(124, 102, 255, 0.16);
}

html[data-theme="dark"] .btn--second {
  background-color: var(--color-primary);
  color: #fff;
}

html[data-theme="dark"] .btn--second:hover {
  background-color: #8d79ff;
  box-shadow: 0 10px 24px -10px rgba(124, 102, 255, 0.7);
}

html[data-theme="dark"] .btn--white {
  background-color: var(--surface-2);
  color: var(--text);
}

html[data-theme="dark"] .btn--white.btn--shadow {
  border-color: var(--line);
  box-shadow: none;
}

html[data-theme="dark"] .btn--white.btn--shadow:hover,
html[data-theme="dark"] .btn--white:hover {
  background-color: #2a2936;
  border-color: rgba(255, 255, 255, 0.14);
}

html[data-theme="dark"] .tabs-btns {
  background-color: var(--surface-2);
}

html[data-theme="dark"] .tabs-btns__btn {
  color: var(--text-muted);
}

html[data-theme="dark"] .tabs-btns__btn.tabs__btn--active {
  background-color: #2c2b3a;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* feedback */
html[data-theme="dark"] .status {
  background-color: rgba(92, 209, 103, 0.16);
  color: #86e391;
}

html[data-theme="dark"] .status--wait {
  background-color: rgba(248, 155, 43, 0.16);
  color: #ffc46b;
}

html[data-theme="dark"] .status--cancel {
  background-color: rgba(243, 65, 65, 0.18);
  color: #ff9090;
}

html[data-theme="dark"] .status--muted {
  background-color: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

html[data-theme="dark"] .note {
  background-color: rgba(248, 155, 43, 0.1);
  color: #f8a94a;
}

html[data-theme="dark"] .note--info {
  background-color: rgba(80, 140, 255, 0.12);
  color: #9cbcff;
}

html[data-theme="dark"] .progress {
  background-color: #262536;
}

/* round switcher arrows are dark icons (img) */
html[data-theme="dark"] .project-round__btn-prev img,
html[data-theme="dark"] .project-round__btn-next img {
  filter: invert(1);
}

/* empty-state illustrations are black line art on a light blob: invert them, keep the purple */
html[data-theme="dark"] .section-empty__img {
  filter: invert(0.88) hue-rotate(180deg);
}

/* on-chain blocks */
html[data-theme="dark"] .chain-stat,
html[data-theme="dark"] .chain-offers__row {
  background-color: var(--surface-2);
}

html[data-theme="dark"] .chain-stat--accent,
html[data-theme="dark"] .chain-offers__row--round {
  background: linear-gradient(135deg, rgba(124, 102, 255, 0.24), rgba(79, 123, 255, 0.12));
}

html[data-theme="dark"] .chain-stat--accent .chain-stat__value {
  color: #b3a6ff;
}

html[data-theme="dark"] .chain-key {
  background-color: rgba(245, 166, 35, 0.08);
}

html[data-theme="dark"] .chain-divider {
  background: var(--line);
  opacity: 1;
}

/* QR codes need a light background to scan */
html[data-theme="dark"] .balance-up__qr {
  background-color: #fff;
  border-color: var(--line);
}

/* rich text editor */
html[data-theme="dark"] .ck.ck-editor__main > .ck-editor__editable,
html[data-theme="dark"] .ck.ck-editor__main > .ck-editor__editable:not(.ck-focused) {
  background-color: #13121b;
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.12);
}

html[data-theme="dark"] .ck.ck-toolbar {
  background-color: var(--surface-2);
  border-color: rgba(255, 255, 255, 0.12);
}

html[data-theme="dark"] .ck.ck-toolbar .ck-button,
html[data-theme="dark"] .ck.ck-toolbar .ck-dropdown__button {
  color: var(--text);
}

/* landing: the light "about" panel and table follow the theme */
html[data-theme="dark"] .about__content {
  background-color: var(--surface);
}

html[data-theme="dark"] .about__content--gradient::before {
  background: linear-gradient(rgba(23, 22, 31, 0) 0%, var(--surface) 100%);
}

/* the hero sits on black: keep its button light */
html[data-theme="dark"] .banner__btn.btn--white {
  background-color: #fff;
  color: #2f2b43;
}

html[data-theme="dark"] .table--bright .table__content {
  background-color: var(--surface);
  border-color: var(--line);
}

html[data-theme="dark"] .table--bright th,
html[data-theme="dark"] .table--bright td {
  color: var(--text);
  border-color: var(--line-soft);
}

/* phone layout (media.css): off-canvas menu, open-menu header, card tables */
@media (max-width: 991px) {
  html[data-theme="dark"] .menu__content,
  html[data-theme="dark"] .header--active,
  html[data-theme="dark"] .header--active.header--scroll {
    background-color: #12111a;
    border-color: var(--line);
  }

  html[data-theme="dark"] .header--active .logo__text-img {
    fill: #fff;
  }

  html[data-theme="dark"] .menu__content .menu__list {
    background-color: transparent;
    box-shadow: none;
  }

  html[data-theme="dark"] .menu__balance {
    background-color: var(--surface-2);
  }

  html[data-theme="dark"] .menu__link--sm-btn-white {
    background-color: var(--surface-2);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--line);
  }

  html[data-theme="dark"] .comment__content,
  html[data-theme="dark"] .project__other {
    background-color: var(--surface);
  }

  html[data-theme="dark"] .project__other-title {
    border-color: var(--line);
  }
}

@media (max-width: 767px) {
  html[data-theme="dark"] .table tr:not(:first-child) {
    border-top-color: var(--canvas);
  }

  html[data-theme="dark"] .table td.td-sm-header {
    border-bottom-color: var(--line);
  }
}

/* theme toggle (both themes) */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  margin-right: 12px;
  border-radius: 10px;
  color: var(--color-second);
  background-color: rgba(var(--color-second--rgb), 0.06);
  transition: background-color 0.2s, transform 0.15s;
  cursor: pointer;
}

.theme-toggle:hover {
  background-color: rgba(var(--color-second--rgb), 0.12);
}

.theme-toggle:active {
  transform: scale(0.94);
}

.theme-toggle:focus-visible {
  outline: none;
  box-shadow: var(--ring, 0 0 0 4px rgba(100, 77, 237, 0.14));
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

.theme-toggle__moon,
html[data-theme="dark"] .theme-toggle__sun {
  display: none;
}

html[data-theme="dark"] .theme-toggle__moon {
  display: block;
}

.header--black .theme-toggle {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.08);
}

@media (max-width: 767px) {
  .theme-toggle {
    width: 36px;
    height: 36px;
    margin-right: 8px;
  }
}

html[data-theme="dark"] .chain-max {
  background-color: rgba(124, 102, 255, 0.2);
  color: #b3a6ff;
}

html[data-theme="dark"] .chain-max:hover,
html[data-theme="dark"] .chain-max:focus-visible {
  background-color: var(--color-primary);
  color: #fff;
}

html[data-theme="dark"] .chain-max:disabled {
  background-color: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.35);
}
