/* Final theme contract. This file is intentionally loaded last.
 * Every application surface consumes the same semantic palette so a page can
 * never be half light and half dark. */
html[data-theme="light"] {
  --theme-canvas: var(--ui-canvas);
  --theme-surface: var(--ui-paper);
  --theme-surface-soft: var(--ui-paper-soft);
  --theme-surface-raised: #e4ded3;
  --theme-line: var(--ui-line-light);
  --theme-line-strong: rgba(49, 42, 31, .17);
  --theme-text: var(--ui-text-light);
  --theme-text-soft: var(--ui-text-light-soft);
  --theme-text-dim: var(--ui-text-light-dim);
  --theme-shadow: 0 14px 34px rgba(49, 42, 31, .08);
  color-scheme: light;
}

html[data-theme="dark"] {
  --theme-canvas: var(--ui-shell);
  --theme-surface: var(--ui-panel);
  --theme-surface-soft: var(--ui-shell-soft);
  --theme-surface-raised: var(--ui-panel-raised);
  --theme-line: var(--ui-line-dark);
  --theme-line-strong: var(--ui-line-dark-strong);
  --theme-text: var(--ui-text-dark);
  --theme-text-soft: var(--ui-text-dark-soft);
  --theme-text-dim: var(--ui-text-dark-dim);
  --theme-shadow: 0 18px 42px rgba(0, 0, 0, .24);
  color-scheme: dark;
}

html,
body,
#app,
.app,
.content,
.view {
  color: var(--theme-text);
  background-color: var(--theme-canvas);
}

/* Application chrome */
.app:not(.product-home-shell),
.app:not(.product-home-shell) > .content,
.app:not(.product-home-shell) .view,
.app:not(.product-home-shell) .sidebar,
.app:not(.product-home-shell) .topbar {
  color: var(--theme-text);
  border-color: var(--theme-line);
  background-color: var(--theme-canvas);
}

.app:not(.product-home-shell) .sidebar,
.app:not(.product-home-shell) .topbar {
  background: color-mix(in srgb, var(--theme-surface) 94%, transparent);
}

.app:not(.product-home-shell) .logo,
.app:not(.product-home-shell) .nav a,
.app:not(.product-home-shell) .account-entry,
.app:not(.product-home-shell) .account-popover,
.app:not(.product-home-shell) .account-menu-link,
.app:not(.product-home-shell) .account-logout {
  color: var(--theme-text);
  border-color: var(--theme-line);
}

.app:not(.product-home-shell) .nav a { color: var(--theme-text-soft); }
.app:not(.product-home-shell) .nav a:hover,
.app:not(.product-home-shell) .account-menu-link:hover,
.app:not(.product-home-shell) .account-logout:hover { background: color-mix(in srgb, var(--theme-text) 5%, transparent); }
.app:not(.product-home-shell) .account-entry,
.app:not(.product-home-shell) .account-popover { background: var(--theme-surface); }

/* Generic panels, forms and data views used by generation, assets, jobs,
 * account management, API management and billing. */
.app:not(.product-home-shell) .view > .card,
.app:not(.product-home-shell) .view .card,
.app:not(.product-home-shell) .view .cover,
.app:not(.product-home-shell) .view .panel,
.app:not(.product-home-shell) .view table,
.app:not(.product-home-shell) .platform-panel,
.app:not(.product-home-shell) .platform-account-card,
.app:not(.product-home-shell) .platform-metric,
.app:not(.product-home-shell) .home-continue-card,
.app:not(.product-home-shell) .home-quick-link,
.app:not(.product-home-shell) .home-project-card,
.app:not(.product-home-shell) .home-jobs-card,
.app:not(.product-home-shell) .empty,
.app:not(.product-home-shell) .permission-denied {
  color: var(--theme-text);
  border-color: var(--theme-line);
  background-color: var(--theme-surface);
}

.app:not(.product-home-shell) .view input,
.app:not(.product-home-shell) .view select,
.app:not(.product-home-shell) .view textarea,
.app:not(.product-home-shell) .view button:not(.primary):not(.btn-electric):not(.btn-gold) {
  color: var(--theme-text);
  border-color: var(--theme-line-strong);
  background-color: var(--theme-surface-soft);
}

.app:not(.product-home-shell) .view input::placeholder,
.app:not(.product-home-shell) .view textarea::placeholder,
.app:not(.product-home-shell) .muted,
.app:not(.product-home-shell) small { color: var(--theme-text-soft); }

.app:not(.product-home-shell) .view[data-page="generate"] > .form-grid {
  color: var(--theme-text);
  border-color: var(--theme-line);
  background: var(--theme-surface);
  box-shadow: var(--theme-shadow);
}
.app:not(.product-home-shell) .view[data-page="generate"] .form-grid input,
.app:not(.product-home-shell) .view[data-page="generate"] .form-grid select,
.app:not(.product-home-shell) .view[data-page="generate"] .form-grid textarea {
  color: var(--theme-text);
  border-color: var(--theme-line-strong);
  background: var(--theme-surface-soft);
}

.app:not(.product-home-shell) .view[data-page="jobs"] > .row:first-child,
.app:not(.product-home-shell) .view[data-page="jobs"] .job-line .t,
.app:not(.product-home-shell) .view[data-page="providers"] > .row:first-child,
.app:not(.product-home-shell) .view[data-page="platform"] > .row:first-child,
.app:not(.product-home-shell) .view[data-page="billing"] > .row:first-child,
.app:not(.product-home-shell) .view[data-page="providers"] .section-title,
.app:not(.product-home-shell) .view[data-page="billing"] h2 { color: var(--theme-text); }
.app:not(.product-home-shell) .view[data-page="jobs"] #job-list {
  color: var(--theme-text);
  border-color: var(--theme-line);
  background: var(--theme-surface);
  box-shadow: var(--theme-shadow);
}
.app:not(.product-home-shell) .view[data-page="jobs"] .job-line { border-color: var(--theme-line); }
.app:not(.product-home-shell) .view[data-page="jobs"] .progress { background: var(--theme-surface-raised); }
.app:not(.product-home-shell) .view[data-page="providers"] table,
.app:not(.product-home-shell) .view[data-page="platform"] table,
.app:not(.product-home-shell) .view[data-page="billing"] table { color: var(--theme-text); border-color: var(--theme-line); background: var(--theme-surface); }
.app:not(.product-home-shell) .view[data-page="providers"] th,
.app:not(.product-home-shell) .view[data-page="platform"] th,
.app:not(.product-home-shell) .view[data-page="billing"] th { color: var(--theme-text-soft); border-color: var(--theme-line); background: var(--theme-surface-soft); }
.app:not(.product-home-shell) .view[data-page="providers"] td,
.app:not(.product-home-shell) .view[data-page="platform"] td,
.app:not(.product-home-shell) .view[data-page="billing"] td { color: var(--theme-text); border-color: var(--theme-line); }

/* Polished project/workspace pages previously carried an independent, fixed
 * charcoal palette. Bind the whole subsystem to the active global theme. */
.wk-page,
.wk-loading,
.wk-warehouse,
.wk-library {
  --wk-bg: var(--theme-canvas);
  --wk-panel: var(--theme-surface);
  --wk-panel-2: var(--theme-surface-soft);
  --wk-line: var(--theme-line);
  --wk-text: var(--theme-text);
  --wk-muted: var(--theme-text-soft);
  color: var(--theme-text);
  background: var(--theme-canvas);
}

.wk-page-head h1,
.wk-hero-content h1,
.wk-summary b,
.wk-project-metrics b,
.wk-panel-head h3,
.wk-section-title h3,
.wk-project-assets,
.wk-entity-copy h3 { color: var(--theme-text); }
.wk-page-head p,
.wk-summary span,
.wk-project-metrics span,
.wk-panel-head p,
.wk-entity-copy p,
.wk-stage-handoff p { color: var(--theme-text-soft); }

.wk-summary,
.wk-project-card,
.wk-project-body,
.wk-panel,
.wk-asset-summary > div,
.wk-entity-card,
.wk-asset-toolbar,
.wk-stage-nav,
.wk-settings,
.wk-stage-handoff {
  color: var(--theme-text);
  border-color: var(--theme-line);
  background: var(--theme-surface);
}
.wk-project-card { box-shadow: var(--theme-shadow); }
.wk-project-body { background-color: var(--theme-surface); }
.wk-project-cover,
.wk-thumb,
.wk-entity-image { background: var(--theme-surface-soft); }
.wk-progress-line,
.wk-project-upload-track { background: var(--theme-surface-raised); }
.wk-stage-dots i { color: var(--theme-text-soft); background: var(--theme-surface-soft); }
.wk-stage-nav a { color: var(--theme-text-soft); border-color: var(--theme-line); }
.wk-stage-nav a.active { color: var(--theme-text); background: var(--ui-accent-soft); }
.wk-filter-tabs button,
.wk-project-assets .wk-head-actions .btn {
  color: var(--theme-text-soft);
  border-color: var(--theme-line-strong);
  background: var(--theme-surface-soft);
}
.wk-project-assets .wk-head-actions .btn-gold { color: #17120a; border-color: var(--ui-accent); background: var(--ui-accent); }
.wk-settings input,
.wk-settings select { color: var(--theme-text) !important; border-color: var(--theme-line-strong) !important; background: var(--theme-surface-soft) !important; }

html[data-theme="light"] .wk-project-cover:not(:has(img)) .wk-cover-shade { background: linear-gradient(180deg, rgba(237,232,223,.08), rgba(237,232,223,.55) 45%, rgba(237,232,223,.97)); }
html[data-theme="light"] .wk-project-cover:not(:has(img)) .wk-cover-copy h2 { color: var(--ui-text-light); }
html[data-theme="light"] .wk-project-cover:not(:has(img)) .wk-cover-copy p { color: var(--ui-text-light-soft); }
html[data-theme="light"] .wk-project-cover:not(:has(img)) .wk-thumb-fallback { color: rgba(32, 29, 24, .46); }
html[data-theme="light"] .wk-project-cover:not(:has(img)) .wk-cover-top span { color: var(--ui-text-light-soft); border-color: var(--ui-line-light); background: rgba(255,253,249,.82); }

/* Storyboard and edit pages had high-specificity dark overrides. */
.shots-page,
.editline-page,
.sb-page,
.sb-workspace,
.sb-shell,
.el2-wrap { color: var(--theme-text) !important; background: var(--theme-canvas) !important; }
.shots-page .card,
.editline-page .card,
.sb-board,
.sb-left,
.sb-center,
.sb-right,
.sb-panel,
.sb-shot-row,
.sb-shot-card,
.el2-toolbar,
.el2-monitor,
.el2-info,
.el2-tl {
  color: var(--theme-text) !important;
  border-color: var(--theme-line) !important;
  background: var(--theme-surface) !important;
}
#sb-eps-top,
.sb-board-head,
.el2-eps,
.el2-eps-title {
  color: var(--theme-text) !important;
  border-color: var(--theme-line) !important;
  background: var(--theme-surface-soft) !important;
}
.shots-page .ep-tabs,
.shots-page .ep-tab,
.sb-ep-tab,
.el2-ep,
.editline-page input,
.editline-page select {
  color: var(--theme-text-soft) !important;
  border-color: var(--theme-line-strong) !important;
  background: var(--theme-surface-soft) !important;
}
.el2-toolbar h2,
.el2-info-seq,
.el2-tl-head { color: var(--theme-text) !important; }
.el2-toolbar p,
.el2-info-meta,
.el2-info-desc,
.el2-tl-hint,
.el2-tl-foot { color: var(--theme-text-soft) !important; }

/* Creator consumes the same semantic surface map. */
.v2-shell,
.v2-shell .workspace,
.v2-shell .stage-content { color: var(--theme-text); background-color: var(--theme-canvas); }
.v2-shell .topbar,
.v2-shell .stage-nav { color: var(--theme-text); border-color: var(--theme-line); background: color-mix(in srgb, var(--theme-surface) 94%, transparent); }
.v2-shell :is(.panel, .card, .asset-card, .stage-card, .script-panel, .setting-panel) {
  color: var(--theme-text);
  border-color: var(--theme-line);
  background-color: var(--theme-surface);
}
.v2-shell :is(input, select, textarea) { color: var(--theme-text); border-color: var(--theme-line-strong); background-color: var(--theme-surface-soft); }

/* Asset galleries keep the same light surface as the rest of the creator.
 * Their older dark gradients otherwise remain visible behind light chrome. */
html[data-theme="light"] .v2-shell .xuanya-category {
  color: var(--theme-text-soft); border-color: var(--theme-line);
  background: #f7f3ec;
}
html[data-theme="light"] .v2-shell .xuanya-category.is-active {
  color: var(--theme-text); border-color: #d6b96f;
  background: #f3ead7; box-shadow: 0 5px 18px rgba(73, 55, 29, .09);
}
html[data-theme="light"] .v2-shell .xuanya-category em {
  color: var(--theme-text); background: rgba(90, 72, 44, .09);
}
html[data-theme="light"] .v2-shell .xuanya-family-card {
  color: var(--theme-text); border-color: var(--theme-line);
  background: #fffdf9; box-shadow: 0 8px 22px rgba(49, 42, 31, .08);
}
html[data-theme="light"] .v2-shell .xuanya-family-card:hover,
html[data-theme="light"] .v2-shell .xuanya-family-card:focus-visible {
  border-color: #d6b96f; box-shadow: 0 12px 26px rgba(49, 42, 31, .13);
}
html[data-theme="light"] .v2-shell .xuanya-family-meta button {
  color: #614a20; border-color: #dbc58e; background: #f7edd3;
}
html[data-theme="light"] .v2-shell :is(.xuanya-cover, .xuanya-card-secondary, .xuanya-child-count) {
  color: var(--theme-text); border-color: var(--theme-line);
  background: #f3eee6;
}
html[data-theme="light"] .v2-shell :is(.xuanya-cover img, .xuanya-card-secondary img) { background: #f3eee6; }
html[data-theme="light"] .v2-shell .xuanya-cover .media-placeholder {
  color: var(--theme-text-dim); background: #f3eee6;
}
html[data-theme="light"] .v2-shell .xuanya-empty-mark { color: rgba(131, 103, 53, .35); }
html[data-theme="light"] .v2-shell .xuanya-card-secondary::after {
  background: linear-gradient(transparent, rgba(243, 238, 230, .97));
}
html[data-theme="light"] .v2-shell .xuanya-child-count strong { color: var(--theme-text); }
html[data-theme="light"] .v2-shell .xuanya-family-card footer span { color: var(--theme-text-soft); }
html[data-theme="light"] .v2-shell .xuanya-family-card footer b { color: #87662b; }

/* Login follows the selected theme too. Provider brand marks retain their own
 * colors, while the surrounding page and fields stay within this palette. */
#login-modal,
.login-shell { color: var(--theme-text); background-color: var(--theme-canvas); }
.login-card,
.login-auth-glass { color: var(--theme-text); border-color: var(--theme-line); background: var(--theme-surface); }
.login-card input,
.login-card select { color: var(--theme-text); border-color: var(--theme-line-strong); background: var(--theme-surface-soft); }

/* Shared, in-place appearance dialog for the homepage and both workspaces. */
.ui-preferences-dialog {
  box-sizing: border-box; width: min(480px, calc(100vw - 32px));
  max-width: none; max-height: calc(100dvh - 32px); margin: auto; padding: 24px;
  overflow: auto; overscroll-behavior: contain; border: 1px solid var(--theme-line-strong);
  border-radius: 20px; color: var(--theme-text); background: var(--theme-surface);
  box-shadow: var(--theme-shadow); font-family: inherit;
}
.ui-preferences-dialog::backdrop { background: rgba(10, 12, 16, .4); backdrop-filter: blur(4px); }
.ui-preferences-dialog .theme-preferences-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin: 0 0 22px; }
.ui-preferences-dialog h2 { margin: 0 0 6px; color: var(--theme-text); font-size: 20px; line-height: 1.35; }
.ui-preferences-dialog .theme-preferences-head p { margin: 0; color: var(--theme-text-soft); font-size: 13px; line-height: 1.6; }
.ui-preferences-dialog button { font-family: inherit; cursor: pointer; }
.ui-preferences-dialog button:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 4px; }
.ui-preferences-dialog .preferences-close { display: grid; place-items: center; flex: 0 0 auto; width: 32px; height: 32px; padding: 6px; border: 0; border-radius: 8px; background: transparent; color: var(--theme-text-soft); }
.ui-preferences-dialog .preferences-close svg { width: 20px; height: 20px; }
.ui-preferences-dialog .preferences-close:hover { background: var(--theme-surface-soft); color: var(--theme-text); }
.ui-preferences-dialog .theme-choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.ui-preferences-dialog .theme-choice { display: grid; min-width: 0; gap: 6px; padding: 14px; text-align: left; border: 1px solid var(--theme-line-strong); border-radius: 12px; color: var(--theme-text); background: var(--theme-surface-soft); transition: border-color .16s ease, box-shadow .16s ease; }
.ui-preferences-dialog .theme-choice:hover { border-color: var(--ui-accent); }
.ui-preferences-dialog .theme-choice.is-active { border-color: var(--ui-accent); box-shadow: 0 0 0 2px var(--ui-accent-soft); }
.theme-choice-preview { position: relative; display: block; width: 100%; height: 86px; overflow: hidden; margin-bottom: 6px; border-radius: 8px; border: 1px solid rgba(127,118,101,.24); }
.theme-choice-preview i { position: absolute; inset: 0 auto 0 0; width: 28%; }
.theme-choice-preview b { position: absolute; top: 13px; left: 39%; right: 10px; height: 13px; border-radius: 4px; }
.theme-choice-preview em { position: absolute; top: 34px; left: 39%; right: 10px; bottom: 11px; border-radius: 5px; }
.theme-choice-preview-light { background: #f4f1eb; }
.theme-choice-preview-light i { background: #fffdf9; border-right: 1px solid rgba(49,42,31,.11); }
.theme-choice-preview-light b { background: #c9a95d; }
.theme-choice-preview-light em { background: #fffdf9; border: 1px solid rgba(49,42,31,.11); }
.theme-choice-preview-dark { background: #0f1115; }
.theme-choice-preview-dark i { background: #171a21; border-right: 1px solid rgba(255,255,255,.09); }
.theme-choice-preview-dark b { background: #c9a95d; }
.theme-choice-preview-dark em { background: #171a21; border: 1px solid rgba(255,255,255,.09); }
.theme-choice strong { align-self: end; color: var(--theme-text); font-size: 15px; }
.theme-choice small { align-self: start; color: var(--theme-text-soft); font-size: 11px; }
.ui-preferences-dialog .theme-preferences-footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--theme-line); }
.ui-preferences-dialog .theme-preferences-footer > span { color: var(--theme-text-soft); font-size: 12px; }
.ui-preferences-dialog .preferences-done { padding: 8px 22px; border: 1px solid var(--ui-accent); border-radius: 9px; color: #211b10; background: var(--ui-accent); font-size: 13px; font-weight: 600; }
@media (max-width: 480px) {
  .ui-preferences-dialog { padding: 20px; border-radius: 16px; }
  .ui-preferences-dialog .theme-choice { padding: 10px; }
}
