/* 禁用 details 元素的折叠动画，确保高度瞬时变化 */
details.card,
.popup-main-card,
.theme-main-card {
  transition-property: none !important;
  transition-duration: 0s !important;
  transition-delay: 0s !important;
  transition-timing-function: unset !important;
  will-change: unset !important;
}
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1d2230;
  --panel-inner: #10131b;
  --panel-soft: #151923;
  --panel-deep: #11151d;
  --text: #e8ebf2;
  --sub: #9aa4ba;
  --primary: #4f8cff;
  --macro: #3f8f6a;
  --border: #2a3142;
  --ok: #4cc38a;
  --err: #ff6b6b;
  --color-scheme: dark;
  --topbar-height: 72px;
  --preview-panel-height: clamp(140px, 22vh, 220px);
  --preview-zoom: 1;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: clamp(12px, 1.8vh, 15px)/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.topbar {
  /* 顶栏随页面滚动（借鉴 foxy-see-me）：滚动离开后由悬浮撤销/回到顶部按钮接管 */
  position: static;
  z-index: 10;
  padding: 10px 16px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(20px, 4.6vw, 28px);
  line-height: 1.15;
}

.topbar h2 {
  margin: 4px 0 0;
  font-size: clamp(12px, 2.4vw, 15px);
  font-weight: 500;
  line-height: 1.25;
  color: var(--sub);
}

.topbar p {
  margin: 0;
  color: var(--sub);
}

.topbar h2 a,
.topbar h2 a:visited,
.topbar h2 a:hover,
.topbar h2 a:active {
  color: inherit;
}

.tabs {
  display: flex;
  gap: clamp(4px, 1vh, 8px);
  padding: clamp(8px, 1.2vh, 12px) clamp(12px, 2.5vh, 20px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 8;
  background: var(--bg);
}

.tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: clamp(5px, 0.8vh, 8px) clamp(8px, 1.5vh, 14px);
  cursor: pointer;
  border-radius: 6px;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
}

main {
  padding: 0 0 24px;
}

.panel {
  display: none;
  gap: clamp(8px, 1.5vh, 14px);
}

.panel.active {
  display: grid;
}

.grid {
  display: grid;
  gap: clamp(8px, 1.5vh, 14px);
  grid-template-columns: 1.4fr 1fr;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: clamp(8px, 1.5vh, 14px);
  margin: 12px 20px 0;
}

.card h2 {
  margin: 0 0 10px;
  font-size: clamp(14px, 2vh, 17px);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: clamp(4px, 1vh, 8px);
  margin-bottom: clamp(6px, 1.2vh, 10px);
}

button, .file-button {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: clamp(5px, 0.8vh, 8px) clamp(6px, 1.2vh, 12px);
  cursor: pointer;
}

summary {
  cursor: pointer;
  font-weight: 650;
}

.keyboard-preview-panel {
  position: relative;
  z-index: 9;
  background: var(--panel-deep);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px 8px;
}

.keyboard-preview-panel > summary {
  padding-right: 80px;
}

/* Overlay meta on summary line (moved out of preview-shell by JS) */
#layout-preview-meta {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-weight: 400;
  color: var(--sub);
  margin: 0;
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.layout-workbench {
  margin: 0 20px;
  display: grid;
  gap: 12px;
}

.layout-main-column {
  min-width: 0;
}

.layout-main-column .card {
  margin: 12px 0 0;
}

.editor-surface {
  padding: 12px 0 0;
  min-width: 0;
}

.spinner-strip {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.spinner-strip select {
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  background: var(--panel-inner);
  color: var(--text);
  color-scheme: var(--color-scheme);
}

.spinner-strip select:disabled {
  color: var(--sub);
  background: var(--panel-soft);
}

.spinner-strip select option {
  background: var(--panel-inner);
  color: var(--text);
}

.spinner-strip select option:checked {
  background: var(--primary);
  color: #fff;
}

.spinner-strip select:first-child {
  flex: 1.2;
}

.spinner-strip select:nth-child(2) {
  flex: 1;
}

.icon-button {
  width: 40px;
  min-width: 40px;
  height: 36px;
  padding: 0;
  border-radius: 0;
  font-size: 16px;
  font-weight: 700;
}

button:hover, .file-button:hover {
  border-color: var(--primary);
}

button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.file-button input {
  display: none;
}

input, select, textarea {
  width: 100%;
  background: var(--panel-inner);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  color-scheme: var(--color-scheme);
}

select option {
  background: var(--panel-inner);
  color: var(--text);
}

input[type="checkbox"] {
  width: auto;
  margin-right: 6px;
}

.form-row {
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-row > label {
  display: inline-block;
  margin-bottom: 0;
  min-width: 80px;
  color: var(--sub);
}

.theme-color-rows {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.theme-workbench {
  align-items: start;
}

.popup-workbench {
  align-items: start;
}

.theme-main-card {
  min-width: 0;
}

.popup-main-card {
  min-width: 0;
}

.popup-entry-list {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  min-width: 0;
}

.popup-entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--panel-inner);
  width: 100%;
  min-width: 0;
}

.popup-entry-key {
  flex: 0 0 auto;
  min-height: 34px;
  min-width: 42px;
  border: 1.5px solid #5e7aff;
  border-radius: 8px;
  background: #232e4a;
  color: #e6eaff;
  box-shadow: 0 1px 4px 0 rgba(94,122,255,0.10), inset 0 -1px 0 rgba(0, 0, 0, .18);
  font-weight: 700;
  font-size: 17px;
  line-height: 1;
  padding: 6px 12px;
}

.popup-entry-values {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 8px;
  overflow: visible;
  white-space: normal;
  min-width: 0;
}

.popup-chip {
  flex: 0 0 auto;
  min-height: 34px;
  min-width: 42px;
  border: 1px solid #3a415a;
  border-radius: 8px;
  padding: 6px 10px;
  background: #242a38;
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .18);
  transition: transform .12s ease, opacity .12s ease, border-color .12s ease, background-color .12s ease;
}

.popup-chip-add {
  background: #263047;
  border-color: var(--border);
  color: var(--text);
  cursor: pointer;
}

.popup-entry-add {
  flex: 0 0 auto;
}

.popup-chip.dragging {
  opacity: 0.55;
  cursor: grabbing;
  transform: scale(0.98);
}

.popup-chip.drop-before {
  border-left-color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}

.popup-chip.drop-after {
  border-right-color: var(--primary);
  box-shadow: inset -3px 0 0 var(--primary);
}

.popup-entry-delete {
  flex: 0 0 auto;
  border: 1px solid #d25858;
  background: #5b2424;
  color: #ffdede;
  font-size: 16px;
  padding: 7px 12px;
}

.theme-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin: 8px 0 12px;
}

.theme-background-editor {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.theme-background-preview-wrap {
  min-width: 0;
}

.theme-background-preview {
  position: relative;
  min-height: 150px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background-color: var(--panel-inner);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.theme-background-preview::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.08);
  pointer-events: none;
}

.theme-background-preview-image {
  position: absolute;
  inset: -18%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.theme-background-preview.empty {
  display: grid;
  place-items: center;
  color: var(--sub);
  font-size: 13px;
}

.theme-background-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  min-width: 0;
}

.theme-background-controls .form-row {
  min-width: 0;
}

.theme-background-controls input[type="range"],
.theme-background-controls input[type="text"],
.theme-background-controls select {
  width: 100%;
}

.theme-background-controls input[type="text"] {
  min-width: 0;
}

.theme-crop-stage-wrap {
  display: grid;
  gap: 8px;
}

.theme-crop-stage {
  position: relative;
  min-height: 260px;
  max-height: 70vh;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-inner);
  display: grid;
  place-items: center;
  touch-action: none;
}

.theme-crop-stage > img {
  display: block;
  max-width: 100%;
  max-height: 68vh;
  user-select: none;
  -webkit-user-drag: none;
}

.theme-crop-selection {
  position: absolute;
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.42);
  cursor: move;
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--primary);
}

.crop-handle.handle-nw { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-handle.handle-ne { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-handle.handle-sw { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-handle.handle-se { right: -8px; bottom: -8px; cursor: nwse-resize; }

.theme-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-inner);
  text-align: left;
}

.theme-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}

.theme-card-title {
  font-weight: 650;
  margin-bottom: 6px;
}

.theme-card-meta {
  color: var(--sub);
  font-size: 12px;
  margin-bottom: 6px;
}

.theme-card-preview {
  position: relative;
  display: block;
  border-radius: 6px;
  min-height: 92px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.theme-card-preview::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.06);
  pointer-events: none;
  z-index: 0;
}

.theme-card-preview-bg {
  position: absolute;
  inset: -18%;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  pointer-events: none;
  z-index: 1;
  border-radius: inherit;
}

.theme-card-preview-bar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  z-index: 2;
}

.theme-card-preview-name {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 35px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 2;
}

.theme-card-preview-key {
  position: absolute;
  overflow: hidden;
  background: var(--theme-card-key-bg, transparent);
  z-index: 2;
}

.theme-card-preview-key-mask {
  position: absolute;
  inset: calc(-1 * var(--theme-card-bg-bleed, 24px));
  background-image: var(--theme-card-bg-url, none);
  background-size: var(--theme-card-bg-width, 100%) var(--theme-card-bg-height, 100%);
  background-position:
    calc(-1 * var(--theme-card-bg-x, 0px) + var(--theme-card-bg-bleed, 24px))
    calc(-1 * var(--theme-card-bg-y, 0px) + var(--theme-card-bg-bleed, 24px));
  background-repeat: no-repeat;
  filter: blur(var(--theme-card-bg-blur, 0px)) brightness(var(--theme-card-bg-brightness, 100%));
  opacity: var(--theme-card-bg-mask-opacity, 0);
}

.theme-card-preview-key-tint {
  position: absolute;
  inset: 0;
  background: var(--theme-card-key-bg, transparent);
  opacity: var(--theme-card-key-tint-opacity, 1);
}

.theme-card-preview-space {
  position: absolute;
  left: 22%;
  width: 56%;
  height: 12px;
  bottom: 8px;
  border-radius: 999px;
}

.theme-card-preview-return {
  position: absolute;
  right: 8px;
  bottom: 7px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
}

.theme-color-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: var(--panel-inner);
}

.theme-color-row > label {
  display: block;
  margin-bottom: 8px;
  color: var(--sub);
}
.surface-active-mark {
  color: var(--primary);
  font-size: 0.85em;
  vertical-align: middle;
}

.theme-color-inputs {
  display: block;
}

.theme-ripple-auto {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--sub);
  font-size: 12px;
  cursor: pointer;
  user-select: none;
}

.theme-ripple-auto input {
  accent-color: var(--primary);
}

.theme-color-input {
  width: 100%;
}

.theme-color-picker {
  width: 56px;
  min-width: 56px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
}

.theme-color-swatches {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.theme-color-swatch {
  width: 22px;
  height: 22px;
  border: 1px solid var(--border);
  border-radius: 50%;
  padding: 0;
}

.theme-preview-extra,
.theme-preview-extra-side {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.theme-preview-mobile-card {
  display: none;
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  background: var(--panel-inner);
}

.theme-preview-mobile-card > summary {
  font-size: 12px;
  color: var(--sub);
}

.theme-preview-extra-mobile {
  display: grid;
  margin-top: 6px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.theme-preview-extra-mobile .theme-preview-extra-item {
  font-size: 13px;
  min-height: 26px;
}

.theme-preview-extra-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 18px;
  min-height: clamp(28px, 3.8vh, 34px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-preview-extra-item .label {
  display: inline;
  color: inherit;
  margin-bottom: 0;
  flex: 0 0 auto;
  font-weight: 600;
}

.theme-preview-extra-item .value {
  display: inline;
  color: inherit;
  font-weight: 600;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.theme-preview-extra-item.is-foreground-tone .label,
.theme-preview-extra-item.is-foreground-tone .value {
  font-weight: 800;
}

@media (max-width: 1100px) {
  .preview-shell {
    grid-template-columns: 1fr;
  }

  .theme-preview-extra-side {
    grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  }
}

.json-editor {
  min-height: 260px;
  resize: vertical;
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.json-editor-fallback {
  display: none;
}

.cm-editor {
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--panel-inner);
  font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.cm-editor.cm-focused {
  outline: 1px solid var(--primary);
}

.cm-editor .cm-scroller {
  min-height: 260px;
  overflow: auto;
}

.cm-editor .cm-content {
  padding: 8px 0;
}

.cm-editor .cm-gutters {
  border-right-color: var(--border);
}

.json-editor.small {
  min-height: 150px;
}

.json-editor.compact {
  min-height: 72px;
}

.json-card {
  min-width: 0;
}

.json-card-body {
  display: block;
}

.status {
  color: var(--sub);
  min-height: 18px;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.2;
}

.status.ok {
  color: var(--ok);
}

.status.err {
  color: var(--err);
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.layout-chip {
  min-width: clamp(36px, 5vh, 44px);
  min-height: clamp(28px, 4vh, 36px);
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--chip-key-bg, #242a38);
  color: var(--chip-key-fg, var(--text));
  padding: clamp(2px, 0.5vh, 5px) clamp(6px, 1.2vh, 12px);
  cursor: grab;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 650;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .18);
  transition: transform .12s ease, opacity .12s ease;
}

.layout-chip:active {
  cursor: grabbing;
}

.layout-chip.dragging {
  opacity: .55;
}

.layout-chip.alt-key {
  background: var(--chip-alt-bg, #303645);
  color: var(--chip-alt-fg, var(--sub));
}

.layout-chip.accent-key {
  background: var(--chip-accent-bg, var(--primary));
  border-color: var(--primary);
  color: var(--chip-accent-fg, white);
}

.layout-chip.macro-key {
  background: var(--macro);
  border-color: var(--macro);
  border-width: 2px;
  color: white;
}

.layout-chip.compose-key {
  color: var(--macro);
}

.layout-chip.space-key {
  min-width: clamp(80px, 12vh, 120px);
  background: var(--chip-space-bg, #2a3140);
  color: var(--chip-key-fg, var(--text));
}

.chip-main {
  line-height: 1;
  font-size: clamp(11px, 1.5vh, 13px);
}

.chip-alt {
  position: absolute;
  top: 3px;
  right: 5px;
  font-size: 10px;
  line-height: 1;
  color: var(--sub);
  font-weight: 500;
}

.layout-row-editor {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  transition: transform .12s ease, opacity .12s ease, background-color .12s ease;
}

.layout-row-editor.dragging {
  opacity: .6;
  background: rgba(96, 165, 250, .08);
}

.row-drag-handle {
  color: var(--sub);
  cursor: grab;
  user-select: none;
  touch-action: none;
  opacity: .55;
  width: 32px;
  text-align: center;

}

.key-list {
  flex: 1;
  min-height: 42px;
  cursor: grab;
}

.layout-preview {
  border-radius: 4px;
  padding: 10px;
  padding-top: calc(10px + var(--preview-top-bar-height, 0px));
  padding-bottom: calc(10px + var(--preview-bottom-padding, 0px));
  background-color: var(--panel-inner);
  max-width: 598px;
  margin: 0 auto;
  --preview-row-gap: 8px;
  --preview-key-hgap: 3px;
  --preview-key-vgap: 7px;
  --preview-key-radius: 6px;
  --preview-keyboard-max-width: 576px;
}

.layout-preview.layout-preview-split {
  max-width: 1248px;
  --preview-keyboard-max-width: 1228px;
}

.preview-shell {
  display: grid;
  grid-template-columns: minmax(160px, auto) minmax(0, 1fr) minmax(160px, auto);
  gap: 10px;
  align-items: start;
  padding-top: 4px;
  /* 两侧主题色块列贴住窗口左右边缘（用户要求），键盘列内部限宽居中 */
}

.preview-center {
  min-width: 0;
}

.layout-row {
  display: flex;
  justify-content: center;
}

.layout-row .keys {
  display: flex;
  gap: 0;
  min-height: var(--row-height, 42px);
  width: min(100%, var(--preview-keyboard-max-width, 576px));
  justify-content: center;
  padding: 0 var(--preview-side-padding, 0px);
}

.layout-key-slot {
  flex: 0 0 var(--key-width, 0%);
  min-width: 0;
  padding: 0 var(--preview-key-hgap, 3px);
  display: flex;
}

.layout-key {
  height: var(--key-height, calc(var(--row-height, 42px) - var(--preview-key-vgap, 0px) * 2));
  width: 100%;
  color: var(--text);
  border-radius: var(--preview-key-radius, 6px);
  border: 1px solid var(--border);
  background: var(--preview-key-bg, #242a38);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  position: relative;
  overflow: hidden;
  padding: 0;
  font-size: clamp(14px, 42cqw, 23px);
  cursor: default;
  container-type: inline-size;
  margin: max(var(--preview-key-vgap, 0px), 2px) 0;
}

.layout-key.placeholder-key-ghost {
  visibility: hidden;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  pointer-events: none;
}

.layout-key.no-border {
  border-width: 0 !important;
}

/* Preview click-to-edit affordance: preview keys open the key editor. */
#layout-preview .layout-key[data-preview-row],
#layout-preview .layout-key[data-preview-aux-key] {
  cursor: pointer;
}

#layout-preview .layout-key[data-preview-row]:hover,
#layout-preview .layout-key[data-preview-aux-key]:hover {
  filter: brightness(1.08);
}

#layout-preview .layout-key[data-preview-row]:focus-visible,
#layout-preview .layout-key[data-preview-aux-key]:focus-visible {
  outline: 2px solid var(--primary, #4f8cff);
  outline-offset: 1px;
}

.layout-key.border-shadow {
  border-width: 0 !important;
  /* 底部实心偏移投影，模拟 app 键位底部阴影层；按键纵向 margin 保证投影有落点 */
  box-shadow: 0 2px 0 var(--preview-key-shadow, rgba(0, 0, 0, 0.18));
}

.layout-key.border-outline {
  box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.18);
}

.layout-key-blur-mask {
  position: absolute;
  inset: calc(-1 * var(--preview-bg-bleed, 32px));
  border-radius: inherit;
  background-image: var(--preview-bg-url, none);
  background-size: var(--preview-bg-width, 100%) var(--preview-bg-height, 100%);
  background-position:
    calc(-1 * var(--preview-bg-x, 0px) + var(--preview-bg-bleed, 32px))
    calc(-1 * var(--preview-bg-y, 0px) + var(--preview-bg-bleed, 32px));
  background-repeat: no-repeat;
  filter: blur(var(--preview-bg-blur, 0px)) brightness(var(--preview-bg-brightness, 100%));
  opacity: var(--preview-bg-mask-opacity, 0);
  pointer-events: none;
}

.layout-key-blur-tint {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: var(--preview-key-bg, transparent);
  opacity: var(--preview-bg-key-tint-opacity, 1);
  pointer-events: none;
}

.layout-key.gboard-pill {
  border-radius: 999px !important;
}

.layout-key.punct-bottom {
  flex-direction: column;
  justify-content: center;
  gap: 1px;
}

.layout-key.punct-top-center {
  flex-direction: column-reverse;
  justify-content: center;
  gap: 1px;
}

.layout-key-main {
  line-height: 1;
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-align: center;
  text-overflow: clip;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

.layout-key.language-key .layout-key-main {
  line-height: 1.2;
  overflow: visible;
}

.row-add-key,
.row-delete {
  min-width: 36px;
  height: 34px;
  padding: 0 8px;
  border-radius: 4px;
}

.add-row-wrap {
  display: flex;
  justify-content: center;
  padding: 18px 0 8px;
}

.add-row-button {
  min-width: 160px;
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  font-weight: 700;
}

.layout-key.alt-key {
  background: var(--preview-key-bg, #303645);
  color: var(--sub);
  font-size: clamp(12px, 34cqw, 16px);
  font-weight: 700;
}

.layout-key.accent-key {
  background: var(--preview-key-bg, var(--primary));
  border-color: var(--primary);
  color: white;
  font-size: clamp(13px, 38cqw, 20px);
}

.layout-key.macro-key {
  background: var(--preview-key-bg, var(--macro));
  border-color: var(--macro);
  border-width: 2px;
  color: white;
  font-size: clamp(13px, 38cqw, 20px);
}

.layout-key.compose-key {
  color: var(--primary);
}

.layout-key.space-key {
  background: var(--preview-key-bg, #2a3140);
  font-size: clamp(12px, 20cqw, 18px);
  color: var(--sub);
}

.layout-key-alt {
  position: absolute;
  top: 4px;
  right: 6px;
  max-width: calc(100% - 12px);
  overflow: hidden;
  text-align: right;
  text-overflow: clip;
  white-space: nowrap;
  font-size: clamp(7px, 18cqw, 10px);
  color: var(--sub);
  line-height: 1;
  z-index: 1;
}

.layout-key-alt.bottom {
  position: static;
  max-width: 100%;
  text-align: center;
  margin-top: 1px;
}

.layout-key-alt.top-center {
  position: absolute;
  top: 4px;
  left: 6px;
  right: 6px;
  max-width: calc(100% - 12px);
  text-align: center;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 500;
  font-size: clamp(8px, 14cqw, 12px);
  color: var(--sub);
  line-height: 1;
}

/* ===== 辅助选择栏预览（写入 __meta__.aux_bar） ===== */
.aux-bar-preview {
  display: flex;
  min-height: 34px;
  overflow: hidden;
}

.aux-bar-preview .aux-bar-keys {
  width: 100%;
}

.aux-bar-preview .keys .layout-key-slot {
  flex: 1 1 0;
}

.aux-bar-preview .layout-key {
  font-size: clamp(10px, 30cqw, 15px);
}

.aux-bar-top {
  margin-bottom: 8px;
}

.aux-bar-bottom {
  margin-top: 8px;
}

.aux-bar-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px dashed var(--border, rgba(255, 255, 255, .25));
  border-radius: var(--preview-key-radius, 6px);
  color: var(--sub);
  font-size: 12px;
  padding: 4px 8px;
  text-align: center;
}

.aux-bar-above-preedit {
  margin-bottom: 4px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border, rgba(255, 255, 255, .18));
}

.aux-bar-hwrap {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.aux-bar-hwrap .aux-bar-main {
  flex: 1 1 auto;
  min-width: 0;
}

.aux-bar-vwrap {
  flex: 0 0 var(--aux-bar-size, 15%);
  min-width: 72px;
  max-width: 40%;
}

.aux-bar-vwrap .aux-bar-preview {
  height: 100%;
  align-items: stretch;
}

.aux-bar-vwrap .aux-bar-preview .aux-bar-keys {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.aux-bar-vwrap .aux-bar-preview .keys .layout-key-slot {
  flex: 1 1 0;
}

.aux-bar-vwrap .aux-bar-preview .layout-key-slot .layout-key {
  height: 100%;
}

/* ===== 辅助选择栏设置对话框 ===== */
.aux-bar-key-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 34px;
  margin-top: 6px;
}

.aux-bar-chip {
  cursor: pointer;
}

.aux-bar-chip-add {
  background: transparent;
  border-style: dashed;
  color: var(--sub);
}

#layout-aux-bar-size {
  flex: 1 1 auto;
}

#layout-aux-bar-size-label.dimmed {
  opacity: .5;
}

#layout-aux-bar-keys-section label {
  color: var(--sub);
}

.qr-wrap {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.qr-wrap[hidden] {
  display: none !important;
}

.qr-wrap canvas {
  width: min(100%, 360px);
  height: auto;
  background: #fff;
}

.qr-nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.qr-wrap-modal {
  justify-items: center;
}

.qr-wrap-modal canvas {
  width: min(100%, 520px);
}

.cm-editor.cm-readonly {
  opacity: 0.9;
}

.editor-dialog {
  width: min(860px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

.editor-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.editor-form {
  padding: 12px;
}

.dialog-titlebar {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  margin: -12px -12px 12px;
  padding: 10px 12px;
}

.dialog-titlebar h3 {
  margin: 0;
  flex: 1;
  font-size: 18px;
}

.details-toolbar {
  margin-top: 12px;
}

.stack-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0 6px;
  align-items: stretch;
  justify-items: stretch;
  /* 响应式：小屏幕时回退为一列 */
}
@media (max-width: 520px) {
  .stack-actions {
    grid-template-columns: 1fr;
  }
}

.sub-edit-summary {
  margin-bottom: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  align-items: center;
  /* 响应式：小屏幕时回退为一列 */
}
@media (max-width: 520px) {
  .sub-edit-summary {
    grid-template-columns: 1fr;
  }
}

.sub-dialog {
  width: min(780px, calc(100vw - 32px));
}

.json-dialog {
  width: min(1040px, calc(100vw - 32px));
}

.json-dialog .form-row,
.json-dialog .cm-editor,
.json-dialog .json-editor {
  width: 100%;
  max-width: 100%;
}

.display-map-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  margin-bottom: 8px;
}

.color-edit-row {
  display: grid;
  grid-template-columns: 140px minmax(110px, 0.9fr) minmax(160px, 1fr) 120px;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}

.color-edit-row > label {
  color: var(--sub);
}

.color-edit-row .color-mode,
.color-edit-row .color-theme-select,
.color-edit-row .color-monet-select,
.color-edit-row .color-custom-input {
  width: 100%;
}

@media (max-width: 640px) {
  .color-edit-row {
    grid-template-columns: 1fr;
    gap: 6px;
    margin-bottom: 12px;
  }

  .color-edit-row > label {
    margin-bottom: 2px;
  }
}

.layout-gradient-anchor-list {
  display: grid;
  gap: 8px;
  margin: 10px 0;
}

.layout-gradient-anchor-row {
  display: grid;
  grid-template-columns: minmax(180px, 1.1fr) repeat(4, minmax(120px, 1fr)) auto;
  gap: 8px;
  align-items: center;
}

.layout-gradient-anchor-row .layout-gradient-anchor-color,
.layout-gradient-anchor-row .layout-gradient-anchor-key {
  width: 100%;
}

.layout-gradient-anchor-remove {
  min-width: 40px;
  padding: 8px 12px;
}

@media (max-width: 640px) {
  .layout-gradient-anchor-row {
    grid-template-columns: 1fr;
  }

  .layout-gradient-anchor-remove {
    width: 100%;
  }
}

.checker-preview {
  width: 120px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: conic-gradient(#b8b8b8 25%, #fff 0 50%, #b8b8b8 0 75%, #fff 0) 0 0/12px 12px;
  overflow: hidden;
}

.checker-preview-color {
  width: 100%;
  height: 100%;
}

.color-palette {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 6px;
}

.color-palette-chip {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: pointer;
}

.macro-step-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: #141925;
  cursor: default;
  touch-action: manipulation;
}

.macro-step-row.dragging {
  opacity: 0.7;
  border-color: var(--primary);
}

.macro-step-type {
  width: auto;
  max-width: 118px;
}

.macro-step-body {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.macro-step-body > textarea {
  flex: 1;
  min-width: 180px;
}

.macro-key-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  min-width: 0;
}

.macro-key-row {
  display: flex;
  gap: 4px;
  align-items: center;
  min-width: 0;
}

.macro-chip,
.macro-chip-select {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #1e2636;
  color: var(--fg);
}

.macro-chip {
  padding: 6px 10px;
}

.macro-chip-select {
  width: auto;
  max-width: 180px;
}

.macro-chip-add {
  background: #263047;
}

.macro-step-delete {
  background: #2e2330;
}

.macro-chip-text {
  min-width: 220px;
  min-height: 40px;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

#theme-app-sync-card .form-grid-2 {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 6px 10px;
}

#theme-app-sync-card .theme-app-sync-layout {
  display: grid;
  gap: 8px;
}

#theme-app-sync-card .theme-app-sync-toggles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 10px;
}

#theme-app-sync-card .theme-app-sync-controls {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 10px;
}

#theme-app-sync-card .form-row {
  margin-bottom: 4px;
}

#theme-app-sync-card .form-row > label {
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  line-height: 1.25;
}

#theme-app-sync-card input[type="number"] {
  width: 78px;
  padding: 4px 6px;
}

#theme-app-sync-card select {
  min-width: 110px;
  padding: 4px 6px;
}

#theme-app-sync-card .form-row.form-inline {
  gap: 6px;
}

#theme-app-sync-card .form-row.form-inline > label {
  margin-bottom: 0;
  flex: 0 0 auto;
  white-space: nowrap;
}

#theme-app-sync-card .form-row.form-inline > select {
  flex: 1 1 auto;
  width: auto;
  min-width: 120px;
}

@media (max-width: 860px) {
  #theme-app-sync-card .theme-app-sync-toggles,
  #theme-app-sync-card .theme-app-sync-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  #theme-app-sync-card .theme-app-sync-toggles,
  #theme-app-sync-card .theme-app-sync-controls {
    grid-template-columns: 1fr;
  }
}

.form-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.form-inline .num {
  width: 90px;
}

/* when a form-row is used with form-inline, keep label inline and remove bottom margin */
.form-row.form-inline > label {
  display: inline-block;
  margin-bottom: 0;
}

/* make inputs behave inside inline form-row: take remaining space */
.form-row.form-inline > input,
.form-row.form-inline > select,
.form-row.form-inline > textarea {
  flex: 1 1 auto;
  width: auto;
}

.footnote {
  padding: 8px 20px 20px;
  color: var(--sub);
}

.visit-stats {
  margin: 2px 0 0;
  text-align: center;
  font-size: 12px;
}

.visit-stats > span {
  display: inline-block;
  margin: 0 4px;
}

.visit-sep {
  opacity: 0.6;
}

@media (min-width: 1081px) {
  .layout-workbench {
    grid-template-columns: minmax(420px, 1fr) minmax(420px, .95fr);
    align-items: stretch;
  }

  .layout-workbench.theme-workbench {
    /* 保持左右两栏在高度上可伸展以匹配并列的 json 卡 */
    align-items: stretch;
  }

  /* 对 popup 工作区，确保左右两栏卡片高度同步（stretch）
     以便 popup-json-card 与 popup-main-card 保持相同高度 */
  .layout-workbench.popup-workbench {
    align-items: stretch;
  }

  .layout-workbench .card {
    margin: 12px 0 0;
  }

  .json-card {
    min-height: 0;
  }

  .json-card[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .json-card[open] .json-card-body {
    min-height: 0;
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    overflow: hidden;
  }

  .json-card .cm-editor,
  .json-card .json-editor {
    min-height: 0;
    width: 100%;
    overflow: hidden;
  }

  .json-card .cm-scroller {
    min-height: 0;
  }

  .json-card .json-editor {
    resize: none;
    overflow: auto;
  }

  /* 让 theme 主卡在展开时采用栅格布局，使其内容区能够拉伸并与 theme-json-card 对齐 */
  .theme-main-card[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .theme-main-card[open] .theme-list,
  .theme-main-card[open] .theme-color-rows {
    min-height: 0;
    overflow: auto;
  }

  /* 让 popup 主卡在展开时也采用与 json-card 相似的栅格布局，
     使 .popup-entry-list 能随着父容器拉伸以填满高度 */
  .popup-main-card[open] {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
  }

  .popup-main-card[open] .popup-entry-list {
    min-height: 0;
    overflow: auto;
  }
}

@media (max-width: 1080px) {

  .grid {
    grid-template-columns: 1fr;
  }

  .layout-workbench,
  .layout-workbench.theme-workbench,
  .layout-workbench.popup-workbench {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .theme-background-editor,
  .theme-background-controls {
    grid-template-columns: 1fr;
  }

  .keyboard-preview-panel {
    padding: 8px 12px 6px;
  }

  .preview-shell {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .preview-center {
    width: 100%;
    min-width: 0;
  }

  .layout-row .keys {
    width: 100%;
    max-width: none;
  }

  .theme-preview-extra-side {
    display: none;
  }

  .layout-preview {
    width: 100% !important;
    max-width: 100%;
    margin: 0;
    padding-left: 8px;
    padding-right: 8px;
  }

  .layout-preview.layout-preview-split {
    max-width: 100%;
  }

  .popup-entry-row {
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
  }

  .popup-entry-key,
  .popup-entry-add,
  .popup-entry-delete {
    flex: 0 0 auto;
  }

  .popup-entry-values {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
    flex-wrap: wrap;
    overflow: visible;
    white-space: normal;
    gap: 6px;
  }

  .theme-preview-mobile-card {
    display: block;
  }
}

/* Compact vertical spacing for shorter viewports so footer can show */
@media (max-height: 980px) {

  .card {
    padding: 8px;
    margin: 6px 10px 0;
  }

  .layout-workbench {
    margin: 0 10px;
    gap: 6px;
  }

  .keyboard-preview-panel {
    padding: 6px 10px;
  }

  .footer-compact {
    padding: 6px 12px 12px;
  }
}

/* ── Icon Theme Editor ── */
.icon-theme-workbench {
  align-items: start;
}

.icon-theme-main-card {
  min-width: 0;
}

.icon-theme-slots {
  display: grid;
  gap: 0;
  margin-top: 10px;
  min-width: 0;
}

.icon-slot-section-header {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  padding: 12px 0 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.icon-slot-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(42, 49, 66, 0.4);
  min-height: 42px;
}

.icon-slot-row:hover {
  background: rgba(79, 140, 255, 0.04);
}

.icon-slot-builtin-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sub);
  font-size: 18px;
}

.icon-slot-name {
  flex: 1 1 auto;
  font-size: 13px;
  color: var(--text);
  min-width: 0;
}

.icon-slot-custom-preview {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: var(--text);
  overflow: hidden;
}

.icon-slot-custom-preview img,
.icon-slot-custom-preview svg {
  max-width: 100%;
  max-height: 100%;
}

.icon-slot-edit-btn {
  flex: 0 0 auto;
  font-size: 12px;
  padding: 3px 10px;
  min-width: 48px;
}

.icon-slot-compare {
  display: flex;
  gap: 16px;
  margin-bottom: 12px;
}

.icon-slot-preview-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.icon-slot-preview-label {
  font-size: 12px;
  color: var(--sub);
}

.icon-slot-preview-box {
  width: 48px;
  height: 48px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel-inner);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  overflow: hidden;
}

.icon-slot-preview-box img,
.icon-slot-preview-box svg {
  max-width: 100%;
  max-height: 100%;
}

.icon-slot-emoji-row {
  margin-bottom: 10px;
}

.icon-slot-emoji-row > label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--sub);
}

/* Grid-based icon theme card for icon theme list */
.icon-theme-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: var(--panel-inner);
  text-align: left;
  cursor: pointer;
}

.icon-theme-card.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary) inset;
}

.icon-theme-card-preview {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  border-radius: 6px;
  min-height: 64px;
  overflow: hidden;
  background: var(--panel);
}

.icon-theme-card-preview-cell {
  width: 100%;
  height: 30px;
  border: 1px solid rgba(42, 49, 66, 0.5);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.03);
}

.icon-theme-card-preview-cell img,
.icon-theme-card-preview-cell svg {
  max-width: 80%;
  max-height: 80%;
}

.icon-theme-card-name {
  font-size: 12px;
  font-weight: 600;
  margin-top: 6px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-theme-card-count {
  font-size: 11px;
  color: var(--sub);
  margin-top: 2px;
}

/* ── 站点亮/暗主题（借鉴 foxy-see-me）────────────────────────
 * html 根元素挂 site-auto / site-light / site-dark 三态类；
 * 亮色调色板覆盖同一组变量，auto 跟随系统偏好。
 * 少数硬编码深色的组件在下方补丁区单独适配。 */
html.site-light {
  --bg: #f3f5fa;
  --panel: #ffffff;
  --panel-2: #eef1f8;
  --panel-inner: #ffffff;
  --panel-soft: #eef1f8;
  --panel-deep: #e9edf5;
  --text: #1d2434;
  --sub: #5c6577;
  --primary: #2f6bff;
  --macro: #2e8f63;
  --border: #d7dce8;
  --ok: #1f9d63;
  --err: #d64545;
  --color-scheme: light;
}

@media (prefers-color-scheme: light) {
  html.site-auto {
    --bg: #f3f5fa;
    --panel: #ffffff;
    --panel-2: #eef1f8;
    --panel-inner: #ffffff;
    --panel-soft: #eef1f8;
    --panel-deep: #e9edf5;
    --text: #1d2434;
    --sub: #5c6577;
    --primary: #2f6bff;
    --macro: #2e8f63;
    --border: #d7dce8;
    --ok: #1f9d63;
    --err: #d64545;
    --color-scheme: light;
  }
}

/* 弹出字符卡片等硬编码深色的补丁 */
html.site-light .popup-entry-key {
  border-color: #9db4ff;
  background: #e4ebff;
  color: #1d2434;
  box-shadow: 0 1px 4px 0 rgba(47, 107, 255, 0.10), inset 0 -1px 0 rgba(0, 0, 0, .06);
}

html.site-light .popup-chip {
  border-color: #c9d1e2;
  background: #f2f4fa;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .06);
}

html.site-light .popup-chip-add {
  background: #e4ebff;
}

html.site-light .popup-entry-delete {
  border-color: #e3a1a1;
  background: #fbeaea;
  color: #8f2020;
}

@media (prefers-color-scheme: light) {
  html.site-auto .popup-entry-key { border-color: #9db4ff; background: #e4ebff; color: #1d2434; box-shadow: 0 1px 4px 0 rgba(47, 107, 255, 0.10), inset 0 -1px 0 rgba(0, 0, 0, .06); }
  html.site-auto .popup-chip { border-color: #c9d1e2; background: #f2f4fa; box-shadow: inset 0 -1px 0 rgba(0, 0, 0, .06); }
  html.site-auto .popup-chip-add { background: #e4ebff; }
  html.site-auto .popup-entry-delete { border-color: #e3a1a1; background: #fbeaea; color: #8f2020; }
}

/* ── 顶栏动作区 ────────────────────────────────────────── */
.topbar-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.topbar-title {
  min-width: 0;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
  padding-top: 4px;
}

.topbar-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.mini-button {
  padding: 4px 8px;
  font-size: 13px;
  line-height: 1.2;
  border-radius: 6px;
}

.mini-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.site-theme-group {
  display: inline-flex;
  gap: 4px;
}

.site-theme-btn.active {
  border-color: var(--primary);
  color: var(--primary);
}

/* ── 悬浮工具（撤销/重做 + 回到顶部）────────────────────── */
.float-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 40;
}

.float-layer > * {
  pointer-events: auto;
}

.float-group {
  position: fixed;
  right: 18px;
  bottom: 70px;
  display: flex;
  gap: 6px;
}

.float-bottom-right {
  position: fixed;
  right: 18px;
  bottom: 22px;
  padding: 8px 14px;
  border-radius: 999px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  font-size: 14px;
}

.float-bottom-right:hover {
  filter: brightness(1.1);
}

/* ── 预览工具条（借鉴 foxy-see-me 的 preview-toolbar）──── */
.preview-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 14px;
  padding: 2px 0 6px;
  font-size: 12px;
  color: var(--sub);
  max-width: 1120px;
  margin: 0 auto;
}

.preview-toolbar .pt-cell {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.preview-toolbar input[type="range"] {
  width: 110px;
  padding: 0;
}

.preview-toolbar .num-input {
  width: 58px;
  padding: 3px 5px;
  border-radius: 6px;
}

.preview-toolbar .pt-unit {
  color: var(--sub);
  margin-left: -2px;
}

.preview-toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  cursor: pointer;
}

.preview-toolbar-sep {
  width: 1px;
  height: 16px;
  background: var(--border);
}

/* ── JSON 校验面板（借鉴 foxy-see-me 的 json-issues）────── */
.json-issues {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 12.5px;
  font-weight: 400;
  display: none;
}

.json-issues.show {
  display: block;
}

.json-issues.warn {
  border-left: 3px solid #e0a34c;
  background: rgba(224, 163, 76, 0.08);
}

.json-issues.error {
  border-left: 3px solid var(--err);
  background: rgba(255, 107, 107, 0.08);
}

.json-issues.ok {
  border-left: 3px solid var(--ok);
  background: rgba(76, 195, 138, 0.08);
}

.json-issues .json-issue-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.json-issues .json-issue-main {
  flex: 1 1 auto;
  min-width: 0;
}

.json-issues .json-issue-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.json-issues button {
  padding: 3px 9px;
  font-size: 12px;
  border-radius: 6px;
}

.json-issue-locatable {
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.json-issue-locatable:hover {
  color: var(--primary);
}

/* ── 预览按键：按压反馈 / 徽章 / 滑动提示 ───────────────── */
.layout-key {
  position: relative;
  transition: filter 0.06s ease;
}

.layout-key:active {
  filter: brightness(1.12);
}

/* 按压时以主题 keyPressHighlightColor 作为整键覆盖层（颜色自带透明度） */
.layout-key.pressed {
  filter: none;
  box-shadow: inset 0 0 0 999px var(--preview-key-press, rgba(127, 127, 127, 0.25));
}

.key-badge {
  position: absolute;
  top: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  pointer-events: none;
}

.key-badge-lp {
  right: 5px;
  background: #4f8cff;
}

.key-badge-macro {
  left: 5px;
  background: #35c26e;
}

.layout-key-hint {
  position: absolute;
  top: 3px;
  right: 6px;
  font-size: 10px;
  line-height: 1.1;
  opacity: 0.72;
  pointer-events: none;
  max-width: 60%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layout-key-main {
  pointer-events: none;
}

.layout-key-icon {
  width: 1.25em;
  height: 1.25em;
  display: block;
}

.layout-key-alt {
  pointer-events: none;
}

.layout-key-blur-mask,
.layout-key-blur-tint {
  pointer-events: none;
}



/* ── 分体预览：中缝空槽 ────────────────────────────────── */
.layout-key-slot.layout-split-gap {
  flex: 0 0 var(--key-width, 0%);
  padding: 0;
  background: transparent;
  border: none;
}

/* ── CodeMirror 跟随站点亮暗（site-mode-light = 解析后的实际亮色模式）── */
html.site-mode-light .cm-editor {
  background: transparent;
  color: #383a42;
}

html.site-mode-light .cm-gutters {
  background: var(--panel-inner);
  color: #8a93a8;
  border-right-color: var(--border) !important;
}

html.site-mode-light .cm-activeLine {
  background: rgba(47, 107, 255, 0.06);
}

html.site-mode-light .cm-activeLineGutter {
  background: rgba(47, 107, 255, 0.10);
  color: var(--text);
}

html.site-mode-light .cm-content {
  caret-color: var(--primary);
}

/* oneDark 令牌色在白底下的对比度修正 */
html.site-mode-light .cm-keyword { color: #a626a4; }
html.site-mode-light .cm-definition { color: #4078f2; }
html.site-mode-light .cm-def { color: #4078f2; }
html.site-mode-light .cm-variable { color: #383a42; }
html.site-mode-light .cm-variableName { color: #383a42; }
html.site-mode-light .cm-property { color: #b76b01; }
html.site-mode-light .cm-string { color: #50a14f; }
html.site-mode-light .cm-number,
html.site-mode-light .cm-atom { color: #986801; }
html.site-mode-light .cm-bool { color: #986801; }
html.site-mode-light .cm-comment { color: #a0a1a7; font-style: italic; }
html.site-mode-light .cm-operator,
html.site-mode-light .cm-punctuation,
html.site-mode-light .cm-separator { color: #383a42; }
html.site-mode-light .cm-meta { color: #4078f2; }
html.site-mode-light .cm-bracket { color: #383a42; }
html.site-mode-light ::selection { background: rgba(47, 107, 255, 0.22); }

/* 暗色下显式光标色（oneDark 用自绘光标，原生 caret 透明；双保险保证可见） */
html.site-mode-dark .cm-content {
  caret-color: #dfe5f2;
}

/* 只读 JSON 文本域的视觉提示 */
textarea[readonly] {
  opacity: 0.72;
  cursor: not-allowed;
}
