/*
 * FingerMagic: the app's interface on top of the Hazen Studio kit
 * (/hazen/hazen.css). The camera stage stays dark in both themes; the toolbar
 * and the panels follow the site theme. The rules join the kit's cascade
 * layers so kit components keep their own spacing.
 */

@layer base {
  h1,
  h2,
  p,
  ol,
  ul {
    margin: 0;
  }
  ol[role="list"],
  ul[role="list"],
  .fm-air {
    padding: 0;
    list-style: none;
  }
  .hidden,
  [hidden] {
    display: none !important;
  }
}

@layer components {
  /* ─── Header ─── */
  .fm-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    height: 100%;
  }
  .fm-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--hz-text);
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    text-decoration: none;
    border-radius: var(--hz-radius-sm);
  }
  .fm-brand em {
    font-family: var(--hz-font-serif);
    font-size: 1.15em;
    font-weight: 400;
    color: var(--hz-accent-text);
  }
  .fm-brand__mark {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--hz-accent);
    color: var(--hz-on-accent);
  }
  .fm-header__note {
    display: none;
    align-items: center;
    gap: 8px;
    color: var(--hz-text-3);
    font-size: var(--hz-text-xs);
  }
  .fm-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--hz-success);
    box-shadow: 0 0 0 4px var(--hz-success-soft);
  }
  @media (min-width: 640px) {
    .fm-header__note {
      display: inline-flex;
    }
  }

  /* ─── Intro ─── */
  .fm-main {
    position: relative;
    padding-block: clamp(2rem, 1.5rem + 2vw, 3.5rem) 2rem;
  }
  .fm-intro {
    display: grid;
    gap: 1.75rem 3rem;
    align-items: end;
    margin-bottom: clamp(1.5rem, 1rem + 2vw, 2.5rem);
  }
  .fm-intro h1 {
    margin-top: 1rem;
    font-size: clamp(2.25rem, 1.6rem + 2.6vw, 3.75rem);
  }
  .fm-gestures {
    display: grid;
    gap: 12px;
  }
  .fm-gestures li {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    color: var(--hz-text-2);
    font-size: var(--hz-text-sm);
    line-height: 1.45;
  }
  .fm-gestures strong {
    display: block;
    color: var(--hz-text);
  }
  .fm-gestures__icon {
    display: grid;
    flex-shrink: 0;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--hz-radius-md);
    background: var(--hz-accent-soft);
    color: var(--hz-accent-text);
  }
  @media (min-width: 1024px) {
    .fm-intro {
      grid-template-columns: 1.2fr 1fr;
    }
  }

  /* ─── Stage: video, drawing and hand canvases ─── */
  .fm-stage {
    position: relative;
    overflow: hidden;
    width: 100%;
    max-width: 960px;
    aspect-ratio: 4 / 3;
    margin-inline: auto;
    border: 1px solid var(--hz-line);
    border-radius: var(--hz-radius-2xl);
    background:
      radial-gradient(90% 70% at 50% 30%, color-mix(in srgb, var(--hz-accent) 16%, transparent), transparent 70%),
      var(--hz-ink-950);
    box-shadow: var(--hz-shadow-lg);
  }
  .fm-stage:focus {
    outline: none;
  }
  #video,
  #drawing-canvas,
  #hand-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }
  #video {
    z-index: 1;
    object-fit: cover;
    transform: scaleX(-1);
  }
  #drawing-canvas {
    z-index: 2;
  }
  #hand-canvas {
    z-index: 3;
  }
  @media (max-width: 768px) {
    .fm-stage {
      aspect-ratio: 1 / 1;
    }
  }

  /* The air buttons script.js listens to: 50 px squares, 20 px from the top
     and right edges, 15 px apart. These circles only show where they are. */
  .fm-air {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 4;
    display: flex;
    gap: 15px;
    pointer-events: none;
  }
  .fm-air li {
    display: grid;
    place-items: center;
    width: 50px;
    height: 50px;
    border: 1px solid rgb(255 255 255 / 0.28);
    border-radius: 50%;
    background: rgb(10 10 11 / 0.35);
    color: rgb(255 255 255 / 0.85);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }

  .fm-start {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: grid;
    place-items: center;
    padding: 1.5rem;
    background:
      radial-gradient(70% 60% at 50% 40%, color-mix(in srgb, var(--hz-accent) 22%, transparent), transparent 70%),
      rgb(10 10 11 / 0.72);
  }
  .fm-start__card {
    display: grid;
    justify-items: center;
    gap: 12px;
    max-width: 26rem;
    color: #fff;
    text-align: center;
  }
  .fm-start__icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgb(255 255 255 / 0.1);
    color: var(--hz-accent);
  }
  .fm-start h2 {
    font-size: var(--hz-text-h3);
  }
  .fm-start p {
    color: rgb(255 255 255 / 0.72);
    font-size: var(--hz-text-sm);
  }
  .fm-start .hz-btn {
    margin-top: 8px;
  }
  .fm-start__error {
    max-width: 22rem;
    padding: 10px 14px;
    border-radius: var(--hz-radius-md);
    background: rgb(255 80 80 / 0.16);
    color: #ffd3d3 !important;
  }

  .fm-indicator {
    position: absolute;
    top: 20px;
    left: 20px;
    z-index: 5;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--hz-radius-full);
    background: rgb(10 10 11 / 0.55);
    color: #fff;
    font-family: var(--hz-font-mono);
    font-size: 11px;
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
  }
  .fm-indicator::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--fm-state, #56db8f);
  }
  .fm-indicator[data-state="off"] {
    --fm-state: #ff8a8a;
  }
  @media (max-width: 640px) {
    .fm-indicator {
      top: auto;
      bottom: 16px;
      left: 16px;
    }
  }

  .fm-toast {
    position: absolute;
    left: 50%;
    bottom: 20px;
    z-index: 6;
    padding: 8px 16px;
    border-radius: var(--hz-radius-full);
    background: rgb(10 10 11 / 0.72);
    color: #fff;
    font-size: var(--hz-text-sm);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px);
    transition:
      opacity var(--hz-dur) var(--hz-ease-out),
      transform var(--hz-dur) var(--hz-ease-out);
  }
  .fm-toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
  }

  /* ─── Toolbar ─── */
  .fm-toolbar {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 16px;
    max-width: 960px;
    margin: 1.25rem auto 0;
  }
  .fm-toolbar__group {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--hz-line);
    border-radius: var(--hz-radius-xl);
    background: var(--hz-bg-raise);
  }
  .control-btn {
    display: grid;
    justify-items: center;
    gap: 4px;
    min-width: 72px;
    min-height: 60px;
    padding: 9px 10px 7px;
    border: 0;
    border-radius: var(--hz-radius-lg);
    background: transparent;
    color: var(--hz-text-2);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition:
      background-color var(--hz-dur-fast) var(--hz-ease-out),
      color var(--hz-dur-fast) var(--hz-ease-out);
  }
  .control-btn:hover {
    background: var(--hz-surface-2);
    color: var(--hz-text);
  }
  .control-btn[aria-expanded="true"] {
    background: var(--hz-accent-soft);
    color: var(--hz-accent-text);
  }
  #color-btn svg {
    color: var(--fm-current, currentColor);
  }
  .control-btn--accent {
    background: var(--hz-accent);
    color: var(--hz-on-accent);
  }
  .control-btn--accent:hover {
    background: var(--hz-accent-strong);
    color: var(--hz-on-accent);
  }
  .fm-hint {
    margin-top: 1rem;
    color: var(--hz-text-3);
    font-size: var(--hz-text-xs);
    text-align: center;
  }

  /* ─── Panels (placed next to their button by script.js) ─── */
  .fm-panel {
    position: fixed;
    z-index: var(--hz-z-overlay);
    display: grid;
    gap: 12px;
    width: min(22rem, calc(100vw - 24px));
    max-height: calc(100svh - 24px);
    overflow: auto;
    padding: 16px;
    border: 1px solid var(--hz-line);
    border-radius: var(--hz-radius-xl);
    background: var(--hz-material-solid);
    color: var(--hz-text);
    box-shadow: var(--hz-shadow-lg);
  }
  .fm-panel__title {
    color: var(--hz-text-3);
    font-family: var(--hz-font-mono);
    font-size: var(--hz-text-eyebrow);
    font-weight: 500;
    letter-spacing: var(--hz-tracking-eyebrow);
    text-transform: uppercase;
  }
  .fm-panel .hz-segmented {
    display: flex;
    width: 100%;
  }
  .fm-panel .hz-segmented > button {
    flex: 1;
    justify-content: center;
  }
  .fm-panel .hz-segmented > .active {
    background: var(--hz-surface);
    color: var(--hz-text);
    box-shadow: var(--hz-shadow-sm), inset 0 0 0 1px var(--hz-line);
  }

  .color-options {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    justify-items: center;
  }
  .color-option {
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    box-shadow:
      inset 0 0 0 1px rgb(0 0 0 / 0.15),
      0 0 0 0 transparent;
    cursor: pointer;
    transition:
      transform var(--hz-dur-fast) var(--hz-ease-out),
      box-shadow var(--hz-dur-fast) var(--hz-ease-out);
  }
  .color-option:hover {
    transform: scale(1.08);
  }
  .color-option.is-selected {
    box-shadow:
      inset 0 0 0 1px rgb(0 0 0 / 0.15),
      0 0 0 3px var(--hz-surface),
      0 0 0 5px var(--hz-text);
  }

  .size-options {
    display: grid;
    gap: 6px;
  }
  .size-option {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--hz-line);
    border-radius: var(--hz-radius-md);
    background: var(--hz-surface);
    color: var(--hz-text);
    font-size: var(--hz-text-sm);
    cursor: pointer;
  }
  .size-option:hover {
    border-color: var(--hz-line-strong);
  }
  .size-option.is-selected {
    border-color: var(--hz-accent-text);
    background: var(--hz-accent-soft);
  }
  .size-dot {
    width: 24px;
    height: var(--d);
    border-radius: var(--hz-radius-full);
    background: currentColor;
  }

  .brush-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .brush-option {
    display: grid;
    justify-items: center;
    gap: 6px;
    padding: 8px;
    border: 1px solid var(--hz-line);
    border-radius: var(--hz-radius-md);
    background: var(--hz-surface);
    color: var(--hz-text);
    cursor: pointer;
    transition: border-color var(--hz-dur-fast) var(--hz-ease-out);
  }
  .brush-option:hover {
    border-color: var(--hz-line-strong);
  }
  .brush-option.active {
    border-color: var(--hz-accent-text);
    background: var(--hz-accent-soft);
  }
  .brush-name {
    font-size: var(--hz-text-xs);
    font-weight: 500;
  }
  .brush-preview {
    position: relative;
    display: block;
    width: 100%;
    height: 52px;
    overflow: hidden;
    border-radius: var(--hz-radius-sm);
    background-color: var(--hz-ink-850);
    background-repeat: no-repeat;
    background-position: center;
  }

  .round-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 Q 40 5 60 25" stroke="white" stroke-width="5" fill="none" stroke-linecap="round" /></svg>');
  }
  .pencil-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 30 L 60 20" stroke="white" stroke-width="2" fill="none" /><path d="M 20 32 L 60 22" stroke="white" stroke-width="1" fill="none" /></svg>');
  }
  .paintbrush-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 Q 40 15 60 25" stroke="white" stroke-width="7" fill="none" stroke-linecap="round" stroke-dasharray="1,3" /></svg>');
  }
  .marker-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 Q 40 15 60 25" stroke="white" stroke-width="8" fill="none" stroke-opacity="0.5" /></svg>');
  }
  .chalk-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 Q 30 20 40 25 Q 50 30 60 25" stroke="white" stroke-width="4" fill="none" stroke-linecap="round" stroke-dasharray="4,2" /></svg>');
  }
  .splatter-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 L 60 25" stroke="white" stroke-width="1" fill="none" /><circle cx="30" cy="25" r="3" fill="white" /><circle cx="35" cy="20" r="2" fill="white" /><circle cx="40" cy="27" r="4" fill="white" /><circle cx="50" cy="23" r="2" fill="white" /></svg>');
  }
  .fur-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 L 60 25" stroke="white" stroke-width="2" fill="none" /><path d="M 25 25 L 25 20" stroke="white" stroke-width="1" /><path d="M 30 25 L 30 30" stroke="white" stroke-width="1" /><path d="M 35 25 L 35 19" stroke="white" stroke-width="1" /><path d="M 40 25 L 40 31" stroke="white" stroke-width="1" /><path d="M 45 25 L 45 22" stroke="white" stroke-width="1" /><path d="M 50 25 L 50 28" stroke="white" stroke-width="1" /><path d="M 55 25 L 55 21" stroke="white" stroke-width="1" /></svg>');
  }
  .dots-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><circle cx="20" cy="25" r="2" fill="white" /><circle cx="28" cy="25" r="2" fill="white" /><circle cx="36" cy="25" r="2" fill="white" /><circle cx="44" cy="25" r="2" fill="white" /><circle cx="52" cy="25" r="2" fill="white" /><circle cx="60" cy="25" r="2" fill="white" /></svg>');
  }
  .neon-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><path d="M 20 25 Q 40 15 60 25" stroke="%23ff00ff" stroke-width="3" fill="none" /><path d="M 20 25 Q 40 15 60 25" stroke="white" stroke-width="1" fill="none" /></svg>');
    box-shadow: inset 0 0 12px rgb(255 0 255 / 0.6);
  }
  .pixel-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><rect x="20" y="24" width="4" height="4" fill="white" /><rect x="28" y="22" width="4" height="4" fill="white" /><rect x="36" y="20" width="4" height="4" fill="white" /><rect x="44" y="22" width="4" height="4" fill="white" /><rect x="52" y="24" width="4" height="4" fill="white" /><rect x="60" y="26" width="4" height="4" fill="white" /></svg>');
  }
  .rainbow-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><defs><linearGradient id="rainbow" x1="0%" y1="0%" x2="100%" y2="0%"><stop offset="0%" stop-color="%23ff0000"/><stop offset="20%" stop-color="%23ffff00"/><stop offset="40%" stop-color="%2300ff00"/><stop offset="60%" stop-color="%2300ffff"/><stop offset="80%" stop-color="%230000ff"/><stop offset="100%" stop-color="%23ff00ff"/></linearGradient></defs><path d="M 20 25 Q 40 15 60 25" stroke="url(%23rainbow)" stroke-width="6" fill="none" /></svg>');
  }
  .galaxy-preview {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="80" height="50"><defs><radialGradient id="galaxy" cx="50%" cy="50%" r="50%"><stop offset="0%" stop-color="white"/><stop offset="20%" stop-color="%23b19cd9"/><stop offset="40%" stop-color="%236a5acd"/><stop offset="60%" stop-color="%230000ff"/><stop offset="100%" stop-color="%23000033"/></radialGradient></defs><path d="M 20 25 Q 40 15 60 25" stroke="url(%23galaxy)" stroke-width="8" fill="none" /></svg>');
  }

  .scaling-options {
    display: grid;
    gap: 6px;
  }
  .scaling-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--hz-line);
    border-radius: var(--hz-radius-md);
    background: var(--hz-surface);
    color: var(--hz-text);
    text-align: left;
    cursor: pointer;
  }
  .scaling-option:hover {
    border-color: var(--hz-line-strong);
  }
  .scaling-option.active {
    border-color: var(--hz-accent-text);
    background: var(--hz-accent-soft);
  }
  .scaling-info {
    display: grid;
  }
  .scaling-name {
    font-size: var(--hz-text-sm);
    font-weight: 600;
  }
  .scaling-desc {
    color: var(--hz-text-3);
    font-size: var(--hz-text-xs);
  }
  .scaling-icon {
    position: relative;
    display: grid;
    flex-shrink: 0;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--hz-ink-850);
  }
  .depth-icon::before {
    content: "";
    width: 20px;
    height: 8px;
    border-radius: 4px;
    background: linear-gradient(90deg, #555, var(--hz-accent));
  }
  .speed-icon::before {
    content: "";
    width: 18px;
    height: 3px;
    border-radius: 2px;
    background: var(--hz-accent);
    box-shadow: -4px -5px 0 -1px var(--hz-accent), -4px 5px 0 -1px var(--hz-accent);
  }
  .hybrid-icon::before {
    content: "";
    width: 18px;
    height: 4px;
    border-radius: 2px;
    background: linear-gradient(90deg, #777, var(--hz-accent));
  }
  .pressure-icon::before {
    content: "";
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--hz-accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--hz-accent) 35%, transparent);
  }
  .calligraphy-icon::before {
    content: "";
    width: 14px;
    height: 14px;
    border: 2px solid var(--hz-accent);
    border-radius: 3px;
    transform: rotate(45deg);
  }
  .scaling-preview {
    padding-top: 12px;
    border-top: 1px solid var(--hz-line);
  }
  #scaling-preview-canvas {
    display: block;
    width: 100%;
    height: 80px;
    border-radius: var(--hz-radius-md);
    background: var(--hz-ink-850);
  }

  .smoothing-options {
    display: grid;
    gap: 12px;
  }
  .smoothing-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
  }
  .smoothing-value {
    color: var(--hz-accent-text);
    font-family: var(--hz-font-mono);
    font-size: 1.25rem;
    font-weight: 500;
  }
  .slider {
    width: 100%;
    accent-color: var(--hz-accent);
  }
  .smoothing-option-row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
  }
  .toggle-switch {
    position: relative;
    display: inline-block;
    flex-shrink: 0;
    width: 40px;
    height: 24px;
  }
  .toggle-switch input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
  }
  .toggle-slider {
    position: absolute;
    inset: 0;
    border-radius: var(--hz-radius-full);
    background: var(--hz-line-strong);
    transition: background-color var(--hz-dur) var(--hz-ease-out);
    pointer-events: none;
  }
  .toggle-slider::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: var(--hz-shadow-sm);
    transition: transform var(--hz-dur) var(--hz-ease-out);
  }
  .toggle-switch input:checked + .toggle-slider {
    background: var(--hz-accent);
  }
  .toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(16px);
  }
  .toggle-switch input:focus-visible + .toggle-slider {
    outline: 2px solid var(--hz-focus);
    outline-offset: 2px;
  }
  .toggle-label {
    font-size: var(--hz-text-sm);
  }

  /* ─── Footer ─── */
  .fm-footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem 2rem;
  }
  .fm-footer a {
    color: var(--hz-text-2);
    text-decoration: none;
  }
  .fm-footer a:hover {
    color: var(--hz-text);
  }
}
