/* ============================================
   ACCIDENTALLY SAID... | SF TECH CONFESSIONS
   ============================================ */

/* CSS Variables */
:root {
    --bg-color: #f8f5eb;
    --land-color: #f8f5eb;
    --line-color: #1a1a1a;
    --street-color: #3a3a3a;
    --major-road: #1a1a1a;
    --water-color: #d4e5f7;
    --water-line: #8ba5bd;
    --park-color: #6b8f6b;
    --label-color: #1a1a1a;
    --bubble-bg: #fffef5;
    --bubble-border: #1a1a1a;
    --text-color: #1a1a1a;
    --accent-color: #c92a2a;
    --accent-secondary: #2a6bc9;
}

/* Dark mode - moody night vibe */
@media (prefers-color-scheme: dark) {
    :root {
        --bg-color: #0d0d0d;
        --land-color: #0d0d0d;
        --line-color: #c8c8c8;
        --street-color: #4a4a4a;
        --major-road: #888;
        --water-color: #0a1520;
        --water-line: #2a4a6a;
        --park-color: #1a2a1a;
        --label-color: #888;
        --bubble-bg: #1a1a1a;
        --bubble-border: #c8c8c8;
        --text-color: #e8e8e8;
        --accent-color: #ff6b6b;
    }
}

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

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

body {
    background-color: var(--bg-color);
    font-family: 'Space Mono', monospace;
    color: var(--text-color);
    cursor: crosshair;
    user-select: none;
    -webkit-user-select: none;
}

/* ============================================
   MAIN CONTAINER
   ============================================ */
#container {
    position: relative;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ============================================
   GRAIN / DITHER OVERLAY
   ============================================ */
#grain-overlay {
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.15;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    animation: grainShift 0.5s steps(1) infinite;
}

@keyframes grainShift {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(-2%, -2%); }
    50% { transform: translate(2%, 1%); }
    75% { transform: translate(-1%, 2%); }
}

/* Scanlines for extra retro feel */
#scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    background: repeating-linear-gradient(
        0deg,
        transparent,
        transparent 2px,
        rgba(0, 0, 0, 0.03) 2px,
        rgba(0, 0, 0, 0.03) 4px
    );
}

/* ============================================
   MAP
   ============================================ */
#map-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    opacity: 0.85;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#sf-map {
    width: auto;
    height: 100%;
    max-width: none;
    border: none;
    object-fit: contain;
    transform: scale(1.3);
    /* GPU acceleration for smoother rendering */
    will-change: transform;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* Invert for dark mode effect if desired */
    /* filter: invert(1); */
}


/* Dark mode map inversion */
@media (prefers-color-scheme: dark) {
    #sf-map {
        filter: invert(0.88) hue-rotate(180deg);
        opacity: 0.7;
    }
}

/* ============================================
   SPEECH BUBBLES - THE STAR OF THE SHOW
   ============================================ */
#bubble-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
}

.speech-bubble {
    position: absolute;
    max-width: 340px;
    min-width: 220px;
    padding: 24px 28px;
    background: var(--bubble-bg);
    border: 3px solid var(--bubble-border);
    font-family: 'Caveat', cursive;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.4;
    pointer-events: auto;
    cursor: pointer;
    transform-origin: bottom left;
    animation: bubbleAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    transition: transform 0.15s ease, box-shadow 0.15s ease;

    /* GPU acceleration for smoother animations */
    will-change: transform, opacity;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    -webkit-transform: translateZ(0);

    /* Hand-drawn wobble effect */
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    box-shadow:
        4px 4px 0 var(--bubble-border),
        2px 2px 20px rgba(0,0,0,0.1);
}

/* Different wobble shapes */
.speech-bubble.shape-1 { border-radius: 255px 15px 225px 15px/15px 225px 15px 255px; }
.speech-bubble.shape-2 { border-radius: 15px 225px 15px 255px/255px 15px 225px 15px; }
.speech-bubble.shape-3 { border-radius: 225px 15px 255px 15px/15px 255px 15px 225px; }
.speech-bubble.shape-4 { border-radius: 15px 255px 15px 225px/225px 15px 255px 15px; }

.speech-bubble:hover {
    transform: scale(1.03) rotate(-1deg);
    box-shadow:
        6px 6px 0 var(--bubble-border),
        4px 4px 30px rgba(0,0,0,0.15);
}

.speech-bubble:active {
    transform: scale(0.98);
}

/* Bubble tail - hand drawn style */
.speech-bubble::before {
    content: '';
    position: absolute;
    bottom: -25px;
    left: 35px;
    width: 30px;
    height: 30px;
    background: var(--bubble-bg);
    border-right: 3px solid var(--bubble-border);
    border-bottom: 3px solid var(--bubble-border);
    transform: rotate(45deg) skewX(-10deg);
    box-shadow: 4px 4px 0 var(--bubble-border);
}

/* Quote styling */
.quote-text {
    margin-bottom: 16px;
    position: relative;
}

.quote-text::before {
    content: '"';
    position: absolute;
    top: -15px;
    left: -15px;
    font-size: 60px;
    opacity: 0.1;
    font-family: Georgia, serif;
    line-height: 1;
}

.quote-text .highlight {
    color: var(--accent-color);
    text-decoration: underline;
    text-decoration-style: wavy;
    text-underline-offset: 3px;
}

.quote-source {
    font-family: 'Space Mono', monospace;
    font-size: 11px;
    font-weight: 400;
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.author-link {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    opacity: 1;
    transition: opacity 0.2s ease;
}

.author-link:hover {
    opacity: 0.7;
    text-decoration: underline;
}

.quote-location {
    white-space: nowrap;
}

/* Typing cursor */
.typing-cursor {
    display: inline-block;
    width: 3px;
    height: 1.2em;
    background: var(--accent-color);
    margin-left: 3px;
    animation: cursorBlink 0.6s ease infinite;
    vertical-align: text-bottom;
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes bubbleAppear {
    0% {
        opacity: 0;
        transform: scale(0) rotate(-20deg) translateY(30px);
    }
    60% {
        transform: scale(1.1) rotate(2deg) translateY(-5px);
    }
    80% {
        transform: scale(0.95) rotate(-1deg);
    }
    100% {
        opacity: 1;
        transform: scale(1) rotate(0deg) translateY(0);
    }
}

@keyframes bubbleFloat {
    0%, 100% {
        transform: translateY(0) rotate(0deg);
    }
    33% {
        transform: translateY(-4px) rotate(0.5deg);
    }
    66% {
        transform: translateY(2px) rotate(-0.5deg);
    }
}

@keyframes bubbleExit {
    0% {
        opacity: 1;
        transform: scale(1) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: scale(0.5) rotate(10deg) translateY(-50px);
    }
}

@keyframes cursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px) rotate(-1deg); }
    75% { transform: translateX(3px) rotate(1deg); }
}

.speech-bubble.floating {
    animation: bubbleFloat 4s ease-in-out infinite;
}

.speech-bubble.exiting {
    animation: bubbleExit 0.4s ease-in forwards;
    pointer-events: none;
}

.speech-bubble.shake {
    animation: shake 0.3s ease;
}

/* ============================================
   RIPPLE EFFECT
   ============================================ */
.ripple {
    position: absolute;
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    opacity: 0;
    animation: rippleExpand 0.8s ease-out forwards;
    pointer-events: none;
    z-index: 50;
}

@keyframes rippleExpand {
    0% {
        width: 0;
        height: 0;
        opacity: 0.6;
    }
    100% {
        width: 150px;
        height: 150px;
        margin-left: -75px;
        margin-top: -75px;
        opacity: 0;
    }
}

/* ============================================
   WHISPER INDICATOR
   ============================================ */
#whisper-indicator {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 200;
}

#whisper-indicator.active {
    opacity: 1;
}

.sound-wave {
    width: 4px;
    height: 20px;
    background: var(--accent-color);
    border-radius: 2px;
    animation: soundWave 0.8s ease-in-out infinite;
}

.sound-wave:nth-child(1) { animation-delay: 0s; height: 12px; }
.sound-wave:nth-child(2) { animation-delay: 0.15s; height: 20px; }
.sound-wave:nth-child(3) { animation-delay: 0.3s; height: 16px; }

@keyframes soundWave {
    0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
    50% { transform: scaleY(1); opacity: 1; }
}

/* ============================================
   HEADER
   ============================================ */
#header {
    position: fixed;
    top: calc(30px + env(safe-area-inset-top, 0px));
    left: calc(30px + env(safe-area-inset-left, 0px));
    z-index: 200;
}

#title {
    font-family: 'Caveat', cursive;
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -1px;
    margin-bottom: 4px;
    opacity: 0.8;
}

#subtitle {
    font-family: 'Space Mono', monospace;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 3px;
    opacity: 0.4;
}

/* ============================================
   HINT
   ============================================ */
#hint {
    position: fixed;
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    opacity: 0.5;
    letter-spacing: 1px;
    z-index: 200;
    transition: opacity 0.5s ease;
    animation: hintPulse 2s ease-in-out infinite;
}

#hint.hidden {
    opacity: 0;
    pointer-events: none;
}

.hint-icon {
    font-size: 16px;
    animation: hintBounce 1s ease infinite;
}

@keyframes hintPulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.8; }
}

@keyframes hintBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

/* ============================================
   COUNTER
   ============================================ */
#counter {
    position: fixed;
    bottom: calc(30px + env(safe-area-inset-bottom, 0px));
    right: calc(30px + env(safe-area-inset-right, 0px));
    text-align: right;
    z-index: 200;
}

#count {
    display: block;
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
    font-family: 'Caveat', cursive;
}

.counter-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    opacity: 0.5;
}

/* Counter pop animation */
#count.pop {
    animation: countPop 0.3s ease;
}

@keyframes countPop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

/* ============================================
   ATTRIBUTION
   ============================================ */
#attribution {
    position: fixed;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    right: calc(30px + env(safe-area-inset-right, 0px));
    z-index: 200;
}

#attribution a {
    font-family: 'Space Mono', monospace;
    font-size: 8px;
    text-transform: lowercase;
    letter-spacing: 0.5px;
    color: var(--text-color);
    text-decoration: none;
    opacity: 0.4;
    transition: opacity 0.2s ease;
}

#attribution a:hover {
    opacity: 0.7;
}

/* ============================================
   MUTE BUTTON
   ============================================ */
#mute-btn {
    position: fixed;
    top: calc(30px + env(safe-area-inset-top, 0px));
    right: calc(30px + env(safe-area-inset-right, 0px));
    width: 44px;
    height: 44px;
    border: 2px solid var(--line-color);
    border-radius: 50%;
    background: var(--bubble-bg);
    cursor: pointer;
    z-index: 200;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    opacity: 1;
    box-shadow: 2px 2px 0 var(--line-color);
}

#mute-btn:hover {
    transform: scale(1.1);
    box-shadow: 3px 3px 0 var(--line-color);
}

#mute-btn .muted { display: none; }
#mute-btn.is-muted .unmuted { display: none; }
#mute-btn.is-muted .muted { display: inline; }

/* ============================================
   PAUSE BUTTON
   ============================================ */
#pause-btn {
    position: fixed;
    top: calc(30px + env(safe-area-inset-top, 0px));
    right: calc(84px + env(safe-area-inset-right, 0px));
    width: 44px;
    height: 44px;
    border: 2px solid var(--line-color);
    border-radius: 50%;
    background: var(--bubble-bg);
    cursor: pointer;
    z-index: 200;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
    opacity: 1;
    box-shadow: 2px 2px 0 var(--line-color);
}

#pause-btn:hover {
    transform: scale(1.1);
    box-shadow: 3px 3px 0 var(--line-color);
}

#pause-btn.is-paused {
    background: var(--accent-color);
    color: white;
    animation: pausePulse 2s ease-in-out infinite;
}

@keyframes pausePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 2px 2px 0 var(--line-color);
    }
    50% {
        transform: scale(1.08);
        box-shadow: 3px 3px 0 var(--line-color), 0 0 20px var(--accent-color);
    }
}

#pause-btn .paused { display: none; }
#pause-btn.is-paused .playing { display: none; }
#pause-btn.is-paused .paused { display: inline; }

/* ============================================
   PAUSED OVERLAY
   ============================================ */
#paused-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 150;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

#paused-overlay span {
    font-family: 'Space Mono', monospace;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 4px;
    color: var(--text-color);
    background: var(--bubble-bg);
    padding: 12px 24px;
    border: 2px solid var(--line-color);
    border-radius: 4px;
    opacity: 0.9;
}

#container.is-paused #paused-overlay {
    opacity: 1;
}

/* ============================================
   START OVERLAY
   ============================================ */
#start-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    cursor: pointer;
    transition: opacity 0.5s ease;
}

#start-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#start-overlay span {
    font-family: 'Caveat', cursive;
    font-size: 28px;
    color: var(--text-color);
    background: var(--bubble-bg);
    padding: 16px 32px;
    border: 3px solid var(--line-color);
    border-radius: 255px 15px 225px 15px/15px 225px 15px 255px;
    box-shadow: 4px 4px 0 var(--line-color);
    animation: startPulse 2s ease-in-out infinite;
}

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

@media (max-width: 600px) {
    #start-overlay span {
        font-size: 22px;
        padding: 14px 24px;
    }
}

/* ============================================
   LOCATION MARKER
   ============================================ */
#location-marker {
    position: absolute;
    width: 12px;
    height: 12px;
    background: var(--accent-color);
    border: 2px solid var(--bubble-bg);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    z-index: 90;
    pointer-events: none;
    box-shadow: 0 0 0 0 var(--accent-color);
    transition: opacity 0.3s ease;
}

#location-marker.active {
    opacity: 1;
    animation: markerPulse 2s ease-out infinite;
}

@keyframes markerPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(201, 42, 42, 0.6);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(201, 42, 42, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(201, 42, 42, 0);
    }
}

@media (prefers-color-scheme: dark) {
    @keyframes markerPulse {
        0% {
            box-shadow: 0 0 0 0 rgba(255, 107, 107, 0.6);
        }
        70% {
            box-shadow: 0 0 0 15px rgba(255, 107, 107, 0);
        }
        100% {
            box-shadow: 0 0 0 0 rgba(255, 107, 107, 0);
        }
    }
}

/* ============================================
   MOBILE STYLES
   ============================================ */
@media (max-width: 600px) {
    .speech-bubble {
        max-width: 220px;
        min-width: 150px;
        padding: 14px 18px;
        font-size: 16px;
    }

    .speech-bubble::before {
        bottom: -18px;
        left: 25px;
        width: 22px;
        height: 22px;
    }

    .quote-text::before {
        font-size: 40px;
        top: -10px;
        left: -10px;
    }

    .quote-source {
        font-size: 9px;
        flex-wrap: wrap;
        letter-spacing: 1.5px;
        gap: 3px 6px;
    }

    #header {
        top: calc(20px + env(safe-area-inset-top, 0px));
        left: calc(20px + env(safe-area-inset-left, 0px));
    }

    #title {
        font-size: 24px;
    }

    #subtitle {
        font-size: 9px;
    }

    #hint {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        font-size: 11px;
    }

    #counter {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        right: calc(15px + env(safe-area-inset-right, 0px));
        padding-right: 5px;
    }

    #count {
        font-size: 28px;
        min-width: 1.5em;
    }

    .counter-label {
        font-size: 9px;
        letter-spacing: 1.5px;
    }

    #mute-btn {
        top: calc(20px + env(safe-area-inset-top, 0px));
        right: calc(20px + env(safe-area-inset-right, 0px));
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    #pause-btn {
        top: calc(20px + env(safe-area-inset-top, 0px));
        right: calc(66px + env(safe-area-inset-right, 0px));
        width: 38px;
        height: 38px;
        font-size: 16px;
    }

    /* Adjust map positioning for mobile - fill more of the screen */
    #map-container {
        width: 100%;
        height: 100%;
    }

    #sf-map {
        width: 100%;
        height: auto;
        min-height: 100%;
        object-fit: cover;
        transform: scale(1.5) translateZ(0);
        /* GPU acceleration */
        -webkit-transform: scale(1.5) translateZ(0);
    }

    /* Reduce animation complexity on mobile for better performance */
    .speech-bubble {
        /* Simpler shadow for mobile */
        box-shadow: 3px 3px 0 var(--bubble-border);
    }

    /* Disable grain animation on mobile - significant performance improvement */
    #grain-overlay {
        animation: none;
        opacity: 0.08;
    }

    /* Disable floating animation on mobile */
    .speech-bubble.floating {
        animation: none;
    }

    #attribution {
        bottom: calc(5px + env(safe-area-inset-bottom, 0px));
        right: calc(15px + env(safe-area-inset-right, 0px));
    }

    #attribution a {
        font-size: 7px;
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    #grain-overlay {
        animation: none;
    }
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
