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

:root {
    --bg: #000;
    --text: #fff;
    --accent: #ff2d55;
    --accent-hover: #ff4f73;
    --secondary: #2c2c2e;
    --secondary-hover: #3a3a3c;
    --danger: #48484a;
    --danger-hover: #636366;
    --success: #30d158;
    --radius: 14px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* Screens */
.screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.screen.active {
    opacity: 1;
    pointer-events: auto;
}

/* Landing */
.landing-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 32px;
    padding: 24px;
    text-align: center;
    max-height: 100%;
    overflow-y: auto;
}

.title {
    font-size: clamp(2.5rem, 10vw, 4.5rem);
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 1.125rem;
    color: #8e8e93;
    margin-top: -16px;
}

.how-it-works {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}

.step {
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
}

.step-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--secondary);
    color: #fff;
    font-weight: 700;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.step p {
    font-size: 0.9rem;
    color: #ccc;
    line-height: 1.35;
    margin: 0;
}

.divider {
    width: 60px;
    height: 1px;
    background: #333;
}

.hint {
    font-size: 0.875rem;
    color: #8e8e93;
    margin-top: -16px;
}

/* Buttons */
.btn {
    font-family: inherit;
    font-size: 1.125rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    padding: 16px 48px;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    width: 100%;
    max-width: 320px;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--secondary);
    color: #fff;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Loading spinner */
.btn.loading {
    position: relative;
    color: transparent;
}

.btn.loading::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -10px;
    margin-top: -10px;
    width: 20px;
    height: 20px;
    border: 2px solid transparent;
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Recording */
#recording {
    justify-content: center;
}

#canvas {
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 9 / 16;
    object-fit: contain;
}

#progressBar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: rgba(255, 255, 255, 0.15);
    z-index: 10;
}

#progressFill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    transition: width linear;
}

#progressFill.animating {
    width: 100%;
}

/* Laugh detection overlay */
.caught-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 45, 85, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 15;
}

.caught-overlay.visible {
    opacity: 1;
}

.caught-text {
    font-size: clamp(3rem, 15vw, 6rem);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: caught-pulse 0.3s ease;
}

@keyframes caught-pulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* Victory overlay */
.victory-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 200, 83, 0.25);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 15;
}

.victory-overlay.visible {
    opacity: 1;
}

.victory-text {
    font-size: clamp(2.5rem, 12vw, 5rem);
    font-weight: 900;
    color: #fff;
    text-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: victory-bounce 0.5s ease;
    z-index: 2;
}

@keyframes victory-bounce {
    0% { transform: scale(0.3); opacity: 0; }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); opacity: 1; }
}

/* Confetti */
.confetti-container {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 1;
}

.confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    top: -10px;
    animation: confetti-fall 2.5s ease-in forwards;
}

.confetti:nth-child(1)  { left: 8%;  background: #ff2d55; animation-delay: 0s;    border-radius: 50%; }
.confetti:nth-child(2)  { left: 18%; background: #30d158; animation-delay: 0.1s;  border-radius: 2px; }
.confetti:nth-child(3)  { left: 28%; background: #5ac8fa; animation-delay: 0.2s;  border-radius: 50%; }
.confetti:nth-child(4)  { left: 38%; background: #ffd60a; animation-delay: 0.05s; border-radius: 2px; }
.confetti:nth-child(5)  { left: 48%; background: #bf5af2; animation-delay: 0.15s; border-radius: 50%; }
.confetti:nth-child(6)  { left: 58%; background: #ff9f0a; animation-delay: 0.25s; border-radius: 2px; }
.confetti:nth-child(7)  { left: 68%; background: #ff2d55; animation-delay: 0.1s;  border-radius: 50%; }
.confetti:nth-child(8)  { left: 78%; background: #30d158; animation-delay: 0.2s;  border-radius: 2px; }
.confetti:nth-child(9)  { left: 88%; background: #5ac8fa; animation-delay: 0.05s; border-radius: 50%; }
.confetti:nth-child(10) { left: 15%; background: #ffd60a; animation-delay: 0.3s;  border-radius: 2px; }
.confetti:nth-child(11) { left: 55%; background: #bf5af2; animation-delay: 0.12s; border-radius: 50%; }
.confetti:nth-child(12) { left: 75%; background: #ff9f0a; animation-delay: 0.18s; border-radius: 2px; }

@keyframes confetti-fall {
    0% { transform: translateY(0) rotate(0deg); opacity: 1; }
    100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* Result */
#result {
    justify-content: center;
    background: var(--bg);
    transition: opacity 0.5s ease;
}

.result-container {
    position: relative;
    width: 100%;
    height: 100%;
    max-width: calc(100vh * 9 / 16);
    display: flex;
    justify-content: center;
    align-items: center;
}

#resultVideo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}

.result-outcome {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.25rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 8px 20px;
    border-radius: 20px;
    z-index: 10;
    white-space: nowrap;
}

.result-outcome.survived {
    background: rgba(48, 209, 88, 0.25);
    color: var(--success);
}

.result-outcome.caught {
    background: rgba(255, 45, 85, 0.25);
    color: var(--accent);
}

.result-share-bottom {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

.result-share-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 36px;
    font-size: 1rem;
    border-radius: 28px;
    width: auto;
    box-shadow: 0 4px 15px rgba(255, 45, 85, 0.4);
}

/* TikTok-style sidebar buttons */
.result-sidebar {
    position: absolute;
    right: 10px;
    bottom: 25%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    z-index: 10;
}

.icon-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 0;
}

.icon-btn:active .icon-circle {
    transform: scale(0.9);
}

.icon-circle {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(40, 40, 40, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: transform 0.1s ease;
}

.icon-circle svg {
    width: 22px;
    height: 22px;
}

.icon-label {
    font-size: 11px;
    color: #fff;
    font-weight: 500;
}

.icon-btn.delete .icon-circle {
    color: var(--accent);
}

/* Error */
#error {
    background: var(--bg);
    z-index: 100;
}

#errorMsg {
    color: #8e8e93;
    font-size: 1rem;
    line-height: 1.5;
    max-width: 300px;
}

/* Create Challenge */
.create-content,
.preview-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
    max-height: 100%;
    overflow-y: auto;
}

.back-btn {
    align-self: flex-start;
    background: none;
    border: none;
    color: var(--accent);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    padding: 8px 0;
    -webkit-tap-highlight-color: transparent;
}

.create-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
}

.create-subtitle {
    color: #8e8e93;
    font-size: 0.9rem;
    text-align: center;
    margin-top: -10px;
}

/* Step progress indicator */
.step-indicator {
    display: flex;
    align-items: center;
    gap: 0;
    justify-content: center;
    margin-bottom: 4px;
}

.step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #3a3a3c;
    transition: background 0.3s ease, transform 0.3s ease;
}

.step-dot.active {
    background: var(--accent);
    transform: scale(1.2);
}

.step-dot.done {
    background: var(--success);
}

.step-line {
    width: 40px;
    height: 2px;
    background: #3a3a3c;
    transition: background 0.3s ease;
}

.step-line.done {
    background: var(--success);
}

/* Change photo link */
.change-photo-btn {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.8rem;
    font-family: inherit;
    cursor: pointer;
    padding: 4px 0;
    -webkit-tap-highlight-color: transparent;
}

.change-photo-btn[hidden] {
    display: none;
}

.preview-subtitle {
    color: #8e8e93;
    font-size: 0.9rem;
    text-align: center;
    margin-top: -10px;
}

/* Try it yourself link */
.try-it-link {
    background: none;
    border: none;
    color: #8e8e93;
    font-family: inherit;
    font-size: 0.875rem;
    cursor: pointer;
    padding: 8px 0;
    -webkit-tap-highlight-color: transparent;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.try-it-link:hover {
    color: #fff;
}

/* Back to preview from result screen */
.back-to-preview-btn {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 20;
    background: rgba(40, 40, 40, 0.8);
    border: none;
    color: #fff;
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.back-to-preview-btn[hidden] {
    display: none;
}

.share-link-label {
    font-size: 0.8rem;
    color: #8e8e93;
    margin-bottom: 6px;
}

.share-link-row {
    display: flex;
    gap: 8px;
    width: 100%;
}

.share-link-row input {
    flex: 1;
    background: var(--secondary);
    border: none;
    border-radius: var(--radius);
    padding: 10px 14px;
    color: #fff;
    font-size: 0.8rem;
    font-family: inherit;
}

.copy-btn {
    padding: 10px 18px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* Mode toggle */
.create-mode-toggle {
    display: flex;
    gap: 0;
    background: var(--secondary);
    border-radius: var(--radius);
    padding: 3px;
    width: 100%;
    max-width: 280px;
}

.mode-btn {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 11px;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    color: #8e8e93;
    background: transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.mode-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Upload area */
.upload-area {
    width: 100%;
    aspect-ratio: 1;
    max-width: 280px;
    border: 2px dashed #3a3a3c;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    overflow: hidden;
    transition: border-color 0.2s ease;
    position: relative;
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--accent);
}

.upload-area.has-image {
    border-style: solid;
    border-color: var(--secondary);
}

.upload-area.small {
    width: 130px;
    max-width: 130px;
}

.upload-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #8e8e93;
}

.upload-hint {
    font-size: 0.7rem;
    color: #636366;
    text-align: center;
    max-width: 180px;
    line-height: 1.3;
}

.upload-placeholder svg {
    width: 48px;
    height: 48px;
    stroke: #636366;
}

.upload-area.small .upload-placeholder svg {
    width: 32px;
    height: 32px;
}

.upload-preview {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.upload-area.has-image .upload-placeholder {
    display: none;
}

.upload-area.has-image .upload-preview {
    display: block;
}

/* Manual upload */
.manual-upload-section {
    width: 100%;
}

.manual-upload-row {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.manual-upload-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.manual-upload-label {
    font-size: 0.75rem;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Prompt selection */
.analyze-status {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #8e8e93;
    font-size: 0.875rem;
    padding: 12px 0;
}

.analyze-status[hidden] {
    display: none;
}

.analyze-spinner {
    width: 18px;
    height: 18px;
    border: 2px solid #3a3a3c;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.surprise-chip {
    width: 100%;
    text-align: center;
    border-style: dashed;
}

.surprise-chip.active {
    border-style: solid;
}

.prompt-section {
    width: 100%;
    max-width: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}

.prompt-section[hidden] {
    display: none;
}

.prompt-section-label {
    font-size: 0.75rem;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    align-self: flex-start;
}

.prompt-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.prompt-chip {
    padding: 8px 14px;
    border: 1px solid #3a3a3c;
    border-radius: 20px;
    background: transparent;
    color: #8e8e93;
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.prompt-chip.active {
    border-color: var(--accent);
    color: #fff;
    background: rgba(255, 45, 85, 0.15);
}

.custom-prompt-toggle {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 4px 0;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.custom-prompt-row {
    width: 100%;
}

.custom-prompt-input {
    width: 100%;
    background: var(--secondary);
    border: none;
    border-radius: var(--radius);
    padding: 12px 16px;
    color: #fff;
    font-size: 0.875rem;
    font-family: inherit;
}

.custom-prompt-input::placeholder {
    color: #636366;
}

.transform-status {
    font-size: 0.875rem;
    color: #8e8e93;
    text-align: center;
    min-height: 20px;
}

.transform-status.error {
    color: var(--accent);
}

/* Challenge Preview */
.preview-images {
    display: flex;
    gap: 16px;
    width: 100%;
    justify-content: center;
}

.preview-image-container {
    flex: 1;
    max-width: 160px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preview-label {
    font-size: 0.75rem;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: center;
}

.preview-image {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: var(--radius);
    background: var(--secondary);
}

.share-link {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 320px;
}

.share-link[hidden] {
    display: none;
}

.share-link input {
    flex: 1;
    background: var(--secondary);
    border: none;
    border-radius: var(--radius);
    padding: 12px 16px;
    color: #fff;
    font-size: 0.875rem;
    font-family: inherit;
}

.share-link .btn {
    width: auto;
    padding: 12px 20px;
    font-size: 0.875rem;
}

/* Featured challenges */
.featured-section {
    width: 100%;
    max-width: 400px;
}

.featured-title {
    font-size: 0.875rem;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
    padding-left: 4px;
}

.featured-row {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px 0;
}

.featured-row::-webkit-scrollbar {
    display: none;
}

.featured-card {
    flex: 0 0 100px;
    aspect-ratio: 1;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    border: 2px solid var(--secondary);
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.featured-card:active {
    transform: scale(0.95);
}

.featured-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
