/* Shared final state layer. Keep legacy component rules from stacking rings. */
:root { --control-focus-color: var(--accent); }

/* Inset 2px indicators preserve control geometry. */
:focus-visible:not(.creation-filters button) {
  outline: 2px solid var(--control-focus-color) !important;
  outline-offset: -2px !important;
  box-shadow: none !important;
}

/* Text fields already have a border: recolor it instead of adding a ring. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  border-color: var(--control-focus-color) !important;
  outline: none !important;
  box-shadow: none !important;
}
.account-form input:focus { background: var(--card); }
/* Change only the fill so select arrows retain their image, size and position. */
.field input:focus, .field select:focus, .field textarea:focus,
.more-desc:focus, .remix-prompt:focus { background-color: var(--card); }
.saved-row select:focus, .text-editor-input-row input:focus,
.whole-prompt textarea:focus { background-color: var(--field); }
.admin-app :is(input, select, textarea):focus { background-color: var(--card); }

/* Compound search controls own the single border, not their inner input. */
:is(.inspiration-search, .creations-search):focus-within {
  border-color: var(--control-focus-color) !important;
  outline: none !important;
  box-shadow: none !important;
  transform: none !important;
}
:is(.inspiration-search, .creations-search) input:focus {
  border: 0 !important;
  background: transparent !important;
}
.inspiration-search:focus-within > .ri-icon { color: inherit; transform: none; }

/* Reserve a 1px border in both states so selection never changes geometry. */
:is(.account-tabs, .account-task-tabs, .edit-mode-switch,
    .canvas-view-switch, .ops-trend-tabs) button {
  border: 1px solid transparent !important;
  background: transparent !important;
  color: var(--muted-strong) !important;
  box-shadow: none !important;
}
:is(.account-tabs, .account-task-tabs, .edit-mode-switch,
    .canvas-view-switch, .ops-trend-tabs)
    button:is(.active, [aria-pressed="true"], [aria-selected="true"], [aria-expanded="true"]) {
  border-color: var(--control-focus-color) !important;
}
:is(.tone-opt, .style-opt) {
  border: 1px solid var(--border) !important;
  background: var(--field) !important;
  color: var(--text-soft) !important;
  box-shadow: none !important;
}
:is(.tone-opt, .style-opt):has(input:checked),
:is(.tone-opt, .style-opt):has(input:focus-visible) {
  border-color: var(--control-focus-color) !important;
  outline: none !important;
}
.color-swatch.active, .color-swatch.keep.active {
  border: 1px solid var(--control-focus-color);
  box-shadow: none !important;
}
.generation-version-button[aria-selected="true"] {
  border-color: var(--control-focus-color);
  color: var(--text-soft);
  background: transparent;
  box-shadow: none;
}
.recharge-tiers button.active {
  border-color: var(--control-focus-color);
  background: var(--surface-2);
  box-shadow: none;
}
#studioView[data-stage="create"] #remixCard .element-inventory-item:is(.is-selected, .is-peeking) {
  border-color: var(--control-focus-color);
  background: var(--card);
  box-shadow: none;
}
#remixCard .quick-element-editor.is-selected > input,
#remixCard .quick-element-editor.is-selected .element-reference-upload {
  border-color: var(--control-focus-color);
  box-shadow: none;
}
/* Border and keyboard outline share the same edge, preventing doubled rings. */
:is(button, a, [tabindex]):focus-visible:not(.creation-filters button) { border-color: var(--control-focus-color) !important; }

/* Overlap the existing border inward for a single 2px stroke, without reflow. */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="file"]):not(.inspiration-search input, .creations-search input):focus,
select:focus, textarea:focus,
:is(.inspiration-search, .creations-search):focus-within,
:is(.account-tabs, .account-task-tabs, .edit-mode-switch,
    .canvas-view-switch, .ops-trend-tabs)
    button:is(.active, [aria-pressed="true"], [aria-selected="true"], [aria-expanded="true"]),
:is(.tone-opt, .style-opt):has(input:checked),
:is(.tone-opt, .style-opt):has(input:focus-visible),
.color-swatch.active, .color-swatch.keep.active,
.generation-version-button[aria-selected="true"],
.recharge-tiers button.active,
#studioView[data-stage="create"] #remixCard .element-inventory-item:is(.is-selected, .is-peeking),
#remixCard .quick-element-editor.is-selected > input,
#remixCard .quick-element-editor.is-selected .element-reference-upload {
  outline: 2px solid var(--control-focus-color) !important;
  outline-offset: -2px !important;
}
/* Only the wrapper is outlined for a compound search field. */
:is(.inspiration-search, .creations-search) input:focus,
:is(.inspiration-search, .creations-search) input:focus-visible {
  outline: none !important;
}

/* Tone selection stays text-only; the radio dot is the sole selected indicator. */
.tone-toggle .tone-opt,
.tone-toggle .tone-opt:has(input:checked),
.tone-toggle .tone-opt:has(input:focus-visible) {
  min-height: 44px;
  padding: 7px 4px;
  border-color: transparent !important;
  outline: none !important;
  background: transparent !important;
  box-shadow: none !important;
}
.tone-toggle .tone-opt { color: var(--text-soft) !important; }
.tone-toggle .tone-opt:has(input:checked) { color: var(--text) !important; }
.tone-toggle .tone-opt input[type="radio"] {
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-content: center;
  width: 16px;
  height: 16px;
  margin: 0;
  flex: 0 0 auto;
  border: 1.5px solid var(--muted-strong);
  border-radius: 50%;
  background: transparent;
  color: var(--control-focus-color);
  cursor: pointer;
}
.tone-toggle .tone-opt input[type="radio"]::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  transform: scale(0);
  transition: transform 120ms ease;
}
.tone-toggle .tone-opt input[type="radio"]:checked {
  border-color: currentColor;
}
.tone-toggle .tone-opt input[type="radio"]:checked::before {
  transform: scale(1);
}
.tone-toggle .tone-opt input[type="radio"]:focus-visible {
  outline: none !important;
  box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--control-focus-color) !important;
}

/* Focused editor: keep the right rail calm and action-led. The canvas layout
   and its interaction surface are intentionally left untouched. */
#studioView.focused-editor[data-stage="create"] #remixCard .context-head-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
}
#studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav,
#studioView.focused-editor[data-stage="create"] #remixCard .edit-mode-switch {
  display: none !important;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu {
  position: relative;
  z-index: 30;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu > summary {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 50%;
  color: var(--muted-strong);
  background: transparent;
  cursor: pointer;
  list-style: none;
  letter-spacing: 2px;
  font-weight: 800;
  line-height: 1;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu > summary::-webkit-details-marker { display: none; }
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu > summary:hover,
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu > summary:focus-visible,
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu[open] > summary {
  color: var(--text);
  background: var(--field);
  outline: none;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  display: grid;
  width: 176px;
  padding: 6px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow-md);
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover button {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  text-align: left;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover button:hover,
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover button:focus-visible {
  background: var(--field);
  outline: none;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover button.is-danger { color: var(--danger, #c62828); }
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: .55;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover .ri-icon { width: 18px; height: 18px; flex: 0 0 auto; }
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual .context-scope {
  display: flex !important;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 0 20px 12px;
  color: var(--muted-strong);
  font-size: 12px;
}
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual .context-scope select {
  min-height: 44px;
  border-radius: 10px;
  background: var(--field);
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-done-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  flex: none;
  padding: 12px 20px 16px;
  border-top: 0;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-actions {
  display: block !important;
  margin: 0;
  padding: 0;
  order: 0;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-applied-status {
  display: block;
  min-height: 20px;
  color: var(--success);
  font-size: 12px;
  line-height: 1.5;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-applied-status:not(.show) { visibility: hidden; }
#studioView.focused-editor[data-stage="create"] #remixCard .context-applied-status.is-error { color: var(--danger, #c62828); }
#studioView.focused-editor[data-stage="create"] #remixCard #contextPendingHint {
  display: none !important;
}
#studioView.focused-editor[data-stage="create"] #remixCard #dynamicElementEditor .element-delete-bar { display: none !important; }
#studioView.focused-editor[data-stage="create"] #remixCard #dynamicElementEditor .field-note {
  margin-top: -4px;
  color: var(--muted);
  font-size: 11px;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-close:focus-visible,
#studioView.focused-editor[data-stage="create"] #remixCard .context-action-menu > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  #studioView.focused-editor[data-stage="create"] #remixCard .context-action-popover { transition: none; }
}

/* Restored all-elements rail. The canvas remains untouched; this only changes
   the inspector's navigation, inventory, and saved-state presentation. */
#studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav {
  display: flex !important;
  margin: 0 20px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--field);
}
#studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav button {
  min-height: 40px;
  border-radius: 10px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 600;
  transition: background-color 160ms ease, color 160ms ease;
}
#studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav button:focus-visible {
  outline: 2px solid var(--border-strong);
  outline-offset: -2px;
}
@media (hover: hover) and (pointer: fine) {
  #studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav button:not([aria-pressed="true"]):not([aria-expanded="true"]):hover {
    color: var(--text);
    background: color-mix(in srgb, var(--card) 55%, var(--field));
  }
}
#studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav button[aria-pressed="true"],
#studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav button[aria-expanded="true"] {
  color: var(--text);
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
@media (prefers-reduced-motion: reduce) {
  #studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav button { transition: none; }
}
#studioView.focused-editor[data-stage="create"] #remixCard #editorAllElementsCount {
  margin-left: 4px;
  color: var(--muted-strong);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
#studioView.focused-editor[data-stage="create"] #remixCard .context-scope,
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual .context-scope { display: none !important; }
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .context-panel-scroll {
  padding: 0 20px 20px;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .context-empty {
  display: block !important;
  min-height: 0;
  padding: 0;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .context-empty-hero,
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .open-all-editable,
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .whole-prompt {
  display: none !important;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory {
  display: grid !important;
  gap: 10px;
  padding: 18px 0 4px;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-head {
  padding: 0 2px 2px;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-head strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-head span {
  color: var(--muted-strong);
  font-size: 12px;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-list {
  display: grid;
  gap: 8px;
  max-height: none;
  overflow: visible;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-item {
  min-height: 56px;
  border-radius: 12px;
  border-color: var(--border);
  background: var(--card);
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-item.is-selected,
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-item.is-peeking {
  border-color: color-mix(in srgb, var(--accent) 62%, var(--border));
  background: color-mix(in srgb, var(--accent-soft) 72%, var(--card));
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 12%, transparent);
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-status.is-keep {
  color: var(--muted);
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-item.is-selected .element-inventory-status.is-keep {
  color: var(--accent);
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .element-inventory-action {
  min-width: 36px;
  min-height: 36px;
}
#studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .context-done-bar {
  display: none !important;
}
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual .context-done-bar {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual #contextPendingHint {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--success);
  font-size: 12px;
}
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual #contextPendingHint::before {
  content: '✓';
  display: inline-block;
  margin-right: 6px;
  font-weight: 800;
}
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual #contextActions {
  flex: 0 0 auto;
  order: 1;
}
#studioView.focused-editor[data-stage="create"] #remixCard.is-contextual .context-applied-status:not(.show) {
  display: none;
}

@media (max-width: 820px) {
  #studioView.focused-editor[data-stage="create"] #remixCard .editor-panel-nav {
    margin-inline: 12px;
  }
  #studioView.focused-editor[data-stage="create"] #remixCard[data-browse-mode="all"] .context-panel-scroll {
    padding-inline: 12px;
  }
}
