/* Edit mode: layer tabs, staged-edit bar, editable keyboard and key picker. */

/* Layer tabs on the left, the staged-edit controls on the right. */
.edit-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.layer-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.layer-tab {
  border: 1px solid var(--key-border);
  background: var(--key);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
}
.layer-tab.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--card);
}
/* A layer holding staged (unwritten) edits. */
.layer-tab.has-drafts::after {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}

.draft-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.draft-summary {
  padding: 5px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}
button.draft-summary { border-color: var(--accent); background: #fff4ee; color: var(--accent); }
button.draft-summary:hover { background: #ffe8dc; }
.draft-summary.is-empty { color: var(--muted); font-weight: 600; }

/* Latest write/sync message and the (collapsible) list of staged keys. */
.draft-panel {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: -4px 0 12px;
  padding: 8px 10px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--key);
}
.draft-panel[hidden] { display: none; }
.draft-status { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink); }
/* Every staged key, each individually revertible; scrolls when a whole
   keymap was carried over from the other half. */
.draft-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 160px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}
.draft-status + .draft-list { padding-top: 6px; border-top: 1px solid var(--rule); }
.draft-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.draft-list-target {
  padding: 2px 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  font-size: 12px;
  text-align: left;
}
.draft-list-target:hover { background: var(--page); color: var(--accent); }
.draft-list-revert {
  flex-shrink: 0;
  padding: 2px 10px;
  border: 1px solid var(--key-border);
  border-radius: 7px;
  background: var(--card);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}
.draft-list-revert:hover { border-color: var(--accent); color: var(--accent); }

.draft-legend-sample {
  width: 14px;
  height: 10px;
  border: 1.5px dashed var(--accent);
  border-radius: 3px;
  background: #fff4ee;
  flex-shrink: 0;
}

.changed-legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--changed);
  flex-shrink: 0;
}

/* Colors for composed keycodes, shared by the edit view's keys, its legend
   and the picker: LT blue, MO green, TO purple, MT amber, mods pink. */
/* Hues spread apart from each other, the red changed-key dot and the
   orange draft border, and dark enough (>= 4.5:1 on --key) to read as text. */
.kind-layer-tap { --kind-color: #1565c0; }
.kind-momentary { --kind-color: #7b3fbf; }
.kind-to { --kind-color: #9c6300; }
.kind-mod-tap { --kind-color: #2e7d32; }
/* Mod+ stays plain ink: the "+" in its label already says it's a combo. */
.kind-mods { --kind-color: var(--ink); }

/* One compact legend row under the keyboard, set off by a rule and a
   "凡例" label like the cheat sheet's own legend. */
.edit-legend-section {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
  padding: 10px 0 0;
  border-top: 1px solid var(--rule);
}
.edit-legend-section .legend-group-title { flex-shrink: 0; }
.edit-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 11px;
  color: var(--muted);
}
.edit-legend li { display: flex; align-items: center; gap: 5px; }
.kind-legend-sample {
  padding: 1px 5px;
  border: 1px solid var(--kind-color);
  border-radius: 5px;
  font-size: 10px;
  font-weight: 700;
  color: var(--kind-color);
  flex-shrink: 0;
}

.keyboard-view {
  position: relative;
  width: 100%;
  margin-bottom: 14px;
}

.editor-key {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: var(--key);
  border: 1px solid var(--key-border);
  border-radius: 9px;
  box-shadow: var(--key-shadow);
  color: var(--ink);
  padding: 2px;
  overflow: hidden;
  transform: rotate(var(--rotation, 0deg));
  transform-origin: top left;
}
.editor-key:hover { border-color: var(--accent); }
.editor-key.is-selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.editor-key.is-pending { opacity: .55; }
.editor-key.is-loading { background: var(--rule); }
.editor-key.is-empty { color: var(--muted); }
.editor-key.is-transparent { color: var(--key-border); }
.editor-key.is-draft { border: 1.5px dashed var(--accent); background: #fff4ee; }
.editor-key.is-draft.is-selected { box-shadow: 0 0 0 2px var(--accent); }
/* The key waiting for its swap partner (交換). */
.editor-key.is-swap-source { border-color: var(--ink); box-shadow: 0 0 0 2px var(--ink); }
/* Keys that differ from GitHub latest get only the corner dot; borders are
   reserved for selection and unwritten drafts. */
.editor-key.is-changed::after {
  content: "";
  position: absolute;
  top: 4px;
  right: 4px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--changed);
  box-shadow: 0 0 0 1px var(--card);
}

.editor-key-main {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  overflow-wrap: anywhere;
}
.editor-key-sub {
  font-size: 10px;
  font-weight: 600;
  color: var(--func);
}
/* LT/MO/MT color the hold label; TO and mods wraps color the main label. */
.editor-key[class*="kind-"] .editor-key-sub { color: var(--kind-color); }
.editor-key.kind-to .editor-key-main { color: var(--kind-color); }
/* ...and that colored label is boxed like the legend's .kind-legend-sample. */
.editor-key:is(.kind-layer-tap, .kind-momentary, .kind-mod-tap) .editor-key-sub,
.editor-key.kind-to .editor-key-main {
  max-width: calc(100% - 4px);
  padding: 0 4px;
  border: 1px solid var(--kind-color);
  border-radius: 5px;
  line-height: 1.3;
}

.key-picker-root { margin-bottom: 4px; }

/* Placeholder in the picker's spot: not connected, or no key selected. */
.key-picker-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 64px;
  padding: 12px 16px;
  border: 1px dashed var(--key-border);
  border-radius: 14px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
.key-picker-notice p { margin: 0; }

.key-picker {
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: var(--key);
  overflow: hidden;
}

.key-picker-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}

.key-picker-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.key-picker-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}
.key-picker-tab.is-active { background: var(--ink); color: var(--card); }

.key-picker-close {
  flex-shrink: 0;
  white-space: nowrap;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  text-decoration: underline;
}

.key-picker-body {
  max-height: 260px;
  overflow-y: auto;
  padding: 10px;
}

.key-picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  gap: 6px;
}

.key-picker-item {
  border: 1px solid var(--key-border);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}
.key-picker-item:hover { border-color: var(--accent); color: var(--accent); }
.key-picker-item:disabled:hover { border-color: var(--key-border); color: var(--ink); }
/* The value this key currently shows (draft, else live). */
.key-picker-item[class*="kind-"] { color: var(--kind-color); }
.key-picker-item.is-current { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

.key-picker-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}
.key-picker-summary-text { margin: 0; font-size: 12px; font-weight: 600; }
.key-picker-summary-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.key-picker-swap {
  padding: 3px 12px;
  border: 1px solid var(--key-border);
  border-radius: 999px;
  background: var(--key);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
}
.key-picker-swap:hover { border-color: var(--ink); }
.key-picker-link {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  text-decoration: underline;
  flex-shrink: 0;
}

.key-picker-hold {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}
.key-picker-hold-label {
  min-width: 4.5em;
  margin-right: 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--kind-color, var(--ink));
}
.key-picker-chip {
  border: 1px solid var(--key-border);
  background: var(--key);
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
}
.key-picker-mods {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--rule);
  background: var(--card);
}
.key-picker-mod {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.key-picker-mod input { accent-color: var(--nums); margin: 0; }
/* 長押し type switch: なし | LT | MT, each active segment in its kind color. */
.key-picker-segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--key-border);
  border-radius: 999px;
  background: var(--key);
}
.key-picker-segment {
  padding: 3px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.key-picker-segment:not(.is-active):hover { color: var(--ink); }
.key-picker-segment.is-active { background: var(--kind-color, var(--ink)); color: var(--card); }
/* The chosen hold type's own options (layer chips / MT checkboxes). */
.key-picker-hold-options {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  margin-left: 4px;
  padding-left: 12px;
  border-left: 1px solid var(--rule);
}
.key-picker-hold-options:not(.kind-mod-tap) { gap: 4px; }
.key-picker-hold-options .key-picker-chip.is-active { background: var(--kind-color); border-color: var(--kind-color); }
.key-picker-hold-options.kind-mod-tap .key-picker-mod input { accent-color: var(--kind-color); }

.key-picker-any { display: flex; flex-direction: column; gap: 8px; }
.key-picker-any-row { display: flex; gap: 8px; }
.key-picker-any-input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid var(--key-border);
  border-radius: 9px;
  background: var(--card);
  color: var(--ink);
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 13px;
}
.key-picker-any-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.key-picker-any-preview { margin: 0; font-size: 12px; font-weight: 600; color: var(--ink); }
.key-picker-any-preview.is-error { color: var(--danger); }
.key-picker-chip.is-active { background: var(--func); border-color: var(--func); color: var(--card); }
.key-picker-note { margin: 0; font-size: 12px; color: var(--muted); }
.key-picker-note + .key-picker-grid { margin-top: 8px; }
