* {
  box-sizing: border-box;
}

:root {
  --bg: #09090b;
  --panel: #111113;
  --panel-hover: rgba(24, 24, 27, 0.72);
  --line: #27272a;
  --line-soft: rgba(63, 63, 70, 0.48);
  --text: #d4d4d8;
  --text-strong: #f4f4f5;
  --muted: #71717a;
  --faint: #52525b;
  --accent: #2dd4bf;
  --accent-soft: rgba(45, 212, 191, 0.12);
  --keyboard-gap: 5px;
  --key-size: clamp(42px, 5vw, 56px);
}

html {
  background: var(--bg);
}

body {
  min-width: 320px;
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: var(--bg);
  color: var(--text);
}

button,
textarea {
  font: inherit;
}

.app-shell {
  width: min(100%, 1200px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 48px 24px 64px;
}

.site-header {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px 24px;
  margin-bottom: 32px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.brand-block h1 {
  margin: 0;
  color: var(--text-strong);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
}

.section-heading h2 {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  line-height: 1.35;
  text-transform: uppercase;
}

.intro,
.header-meta,
.hint {
  margin: 4px 0 0;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.6;
}

.intro {
  grid-column: 1 / -1;
  margin-top: 0;
}

.import-status {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--accent);
  font-size: 12px;
  line-height: 1.6;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.header-actions,
.download-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
}

button {
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
}

.text-action {
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  transition: color 120ms ease, background-color 120ms ease;
}

.text-action:hover,
.text-action:focus-visible {
  color: var(--text-strong);
  background: var(--panel-hover);
  outline: none;
}

.text-action--strong {
  color: var(--accent);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 9, 11, 0.72);
}

.import-modal {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  background: #0f0f11;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.import-modal h2 {
  margin: 0;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}

.import-modal p {
  margin: 0;
  padding: 14px 14px 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.import-modal code {
  display: block;
  margin: 0 14px 14px;
  overflow-x: auto;
  border: 1px solid var(--line-soft);
  padding: 9px 10px;
  background: var(--bg);
  color: var(--text-strong);
  font-size: 12px;
  line-height: 1.4;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 1px solid var(--line-soft);
}

.content-section {
  margin-top: 32px;
}

.section-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.layer-indicator {
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.layer-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.layout-tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  margin-bottom: 12px;
}

.layout-tab {
  min-width: 48px;
  padding: 6px 10px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  font-size: 12px;
  line-height: 1.2;
}

.layout-tab:last-child {
  border-right: 0;
}

.layout-tab:hover,
.layout-tab:focus-visible {
  color: var(--text);
  background: var(--panel-hover);
  outline: none;
}

.layout-tab--active {
  color: var(--text-strong);
  background: var(--accent-soft);
}

.layer-tab {
  padding: 4px 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  transition: color 120ms ease, background-color 120ms ease;
}

.layer-tab:hover,
.layer-tab:focus-visible {
  color: var(--text);
  background: var(--panel-hover);
  outline: none;
}

.layer-tab--active {
  color: var(--text-strong);
  background: var(--accent-soft);
}

.keyboard-wrapper {
  overflow-x: auto;
  padding: 4px 0 10px;
}

.keyboard {
  display: flex;
  min-width: max-content;
  flex-direction: column;
  gap: var(--keyboard-gap);
}

.key-row {
  display: flex;
  gap: var(--keyboard-gap);
}

.key-spacer {
  width: var(--key-size);
  height: var(--key-size);
  flex: 0 0 var(--key-size);
  pointer-events: none;
  visibility: hidden;
}

.key {
  position: relative;
  display: flex;
  width: var(--key-size);
  height: var(--key-size);
  flex: 0 0 var(--key-size);
  flex-direction: column;
  justify-content: space-between;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
  color: var(--text);
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
}

.key:hover,
.key:focus-visible {
  border-color: rgba(45, 212, 191, 0.58);
  background: var(--panel-hover);
  color: var(--text-strong);
  outline: none;
}

.key--active {
  border-color: var(--accent);
  background: linear-gradient(90deg, var(--accent-soft), var(--panel));
}

.key--remapped {
  border-color: rgba(45, 212, 191, 0.38);
  background: linear-gradient(90deg, rgba(45, 212, 191, 0.08), var(--panel));
}

.key--triggered {
  box-shadow: inset 0 -2px 0 rgba(45, 212, 191, 0.28);
}

.key-symbol {
  max-width: 100%;
  overflow: hidden;
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-symbol--small {
  font-size: 11px;
}

.key-trigger {
  position: absolute;
  right: 6px;
  top: 6px;
  max-width: calc(100% - 12px);
  overflow: hidden;
  padding: 2px 4px;
  border: 1px solid rgba(45, 212, 191, 0.36);
  background: rgba(45, 212, 191, 0.1);
  color: var(--accent);
  font-size: 9px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-trigger--small {
  font-size: 8px;
}

.key-code {
  align-self: flex-end;
  color: var(--faint);
  font-size: 10px;
  letter-spacing: 0.04em;
  line-height: 1;
}

.key-editor-popover {
  position: absolute;
  z-index: 20;
  width: 260px;
  border: 1px solid var(--line);
  background: #0f0f11;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.45);
}

.key-editor-popover--picking {
  border-color: var(--accent);
  opacity: 0.42;
  pointer-events: none;
}

.key-editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  cursor: move;
  touch-action: none;
  user-select: none;
}

.key-editor-title,
.key-editor-layer,
.key-editor-close,
.rebind-block h3,
.field-row span {
  display: block;
  font-size: 11px;
  line-height: 1.4;
}

.key-editor-title,
.rebind-block h3 {
  font-weight: 500;
}

.key-editor-name {
  color: var(--text-strong);
}

.key-editor-code {
  color: var(--faint);
  font-weight: 400;
}

.key-editor-layer,
.field-row span {
  color: var(--faint);
}

.key-editor-close {
  padding: 0;
  color: var(--muted);
  cursor: pointer;
}

.key-editor-close:hover,
.key-editor-close:focus-visible {
  color: var(--text-strong);
  outline: none;
}

.rebind-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--line);
}

.rebind-mode-tab {
  padding: 8px 10px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  font-size: 11px;
  line-height: 1.4;
  text-align: left;
}

.rebind-mode-tab:last-child {
  border-right: 0;
}

.rebind-mode-tab:hover,
.rebind-mode-tab:focus-visible {
  color: var(--text);
  background: var(--panel-hover);
  outline: none;
}

.rebind-mode-tab--active {
  color: var(--text-strong);
  background: var(--accent-soft);
}

.rebind-block {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.rebind-block:last-child {
  border-bottom: 0;
}

.rebind-block h3,
.rebind-block p {
  margin: 0;
}

.rebind-block p {
  color: var(--faint);
  font-size: 11px;
  line-height: 1.45;
}

.rebind-block--disabled {
  opacity: 0.55;
}

.field-row {
  display: grid;
  gap: 4px;
}

.trigger-picker-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 5px;
}

.trigger-picker-button {
  border: 1px solid var(--line);
  padding: 7px 8px;
  color: var(--muted);
  background: var(--bg);
  font-size: 12px;
  line-height: 1;
}

.trigger-picker-button:hover,
.trigger-picker-button:focus-visible {
  border-color: rgba(45, 212, 191, 0.58);
  color: var(--text-strong);
  outline: none;
}

.trigger-picker-button--active {
  border-color: var(--accent);
  color: var(--accent);
}

.rebind-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 7px 8px;
  background: var(--bg);
  color: var(--text-strong);
  font: inherit;
  font-size: 12px;
}

.rebind-input:focus {
  border-color: rgba(45, 212, 191, 0.58);
  outline: none;
}

.export-section {
  display: grid;
  gap: 14px;
}

.download-actions {
  justify-content: flex-start;
}

.option-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.option-toggle input {
  width: 13px;
  height: 13px;
  margin: 0;
  accent-color: var(--accent);
}

.snippet {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px 16px;
  background: #0f0f11;
  color: var(--text);
  font-size: 12px;
  line-height: 1.6;
}

.snippet:focus {
  border-color: rgba(45, 212, 191, 0.58);
  outline: none;
}

@media (max-width: 680px) {
  .app-shell {
    padding: 32px 16px 48px;
  }

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

  .header-actions {
    justify-content: flex-start;
  }

  .section-heading {
    align-items: start;
    flex-direction: column;
    gap: 6px;
  }
}
