/* Catcha Engine Styles */

body.catcha {
  --catcha-bg: #0e0e12;
  --catcha-fg: #f5f5f5;
  --catcha-accent: #ff7a00;
  --catcha-accent-soft: #ffb47a;
  --catcha-muted: #8a8a92;
  --catcha-card: #1a1a22;

  .intro {
    max-width: 40rem;
    margin: 2rem auto;
    padding: 1.5rem;

    h2 {
      font-size: 2.5rem;
      margin: 0 0 0.5rem;
    }

    h3 {
      margin: 2rem 0 0.5rem;
      font-size: 1.25rem;
    }

    .lead {
      font-size: 1.1rem;
      line-height: 1.5;
    }

    .how-to {
      padding-left: 1.25rem;
      line-height: 1.6;
    }

    .how-to li {
      margin-bottom: 0.35rem;
    }

    p {
      line-height: 1.5;
    }
  }

  .lobby-actions {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 22rem;
    margin: 1.5rem auto;

    /* button_to wraps its <button> in a <form class="button_to">. We want the
       button to be the flex item, not the form, so it stretches to the same
       width as the sibling <a class="button">. */
    .button_to {
      display: contents;
    }
  }

  .back-link {
    display: inline-block;
    margin: 0 0 0.25rem;
    padding: 0;
    color: inherit;
    text-decoration: none;
    font-size: 0.75rem;
    opacity: 0.55;
    line-height: 1;

    &:hover {
      opacity: 1;
    }
  }

  .button {
    display: inline-block;
    padding: 0.75rem 1.5rem;
    border: 2px solid currentColor;
    border-radius: 0.5rem;
    background: transparent;
    font-size: 1.1rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
  }

  .button--primary {
    background: var(--catcha-accent);
    border-color: var(--catcha-accent);
    color: var(--catcha-bg);
  }

  .join {
    max-width: 24rem;
    margin: 4rem auto;
    padding: 2rem;
    text-align: center;
  }

  .join-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
  }

  .code-input {
    font-size: 2.5rem;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    text-align: center;
    letter-spacing: 0.4rem;
    text-transform: uppercase;
    padding: 0.5rem;
    border: 2px solid var(--catcha-muted);
    border-radius: 0.5rem;
    background: var(--catcha-card);
    color: var(--catcha-fg);
  }

  /* Cat room — dashboard view (normal flow) */
  .cat-screen {
    position: relative;
  }

  .dashboard:not([hidden]) {
    max-width: 32rem;
    margin: 2rem auto;
    padding: 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
  }

  .code-label {
    color: var(--catcha-muted);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1rem;
    margin: 0;
  }

  .code {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: clamp(3rem, 12vw, 6rem);
    letter-spacing: 0.5rem;
    margin: 0;
    color: var(--catcha-accent);
  }

  .share-row {
    display: flex;
    gap: 1rem;
    align-items: stretch;
    justify-content: center;
    flex-wrap: wrap;
  }

  .qr-placeholder {
    border: 2px dashed var(--catcha-muted);
    padding: 0.75rem 1.25rem;
    color: var(--catcha-muted);
    font-size: 0.875rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
  }

  .human-status {
    margin: 0;
    color: var(--catcha-muted);
    font-style: italic;
  }

  .listened-to {
    margin: 0;
    padding: 0.4rem 0.75rem;
    border-radius: 0.4rem;
    background: rgba(255, 122, 0, 0.18);
    color: var(--catcha-accent);
    font-size: 0.9rem;
  }

  .device-tests {
    border: 2px solid var(--catcha-muted);
    border-radius: 0.5rem;
    padding: 1rem;
    color: var(--catcha-fg);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;

    legend {
      padding: 0 0.5rem;
      font-size: 0.85rem;
      color: var(--catcha-muted);
    }

    button {
      appearance: none;
      -webkit-appearance: none;
      padding: 0.5rem 1rem;
      border: 1px solid var(--catcha-fg);
      border-radius: 0.25rem;
      background: var(--catcha-card);
      color: var(--catcha-fg);
      font: inherit;
      cursor: pointer;
    }

    button:hover {
      background: var(--catcha-fg);
      color: var(--catcha-bg);
    }
  }

  .device-tests-status {
    flex-basis: 100%;
    margin: 0;
    color: var(--catcha-muted);
    font-size: 0.85rem;
    text-align: center;
    min-height: 1.2em;
  }

  .local-preview {
    flex-basis: 100%;
    width: 100%;
    max-width: 160px;
    aspect-ratio: 16 / 9;
    margin: 0 auto;
    border-radius: 0.4rem;
    background: #000;
    object-fit: cover;
  }

  .start-game {
    margin-top: 0.5rem;

    &:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
  }

  .start-hint {
    margin: -0.5rem 0 0;
    color: var(--catcha-muted);
    font-size: 0.85rem;
    font-style: italic;
  }

  /* Cat room — fullscreen game */
  .cat-screen:fullscreen {
    /* lockdown */
    touch-action: none;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-drag: none;
    cursor: none;
    caret-color: transparent;
    overflow: hidden;

    background: var(--catcha-bg);
    color: var(--catcha-fg);

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }

  .game:not([hidden]) {
    position: absolute;
    inset: 0;
    display: block;
  }

  .toys-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
  }

  /* Tail layer (one SVG that holds every mouse's polylines). The SVG
     itself doesn't catch events; the per-toy hit polylines do. */
  .toys-tails {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 1;
  }

  .toys-tails .toy-tail-hit {
    pointer-events: stroke;
    cursor: pointer;
  }

  /* Mouse-from-above. Size and color come from inline custom properties
     set by the ToyEngine (see TOY_KINDS in cat_room_controller.js). The
     element is much larger than the visible body so a cat paw has room
     to land on it; the body sits centered inside that hitbox. */
  .toy {
    --toy-hitbox-size: max(96px, calc(var(--toy-size, 48px) * 2));
    position: absolute;
    top: 0;
    left: 0;
    width: var(--toy-hitbox-size);
    height: var(--toy-hitbox-size);
    pointer-events: auto;
    will-change: transform;
    touch-action: none;
    transform-origin: 50% 50%;
    z-index: 2;
  }

  .toy-body {
    position: absolute;
    top: 50%;
    left: 50%;
    width: var(--toy-size, 48px);
    height: var(--toy-size, 48px);
    margin-left: calc(var(--toy-size, 48px) / -2);
    margin-top: calc(var(--toy-size, 48px) / -2);
    background: var(--toy-color, #00d4ff);
    border-radius: 50%;
    box-shadow:
      0 0 12px var(--toy-color, #00d4ff),
      0 4px 8px rgba(0, 0, 0, 0.5);
    transition: filter 0.1s ease-out;
  }

  .toy-eye {
    position: absolute;
    width: 22%;
    height: 22%;
    background: #fefefe;
    border-radius: 50%;
    right: 12%;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
  }

  .toy-eye::after {
    content: "";
    position: absolute;
    inset: 28%;
    background: #111;
    border-radius: 50%;
  }

  .toy-eye--a { top: 18%; }
  .toy-eye--b { bottom: 18%; }

  .toy--held .toy-body {
    filter: brightness(1.4) saturate(1.5);
  }

  /* Holes that briefly appear on the border when a critter spawns or
     retreats. The dark center is the "tunnel"; the warm rim makes it
     visible against the dark game background. Centered via translate(-50%,
     -50%) — see the keyframes in JS. */
  .toy-hole {
    position: absolute;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background:
      radial-gradient(
        circle,
        #000 0%,
        #000 30%,
        rgba(255, 122, 0, 0.65) 48%,
        rgba(255, 122, 0, 0.2) 62%,
        transparent 75%
      );
    pointer-events: none;
    transform: translate(-50%, -50%);
    z-index: 0;
  }

  .toy-count {
    display: inline-block;
    margin-left: 0.5rem;
    min-width: 1.5em;
    text-align: right;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    color: var(--catcha-accent);
    font-weight: 600;
  }

  /* Hideout where mice can stash themselves. The dark "opening" gives a
     visual cue that mice can disappear into it; tapping anywhere on the
     element scares whoever is inside back out. */
  .toy-hideout {
    position: absolute;
    width: var(--hideout-w, 110px);
    height: var(--hideout-h, 84px);
    transform: translate(-50%, -50%);
    pointer-events: auto;
    cursor: pointer;
    z-index: 1;
    touch-action: none;
  }

  .toy-hideout-body {
    position: absolute;
    inset: 0;
    border-radius: 18px 18px 22px 22px / 26px 26px 18px 18px;
    background:
      radial-gradient(ellipse at 30% 28%, #4ec06a 0%, #2d8a44 38%, #1a5a2a 70%, #0c3015 100%);
    box-shadow:
      0 10px 18px rgba(0, 0, 0, 0.5),
      inset 0 0 0 2px rgba(0, 0, 0, 0.4),
      inset 0 -6px 12px rgba(0, 0, 0, 0.4),
      0 0 24px rgba(78, 192, 106, 0.25);
  }

  .toy-hideout-opening {
    position: absolute;
    bottom: 14%;
    left: 50%;
    transform: translateX(-50%);
    width: 38%;
    height: 42%;
    border-radius: 50% 50% 30% 30% / 60% 60% 30% 30%;
    background:
      radial-gradient(ellipse at top, #050905 0%, #000 70%);
    box-shadow:
      inset 0 6px 12px rgba(0, 0, 0, 0.9),
      0 0 4px rgba(0, 0, 0, 0.8);
  }

  .toy-hideout--occupied .toy-hideout-body {
    box-shadow:
      0 10px 18px rgba(0, 0, 0, 0.5),
      inset 0 0 0 2px rgba(0, 0, 0, 0.4),
      inset 0 -6px 12px rgba(0, 0, 0, 0.4),
      0 0 32px rgba(255, 122, 0, 0.45);
  }

  /* Human panel */
  .human-panel {
    max-width: 40rem;
    margin: 2rem auto;
    padding: 1.5rem;

    header h2 {
      margin: 0;
    }

    .status {
      color: var(--catcha-muted);
      margin: 0.25rem 0 1.5rem;
    }
  }

  .panel-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
  }

  .remote-video-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #000;
    border-radius: 0.5rem;
    overflow: hidden;
  }

  .remote-video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
  }

  .audio-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    align-items: stretch;
  }

  .audio-row .talk-status {
    grid-column: 1 / -1;
  }

  .listen-btn {
    padding: 1rem;
    font-size: 1.05rem;
  }

  .listen-btn--active {
    background: var(--catcha-accent);
    border-color: var(--catcha-accent);
    color: var(--catcha-bg);
  }

  .talk-btn {
    padding: 1rem;
    font-size: 1.15rem;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;

    &:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }
  }

  .talk-btn--active {
    background: #ff3a3a;
    border-color: #ff3a3a;
    box-shadow: 0 0 0 4px rgba(255, 58, 58, 0.25);
  }

  .talk-status {
    margin: 0;
    color: var(--catcha-muted);
    font-size: 0.85rem;
    text-align: center;
  }

  .stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .stat-card {
    background: var(--catcha-card);
    color: var(--catcha-fg);
    border-radius: 0.5rem;
    padding: 0.75rem 0.5rem;
    text-align: center;
    min-width: 0;
  }

  .stat-label {
    color: var(--catcha-muted);
    margin: 0 0 0.25rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08rem;
  }

  .stat-value {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 2rem;
    margin: 0;
    color: var(--catcha-accent);
  }

  .controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  .toy-controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .toy-controls-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 0.5rem;
    align-items: center;
  }

  .toy-controls-label {
    font-size: 1rem;
  }

  .button--icon {
    padding: 0.5rem 0.9rem;
    font-size: 1.25rem;
    min-width: 3rem;
    line-height: 1;
  }
}
