@layer reset, base, components;

@layer reset {
  :where(*, *::before, *::after) {
    box-sizing: border-box;
  }

  :where(body, h1, h2, p, ul) {
    margin: 0;
  }

  :where(ul) {
    padding: 0;
    list-style: none;
  }
}

:root {
  --bg-deep: #04090a;
  --bg-radial: radial-gradient(circle at 50% 35%, #0c2320 0%, #050b0d 55%, #020406 100%);
  --gold-bright: #ffd97d;
  --gold-warm: #e6b85c;
  --emerald-glow: #38d9a9;
  --text-primary: #f8f5ec;
  --text-muted: rgba(248, 245, 236, 0.7);
  --glass-bg: rgba(8, 18, 20, 0.56);
  --glass-border: rgba(255, 217, 125, 0.24);
  --radius-lg: 18px;
  --radius-pill: 999px;
  --font-display: "Cinzel", "Noto Sans SC", serif;
  --font-body: "Noto Sans SC", system-ui, -apple-system, sans-serif;
}

@layer base {
  html,
  body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-deep);
    background-image: var(--bg-radial);
    color: var(--text-primary);
    font-family: var(--font-body);
    color-scheme: dark;
  }
}

@layer components {
  .stage {
    position: relative;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
  }

  #tree-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
    touch-action: none;

    &:active {
      cursor: grabbing;
    }
  }

  .hud-header {
    position: absolute;
    inset-block-start: 20px;
    inset-inline-start: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
    z-index: 10;
  }

  .brand-kicker {
    font-size: 0.72rem;
    letter-spacing: 0.28em;
    color: var(--gold-bright);
    opacity: 0.9;
  }

  .brand-title {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 2.8vw, 2.35rem);
    font-weight: 700;
    letter-spacing: 0.08em;
    background: linear-gradient(135deg, #fff6d6 0%, var(--gold-bright) 45%, #d49b38 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 4px 24px rgba(255, 217, 125, 0.22);
  }

  .status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(12px);
    font-size: 0.85rem;
    color: var(--text-primary);
  }

  .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--emerald-glow);
    box-shadow: 0 0 10px var(--emerald-glow);
  }

  .camera-card {
    position: absolute;
    inset-block-start: 20px;
    inset-inline-end: 24px;
    width: 210px;
    padding: 10px;
    border-radius: var(--radius-lg);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 10;
  }

  .camera-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.08);
  }

  #webcam-video,
  #hand-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
  }

  .camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-align: center;
    padding: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);

    &.hidden {
      display: none;
    }

    & small {
      font-size: 0.7rem;
      opacity: 0.75;
    }
  }

  .camera-actions {
    display: flex;
  }

  .guide-card {
    position: absolute;
    inset-block-end: 86px;
    inset-inline-start: 24px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(14px);
    max-width: 260px;
    z-index: 10;
  }

  .guide-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gold-bright);
    margin-block-end: 10px;
    letter-spacing: 0.06em;
  }

  .guide-list {
    display: flex;
    flex-direction: column;
    gap: 8px;

    & li {
      display: flex;
      align-items: center;
      gap: 10px;
      font-size: 0.78rem;
      line-height: 1.25;
    }

    & .emoji {
      font-size: 1.05rem;
      width: 22px;
      text-align: center;
    }

    & strong {
      display: block;
      color: var(--text-primary);
      font-weight: 500;
    }

    & span:not(.emoji) {
      color: var(--text-muted);
      font-size: 0.72rem;
    }
  }

  .control-dock {
    position: absolute;
    inset-block-end: 20px;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-pill);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    max-width: calc(100vw - 32px);
    z-index: 10;
  }

  .btn {
    appearance: none;
    border: 1px solid transparent;
    border-radius: var(--radius-pill);
    padding: 7px 14px;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: transform 0.18s ease, background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;

    &:focus-visible {
      outline: 2px solid var(--gold-bright);
      outline-offset: 2px;
    }

    &:hover:not(:disabled) {
      transform: translateY(-1px);
    }

    &:active:not(:disabled) {
      transform: translateY(0);
    }
  }

  .btn-primary {
    width: 100%;
    background: linear-gradient(135deg, #ffd97d, #d89b32);
    color: #1b1305;
    font-weight: 600;

    &:hover:not(:disabled) {
      box-shadow: 0 0 18px rgba(255, 217, 125, 0.45);
    }
  }

  .btn-glass {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);

    &:hover:not(:disabled) {
      background: rgba(255, 255, 255, 0.16);
      border-color: var(--glass-border);
    }

    &.active {
      background: rgba(255, 255, 255, 0.22);
      border-color: var(--gold-bright);
      color: var(--gold-bright);
    }
  }

  @media (max-width: 720px) {
    .guide-card {
      display: none;
    }

    .camera-card {
      width: 150px;
      inset-inline-end: 12px;
      inset-block-start: 12px;
    }

    .hud-header {
      inset-inline-start: 14px;
      inset-block-start: 14px;
    }

    .control-dock {
      inset-block-end: 12px;
      border-radius: 16px;
    }
  }

  @media (prefers-reduced-motion: reduce) {
    .btn {
      transition: none;
    }
  }
}
