/**
 * last-letter/last-letter.css
 * Interlocking chain identity styles for Last Letter.
 */

:root {
    --game-accent: #84cc16;
    --game-accent-dim: #65a30d;
    --game-accent-contrast: #0f172a;
    --ll-bg: #0f172a;
    --ll-card-bg: #1e293b;
    --ll-link-bg: #334155;
    --ll-link-border: #84cc16;
    --ll-link-text: #f8fafc;
}

body.game-standalone.cosy-game-theme {
    background-color: var(--ll-bg);
    color: #f8fafc;
}

.ll-game-wrapper {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--ll-card-bg);
    border-radius: 16px;
    border: 2px solid rgba(132, 204, 22, 0.3);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    max-width: 900px;
    margin: 0 auto;
}

.ll-score-bar {
    display: flex;
    justify-content: space-around;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(132, 204, 22, 0.25);
    padding: 1rem;
    border-radius: 12px;
}

.ll-sb-item {
    text-align: center;
}

.ll-sb-val {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--game-accent);
}

.ll-sb-lbl {
    font-size: 0.85rem;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Chain Display Area */
.ll-chain-container {
    position: relative;
    min-height: 140px;
    max-height: 380px;
    background: #090d16;
    border: 2px dashed rgba(132, 204, 22, 0.3);
    border-radius: 14px;
    padding: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    align-content: flex-start;
    gap: 0;
    overflow-x: auto;
    overflow-y: auto;
}

.ll-chain-empty {
    color: #64748b;
    font-style: italic;
    width: 100%;
    text-align: center;
    margin: auto 0;
}

/* Chain Link Element (Interlocking Notch Shape) */
.ll-chain-link.ll-unverified {
    border-style: dashed;
    opacity: .85;
}

.ll-chain-link {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.4rem;
    margin-right: -12px;
    background: var(--ll-link-bg);
    border: 2px solid var(--game-accent);
    color: var(--ll-link-text);
    font-weight: 700;
    font-size: 1.15rem;
    letter-spacing: 0.03em;
    border-radius: 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    z-index: 1;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Interlocking Notches/Connectors */
.ll-chain-link::before,
.ll-chain-link::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--ll-card-bg);
    border: 2px solid var(--game-accent);
}

.ll-chain-link::before {
    left: -8px;
    border-right: none;
    border-bottom: none;
}

.ll-chain-link::after {
    right: -8px;
    border-left: none;
    border-top: none;
}

/* Highlighted last letter in word */
.ll-chain-link .ll-last-letter {
    color: var(--game-accent);
    font-weight: 900;
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* Motion: Chain Snap & Clink Bounce */
@keyframes motionSlideChain {
    0% {
        opacity: 0;
        transform: translateX(40px) scale(0.7);
    }
    60% {
        opacity: 1;
        transform: translateX(-6px) scale(1.15);
    }
    80% {
        transform: translateX(3px) scale(0.95);
    }
    100% {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.motion-slide-chain {
    animation: motionSlideChain 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.ll-clink-bounce {
    animation: motionSlideChain 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Motion: Invalid Link Attempt Bounce & Fall Away */
@keyframes linkInvalidBounce {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1) rotate(0deg);
    }
    20% {
        transform: translateY(-20px) scale(1.05) rotate(-5deg);
    }
    40% {
        transform: translateY(0) scale(0.95) rotate(5deg);
    }
    100% {
        opacity: 0;
        transform: translateY(100px) scale(0.6) rotate(25deg);
    }
}

.link-invalid-bounce {
    animation: linkInvalidBounce 0.75s ease-in forwards;
    border-color: #ef4444 !important;
    background: #450a0a !important;
    color: #fca5a5 !important;
}

/* Form Controls */
.ll-input-group {
    display: flex;
    gap: 0.75rem;
}

.ll-input {
    flex: 1;
    padding: 0.85rem 1.2rem;
    border-radius: 10px;
    border: 2px solid rgba(132, 204, 22, 0.4);
    background: #0f172a;
    color: #f8fafc;
    font-size: 1.1rem;
    outline: none;
    transition: border-color 0.2s;
}

.ll-input:focus {
    border-color: var(--game-accent);
    box-shadow: 0 0 0 3px rgba(132, 204, 22, 0.25);
}

/* Feedback message */
.ll-feedback {
    min-height: 2rem;
    font-weight: 600;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.95rem;
    display: none;
}

.ll-feedback.show {
    display: block;
}

.ll-feedback.ok {
    background: rgba(132, 204, 22, 0.15);
    border: 1px solid var(--game-accent);
    color: #bef264;
}

.ll-feedback.bad {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid #ef4444;
    color: #fca5a5;
}

/* Responsive Overrides */

/* Phone Context (data-context="phone"): Vertical chain layout with auto-scroll */
[data-context="phone"] .ll-chain-container {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    gap: 0.85rem;
    max-height: 320px;
    overflow-y: auto;
}

[data-context="phone"] .ll-chain-link {
    margin-right: 0;
    margin-bottom: -6px;
    width: 100%;
}

[data-context="phone"] .ll-chain-link::before {
    left: 50%;
    top: -8px;
    transform: translateX(-50%);
    border-right: none;
    border-bottom: none;
}

[data-context="phone"] .ll-chain-link::after {
    left: 50%;
    top: auto;
    bottom: -8px;
    transform: translateX(-50%);
    border-left: none;
    border-top: none;
}

/* Online Context (data-context="online"): 2-second accent-colored glow/outline for latest addition */
[data-context="online"] .ll-chain-link.ll-latest-link {
    animation: motionSlideChain 0.45s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards,
               onlineLinkGlow 2s ease-out forwards;
}

@keyframes onlineLinkGlow {
    0% {
        box-shadow: 0 0 0 6px var(--game-accent), 0 0 25px var(--game-accent);
        border-color: #fef08a;
    }
    70% {
        box-shadow: 0 0 0 4px var(--game-accent), 0 0 15px var(--game-accent);
    }
    100% {
        box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
        border-color: var(--game-accent);
    }
}
