/* ═══════════════════════════════════════════════════════════════════════════
   NAME FROM A HAT (name-from-a-hat-engine.js)
   A top hat that shakes; a folded paper slip rises out and unfolds to show the
   drawn name. Theme-variable chrome; the hat itself is a fixed illustration.
   ═══════════════════════════════════════════════════════════════════════════ */

.nh-stage {
    position: relative;
    width: 100%;
    max-width: 380px;
    margin: 0 auto;
    padding-top: 90px;   /* room for the slip to rise above the hat */
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* The paper slip that flies up out of the hat and unfolds */
.nh-slip {
    position: absolute;
    top: 6px;
    left: 50%;
    width: 62%;
    max-width: 230px;
    transform: translateX(-50%) translateY(40px) scaleY(0.05);
    transform-origin: bottom center;
    opacity: 0;
    background: linear-gradient(180deg, #fffdf5, #f3ecd8);
    border: 1px solid #e6dcc0;
    border-radius: 6px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18);
    padding: 0.85rem 0.75rem;
    text-align: center;
    z-index: 3;
    pointer-events: none;
}

/* fold lines */
.nh-slip::before,
.nh-slip::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 1px;
    background: rgba(0, 0, 0, 0.07);
}
.nh-slip::before { top: 33%; }
.nh-slip::after { top: 66%; }

.nh-slip-name {
    font-weight: 800;
    font-size: clamp(1.1rem, 4vw, 1.5rem);
    color: #3f3320;
    word-break: break-word;
}

.nh-slip.nh-slip-show {
    animation: nhUnfold 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
               nhSlipGlow 0.9s ease-out;
}

@keyframes nhUnfold {
    0%   { opacity: 0; transform: translateX(-50%) translateY(96px) scale(0.12) rotate(-22deg); }
    32%  { opacity: 1; transform: translateX(-50%) translateY(-34px) scale(0.9) rotate(13deg); }
    58%  { transform: translateX(-50%) translateY(-6px) scale(1.16) rotate(-5deg); }
    80%  { transform: translateX(-50%) translateY(0) scale(0.97) rotate(2deg); }
    100% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1) rotate(0deg); }
}

@keyframes nhSlipGlow {
    0%   { box-shadow: 0 0 0 rgba(255, 215, 90, 0); }
    40%  { box-shadow: 0 0 34px 8px rgba(255, 205, 70, 0.75); }
    100% { box-shadow: 0 10px 24px rgba(0, 0, 0, 0.18); }
}

/* The hat */
.nh-hat {
    position: relative;
    width: 100%;
    max-width: 300px;
    cursor: pointer;
    z-index: 2;
    -webkit-tap-highlight-color: transparent;
}
.nh-hat svg { width: 100%; height: auto; display: block; }

.nh-hat {
    transform-origin: 50% 90%;
}

.nh-hat.nh-shaking {
    animation: nhShake 0.9s cubic-bezier(0.34, 1.3, 0.5, 1);
}

/* The hat tips back, jumps, and jiggles hard as if someone's rummaging inside. */
@keyframes nhShake {
    0%   { transform: translateY(0) rotate(0deg) scale(1); }
    12%  { transform: translateY(-6px) rotate(-16deg) scale(1.04); }
    24%  { transform: translateY(-26px) rotate(10deg) scale(1.08); }
    38%  { transform: translateY(-10px) rotate(-13deg) scale(1.05); }
    52%  { transform: translateY(-30px) rotate(12deg) scale(1.09); }
    66%  { transform: translateY(-8px) rotate(-8deg) scale(1.04); }
    80%  { transform: translateY(-12px) rotate(5deg) scale(1.02); }
    92%  { transform: translateY(2px) rotate(-2deg) scale(1); }
    100% { transform: translateY(0) rotate(0deg) scale(1); }
}

/* A little puff of "magic" dust rises from the hat brim as the slip appears. */
.nh-stage::after {
    content: "";
    position: absolute;
    top: 60px;
    left: 50%;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    transform: translate(-50%, 0) scale(0.2);
    background: radial-gradient(circle, rgba(255, 214, 102, 0.55) 0%, rgba(255, 214, 102, 0) 70%);
    opacity: 0;
    pointer-events: none;
    z-index: 1;
}
.nh-stage.nh-puff::after {
    animation: nhPuff 0.7s ease-out;
}
@keyframes nhPuff {
    0%   { opacity: 0; transform: translate(-50%, 0) scale(0.2); }
    40%  { opacity: 1; transform: translate(-50%, -18px) scale(1.1); }
    100% { opacity: 0; transform: translate(-50%, -46px) scale(1.6); }
}

/* Drawn-names strip */
.nh-drawn {
    margin-top: 1rem;
    text-align: center;
    line-height: 2;
}
.nh-drawn-label { font-weight: 700; color: var(--theme-muted, #6c757d); margin-right: 0.25rem; }
.nh-drawn-chip {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    margin: 0.15rem;
    border-radius: 999px;
    background: var(--theme-surface, #f1f3f5);
    border: 1px solid var(--theme-border, #dbe0e6);
    color: var(--theme-text, #343a40);
    font-size: 0.85rem;
    font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
    .nh-hat.nh-shaking { animation: none; }
    .nh-slip.nh-slip-show { animation: none; opacity: 1; transform: translateX(-50%) translateY(0) scaleY(1); }
}
