/*!
 * NuttyFi Latency Demo
 * Styles for the [nuttyfi_latency] shortcode.
 * Every rule is namespaced under .latency-sme so it cannot leak into a theme.
 */
.latency-sme {
    --text-main: #14121a;
    --text-muted: #5b5566;
    --border-light: #e4e0ec;
    --card-bg: #ffffff;
    --page-bg: #ffffff;
    --tabs-bg: rgba(20, 18, 26, 0.06);
    --tab-inactive: #5b5566;
    --visual-idle-bg: #e7e5ec;

    /* Visual size — change these two numbers to resize every device */
    --visual-size: 160px;
    --visual-icon: 88px;

    position: relative;
    background: var(--page-bg);
    padding: 96px 24px;
    box-sizing: border-box;
  }
  .latency-sme *, .latency-sme *::before, .latency-sme *::after {
    box-sizing: border-box;
  }
  .latency-sme [hidden] { display: none !important; }

  @media (max-width: 480px) {
    .latency-sme {
      --visual-size: 120px;
      --visual-icon: 64px;
    }
  }

  .latency-sme-container {
    max-width: 1000px;
    margin: 0 auto;
  }

  /* Heading */
  .latency-sme-head {
    text-align: center;
    max-width: 640px;
    margin: 0 auto 48px;
  }
  .latency-sme-title {
    margin: 0;
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-main);
  }
  @media (min-width: 768px) {
    .latency-sme-title { font-size: 40px; }
  }
  .latency-sme-subtitle {
    margin: 16px 0 0;
    font-size: 17px;
    line-height: 1.6;
    color: var(--text-muted);
  }

  /* Card */
  .latency-sme-card {
    max-width: 880px;
    margin: 0 auto;
    border-radius: 24px;
    border: 1px solid var(--border-light);
    background: var(--card-bg);
    padding: 40px;
    box-shadow: 0 20px 60px rgba(20, 18, 26, 0.08);
  }

  /* Tabs — the strip scrolls sideways once there are more than a
     couple of devices, so nothing wraps or squashes on a phone. */
  .latency-sme-tabs-row {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 40px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 2px;
  }
  .latency-sme-tabs-row::-webkit-scrollbar { display: none; }
  @media (min-width: 768px) {
    .latency-sme-tabs-row { justify-content: center; }
  }
  .latency-sme-tabs {
    display: inline-flex;
    flex: 0 0 auto;
    margin: 0 auto;
    border-radius: 999px;
    border: 1px solid var(--border-light);
    background: var(--tabs-bg);
    padding: 4px;
    gap: 4px;
  }
  .latency-sme-tab {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
    border: none;
    background: transparent;
    border-radius: 999px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--tab-inactive);
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    font-family: inherit;
  }
  .latency-sme-tab:hover { color: var(--text-main); }
  .latency-sme-tab.is-active {
    background: var(--accent) !important;
    color: #ffffff !important;
  }

  /* Body layout */
  .latency-sme-body {
    display: flex;
    flex-direction: column;
    gap: 48px;
    justify-content: space-between;
  }
  @media (min-width: 1024px) {
    .latency-sme-body { flex-direction: row; }
  }

  /* Left */
  .latency-sme-left {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  @media (min-width: 1024px) {
    .latency-sme-left {
      align-items: flex-start;
      text-align: left;
      max-width: 380px;
    }
  }
  .latency-sme-device-meta {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-light);
    width: 100%;
  }
  .latency-sme-device-title {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
  }
  .latency-sme-device-id {
    margin: 8px 0 0;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 14px;
    color: var(--text-muted);
  }

  /* min-height keeps the card from jumping as you move between a
     one-button device and a three-slider one. */
  .latency-sme-controls {
    width: 100%;
  }
  @media (min-width: 1024px) {
    .latency-sme-controls { min-height: calc(var(--visual-size) + 48px); }
  }

  /* Shared action button (LED + buzzer) */
  .latency-sme-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: none;
    border-radius: 12px;
    padding: 16px 32px;
    font-size: 15px;
    font-weight: 600;
    color: #ffffff !important;
    background: var(--accent, #10B981) !important;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    font-family: inherit;
  }
  .latency-sme-action-btn * { color: #ffffff !important; }
  .latency-sme-action-btn:hover { background: var(--accent-hover, #059669) !important; }
  .latency-sme-action-btn:active { transform: scale(0.97); }
  .latency-sme-action-btn.is-off { --accent: #10B981; --accent-hover: #059669; }
  .latency-sme-action-btn.is-on  { --accent: #ef4444; --accent-hover: #dc2626; }

  /* Round power button — the LED's on/off control. The caption sits
     under the circle rather than inside it, so the button stays a
     true circle at any label length. */
  .latency-sme-power-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    width: fit-content;
    margin: 0 auto;
  }
  @media (min-width: 1024px) {
    .latency-sme-power-wrap { margin: 0; }
  }
  .latency-sme-power-btn {
    /* Same size as the device circle on the right, so the two line
       up on one centre line at every breakpoint. */
    width: var(--visual-size);
    height: var(--visual-size);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff !important;
    background: var(--accent, #10B981) !important;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.2s ease, box-shadow 0.25s ease, transform 0.1s ease;
  }
  .latency-sme-power-btn * { color: #ffffff !important; }
  .latency-sme-power-btn > svg {
    width: calc(var(--visual-icon) * 0.68);
    height: calc(var(--visual-icon) * 0.68);
  }
  .latency-sme-power-btn:hover { background: var(--accent-hover) !important; }
  .latency-sme-power-btn:active { transform: scale(0.95); }
  .latency-sme-power-btn.is-off {
    --accent: #10B981;
    --accent-hover: #059669;
    box-shadow: 0 14px 38px rgba(16, 185, 129, 0.34);
  }
  .latency-sme-power-btn.is-on {
    --accent: #ef4444;
    --accent-hover: #dc2626;
    box-shadow: 0 14px 38px rgba(239, 68, 68, 0.36);
  }
  .latency-sme-power-btn.is-buzz {
    --accent: #F59E0B;
    --accent-hover: #d97706;
    box-shadow: 0 14px 38px rgba(245, 158, 11, 0.34);
  }
  .latency-sme-power-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-main);
  }

  .latency-sme-power-btn:focus-visible,
  .latency-sme-action-btn:focus-visible,
  .latency-sme-tab:focus-visible,
  .latency-sme-chip:focus-visible,
  .latency-sme-swatch:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 3px;
  }

  /* Rows, marks */
  .latency-sme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 12px;
  }
  .latency-sme-row-label {
    font-weight: 600;
    color: var(--text-main);
  }
  .latency-sme-row-value {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    color: var(--text-main);
  }
  .latency-sme-marks {
    margin-top: 8px;
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
  }

  /* Sliders — accent comes from --slider-accent set inline per input */
  .latency-sme-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--border-light);
    border-radius: 999px;
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
    cursor: pointer;
    margin: 8px 0;
    touch-action: none;
  }
  .latency-sme-slider-tight { height: 6px; margin: 6px 0; }

  .latency-sme-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--slider-accent, #7C3AED);
    border: none !important;
    outline: none !important;
    box-shadow: 0 2px 6px rgba(20, 18, 26, 0.28);
    transition: transform 0.15s ease;
  }
  .latency-sme-slider::-webkit-slider-thumb:hover { transform: scale(1.15); }
  .latency-sme-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--slider-accent, #7C3AED);
    border: none !important;
    outline: none !important;
    box-shadow: 0 2px 6px rgba(20, 18, 26, 0.28);
    transition: transform 0.15s ease;
  }
  .latency-sme-slider:focus,
  .latency-sme-slider:focus-visible,
  .latency-sme-slider:active,
  .latency-sme-slider::-moz-focus-inner {
    outline: none !important;
    border: none !important;
    box-shadow: none !important;
  }

  .latency-sme-mini-label {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text-muted);
  }

  /* Colour wheel — hue runs around the rim, saturation from the
     middle outwards, exactly how the knob position is read in JS. */
  .latency-sme-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 24px;
  }
  @media (min-width: 1024px) {
    .latency-sme-picker { flex-wrap: nowrap; justify-content: flex-start; }
  }
  .latency-sme-picker-side {
    flex: 1 1 180px;
    min-width: 170px;
  }

  .latency-sme-wheel {
    position: relative;
    width: 150px;
    height: 150px;
    flex: 0 0 auto;
    border-radius: 50%;
    cursor: crosshair;
    touch-action: none;
    outline: none;
  }
  .latency-sme-wheel:focus-visible {
    outline: 2px solid var(--text-main);
    outline-offset: 4px;
  }
  .latency-sme-wheel-disc,
  .latency-sme-wheel-shade {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    pointer-events: none;
  }
  .latency-sme-wheel-disc {
    background:
      radial-gradient(circle closest-side, #ffffff 0%, rgba(255, 255, 255, 0) 100%),
      conic-gradient(from 0deg,
        #ff0000, #ffff00 60deg, #00ff00 120deg,
        #00ffff 180deg, #0000ff 240deg, #ff00ff 300deg, #ff0000 360deg);
    box-shadow: 0 6px 20px rgba(20, 18, 26, 0.16);
  }
  /* Dimming layer — opacity is set from the brightness slider */
  .latency-sme-wheel-shade {
    background: #000000;
    opacity: 0;
    transition: opacity 0.15s ease;
  }
  .latency-sme-wheel-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border-radius: 50%;
    border: 3px solid #ffffff;
    background: var(--rgb-color, #EC4899);
    box-shadow: 0 2px 8px rgba(20, 18, 26, 0.45);
    pointer-events: none;
  }
  .latency-sme-wheel-hub {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 52px;
    height: 52px;
    margin: -26px 0 0 -26px;
    border-radius: 50%;
    background: var(--card-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--rgb-color, #EC4899);
    box-shadow: 0 4px 14px rgba(20, 18, 26, 0.22);
    pointer-events: none;
  }

  /* Presets: servo chips + rgb swatches */
  .latency-sme-presets {
    margin-top: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
  }
  @media (min-width: 1024px) {
    .latency-sme-presets { justify-content: flex-start; }
  }
  .latency-sme-chip {
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-muted);
    border-radius: 999px;
    padding: 7px 16px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
  }
  .latency-sme-chip:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
  /* The colour arrives as --swatch rather than an inline background,
     because a theme's dark-mode `button { background: ... !important }`
     would otherwise flatten all five swatches to one colour. */
  .latency-sme-swatch {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 1px solid var(--border-light);
    background: var(--swatch, #cccccc) !important;
    padding: 0;
    cursor: pointer;
    transition: transform 0.15s ease;
  }
  .latency-sme-swatch:hover { transform: scale(1.12); }

  .latency-sme-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
  }
  .latency-sme-check input { accent-color: #F59E0B; cursor: pointer; }

  /* Right */
  .latency-sme-right {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
  }
  @media (min-width: 1024px) {
    .latency-sme-right { width: auto; }
  }
  .latency-sme-stage {
    position: relative;
    width: var(--visual-size);
    height: var(--visual-size);
  }

  /* Visuals — all five share one size so switching tabs never
     shifts the layout. CSS width/height wins over the SVG attrs. */
  .latency-sme-visual-circle {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.25s ease, box-shadow 0.25s ease, color 0.25s ease;
  }
  .latency-sme-visual-circle > svg {
    width: var(--visual-icon);
    height: var(--visual-icon);
  }

  /* LED */
  .latency-sme-led-circle.is-off {
    background: var(--visual-idle-bg);
    color: #94909e;
  }
  .latency-sme-led-circle.is-on {
    background: #10B981;
    color: #ffffff;
    box-shadow: 0 0 80px rgba(16, 185, 129, 0.65);
  }
  .latency-sme-led-circle.is-pulsing {
    animation: latency-sme-pulse 0.25s ease;
  }
  @keyframes latency-sme-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.08); }
    100% { transform: scale(1); }
  }

  /* Fan */
  .latency-sme-fan-circle {
    background: var(--visual-idle-bg);
    color: #7C3AED;
  }
  .latency-sme-fan-svg-spin {
    animation: latency-sme-spin 2.25s linear infinite;
    animation-play-state: paused;
  }
  @keyframes latency-sme-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
  }

  /* Servo — the arm swings to the commanded angle with a small
     overshoot, the way a real horn settles. */
  .latency-sme-servo-circle {
    background: var(--visual-idle-bg);
    color: #0EA5E9;
  }
  .latency-sme-servo-arm {
    transform-box: view-box;
    transform-origin: 50px 66px;
    transform: rotate(90deg);
    transition: transform 0.45s cubic-bezier(0.34, 1.45, 0.5, 1);
  }
  .latency-sme-servo-circle.is-sweeping .latency-sme-servo-arm {
    transition: transform 1.1s ease-in-out;
  }

  /* RGB — colour and glow are driven from JS custom properties */
  .latency-sme-rgb-circle {
    background: var(--rgb-color, #EC4899);
    color: var(--rgb-ink, #ffffff);
    box-shadow: 0 0 70px var(--rgb-glow, rgba(236, 72, 153, 0.6));
  }

  /* Buzzer */
  .latency-sme-buzz-circle {
    background: var(--visual-idle-bg);
    color: #F59E0B;
    overflow: visible;
  }
  .latency-sme-buzz-circle.is-buzzing {
    background: #F59E0B;
    color: #ffffff;
    animation: latency-sme-shake 0.09s linear infinite;
  }
  @keyframes latency-sme-shake {
    0%   { transform: translate(0, 0); }
    25%  { transform: translate(1.5px, -1px); }
    50%  { transform: translate(-1px, 1.5px); }
    75%  { transform: translate(-1.5px, -1px); }
    100% { transform: translate(0, 0); }
  }
  .latency-sme-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid #F59E0B;
    opacity: 0;
    pointer-events: none;
  }
  .latency-sme-buzz-circle.is-buzzing .latency-sme-ring {
    animation: latency-sme-ripple 0.9s ease-out infinite;
  }
  .latency-sme-buzz-circle.is-buzzing .latency-sme-ring:nth-child(2) { animation-delay: 0.3s; }
  .latency-sme-buzz-circle.is-buzzing .latency-sme-ring:nth-child(3) { animation-delay: 0.6s; }
  @keyframes latency-sme-ripple {
    0%   { transform: scale(1); opacity: 0.7; }
    100% { transform: scale(1.85); opacity: 0; }
  }

  /* Latency pill */
  .latency-sme-latency-pill {
    margin-top: 32px;
    display: inline-flex;
    justify-content: center;
    border-radius: 999px;
    background: #000000;
    padding: 12px 24px;
    width: 100%;
  }
  @media (min-width: 1024px) {
    .latency-sme-latency-pill { width: auto; }
  }
  .latency-sme-latency-text {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-weight: 700;
    color: #fb923c;
  }
  .latency-sme-latency-text.is-good { color: #34d399; }

  .latency-sme-footnote {
    margin: 16px 0 0;
    max-width: 280px;
    text-align: center;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-muted);
  }

  /* Fade-in-up on scroll */
  .latency-sme-fade {
    opacity: 0;
    transform: translateY(24px);
    transition: opacity 0.6s ease, transform 0.6s ease;
  }
  .latency-sme-fade.is-visible {
    opacity: 1;
    transform: translateY(0);
  }
  @media (prefers-reduced-motion: reduce) {
    .latency-sme-fade {
      opacity: 1;
      transform: none;
      transition: none;
    }
    .latency-sme-led-circle.is-pulsing,
    .latency-sme-buzz-circle.is-buzzing,
    .latency-sme-buzz-circle.is-buzzing .latency-sme-ring {
      animation: none;
    }
    .latency-sme-servo-arm { transition: none; }
  }

  /* Dark mode — follows the site-wide toggle (html.dark-mode class) */
  html.dark-mode .latency-sme {
    --page-bg: #0a0b14;
    --card-bg: #14121e;
    --text-main: #ffffff;
    --text-muted: #a9a4bd;
    --border-light: rgba(255, 255, 255, 0.12);
    --tabs-bg: rgba(255, 255, 255, 0.06);
    --tab-inactive: #a9a4bd;
    --visual-idle-bg: #201d2c;
  }
  html.dark-mode .latency-sme .latency-sme-card {
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  }
  /* Reclaim button colours from site-wide dark mode overrides */
  html.dark-mode .latency-sme .latency-sme-tab {
    background: transparent !important;
    color: var(--tab-inactive) !important;
  }
  html.dark-mode .latency-sme .latency-sme-tab:hover { color: var(--text-main) !important; }
  html.dark-mode .latency-sme .latency-sme-tab.is-active {
    background: var(--accent) !important;
    color: #ffffff !important;
  }
  html.dark-mode .latency-sme .latency-sme-power-btn {
    background: var(--accent) !important;
    color: #ffffff !important;
  }
  html.dark-mode .latency-sme .latency-sme-power-btn:hover {
    background: var(--accent-hover) !important;
  }
  html.dark-mode .latency-sme .latency-sme-action-btn {
    background: var(--accent, #10B981) !important;
    color: #ffffff !important;
  }
  html.dark-mode .latency-sme .latency-sme-action-btn:hover {
    background: var(--accent-hover, #059669) !important;
  }
  html.dark-mode .latency-sme .latency-sme-swatch {
    background: var(--swatch, #cccccc) !important;
  }
  html.dark-mode .latency-sme .latency-sme-chip {
    background: transparent !important;
    color: var(--text-muted) !important;
  }
  html.dark-mode .latency-sme .latency-sme-chip:hover { color: var(--accent) !important; }
