:root {
    --text: #2d3250;
    --text-soft: #6b7094;
    --card-bg: #ffffff;
    --shadow: rgba(45, 50, 80, 0.08);
    --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --spring-soft: cubic-bezier(0.175, 0.885, 0.32, 1.275);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background: radial-gradient(ellipse at 50% 38%, #ffffff 0%, #f3f4f9 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Nunito', 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ── Screen gate ── */

#screen-gate {
    display: none;
    position: fixed;
    inset: 0;
    background: #f3f4f9;
    z-index: 1000;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

#screen-gate p {
    font-size: clamp(1rem, 3vw, 1.3rem);
    color: var(--text);
    line-height: 1.5;
}

@media (max-width: 359px), (max-height: 499px) {
    #screen-gate { display: flex; }
    #game-container { display: none !important; }
}

/* ── Confetti canvas ── */

#confetti-canvas {
    position: fixed;
    inset: 0;
    z-index: 100;
    pointer-events: none;
}

/* ── Home button (upper right) ── */

#home-btn {
    position: fixed;
    top: clamp(14px, 2.4vh, 26px);
    right: clamp(14px, 2.4vw, 26px);
    width: clamp(44px, 5.5vw, 56px);
    height: clamp(44px, 5.5vw, 56px);
    border-radius: 50%;
    background: linear-gradient(145deg, #ffffff 0%, #fff5f7 100%);
    border: 1.5px solid rgba(244, 114, 182, 0.35);
    color: #9d3b5a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    text-decoration: none;
    box-shadow:
        0 4px 16px rgba(244, 114, 182, 0.22),
        0 1px 3px rgba(45, 50, 80, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    transition: transform 0.28s var(--spring),
                background 0.2s ease,
                color 0.2s ease,
                box-shadow 0.25s ease,
                border-color 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

#home-btn svg {
    width: 54%;
    height: 54%;
    transition: transform 0.28s var(--spring);
}

#home-btn:hover {
    transform: translateY(-2px) scale(1.06);
    background: linear-gradient(145deg, #fff5f7 0%, #ffe4ec 100%);
    color: #db2777;
    border-color: rgba(219, 39, 119, 0.55);
    box-shadow:
        0 8px 24px rgba(244, 114, 182, 0.35),
        0 2px 6px rgba(45, 50, 80, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

#home-btn:hover svg {
    transform: scale(1.06);
}

#home-btn:active {
    transform: scale(0.94);
}

/* ── Game container ── */

#game-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 900px;
    padding: clamp(1.5rem, 4vh, 3rem) clamp(0.5rem, 2vw, 1.5rem);
}

/* ── Question ── */

#question {
    font-size: clamp(1.5rem, 4vw, 2.4rem);
    color: var(--text);
    font-weight: 800;
    letter-spacing: -0.02em;
    opacity: 0;
    animation: fadeIn 0.7s ease-out 0.05s forwards;
    text-align: center;
    transition: opacity 0.28s ease, transform 0.45s var(--spring-soft),
                background 0.45s ease, padding 0.45s ease,
                box-shadow 0.45s ease, border-color 0.45s ease, color 0.45s ease;
}

#question.fade-swap {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
}

#question.answer {
    color: var(--text);
    background: linear-gradient(160deg, #ffffff 0%, #fff5f7 60%, #ffeaf0 100%);
    border: 1.5px solid rgba(244, 114, 182, 0.3);
    padding: clamp(0.8rem, 1.8vw, 1.2rem) clamp(1.5rem, 3vw, 2.4rem);
    border-radius: 999px;
    box-shadow:
        0 10px 32px rgba(244, 114, 182, 0.2),
        0 3px 10px rgba(45, 50, 80, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    display: inline-block;
    align-self: center;
    animation: answerBubble 0.55s var(--spring-soft);
}

#question.answer .highlight-unique {
    color: #db2777;
    font-weight: 900;
}

@keyframes answerBubble {
    0%   { transform: scale(0.9) translateY(-4px); }
    60%  { transform: scale(1.04) translateY(0); }
    100% { transform: scale(1) translateY(0); }
}

/* ── Shapes row ── */

#shapes-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: clamp(0.4rem, 2vw, 2.5rem);
    margin: clamp(2.5rem, 7vh, 5rem) 0 clamp(3.5rem, 7vh, 5.5rem);
    overflow: visible;
}

/* ── Shape wrappers ── */

.shape-wrapper {
    position: relative;
    width: clamp(56px, 14vw, 130px);
    height: clamp(56px, 14vw, 130px);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    animation: entrance 0.55s var(--spring) forwards;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.28s var(--spring);
    overflow: visible;
}

.shape-wrapper.small {
    width: clamp(36px, 9vw, 84px);
    height: clamp(36px, 9vw, 84px);
}

.shape-wrapper:hover {
    transform: translateY(-6px) scale(1.08);
}

.shape-wrapper:active {
    transform: scale(0.92);
    transition-duration: 0.06s;
}

.shape-wrapper.done {
    cursor: default;
    pointer-events: none;
}

.shape-wrapper.done:hover {
    transform: none;
}

/* ── Shape SVG ── */

.shape-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
    transition: filter 0.28s ease;
    animation: breathe 3.2s ease-in-out infinite;
}

.shape-wrapper:hover .shape-svg {
    filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.2));
}

.shape-wrapper:nth-child(1) .shape-svg { animation-delay: 0s; }
.shape-wrapper:nth-child(2) .shape-svg { animation-delay: 0.65s; }
.shape-wrapper:nth-child(3) .shape-svg { animation-delay: 1.3s; }
.shape-wrapper:nth-child(4) .shape-svg { animation-delay: 1.95s; }
.shape-wrapper:nth-child(5) .shape-svg { animation-delay: 2.6s; }

/* ── Coward state — leave the shape exactly as it is; arrow does the pointing ── */

.shape-wrapper.coward-shame {
    pointer-events: none;
}

/* ── Arrow that points up at the coward (static) ── */

.coward-arrow {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    width: clamp(18px, 2.2vw, 30px);
    height: clamp(28px, 3.6vw, 48px);
    pointer-events: none;
    z-index: 6;
    opacity: 0;
    transform: translateX(-50%) translateY(-4px);
    transition: opacity 0.35s ease, transform 0.45s var(--spring-soft);
}

.coward-arrow.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.coward-arrow svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 3px 6px rgba(229, 57, 53, 0.25));
}

/* ── Hero glow ── */

.shape-wrapper.hero .shape-svg {
    filter: drop-shadow(0 0 14px rgba(74, 143, 231, 0.45))
            drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
    animation: heroGlow 1.8s ease-in-out infinite;
}

/* ── Speech bubble ── */

.speech-bubble {
    position: absolute;
    top: calc(100% + 14px);
    left: 50%;
    transform: translateX(-50%) scale(0.85) translateY(-6px);
    background: var(--card-bg);
    border-radius: 16px;
    padding: clamp(10px, 1.5vw, 16px) clamp(14px, 2vw, 22px);
    box-shadow: 0 6px 28px rgba(0, 0, 0, 0.13);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s var(--spring-soft);
    width: max-content;
    max-width: clamp(180px, 35vw, 260px);
    text-align: center;
    z-index: 10;
    pointer-events: none;
}

.speech-bubble.visible {
    opacity: 1;
    transform: translateX(-50%) scale(1) translateY(0);
}

.speech-bubble p {
    font-size: clamp(0.72rem, 1.3vw, 0.9rem);
    color: var(--text);
    line-height: 1.45;
    font-weight: 600;
}

.bubble-tail {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-bottom: 9px solid var(--card-bg);
}

/* ── Quality labels (above shapes on correct answer) ── */

.quality-labels {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.4s var(--spring-soft);
    pointer-events: none;
    z-index: 10;
}

.quality-labels.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(-4px);
}

.quality-label {
    background: linear-gradient(145deg, #fff5f7, #ffe4ec);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: clamp(0.62rem, 1.05vw, 0.8rem);
    color: #9d3b5a;
    white-space: nowrap;
    font-weight: 800;
    letter-spacing: 0.02em;
    border: 1.5px solid rgba(244, 114, 182, 0.35);
    box-shadow:
        0 2px 10px rgba(244, 114, 182, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    opacity: 0;
    animation: labelPop 0.35s var(--spring) forwards;
}

/* ── Result card ── */

#result-card {
    text-align: center;
    max-width: 560px;
    padding: clamp(1.4rem, 3vw, 2rem) clamp(1.5rem, 3.5vw, 2.5rem);
    background: linear-gradient(160deg, #ffffff 0%, #fff5f7 60%, #ffeaf0 100%);
    border: 1.5px solid rgba(244, 114, 182, 0.3);
    border-radius: 20px;
    box-shadow:
        0 12px 40px rgba(244, 114, 182, 0.18),
        0 4px 14px rgba(45, 50, 80, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.9);
    opacity: 0;
    transform: translateY(12px) scale(0.97);
    transition: opacity 0.55s ease, transform 0.55s var(--spring-soft);
}

#result-card:empty {
    display: none;
}

#result-card.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.result-line {
    font-size: clamp(1rem, 1.95vw, 1.22rem);
    color: var(--text);
    line-height: 1.55;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.result-line .highlight-unique {
    color: #db2777;
    font-weight: 900;
}

.result-line .highlight-coward {
    color: #9d3b5a;
    font-weight: 900;
    letter-spacing: 0.01em;
}

.moral {
    margin-top: clamp(0.85rem, 1.8vh, 1.2rem);
    padding-top: clamp(0.85rem, 1.8vh, 1.2rem);
    border-top: 1px dashed rgba(244, 114, 182, 0.35);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.5s ease, transform 0.5s var(--ease-out);
    font-weight: 700;
    color: var(--text-soft);
    font-size: clamp(0.9rem, 1.7vw, 1.08rem);
}

.moral.visible {
    opacity: 1;
    transform: translateY(0);
}

.moral:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

/* ── Keyframes ── */

@keyframes entrance {
    0%   { opacity: 0; transform: scale(0.2) translateY(20px); }
    55%  { opacity: 1; transform: scale(1.1) translateY(-5px); }
    78%  { transform: scale(0.96) translateY(1px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes breathe {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.04); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    15%, 55% { transform: translateX(-6px); }
    35%, 75% { transform: translateX(6px); }
}

@keyframes cower {
    0%, 100% { transform: scale(1) rotate(0deg); }
    30%      { transform: scale(0.96) rotate(-1.5deg); }
    70%      { transform: scale(0.96) rotate(1.5deg); }
}

@keyframes heroGlow {
    0%, 100% {
        filter: drop-shadow(0 0 10px rgba(74, 143, 231, 0.3))
                drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
    }
    50% {
        filter: drop-shadow(0 0 18px rgba(74, 143, 231, 0.55))
                drop-shadow(0 4px 8px rgba(0, 0, 0, 0.12));
    }
}

@keyframes labelPop {
    from { opacity: 0; transform: scale(0.7) translateY(6px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Orientation-aware gate messages (mobile rotation) ── */
/* ── Two-step reveal: next-step button + step transition ──────────
   Step 1 shows "4 shapes have something unique" and a bouncing
   down-arrow button. Clicking advances to the moral. */
.next-step-btn {
  margin: clamp(0.9rem, 2vh, 1.3rem) auto 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: clamp(40px, 5.5vw, 50px);
  height: clamp(40px, 5.5vw, 50px);
  border-radius: 50%;
  border: 2px solid rgba(244, 114, 182, 0.55);
  background: linear-gradient(160deg, #ffffff, #fff5f7);
  color: #db2777;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(244, 114, 182, 0.2);
  transition: transform 0.2s ease, box-shadow 0.25s ease, background 0.2s ease;
  animation: nextStepBounce 1.5s ease-in-out infinite;
}
.next-step-btn svg {
  width: 60%;
  height: 60%;
  display: block;
}
.next-step-btn:hover {
  transform: translateY(2px);
  background: linear-gradient(160deg, #fff5f7, #ffd6e3);
  box-shadow: 0 6px 18px rgba(244, 114, 182, 0.32);
}
.next-step-btn:active { transform: scale(0.94); }
.next-step-btn:disabled {
  opacity: 0.35;
  cursor: default;
  animation: none;
}
@keyframes nextStepBounce {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(4px); }
}

#result-card.step-transition {
  opacity: 0;
  transition: opacity 0.25s ease;
}

/* ── Mobile (≤640px) fine-tuning for the label/shape row ──────── */
@media (max-width: 640px) {
  /* Small circle's label appears below to avoid overlap with neighbors */
  .shape-wrapper.small .quality-labels {
    bottom: auto;
    top: calc(100% + 8px);
  }

  /* Stagger label heights: the middle "only square" sits higher so the
     long "only shape without border" label can use the lower row
     without crashing into its neighbor. */
  .quality-labels.label-tier-high { bottom: calc(100% + 36px); }
  .quality-labels.label-tier-low  { bottom: calc(100% + 6px); }

  /* Dotted line connecting label to shape — clarifies which label
     belongs to which shape now that some are raised. */
  .quality-labels::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    height: 6px;
    border-left: 2px dotted rgba(244, 114, 182, 0.55);
    opacity: 0;
    transition: opacity 0.35s ease;
  }
  .quality-labels.visible::after { opacity: 1; }
  .quality-labels.label-tier-high::after { height: 32px; }
  /* For labels below the shape (small circle), the dotted line goes UP */
  .shape-wrapper.small .quality-labels::after {
    top: auto;
    bottom: 100%;
  }

  /* Speech bubbles: constrain width so they don't overflow the viewport
     on edge shapes, and anchor edge shapes' bubbles inside the viewport. */
  .speech-bubble {
    max-width: min(72vw, 260px);
    width: max-content;
  }
  .shape-wrapper:first-child .speech-bubble {
    left: 0;
    transform: translateX(0) scale(0.85) translateY(-6px);
  }
  .shape-wrapper:first-child .speech-bubble.visible {
    transform: translateX(0) scale(1) translateY(0);
  }
  .shape-wrapper:first-child .bubble-tail {
    left: clamp(20px, 8vw, 40px);
    transform: none;
  }
  .shape-wrapper:last-child .speech-bubble {
    left: auto;
    right: 0;
    transform: translateX(0) scale(0.85) translateY(-6px);
  }
  .shape-wrapper:last-child .speech-bubble.visible {
    transform: translateX(0) scale(1) translateY(0);
  }
  .shape-wrapper:last-child .bubble-tail {
    left: auto;
    right: clamp(20px, 8vw, 40px);
    transform: none;
  }

  /* Small circle (4th of 5) sits near the right edge — anchor its bubble's
     right side to the wrapper so it can't overflow off-screen. */
  .shape-wrapper.small .speech-bubble {
    left: auto;
    right: 0;
    transform: translateX(0) scale(0.85) translateY(-6px);
  }
  .shape-wrapper.small .speech-bubble.visible {
    transform: translateX(0) scale(1) translateY(0);
  }
  .shape-wrapper.small .bubble-tail {
    left: auto;
    right: clamp(18px, 4.5vw, 42px);
    transform: none;
  }
}

.gate-rotate,
.gate-small {
  display: none;
}
@media (max-width: 479px) {
  .gate-small { display: block; }
}
@media (max-height: 499px) and (min-width: 480px) {
  .gate-rotate { display: block; }
}
