:root {
  --nord-dark-bg: #1c1f26;
  --nord0: #2e3440;
  --nord1: #3b4252;
  --nord2: #434c5e;
  --nord3: #4c566a;
  --nord4: #d8dee9;
  --nord5: #e5e9f0;
  --nord6: #eceff4;
  --nord7: #8fbcbb;
  --nord8: #88c0d0;
  --nord9: #81a1c1;
  --nord10: #5e81ac;
  --nord11: #bf616a;
  --nord12: #d08770;
  --nord13: #ebcb8b;
  --nord14: #a3be8c;
  --nord15: #b48ead;

  --bg-1: var(--nord-dark-bg);
  --bg-2: var(--nord0);
  --bg-3: var(--nord1);
  --bg-4: var(--nord2);

  --page-bg: var(--bg-1);
  --text: var(--nord4);
  --muted: color-mix(in srgb, var(--text) 60%, transparent);
  --card-bg: var(--bg-2);
  --card-border: var(--bg-3);
  --btn-bg: var(--bg-3);
  --btn-text: var(--text);
  --btn-border: var(--bg-4);
  --btn-hover-border: var(--bg-4);
  --toggle-active-bg: var(--bg-4);
  --hover-bg: var(--bg-4);
  --accent: var(--nord14);
  --logo-color: var(--text);
  --nav-hover-bg: var(--bg-2);
  --nav-hover-border: var(--bg-3);
  --footer-bg: var(--bg-2);
  --footer-border: var(--bg-3);
}

html[data-theme="light"] {
  --bg-1: #ffffff;
  --bg-2: var(--nord6);
  --bg-3: var(--nord5);
  --bg-4: var(--nord4);

  --text: var(--nord0);
  --muted: var(--nord3);
  --accent: var(--nord10);
  --nav-hover-bg: #c8d0dc;
  --nav-hover-border: #c8d0dc;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
  color: var(--text);
  font-family: 'Nunito', system-ui, sans-serif;
}

/* Sticky header / navigation */
.navigation {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in srgb, var(--page-bg) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 10px;
  min-height: 70px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
}

.nav-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  position: relative;
}

.logo-link {
  color: var(--logo-color);
  display: flex;
  align-items: center;
}

.logo-link:hover {
  filter: brightness(1.3);
}

html[data-theme="light"] .logo-link:hover {
  filter: brightness(0.7);
}

/* Icon mask: paints the SVG's alpha channel in the current text color.
   Sizing/placement lives in the per-context rules below. */
.icon {
  display: inline-block;
  background-color: currentColor;
  -webkit-mask-position: center;
  mask-position: center;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
  /* Default 1:1; the glyph's real ratio lives on each .icon-<name> rule so an
     icon sized by height alone fills the full row height. */
  aspect-ratio: 1 / 1;
}

.icon-keyboard { -webkit-mask-image: url("/icons/keyboard.svg"); mask-image: url("/icons/keyboard.svg"); aspect-ratio: 576 / 512; }
.icon-layer-group { -webkit-mask-image: url("/icons/layer-group.svg"); mask-image: url("/icons/layer-group.svg"); }
.icon-fire { -webkit-mask-image: url("/icons/fire.svg"); mask-image: url("/icons/fire.svg"); aspect-ratio: 448 / 512; }
.icon-microchip { -webkit-mask-image: url("/icons/microchip.svg"); mask-image: url("/icons/microchip.svg"); }
.icon-auto { -webkit-mask-image: url("/icons/auto.svg"); mask-image: url("/icons/auto.svg"); }
.icon-reboot { -webkit-mask-image: url("/icons/reboot.svg"); mask-image: url("/icons/reboot.svg"); }
.icon-profile { -webkit-mask-image: url("/icons/profile.svg"); mask-image: url("/icons/profile.svg"); }
.icon-bulb { -webkit-mask-image: url("/icons/bulb.svg"); mask-image: url("/icons/bulb.svg"); aspect-ratio: 384 / 512; }
.icon-display { -webkit-mask-image: url("/icons/display.svg"); mask-image: url("/icons/display.svg"); aspect-ratio: 576 / 512; }
.icon-code { -webkit-mask-image: url("/icons/code.svg"); mask-image: url("/icons/code.svg"); aspect-ratio: 640 / 512; }
.icon-download { -webkit-mask-image: url("/icons/download.svg"); mask-image: url("/icons/download.svg"); }
.icon-upload { -webkit-mask-image: url("/icons/upload.svg"); mask-image: url("/icons/upload.svg"); aspect-ratio: 448 / 512; }
.icon-light { -webkit-mask-image: url("/icons/light.svg"); mask-image: url("/icons/light.svg"); aspect-ratio: 576 / 512; }
.icon-dark { -webkit-mask-image: url("/icons/dark.svg"); mask-image: url("/icons/dark.svg"); }
.icon-web { -webkit-mask-image: url("/icons/web.svg"); mask-image: url("/icons/web.svg"); }
.icon-docs { -webkit-mask-image: url("/icons/docs.svg"); mask-image: url("/icons/docs.svg"); aspect-ratio: 384 / 512; }
.icon-etsy { -webkit-mask-image: url("/icons/etsy.svg"); mask-image: url("/icons/etsy.svg"); aspect-ratio: 576 / 512; }
.icon-trash { -webkit-mask-image: url("/icons/trash.svg"); mask-image: url("/icons/trash.svg"); aspect-ratio: 448 / 512; }
.icon-circle-plus { -webkit-mask-image: url("/icons/circle-plus.svg"); mask-image: url("/icons/circle-plus.svg"); }
.icon-floppy-disk { -webkit-mask-image: url("/icons/floppy-disk.svg"); mask-image: url("/icons/floppy-disk.svg"); aspect-ratio: 448 / 512; }
.icon-github { -webkit-mask-image: url("/icons/github.svg"); mask-image: url("/icons/github.svg"); }
.icon-info { -webkit-mask-image: url("/icons/info.svg"); mask-image: url("/icons/info.svg"); }
.icon-gamepad { -webkit-mask-image: url("/icons/gamepad.svg"); mask-image: url("/icons/gamepad.svg"); aspect-ratio: 640 / 512; }
.icon-music { -webkit-mask-image: url("/icons/music.svg"); mask-image: url("/icons/music.svg"); }

/* Brand logo: .logo defines the colors (the SVG's alpha channel painted in
   the theme's foreground color); sizing lives in .nav-logo / .hero-logo. */
.logo {
  display: block;
  background-color: var(--text);
  -webkit-mask-image: url("/icons/logo.svg");
  mask-image: url("/icons/logo.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  aspect-ratio: 228.846 / 121.94489;
}

.mp2040-logo {
  display: block;
  background-color: var(--text);
  -webkit-mask-image: url("/icons/mp2040.svg");
  mask-image: url("/icons/mp2040.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  aspect-ratio: 228.846 / 121.94489;
}

.nav-logo {
  height: 40px;
}

/* Navbar reboot button (green = success action) */
.nav-reboot {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: var(--nord14);
  color: var(--nord0);
  border-color: transparent;
}

.nav-reboot:hover {
  background: color-mix(in srgb, var(--nord14) 75%, var(--nord0));
  border-color: transparent;
}

.nav-reboot .icon {
  height: 16px;
  display: block;
}

/* Nav links (Layout / Settings), pushed right with the reboot button */
.nav-links {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: inherit;
  font-size: 20px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
}

.nav-link .icon {
  height: 16px;
  display: block;
}

.nav-link:hover,
.nav-link.active {
  background: var(--nav-hover-bg);
  border-color: var(--nav-hover-border);
}

.nav-link.active:hover {
	background: var(--bg-4);
}

.theme-btn .icon {
  height: 15px;
  display: block;
}

.theme-toggle {
  display: flex;
  border: none;
	background: var(--bg-1);
	gap: 2px;
	padding: 2px;
  border-radius: 999px;
  overflow: hidden;
}

.theme-btn {
  background: transparent;
  border: none;
  color: inherit;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 15px;
  transition: background 0.15s;
	border-radius: 999px;
}

.theme-btn.active {
  background: var(--bg-3);
}

main {
  flex: 1;
  width: 100%;
  padding: 20px 0;
  box-sizing: border-box;
}

/* Routed pages: each page div carries the flex layout main used to have */
.page {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* Routed pages: only the active one is visible */
.page[hidden] {
  display: none;
}

/* Loading indicator shown in the main content until the config loads. Uses
   the same flex layout as .page so it occupies the same area. */
.loading {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 0;
  font-size: 24px;
}

.loading[hidden] {
  display: none;
}

.loading-spinner {
  width: 100px;
  height: 100px;
  border: 10px solid var(--bg-2);
  border-top-color: var(--accent, #4a90d9);
  border-radius: 50%;
  animation: loading-spin 0.8s linear infinite;
}

@keyframes loading-spin {
  to { transform: rotate(360deg); }
}

/* Footer */
.footer {
  background: var(--footer-bg);
  border: 1px solid var(--footer-border);
  border-bottom: none;
  border-radius: 20px 20px 0 0;
  max-width: 1000px;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
  transition: border-radius 0.15s;
}

.footer-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 16px 30px;
  font-size: 15px;
  height:70px;
}

.footer-inner > :first-child {
  flex: 1;
  text-align: left;
}

.footer-inner > .theme-toggle {
  justify-content: center;
}

.footer-inner > :last-child {
  flex: 1;
  text-align: right;
  color: var(--muted);
}

/* Social links on the right side of the footer */
.footer-links {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.footer-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
}

.footer-link .icon {
  height: 20px;
  display: block;
}

/* Board view */
#board-panel {
  display: flex;
  justify-content: center;
}

#board-panel svg {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 600px;
  user-select: none;
  filter: drop-shadow(0 0 10px rgba(0, 0, 0, 0.1));
}

/* Live touch-ring pressed-position marker (board view) */
.ring-marker {
  fill: var(--nord13);
  stroke: var(--bg-1);
  stroke-width: 1.5;
}

.board-placeholder {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 1rem;
  border: 1px dashed var(--card-border);
  border-radius: 20px;
}

/* Hover tooltip for board LEDs in non-custom LED modes */
.board-tooltip,
.tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 350px;
  padding: 8px 12px;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  pointer-events: none;
  user-select: none;
}

.tooltip {
  max-width: 350px;
}

/* Cards */
section {
  width: 100%;
  max-width: 1000px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 20px ;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-radius 0.15s;
}

section h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: normal;
  display: flex;
  align-items: center;
  gap: 10px;
}

.heading-icon {
  height: 22px;
  display: block;
  flex: none;
}

/* Per-section unsaved-changes dot: appended to the section heading when the
   section's fields differ from the board snapshot (see updateDirtyUi). */
section.section-dirty > h2::after {
  content: '';
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 2px;
}

/* Header action buttons, pushed to the right edge of the section heading. */
.section-header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Small variant of the default button: less padding for tight spots like
   section headers. The button keeps its stock `button` base + hover rules. */
.btn-small {
  padding: 4px 16px;
  white-space: nowrap;
}

/* A select styled as a small button (e.g. the "Copy from…" header control).
   background-color (not the shorthand) so the chevron background-image from
   the global select rule survives base and hover. */
select.btn-small {
  background-color: var(--btn-bg);
  color: var(--btn-text);
  border-color: var(--btn-border);
  padding: 4px 2rem 4px 16px;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background-color 0.15s;
}

select.btn-small:hover {
  background-color: var(--bg-4);
  border-color: var(--btn-hover-border);
}

.hint {
  color: var(--muted);
  font-size: 1rem;
  margin: 0;
}

/* Landing page */
.hero-row {
  width: 100%;
  max-width: 1000px;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

.hero {
  align-items: center;
  text-align: center;
  padding: 48px 28px;
}

.hero-logo {
  width: 120px;
  height: auto;
  margin-bottom: 12px;
}

.hero h2 {
  justify-content: center;
  margin: 0;
  font-size: 2rem;
  font-weight: 600;
}

.hero h2 span {
  color: var(--accent);
}

.landing-cards {
  width: 100%;
  max-width: 1000px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.landing-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 24px 28px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, border-radius 0.15s;
}

.landing-card:hover {
	background: var(--bg-3);
	border-color: var(--bg-4);
}

.landing-card-icon {
  height: 40px;
  flex: none;
}

.landing-card h3 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
}

.landing-card p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.landing-version {
  text-align: center;
}

.update-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 28px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, transform 0.15s, background 0.15s;
}

.update-card:hover {
  background: var(--bg-3);
  border-color: var(--bg-4);
}

.update-card[hidden] {
  display: none;
}

.update-card-icon {
  height: 60px;
  flex: none;
  color: var(--text);
}

.update-card #update-latest {
  color: var(--accent);
}

@media (max-width: 700px) {
  .hero-row {
    grid-template-columns: 1fr;
  }
}

.hero-row:has(#update-card[hidden]) {
  grid-template-columns: 1fr;
}

/* Landing Links row: button-styled links filling the width */
.landing-links {
  width: 100%;
  max-width: 1000px;
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
}

.landing-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--card-border);
  color: var(--btn-text);
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.landing-link:hover {
	background: var(--bg-3);
	border-color: var(--bg-4);
}

.landing-link-icon {
  height: 18px;
  display: block;
  flex: none;
}

/* Landing credit: heart centered, text mirrored on either side */
.landing-credit {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.landing-credit .credit-left {
  text-align: right;
}

.landing-credit .credit-right {
  text-align: left;
}

/* Profile tabs */
.profile-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
	background: var(--bg-1);
	padding: 5px;
	border-radius: 999px;
}

.profile-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex: 1 1 0;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 1rem;
	background: var(--bg-2);
	border: none;
}

.profile-tab.boot::after {
  content: '';
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: -12px;
  width: 80%;
  height: 4px;
  border-radius: 999px;
  background: var(--accent);
}

.profile-tab.active {
  background: var(--bg-4);
  border-color: transparent;
}

/* Per-profile unsaved-changes dot: top-right of the tab (the boot indicator
   already uses ::after, so the dirty dot uses ::before). */
.profile-tab.dirty::before {
  content: '';
  position: absolute;
  top: 6px;
  right: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

select, input[type="number"] {
  background: var(--page-bg);
  color: var(--text);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  width: 100%;
  font-family: inherit;
}

select {
	border-radius: 999px;
	padding: 5px 10px;
	font-size: 1rem;
	appearance: none;
	-webkit-appearance: none;
	padding-right: 2.5rem;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23d8dee9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: right 12px center;
	background-size: 12px 8px;
}

/* Lighter chevron stroke for the light theme */
html[data-theme="light"] select {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%234c566a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

/* MultiSelect widget */
.ms {
  position: relative;
  width: 100%;
}

.ms-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  min-height: 2.3rem;
  padding: 6px;
  background: var(--page-bg);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  cursor: pointer;
}

.ms-control:focus,
.ms.open .ms-control {
  outline: none;
  border-color: var(--accent);
}

.ms-control {
	min-height: 43px;
}

.ms-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  flex: 1;
}

.ms-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  font-size: 1rem;
  padding: 0.15rem 0.5rem;
}

.ms-tag-x {
  position: relative;
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0;
}

/* The × glyph drawn via a centered mask instead of the text character, whose
   optical center sits off-center in many fonts. */
.ms-tag-x::before {
  content: '';
  position: absolute;
  inset: 15%;
  background-color: currentColor;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 3l6 6M9 3l-6 6' stroke='%23000' stroke-width='1.5' stroke-linecap='round' fill='none'/%3E%3C/svg%3E");
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 3l6 6M9 3l-6 6' stroke='%23000' stroke-width='1.5' stroke-linecap='round' fill='none'/%3E%3C/svg%3E");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-position: center;
  mask-position: center;
}

.ms-tag-x:hover {
  background: var(--nord11);
  color: var(--nord6);
}

/* Whole-selection clear in the control bar (hidden until something is
   selected). Uses the trash icon, sized for its standalone spot next to the
   caret. */
.ms-clear {
  position: relative;
  flex: 0 0 auto;
  width: 1.2rem;
  height: 1.2rem;
  border-radius: 50%;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font-size: 0;
  display: none;
}

.ms-clear::before {
  content: '';
  position: absolute;
  inset: 18%;
  background-color: currentColor;
  -webkit-mask-image: url("/icons/trash.svg");
  mask-image: url("/icons/trash.svg");
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-position: center;
  mask-position: center;
}

.ms-clear:hover {
  background: var(--nord11);
  color: var(--nord6);
}

/* Fixed rows are non-interactive: keep the × bg clear even on hover. */
.ms.disabled .ms-tag-x:hover {
  background: transparent;
}

.ms-placeholder {
  color: var(--muted);
  font-size: 1rem;
  margin: 0px 10px;
}

/* Right-side controls (clear + caret) spaced with a flex gap. */
.ms-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.ms-caret {
	width: 12px;
	height: 8px;
	margin-right: 10px;
	font-size: 0;
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23d8dee9' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
	background-repeat: no-repeat;
	background-position: center;
	background-size: 12px 8px;
}


/* @SCREENPAD_START@ */
.fa-glyph {
  font-family: 'Font Awesome 7 Free';
  font-weight: 900;
  font-style: normal;
}
/* @SCREENPAD_END@ */

html[data-theme="light"] .ms-caret {
	background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%234c566a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

.ms-menu {
  display: none;
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 2px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
	box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.3);
}

.ms.open .ms-menu {
  display: block;
}

.ms-search {
  width: 100%;
  box-sizing: border-box;
  padding: 10px;
  background: var(--page-bg);
  color: var(--text);
  border: none;
  border-bottom: 1px solid var(--card-border);
  font-family: inherit;
	font-size: 1rem;
}

.ms-search:focus {
  outline: none;
}

.ms-list {
  max-height: 13em;
  overflow-y: auto;
}

.ms-group-label {
  padding: 0.3rem 0.5rem;
  font-size: 1rem;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--page-bg);
}

.ms-option {
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  font-size: 1rem;
}

.ms-option:hover,
.ms-option.highlighted {
  background: var(--hover-bg);
}

.ms-option.selected {
  color: var(--accent);
}

.ms-option.selected::after {
  content: ' \2713';
}

.ms-empty {
  padding: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

/* Small pill showing a pin's action (e.g. the key "A" next to "Pin 5"),
   used inside .ms-option rows and .ms-tag tags. */
.ms-pill {
  display: inline-block;
  margin-left: 0.3rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--hover-bg);
  border: 1px solid var(--card-border);
  font-size: 0.8rem;
  line-height: 1.35;
  vertical-align: middle;
}

.ms.disabled .ms-control {
  cursor: default;
  opacity: 0.55;
}

.ms.disabled .ms-caret {
  display: none;
}

/* LED form */
.led-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.led-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  flex-wrap: wrap;
}

.led-row .led-mode-label {
  display: flex;
  align-items: center;
  white-space: nowrap;
}

.led-row select {
  flex: 1 1 0;
  min-width: 0;
}

.led-row .led-slider {
  flex: 1 1 0;
}

.led-row > .led-colors {
  flex: 0 1 auto;
  min-width: 0;
}

/* Default input mode selector */
.general-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.general-form label {
  white-space: nowrap;
}



/* Checkbox row in the general form (e.g. Serial control). Full-width so it
   sits on its own line, with the checkbox aligned to the text baseline. */
.checkbox-label {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* display:flex above would override the hidden attribute's UA default */
.checkbox-label[hidden] {
  display: none;
}

.checkbox-label input[type="checkbox"] {
  accent-color: var(--accent, #81a1c1);
}

/* Info icon next to a field label; shows a tooltip on hover (see tooltip.js) */
.field-info {
  width: 16px;
  height: 16px;
  color: var(--muted);
  cursor: help;
}

.general-form select {
  flex: 1 1 0;
  min-width: 0;
}

.general-form .hint {
  flex-basis: 100%;
}

/* Input History + History Timeout row inside the Display settings. Keeps the
   toggle and the timeout spinner on the same line; the timeout group is pushed
   to the right edge while the toggle stays left. */
#input-history-row {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

/* PillToggle (port of GP2040-th's PillToggle): a pill-shaped on/off button
   with its label inside. Off is a dimmed outline; active fills with the accent
   color. */
.pill-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 5px 10px;
  border: 1px solid var(--bg-4);
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--text);
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

.pill-toggle:hover {
  opacity: 0.85;
}

.pill-toggle.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg-2);
  opacity: 1;
}

/* The info icon paints in currentColor; make it follow the pill's text color
   (muted when off, the active text color when on) instead of .field-info's
   fixed muted color. */
.pill-toggle .field-info {
  color: inherit;
}

.pill-toggle.active:hover {
  opacity: 0.85;
}

.pill-toggle:disabled {
  opacity: 0.2;
  cursor: not-allowed;
}

/* display:inline-flex above would override the hidden attribute's UA default */
.pill-toggle[hidden] {
  display: none;
}

/* Configurable hotkeys editor (Settings page). One row per hotkey: a key
   multi-select (flexible), an action dropdown and a remove button. */
.hotkeys-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hotkeys-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hotkey-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hotkey-row .hotkey-keys {
  flex: 1 1 0;
  min-width: 0;
}

/* Inert rows (nothing to save: empty or half-filled) get a dashed control
   so it's legible they won't take effect. No opacity: it makes the
   multiselect dropdowns harder to read. */
.hotkey-row.incomplete .ms-control {
  border-style: dashed;
}

.hotkey-action-wrap {
  flex: 0 0 200px;
}

/* "Add Hotkey" / "Add Boot Key" buttons (direct children of the panel):
   icon aligned inline before the label. */
.hotkeys-panel > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.hotkeys-panel > button .icon {
  height: 16px;
}

/* Match the multi-select pill (`.ms-control` is min-height 43px): same
   border-box height, with the text vertically centered in the remaining
   space (padding keeps the chevron area on the right). */
.hotkey-action {
  width: 100%;
  height: 43px;
  line-height: 1;
  padding: 11px 10px;
  padding-right: 2.5rem;
}

/* Circular remove button sized to the row's control height, so the ✕ sits
   vertically centered next to the key / action controls. */
.hotkey-remove {
  flex: 0 0 auto;
  width: 43px;
  height: 43px;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* Board-fixed boot pins (web config / USB boot loader) shown above the
   editable boot keys. They mirror the editable rows exactly (same row layout,
   pin select + mode select + remove button) but are greyed out to show they
   can't be changed. */
.bootkeys-fixed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bootkey-fixed-row {
  opacity: 0.55;
}

.bootkey-fixed-row select,
.bootkey-fixed-row .hotkey-remove {
  cursor: default;
  color: var(--muted);
  border-color: var(--card-border);
}

/* Input mode + debounce row. Always keeps the debounce control on the same
   line as the input mode selector, regardless of the current mode. */
#mode-row {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

/* Import/Export + Reset row at the bottom of the General card */
.general-import-export {
  flex-basis: 100%;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.general-import-export button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 1 1 0;
  min-width: 0;
}

.general-import-export button .icon {
  height: 14px;
}

/* MIDI-only General controls (hidden unless the input mode is MIDI).
   Full-width so they sit on their own row below the input mode / debounce
   row. */
#midi-settings {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#midi-settings[hidden] {
  display: none;
}

/* Gamepad-only General controls (hidden unless the input mode is a gamepad
   mode). Full-width so they sit on their own row below the input mode /
   MIDI settings. */
#gamepad-settings {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#gamepad-settings[hidden] {
  display: none;
}

/* SOCD + Nintendo layout row inside the gamepad settings. Keeps both controls
   on the same line; the Nintendo toggle is pushed to the right edge. */
#dpad-socd-row {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

#dpad-socd-row select {
  flex: 1 1 0;
  min-width: 0;
}

#dpad-socd-row .pill-toggle {
  margin-left: auto;
}

/* Touch pad controls (Margin / Hysteresis). Full-width so they sit on their
   own row, below Debounce. Labels are inline-flex so the text and info icon
   are vertically centered together within the row. */
#touch-settings {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#touch-settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#touch-settings[hidden] {
  display: none;
}

/* Display settings: hidden entirely on boards without an OLED display.
   (The generic section rule sets display:flex, which would otherwise beat
   the [hidden] attribute.) */
#display-settings[hidden] {
  display: none;
}

/* Layout LEDs section: hidden entirely on boards without an addressable LED
   strip, same display:flex override reason as above. */
#led-section[hidden] {
  display: none;
}

/* Key modal picker groups: the active tab's group is shown. The groups are
   display:flex (see .key-modal-group below), which would override the hidden
   attribute, so keep an explicit display:none override. */
#key-modal-group-keyboard[hidden],
#key-modal-group-midi[hidden],
#key-modal-group-gamepad[hidden] {
  display: none;
}

/* @SCREENPAD_START@ */
/* Button color section for boards whose "LEDs" are on-screen keys. It lives in
   the modal action row so it never shrinks the keyboard/MIDI/gamepad picker. */
.key-modal-color {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.key-modal-color[hidden] {
  display: none;
}

.key-modal-color > .led-mode-label {
  white-space: nowrap;
}

#key-modal .modal-actions {
  align-items: center;
  flex-wrap: wrap;
  row-gap: 8px;
}

/* @SCREENPAD_END@ */
.key-modal-buttons {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.midi-kb {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1 1 0;
  min-height: 0;
}

/* The MIDI tab fills the modal's constant-height region so the piano can use
   the leftover space: the group is full height, the inner container grows,
   and the piano (flex:1) takes everything below the controls + status rows. */
#key-modal-group-midi {
  height: 100%;
}

#key-modal-group-midi > #key-modal-midi {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* The gamepad tab also fills the constant-height region: the controller
   widget expands to fill the space below the control multi-select. */
#key-modal-group-gamepad {
  height: 100%;
}

#key-modal-gamepad-widget {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* The keyboard tab fills the constant-height region too: the widget grows and
   the main keyboard's rows share the extra height (keys get taller). Scoped
   to the key modal so the macro builder's picker is unaffected. */
#key-modal-group-keyboard {
  height: 100%;
}

#key-modal-group-keyboard > #key-modal-keyboard {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#key-modal-keyboard .keyboard-widget {
  flex: 1 1 0;
  min-height: 0;
}

#key-modal-keyboard .kb-main-centered {
  flex: 1 1 0;
  min-height: 0;
}

#key-modal-keyboard .kb-main-centered .keyboard-row {
  height: auto;
  flex: 1 1 0;
  min-height: 40px;
}

#key-modal-keyboard .kb-main-centered .kb-key,
#key-modal-keyboard .kb-main-centered .kb-flex-spacer {
  height: 100%;
}

.midi-kb-controls {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.midi-kb-control {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

/* Spinner (numerical stepper): - [input] + */
.spinner {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--page-bg);
}

.spinner-btn {
  flex: 0 0 auto;
	padding: 10px;
  background: transparent;
  border: none;
  color: var(--text);
  line-height: 1;
  cursor: pointer;
  border-radius: 0px;
}

.spinner-btn:hover {
  background: var(--bg-3);
}

.spinner-input {
  width: 3.2em;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text);
  text-align: center;
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0;
}

/* Spinner container on the General page (sits inline next to its label) */
.midi-spinner {
  display: inline-flex;
}

.general-form .midi-spinner {
  flex: 0 0 auto;
}

.midi-kb-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.midi-kb-selected {
  color: var(--text);
  font-weight: 600;
}

.midi-kb-clear {
  background: var(--bg-3);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 2px 14px;
  color: var(--text);
  cursor: pointer;
}

.midi-kb-clear:hover {
  border-color: var(--nord11);
  color: var(--nord11);
}

/* Piano: stretches across the modal width and fills the remaining height
   below the controls + status rows. */
.midi-kb-piano {
  position: relative;
  width: 100%;
  height: auto;
  flex: 1 1 0;
  min-height: 0;
  overflow: hidden; /* keys always fill the width; never scroll */
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--bg-1);
  user-select: none;
}

/* White keys: flex row so they always fill the width evenly. */
.midi-kb-whites {
  position: absolute;
  inset: 8px 8px 26px 8px;
  display: flex;
}

.midi-key-white {
  flex: 1 1 0;
  min-width: 0;
  height: 100%;
  /* Reset the generic pill-button padding/radius/font so keys can shrink
     to fit any number of octaves instead of being forced to a minimum
     ~50px width by that rule's 24px horizontal padding. */
  padding: 6px 0 6px;
  border: 1px solid var(--nord3);
  border-radius: 4px;
  background: var(--nord4);
  color: var(--nord0);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  cursor: pointer;
  overflow: hidden;
}

.midi-key-white:hover {
	background: var(--nord4);
	opacity: 0.8;
}

/* Black keys: absolutely positioned (in %) over the white-key row. */
.midi-kb-blacks {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  height: 60%;
  pointer-events: none;
}

.midi-key-black {
  position: absolute;
  top: 0;
  height: 100%;
  min-width: 0;
  /* Same reset as .midi-key-white: without this the generic button rule's
     24px horizontal padding forces every key to ~50px wide regardless of
     the computed inline width, which is what caused the overlap. */
  padding: 0;
  border: 1px solid var(--nord3);
  border-radius: 0 0 4px 4px;
  background: var(--nord0);
  z-index: 1;
  pointer-events: auto;
  cursor: pointer;
}

.midi-key-white.inscale,
.midi-key-black.inscale {
  /* scale tones keep their normal piano colors; only the selected key stands out */
}

.midi-key-white.selected,
.midi-key-black.selected {
  background: var(--accent);
  color: #fff;
}

/* Octave labels under the keys */
.midi-kb-labels {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  height: 16px;
}

.midi-kb-octave {
  position: absolute;
  top: 0;
  height: 16px;
  text-align: center;
  font-size: 1rem;
  color: var(--muted);
}

.midi-kb-octave.current {
  color: var(--accent);
  font-weight: 700;
}

.midi-key-white:disabled,
.midi-key-black:disabled {
  opacity: 0.3;
  cursor: default;
}

.midi-key-note {
  opacity: 0.7;
  font-size: 1rem;
}

/* Color picker pill buttons */
.led-colors {
  display: flex;
  gap: 10px;
}

.led-color-picker {
  display: flex;
  align-items: stretch;
  flex: 0 1 auto;
  min-width: 0;
}

.color-picker {
  position: relative;
  width: 100%;
}

.led-color-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--btn-text);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.color-picker:hover .led-color-btn {
  border-color: var(--btn-hover-border);
	background-color: var(--bg-4);
}

.led-color-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.led-color-circle {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.3);
  flex-shrink: 0;
  display: inline-block;
}

.color-picker input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}

/* Per-LED color popover (custom mode): anchored to the clicked LED */
.led-popover {
  position: fixed;
  z-index: 1000;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--card-bg);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  padding: 6px 8px;
}

.led-popover::after,
.led-popover::before {
  content: '';
  position: absolute;
  top: 100%;
  transform: translateX(-50%);
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
}

.led-popover::after {
  left: var(--arrow-left, 11px);
  border-top: 9px solid var(--card-border);
}

.led-popover::before {
  left: var(--arrow-left, 12px);
  border-top: 8px solid var(--card-bg);
  z-index: 1;
}

.led-popover.arrow-up::after {
  top: auto;
  bottom: 100%;
  border-top: none;
  border-bottom: 9px solid var(--card-border);
}

.led-popover.arrow-up::before {
  top: auto;
  bottom: 100%;
  border-top: none;
  border-bottom: 8px solid var(--card-bg);
}

.led-popover-body {
  display: flex;
  align-items: center;
  gap: 4px;
}

.led-popover-color {
  position: relative;
}

.led-popover-color .led-color-btn {
  width: auto;
  height: 2.1rem;
  padding: 0 0.9rem;
}

.led-popover-unset {
  width: 2.1rem;
  height: 2.1rem;
  padding: 0;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--btn-text);
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}

.led-popover-unset .icon {
  height: 14px;
}

.led-popover-unset:hover:not(:disabled) {
  border-color: var(--btn-hover-border);
}

.led-popover-color input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: none;
  opacity: 0;
  cursor: pointer;
}

/* Pill slider (brightness / speed) */
.led-slider {
  min-width: 0;
	display: flex;
}

/* Status LED controls (toggle + min/max sliders) on one row. The sliders fill
   the remaining width evenly beside the toggle; the label lives inside each
   pill slider ("Minimum: 10" / "Maximum: 255"). */
.status-led-row {
  display: flex;
  align-items: stretch;
  gap: 12px;
  flex-wrap: wrap;
}

.status-led-row .led-slider {
  flex: 1 1 0;
  min-width: 0;
}

.status-led-row[hidden] {
  display: none;
}

.pill-slider {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--page-bg);
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  white-space: nowrap;
}

.pill-slider:focus {
  outline: none;
  /*border-color: var(--accent);*/
}

.pill-slider.disabled {
  opacity: 0.3;
  cursor: not-allowed;
  pointer-events: none;
}

.pill-slider-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: var(--accent);
  pointer-events: none;
}

.pill-slider-label {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  font-size: 1rem;
	font-weight: 600;
  pointer-events: none;
  z-index: 1;
}

.pill-slider-value {
  display: inline-block;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pill-slider-label-fill {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--page-bg);
  font-size: 1rem;
	font-weight: 600;
  pointer-events: none;
  z-index: 2;
}

/* Buttons */
/* Save-row wrapper: sticky to the viewport bottom so Save stays reachable
   without scrolling back down. Mirrors the nav's blur treatment. */
.actions-container {
  width: 100%;
  position: sticky;
  bottom: 0px;
  z-index: 50;
}

.actions {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: color-mix(in srgb, var(--bg-1) 85%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 0px;
  padding: 8px 10px;
}

/* Save buttons (Layout + Settings pages): icon aligned inline before label. */
.actions button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.actions button .icon {
  height: 16px;
}

/* Unsaved-changes indicator: the Save button fills with the accent color
   while there are edits not yet written to the board. */
.actions button.dirty {
  background: var(--accent);
  color: var(--nord0);
  border-color: var(--accent);
}

.actions button.dirty:not(:disabled):hover {
  background: color-mix(in srgb, var(--accent) 75%, var(--nord0));
  border-color: transparent;
}

/* Discard button: neutral when clean, orange while unsaved changes exist
   (same mechanism as the Save button's dirty state, but distinct from both
   the green Save fill and the red blocked/danger states). */
.actions button.discard.dirty {
  background: var(--nord12);
  color: var(--nord0);
  border-color: transparent;
}

.actions button.discard.dirty:not(:disabled):hover {
  background: color-mix(in srgb, var(--nord12) 75%, var(--nord0));
  border-color: transparent;
}

/* Save blocked by conflicting hotkeys: red until the conflict is fixed. */
.actions button.blocked {
  background: var(--nord11);
  color: var(--nord6);
  border-color: transparent;
}

.actions button.blocked:not(:disabled):hover {
  background: color-mix(in srgb, var(--nord11) 75%, var(--nord0));
  border-color: transparent;
}

/* Rows sharing an exact hotkey combo: red multiselect border on each. */
.hotkey-row.conflict .ms-control {
  border-color: var(--nord11);
}

button {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  padding: 10px 24px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: border-color 0.15s, background 0.15s;
}

button:not(:disabled):hover {
  border-color: var(--btn-hover-border);
	background: var(--bg-4);
}

button.danger {
  background: var(--nord11);
  color: var(--nord6);
  border-color: transparent;
}

button.secondary {
  background: transparent;
  color: inherit;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Key edit modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
}

/* Keep the overlay hidden when the modal is closed (the display:flex above
   would otherwise override the HTML hidden attribute). */
.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 20px;
  width: 100%;
  max-width: 820px;
  max-height: 90vh;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.modal-reboot {
	max-width: 400px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-close {
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 1.2rem;
  line-height: 1;
}

.modal-close:hover {
  background: var(--hover-bg);
}

.modal h3 {
  margin: 0 0 0.25rem;
  color: var(--accent);
}

/* Key modal mode tabs (Keyboard / MIDI / Gamepad). Same visual language as
   the profile tabs: a pill bar with the active tab filled. */
.modal-tabs {
  display: flex;
  gap: 8px;
  background: var(--bg-1);
  padding: 5px;
  border-radius: 999px;
}

.modal-tab {
  flex: 1 1 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 1rem;
  background: var(--bg-2);
  border: none;
}

.modal-tab .icon {
  height: 16px;
}

.modal-tab.active {
  background: var(--bg-4);
}

/* Constant-height content region for the key modal: sized to fit the tallest
   picker group (keyboard) so switching tabs never resizes the modal. Shrinks
   and scrolls when the modal's 90vh cap leaves less room. */
#key-modal-content {
  display: flex;
  flex-direction: column;
  height: 600px;
  min-height: 0;
  overflow-y: auto;
  flex: 1 1 auto;
}

/* Vertically center the active picker group (shorter modes like MIDI get
   centered instead of leaving a gap). Auto margins degrade to 0 when the
   content is taller than the region, so it scrolls from the top. */
#key-modal-content > .key-modal-group:not([hidden]) {
  margin: auto 0;
}

.key-modal-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* The key modal's footer splits its actions: Cancel (left) and Save (right).
   Other modals keep the single right-aligned action. */
#key-modal .modal-actions {
  justify-content: space-between;
}

/* Select form layout inside a modal (e.g. the touch ring modal). Each control
   group stacks its selects full-width, one per row. */
.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0.5rem 0 1rem;
}

.modal-form select {
  width: 100%;
}

/* Reboot mode picker */
.modal-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-options .modal-option {
  width: 100%;
  padding: 10px 24px;
  text-align: center;
}

.modal-options #reboot-webconfig {
  background: var(--nord14);
  color: var(--nord0);
  border-color: transparent;
}

.modal-options #reboot-webconfig:not(:disabled):hover {
  background: color-mix(in srgb, var(--nord14) 75%, var(--nord0));
  border-color: transparent;
}

/* Generic confirm modal actions: primary (save/confirm) and danger
   (destructive confirm) variants of the reboot-picker option buttons. */
.modal-options .modal-option.primary {
  background: var(--nord14);
  color: var(--nord0);
  border-color: transparent;
}

.modal-options .modal-option.primary:not(:disabled):hover {
  background: color-mix(in srgb, var(--nord14) 75%, var(--nord0));
  border-color: transparent;
}

.modal-options .modal-option.danger {
  background: var(--nord11);
  color: var(--nord6);
  border-color: transparent;
}

.modal-options .modal-option.danger:not(:disabled):hover {
  background: color-mix(in srgb, var(--nord11) 75%, var(--nord0));
  border-color: transparent;
}

/* display:flex on .modal-options would override the hidden attribute */
.modal-options #reboot-save[hidden],
#reboot-dirty-hint[hidden] {
  display: none;
}

/* Post-reboot full-page overlay: the board is gone, so there is nothing to
   interact with. Solid page background, status text, and (when leaving web
   config) a simplified board graphic with the web config button highlighted. */
.rebooted-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--page-bg);
}

.rebooted-overlay[hidden] {
  display: none;
}

.rebooted-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 560px;
  text-align: center;
}

.rebooted-card h2 {
  margin: 0;
}

.rebooted-spinner {
  display: flex;
  justify-content: center;
  padding: 8px 0;
}

.rebooted-spinner[hidden] {
  display: none;
}

.loading-spinner-small {
  width: 48px;
  height: 48px;
  border-width: 6px;
}

#rebooted-message {
  margin: 0;
}

#rebooted-hint {
  margin: 0;
}

#rebooted-status {
  margin: 0;
}

#rebooted-status[hidden] {
  display: none;
}

.rebooted-board {
  width: 100%;
}

.rebooted-board[hidden] {
  display: none;
}

.rebooted-board svg {
  display: block;
  width: min(100%, 520px);
  height: auto;
  max-height: 55vh;
  margin: 0 auto;
}

/* Keyboard widget (port of GP2040-th's KeyboardWidget) */
.keyboard-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  user-select: none;
}

.kb-main-centered {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: fit-content;
}

.f-row {
  width: 100%;
  justify-content: space-between;
}

.f-cluster {
  display: flex;
  gap: 3px;
}

.kb-clusters-row {
  display: flex;
  justify-content: space-evenly;
  gap: 12px;
  margin-top: 4px;
}

.kb-cluster {
  flex: 0 1 auto;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  padding: 6px;
  gap: 3px;
  display: flex;
  flex-direction: column;
}

.kb-cluster-label {
  font-size: 0.6rem;
  opacity: 0.5;
  text-align: center;
  padding-bottom: 2px;
}

.kb-spacer {
  pointer-events: none;
  visibility: hidden;
}

.keyboard-row {
  display: flex;
  gap: 3px;
  height: 48px;
  width: 100%;
}

.sz-1u { min-width: 48px; }
.sz-1_25u { min-width: 60px; }
.sz-1_5u { min-width: 72px; }
.sz-1_75u { min-width: 84px; }
.sz-2u { min-width: 96px; }
.sz-2_25u { min-width: 108px; }
.sz-2_75u { min-width: 132px; }
.sz-6_25u { min-width: 300px; }

.kb-key {
  height: 48px;
  padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 4px;
  background: var(--bg-3);
  color: inherit;
  font-size: 1rem;
  font-family: 'Nunito', monospace;
  text-align: center;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.kb-key:hover {
  background: var(--hover-bg);
  border-color: var(--nord10);
}

.kb-key.mod:hover {
  border-color: var(--nord12);
}

.kb-key.selected {
  background: var(--nord10);
  color: #fff;
}

.kb-key.mod.selected {
  background: var(--nord12);
}

.kb-flex-spacer {
  height: 48px;
  flex: 1;
  pointer-events: none;
  visibility: hidden;
}

.kb-key-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.1;
}

.kb-key-sub {
  font-size: 0.75rem;
  opacity: 0.5;
}

.kb-key-main {
  font-size: 1rem;
}

/* Macro slot row (key picker: assign M1-M8 to a pin) */
.kb-macro-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.kb-macro-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.5;
  margin-right: 2px;
}

.kb-macro-slot {
  width: 44px;
  height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  background: var(--bg-3);
  color: inherit;
  font-size: 0.85rem;
  font-family: 'Nunito', monospace;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.kb-macro-slot:hover {
  background: var(--hover-bg);
  border-color: var(--nord12);
}

.kb-macro-slot.selected {
  background: var(--nord12);
  color: #fff;
  border-color: transparent;
}

/* Controller widget (port of GP2040-th's ControllerWidget): the clickable
   SVG gamepad in the key modal's gamepad mode. Fills the modal region's
   remaining height below the control multi-select. */
.controller-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  user-select: none;
}

.controller-widget .cgp-svg {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  max-width: none;
}

/* Button controls brighten on hover. The base fill is an inline style, so the
   hover rule needs !important to override it. */
.controller-widget .cgp-btn:hover {
  fill: var(--bg-4) !important;
}

.controller-widget .cgp-label {
  font-size: 12px;
  font-weight: 700;
  fill: currentColor;
  pointer-events: none;
  user-select: none;
}

/* Held modifier highlight (macro builder keyboard) */
.kb-key.mod.active {
  background: var(--nord12);
  color: #fff;
  border-color: transparent;
}

/* Live step summary shown inside the macro key picker modal */
.macro-modal-steps {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 6px 0 2px;
  line-height: 1.4;
}

/* Macro builder (Settings page) */
.macro-builder {
	display:flex;
	flex-direction: column;
	gap: 10px;
}

.macro-steps {
}

.macro-steps-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.macro-steps-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.macro-add-btn,
.macro-clear-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 1rem;
  cursor: pointer;
}

.macro-add-btn .icon {
  height: 14px;
}

.macro-add-btn:hover {
  background: var(--hover-bg);
  border-color: var(--nord10);
}

.macro-clear-btn:hover {
  background: var(--hover-bg);
  border-color: var(--nord11);
}

.macro-step-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  /* Fixed height: ~6 chips worth of space, scrolls beyond. Keeps the page
     layout stable as steps are added (no shifting). */
  height: 330px;
  overflow-y: auto;
	border: 2px dashed var(--bg-3);
	border-radius: 10px;
	padding: 10px;
}

.macro-step-list-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1rem;
  color: var(--muted);
  opacity: 0.8;
  user-select: none;
}

.macro-step-chip {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--bg-4);
  border: 1px solid var(--card-border);
  border-radius: 999px;
}

.macro-step-grip {
  cursor: grab;
  color: var(--muted);
  opacity: 0.6;
  font-size: 1rem;
  line-height: 1;
  user-select: none;
  flex: 0 0 auto;
}

.macro-step-grip:hover {
  opacity: 1;
  color: var(--text);
}

.macro-step-chip.dragging {
  opacity: 0.4;
}

.macro-step-chip.drag-over {
  border-color: var(--nord10);
  box-shadow: 0 0 0 1px var(--nord10);
}

/* Insertion line shown while dragging between two steps */
.macro-step-chip.insert-before::before,
.macro-step-chip.insert-after::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: 999px;
  background: var(--nord10);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--nord10) 40%, transparent);
}

.macro-step-chip.insert-before::before {
  top: -5px;
}

.macro-step-chip.insert-after::after {
  bottom: -5px;
}

.macro-step-label {
  min-width: 90px;
  font-family: 'Nunito', monospace;
  font-weight: 700;
  flex: 1 1 auto;
  white-space: nowrap;
}

.macro-step-time {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 1rem;
  color: var(--muted);
}

/* Compact spinners (no transform-scale, so no phantom space on the right) */
.macro-step-time .spinner-btn {
  padding: 6px;
}

.macro-step-time .spinner-input {
  width: 2.6em;
  height: 24px;
  font-size: 0.85rem;
}

.macro-step-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--bg-1);
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.macro-step-remove:hover {
  background: var(--nord11);
  border-color: transparent;
  color: #fff;
}

.macro-step-edit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: var(--bg-1);
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.macro-step-edit:hover {
  background: var(--nord10);
  border-color: transparent;
  color: #fff;
}

.macro-step-edit-icon {
  width: 12px;
  height: 12px;
  display: block;
  background-color: var(--muted);
  -webkit-mask: url('/icons/edit.svg') center / contain no-repeat;
  mask: url('/icons/edit.svg') center / contain no-repeat;
}

.macro-step-edit:hover .macro-step-edit-icon {
  background-color: #fff;
}

/* Toast / Notification (port of GP2040-th's toast styles) */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 110;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
  max-width: 400px;
}

.toast {
  pointer-events: auto;
  padding: 0.75rem 1.25rem;
  border-radius: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.25);
  font-weight: 500;
  cursor: pointer;
  animation: toast-in 0.3s ease forwards;
  background-color: color-mix(in srgb, var(--bg-2) 80%, transparent);
  backdrop-filter: blur(8px);
  user-select: none;
}

.toast.exiting {
  animation: toast-out 0.3s ease forwards;
}

.toast-success {
  color: var(--nord14);
  border: 1px solid var(--nord14);
}

.toast-error {
  color: var(--nord11);
  border: 1px solid var(--nord11);
}

.toast-info {
  color: var(--nord10);
  border: 1px solid var(--nord10);
}

.toast-warning {
  color: var(--nord13);
  border: 1px solid var(--nord13);
}

@keyframes toast-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes toast-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* At narrower widths the cards go edge-to-edge, so drop the rounded corners.
   Kept last so it overrides the base section/landing-card radius. */
@media (max-width: 999px) {
  section,
  .landing-card,
  .footer {
    border-radius: 0;
  }
}

/* @SCREENPAD_START@ */
/* Per-key Font Awesome icon button in the key modal's action row. */
.key-modal-icon {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.key-modal-icon[hidden] {
  display: none;
}

#key-icon-btn {
  min-width: 56px;
  min-height: 34px;
  justify-content: center;
}

#key-icon-preview {
  font-size: 20px;
  line-height: 1;
}

.icon-preview-text {
  font-size: 0.95rem;
  font-weight: 600;
}

.icon-modal {
  width: min(760px, 94vw);
  height: min(640px, 86vh);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.icon-search {
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  background: var(--bg-1);
  color: var(--text);
  font: inherit;
}

.icon-grid {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
  gap: 6px;
  padding-right: 4px;
}

.icon-grid-btn {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-text);
  font-size: 21px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.icon-grid-btn:hover {
  border-color: var(--btn-hover-border);
  background: var(--bg-4);
}

/* @SCREENPAD_END@ */

