/* 禁用 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;
  --text: #e8ebf2;
  --sub: #9aa4ba;
  --primary: #4f8cff;
  --macro: #3f8f6a;
  --border: #2a3142;
  --ok: #4cc38a;
  --err: #ff6b6b;
  --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 {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
  min-height: var(--topbar-height);
  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: calc(var(--topbar-height) + var(--preview-panel-height));
  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: calc(var(--topbar-height) + var(--preview-panel-height)) 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: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  z-index: 9;
  background: #11151d;
  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: #10131b;
  color: var(--text);
  color-scheme: dark;
}

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

.spinner-strip select option {
  background: #10131b;
  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: #10131b;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  color-scheme: dark;
}

select option {
  background: #10131b;
  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: #10131b;
  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-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  background: #10131b;
  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: 1px solid var(--border);
  border-radius: 6px;
  min-height: 92px;
  overflow: hidden;
  background-size: cover;
  background-position: center;
}

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

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

.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;
}

.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: #10131b;
}

.theme-color-row > label {
  display: block;
  margin-bottom: 8px;
  color: var(--sub);
}

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

.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: #10131b;
}

.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: #10131b;
  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: #242a38;
  color: 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: #303645;
  color: var(--sub);
}

.layout-chip.accent-key {
  background: var(--primary);
  border-color: var(--primary);
  color: 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: #2a3140;
}

.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: 1px solid var(--border);
  border-radius: 4px;
  padding: 10px;
  background: #10131b;
  max-width: 760px;
  margin: 0 auto;
  --preview-row-gap: 8px;
  --preview-key-hgap: 3px;
  --preview-key-vgap: 7px;
  --preview-key-radius: 4px;
}

.preview-shell {
  display: grid;
  grid-template-columns: minmax(160px, auto) minmax(0, 1fr) minmax(160px, auto);
  gap: 10px;
  align-items: start;
  padding-top: 4px;
  zoom: var(--preview-zoom, 1);
}

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

.layout-row {
  margin-bottom: var(--preview-row-gap, 8px);
  display: flex;
  justify-content: center;
}

.layout-row .keys {
  display: flex;
  gap: 0;
  min-height: var(--row-height, 42px);
  width: min(100%, 720px);
  justify-content: center;
}

.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, 4px);
  border: 1px solid var(--border);
  background: #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: var(--preview-key-vgap, 0px) 0;
}

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

.layout-key.border-shadow {
  border-width: 0 !important;
  box-shadow: inset 0 -1px 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.gboard-pill {
  border-radius: 999px !important;
}

.layout-key.punct-bottom {
  flex-direction: column;
  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;
}

.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: #303645;
  color: var(--sub);
  font-size: clamp(12px, 34cqw, 16px);
  font-weight: 700;
}

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

.layout-key.macro-key {
  background: 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: #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;
}

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

.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) {
  :root {
    --topbar-height: 96px;
    --preview-panel-height: clamp(140px, 22vh, 220px);
  }

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

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

  .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%;
    max-width: 100%;
    margin: 0;
    padding: 8px;
  }

  .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) {
  :root {
    --topbar-height: 64px;
    --preview-panel-height: clamp(120px, 18vh, 180px);
  }

  .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;
  }
}
