/* Newzino Connections daily game styles.
 *
 * Layout is mostly Tailwind classes inline in the templates. This file holds:
 *   - 4x4 tile grid with consistent square ratios
 *   - Selection state (rose accent ring + lift)
 *   - Shake animation for "one away" and "wrong" feedback
 *   - Solved-group pill animation (4 tiles consolidate into a single colored bar)
 *   - Tier-color tokens used in both the live game and the share grid
 */

:root {
    --tl-tier-yellow:  rgb(234, 179, 8);
    --tl-tier-green:   rgb(34, 197, 94);
    --tl-tier-blue:    rgb(59, 130, 246);
    --tl-tier-purple:  rgb(168, 85, 247);
    --tl-tier-yellow-bg: rgba(234, 179, 8, 0.18);
    --tl-tier-green-bg:  rgba(34, 197, 94, 0.18);
    --tl-tier-blue-bg:   rgba(59, 130, 246, 0.18);
    --tl-tier-purple-bg: rgba(168, 85, 247, 0.18);
}

.cn-shell { transition: border-color 200ms ease-out; }

/* === Tile grid === */
.cn-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.cn-tile {
    position: relative;
    aspect-ratio: 1 / 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 4px 3px;
    border-radius: 8px;
    background-color: #1f2937;
    color: white;
    font-size: 0.7rem;
    line-height: 1.1;
    font-weight: 600;
    cursor: pointer;
    transition: transform 180ms ease-out, background-color 180ms ease-out,
                box-shadow 180ms ease-out, border-color 180ms ease-out;
    border: 2px solid transparent;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
    /* Wrap at word boundaries only — never break a word mid-letter, which
     * looks broken on long surnames like 'Alekseyev'. */
    word-break: normal;
    overflow-wrap: break-word;
}

/* Tighten further at sub-360px viewports — at 320px wide, tile width is
 * (288 - 24) / 4 = 66px, which clips 10-char names like "Spanberger" at
 * the default 0.7rem. Padding shrinks too so character cells have room. */
@media (max-width: 359px) {
    .cn-tile { font-size: 0.62rem; padding: 3px 2px; letter-spacing: -0.01em; }
}
@media (min-width: 480px) {
    .cn-tile { font-size: 0.82rem; padding: 6px; }
}
@media (min-width: 640px) {
    .cn-tile { font-size: 0.95rem; padding: 8px; }
}

.cn-tile:hover:not(:disabled):not(.cn-tile--selected) {
    background-color: #374151;
}

/* Keyboard focus ring — matches the game's rose accent and is bright enough
 * to spot at a glance on the dark grid. Tab order is left-to-right top-to-
 * bottom by DOM insertion order (no aria-roledescription / grid roles
 * needed at this size). */
.cn-tile:focus-visible {
    outline: 2px solid rgb(244, 114, 182);  /* rose-400 */
    outline-offset: 2px;
}

.cn-tile--selected {
    background-color: rgb(225, 29, 72);  /* rose-600 */
    color: white;
    transform: scale(0.94);
    box-shadow:
        0 0 0 2px rgba(244, 114, 182, 0.55),
        0 6px 20px -6px rgba(225, 29, 72, 0.65);
    animation: cnTileTap 220ms ease-out;
}
@keyframes cnTileTap {
    0%   { transform: scale(1.04); }
    60%  { transform: scale(0.92); }
    100% { transform: scale(0.94); }
}

.cn-tile:disabled,
.cn-tile[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

/* === Feedback animations === */
@keyframes cnShake {
    0%, 100% { transform: translateX(0); }
    15%      { transform: translateX(-9px) rotate(-1.5deg); }
    30%      { transform: translateX(9px)  rotate(1.5deg); }
    45%      { transform: translateX(-7px) rotate(-1deg); }
    60%      { transform: translateX(7px)  rotate(1deg); }
    75%      { transform: translateX(-4px); }
    90%      { transform: translateX(4px); }
}
.cn-tile--shake { animation: cnShake 520ms ease-in-out; }

@keyframes cnFlashWrong {
    0%, 100% { background-color: rgb(225, 29, 72); box-shadow: 0 0 0 2px rgba(244, 114, 182, 0.55); }
    50%      { background-color: rgb(127, 29, 29); box-shadow: 0 0 0 3px rgba(127, 29, 29, 0.9); }
}
.cn-tile--flash-wrong {
    animation: cnFlashWrong 520ms ease-in-out;
}

@keyframes cnBounce {
    0%   { transform: translateY(0)    scale(0.94); }
    35%  { transform: translateY(-14px) scale(1.06); }
    65%  { transform: translateY(-4px)  scale(1.02); }
    100% { transform: translateY(0)    scale(1); }
}
.cn-tile--bounce {
    animation: cnBounce 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Color burst for correct tiles — paint with the tier color a beat before
 * they consolidate into the solved row. Tier set as a CSS var by JS. */
.cn-tile--correct {
    background-color: var(--cn-correct-color, rgb(34, 197, 94)) !important;
    color: rgb(15, 23, 42) !important;
    box-shadow:
        0 0 0 3px var(--cn-correct-color, rgb(34, 197, 94)),
        0 0 28px 4px var(--cn-correct-glow, rgba(34, 197, 94, 0.55)) !important;
}
.cn-tile--correct.cn-tile--bounce {
    animation: cnCorrectBounce 420ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cnCorrectBounce {
    0%   { transform: translateY(0)    scale(0.94); }
    30%  { transform: translateY(-18px) scale(1.10); }
    60%  { transform: translateY(-4px)  scale(1.02); }
    100% { transform: translateY(0)    scale(1); }
}

/* === Solved-group pill (one row, colored by tier) === */
.cn-solved-row {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 12px;
    border-radius: 8px;
    text-align: center;
    color: rgb(15, 23, 42);
    font-weight: 700;
    flex-direction: column;
    line-height: 1.2;
    animation: cnSolvedPop 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: 0 4px 16px -6px rgba(0, 0, 0, 0.4);
}
@keyframes cnSolvedPop {
    0%   { transform: scale(0.7)  translateY(-8px); opacity: 0; }
    55%  { transform: scale(1.06) translateY(0);    opacity: 1; }
    100% { transform: scale(1)    translateY(0);    opacity: 1; }
}

.cn-solved-row--yellow { background: var(--tl-tier-yellow); }
.cn-solved-row--green  { background: var(--tl-tier-green); }
.cn-solved-row--blue   { background: var(--tl-tier-blue);   color: white; }
.cn-solved-row--purple { background: var(--tl-tier-purple); color: white; }

.cn-solved-row__label {
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.cn-solved-row__members {
    font-size: 0.75rem;
    font-weight: 500;
    opacity: 0.9;
}

/* === Mistake dots === */
.cn-mistakes {
    display: inline-flex;
    gap: 7px;
    align-items: center;
}
.cn-mistake-dot {
    width: 12px;
    height: 12px;
    border-radius: 999px;
    background: rgb(244, 63, 94);
    box-shadow: 0 0 8px -1px rgba(244, 63, 94, 0.55);
    transition: background-color 240ms ease-out,
                transform 240ms ease-out,
                box-shadow 240ms ease-out;
}
.cn-mistake-dot--used {
    background: rgb(55, 65, 81);
    transform: scale(0.55);
    box-shadow: none;
}
@keyframes cnDotBurst {
    0%   { transform: scale(1);   box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.6); }
    40%  { transform: scale(1.7); box-shadow: 0 0 0 8px rgba(244, 63, 94, 0); }
    100% { transform: scale(0.55); box-shadow: none; }
}
.cn-mistake-dot--bursting {
    animation: cnDotBurst 520ms ease-out forwards;
}

/* === Idle-state lifetime stats (iter 9) ===
 * Returning-player hook: shows streak flame + games/win-rate before the
 * Play button. First-timers see nothing (the block stays hidden). */
.cn-idle-stats {
    text-align: center;
    margin-bottom: 22px;
    animation: cnIdleStatsEnter 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cnIdleStatsEnter {
    0%   { opacity: 0; transform: translateY(6px) scale(0.97); }
    60%  { opacity: 1; transform: translateY(0) scale(1.02); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}
.cn-idle-stats__streak {
    display: inline-flex;
    align-items: baseline;
    gap: 8px;
    padding: 8px 18px;
    border-radius: 999px;
    background: linear-gradient(135deg,
        rgba(251, 146, 60, 0.18),
        rgba(244, 63, 94, 0.22));
    border: 1px solid rgba(251, 146, 60, 0.50);
    box-shadow: 0 8px 22px -10px rgba(251, 146, 60, 0.55);
}
.cn-idle-stats__flame {
    font-size: 1.15rem;
    line-height: 1;
    filter: drop-shadow(0 0 6px rgba(251, 146, 60, 0.6));
    animation: cnFlameFlicker 2.4s ease-in-out infinite;
    display: inline-block;
    transform-origin: 50% 80%;
}
@keyframes cnFlameFlicker {
    0%, 100% { transform: scale(1) rotate(-2deg); }
    25%      { transform: scale(1.05) rotate(2deg); }
    50%      { transform: scale(1.1) rotate(-1deg); }
    75%      { transform: scale(1.03) rotate(2deg); }
}
.cn-idle-stats__streak-num {
    font-size: 1.3rem;
    font-weight: 800;
    color: white;
    font-variant-numeric: tabular-nums;
    text-shadow: 0 0 12px rgba(251, 146, 60, 0.55);
}
.cn-idle-stats__streak-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    color: rgb(254, 215, 170);
}
.cn-idle-stats__sub {
    margin-top: 8px;
    font-size: 0.78rem;
    color: rgb(156, 163, 175);
}

@media (prefers-reduced-motion: reduce) {
    .cn-idle-stats,
    .cn-idle-stats__flame {
        animation: none !important;
    }
}

/* === Status bar — group counter + streak chip === */
.cn-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.cn-status__left,
.cn-status__right {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.cn-progress {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.72rem;
    color: rgb(209, 213, 219);
}
.cn-progress__count {
    font-weight: 700;
    color: white;
    font-size: 0.95rem;
    line-height: 1;
    min-width: 1.2em;
    display: inline-block;
    transition: transform 240ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cn-progress__count--pop {
    animation: cnCountPop 460ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cnCountPop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.6); color: rgb(244, 114, 182); }
    100% { transform: scale(1); }
}
.cn-progress__bar {
    width: 64px;
    height: 6px;
    border-radius: 999px;
    background: rgba(244, 63, 94, 0.18);
    overflow: hidden;
    position: relative;
}
.cn-progress__bar-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0%;
    background: linear-gradient(90deg,
        rgb(234, 179, 8) 0%,
        rgb(34, 197, 94) 33%,
        rgb(59, 130, 246) 66%,
        rgb(168, 85, 247) 100%);
    background-size: 100% 100%;
    border-radius: 999px;
    transition: width 380ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cn-streak-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px 3px 8px;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.18), rgba(244, 63, 94, 0.22));
    border: 1px solid rgba(251, 146, 60, 0.45);
    font-size: 0.72rem;
    font-weight: 600;
    color: rgb(254, 215, 170);
    line-height: 1;
    white-space: nowrap;
}
.cn-streak-chip__flame {
    display: inline-block;
    font-size: 0.85rem;
    line-height: 1;
    filter: drop-shadow(0 0 4px rgba(251, 146, 60, 0.6));
}
.cn-streak-chip__num {
    font-weight: 800;
    color: white;
}
.cn-streak-chip--big {
    padding: 6px 14px;
    font-size: 0.82rem;
    box-shadow: 0 6px 22px -8px rgba(251, 146, 60, 0.55);
}

/* Floating "+1 group" toast that rises from the grid on a correct guess. */
.cn-floater {
    position: absolute;
    left: 50%;
    transform: translate(-50%, 0);
    top: 40%;
    z-index: 25;
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.92);
    color: white;
    font-weight: 700;
    font-size: 0.85rem;
    pointer-events: none;
    opacity: 0;
    animation: cnFloater 1000ms ease-out forwards;
    box-shadow: 0 8px 22px -6px rgba(0, 0, 0, 0.55);
    border: 1px solid var(--cn-floater-color, rgba(244, 114, 182, 0.6));
}
@keyframes cnFloater {
    0%   { opacity: 0; transform: translate(-50%, 10px) scale(0.9); }
    20%  { opacity: 1; transform: translate(-50%, -8px) scale(1.05); }
    80%  { opacity: 1; transform: translate(-50%, -28px) scale(1); }
    100% { opacity: 0; transform: translate(-50%, -46px) scale(0.98); }
}

/* Confetti pieces fired from the shell center on a win. */
.cn-confetti {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 8px;
    height: 14px;
    border-radius: 2px;
    z-index: 24;
    pointer-events: none;
    opacity: 0;
    animation: cnConfetti 1400ms cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
}
@keyframes cnConfetti {
    0%   { opacity: 0; transform: translate(-50%, -50%) rotate(0deg) scale(0.6); }
    10%  { opacity: 1; }
    100% { opacity: 0;
        transform:
            translate(calc(-50% + var(--dx, 0px)),
                      calc(-50% + var(--dy, 0px)))
            rotate(var(--rot, 540deg))
            scale(1); }
}

/* === Share grid === */
.cn-share-grid {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 1.55rem;
    letter-spacing: 0.10em;
    line-height: 1.05;
    text-align: center;
    white-space: pre-line;
}

/* === End state polish === */
.cn-end-trophy {
    font-size: 2.6rem;
    line-height: 1;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 12px rgba(251, 146, 60, 0.5));
    animation: cnTrophyPop 700ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes cnTrophyPop {
    0%   { transform: scale(0); opacity: 0; }
    60%  { transform: scale(1.25); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}
.cn-end-headline {
    font-size: 1.15rem;
    font-weight: 800;
    color: white;
    margin-bottom: 6px;
    letter-spacing: -0.01em;
}
.cn-end-headline--win {
    background: linear-gradient(135deg, #fde68a, #fb7185, #f0abfc);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
.cn-end-stats {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}
.cn-end-stat {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 0.72rem;
    color: rgb(209, 213, 219);
    font-weight: 500;
}
.cn-end-stat__num {
    font-weight: 700;
    color: white;
}
.cn-share-btn--prominent {
    background: linear-gradient(135deg, rgb(244, 63, 94), rgb(225, 29, 72));
    color: white;
    border-color: rgb(244, 63, 94);
    box-shadow: 0 10px 28px -10px rgba(244, 63, 94, 0.7);
}
.cn-share-btn--prominent:hover {
    background: linear-gradient(135deg, rgb(251, 113, 133), rgb(244, 63, 94));
}

/* === Toast === */
.cn-toast {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.95);
    color: white;
    font-size: 0.78rem;
    font-weight: 600;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease-out, transform 200ms ease-out;
    z-index: 20;
}
.cn-toast--visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Submit button glows when armed (4 selected) — a tiny "ready" affordance
 * that makes the moment of decision feel charged. */
.cn-submit:not(:disabled) {
    box-shadow: 0 0 0 0 rgba(244, 114, 182, 0.0);
    animation: cnSubmitPulse 1800ms ease-in-out infinite;
}
@keyframes cnSubmitPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(244, 114, 182, 0.0); }
    50%      { box-shadow: 0 0 0 6px rgba(244, 114, 182, 0.18); }
}

@media (prefers-reduced-motion: reduce) {
    .cn-tile,
    .cn-tile--shake,
    .cn-tile--flash-wrong,
    .cn-tile--bounce,
    .cn-tile--correct,
    .cn-solved-row,
    .cn-floater,
    .cn-confetti,
    .cn-end-trophy,
    .cn-mistake-dot--bursting,
    .cn-progress__count--pop,
    .cn-submit:not(:disabled) {
        animation: none !important;
        transition: none !important;
    }
}

/* === Give-up confirm sheet ===
 * Inline overlay that lives inside .cn-shell. Custom instead of native
 * confirm() because confirm() looks alien on mobile, blocks the JS thread,
 * and is ignored by screen-reader testing tools. */
.cn-confirm {
    position: absolute;
    inset: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    opacity: 0;
    transition: opacity 160ms ease-out;
    pointer-events: none;
}
.cn-confirm--visible {
    opacity: 1;
    pointer-events: auto;
}
.cn-confirm__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(13, 17, 23, 0.85);
    backdrop-filter: blur(2px);
}
.cn-confirm__panel {
    position: relative;
    max-width: 320px;
    width: 100%;
    background: #161B24;
    border: 1px solid rgba(225, 29, 72, 0.30);
    border-radius: 12px;
    padding: 18px 18px 16px;
    box-shadow: 0 12px 28px -8px rgba(0, 0, 0, 0.55);
    transform: scale(0.96);
    transition: transform 160ms ease-out;
}
.cn-confirm--visible .cn-confirm__panel {
    transform: scale(1);
}
.cn-confirm__title {
    font-size: 0.95rem;
    font-weight: 700;
    color: white;
    margin-bottom: 6px;
}
.cn-confirm__body {
    font-size: 0.8rem;
    color: rgb(156, 163, 175);
    line-height: 1.45;
    margin-bottom: 14px;
}
.cn-confirm__actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.cn-confirm__btn {
    min-height: 44px;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background-color 120ms ease-out, border-color 120ms ease-out;
    cursor: pointer;
}
.cn-confirm__btn:focus-visible {
    outline: 2px solid rgb(244, 114, 182);
    outline-offset: 2px;
}
.cn-confirm__btn--cancel {
    background: transparent;
    border: 1px solid rgb(75, 85, 99);
    color: rgb(209, 213, 219);
}
.cn-confirm__btn--cancel:hover {
    border-color: rgb(156, 163, 175);
    color: white;
}
.cn-confirm__btn--accept {
    background: rgb(225, 29, 72);
    border: 1px solid rgb(225, 29, 72);
    color: white;
}
.cn-confirm__btn--accept:hover {
    background: rgb(244, 63, 94);
}

@media (prefers-reduced-motion: reduce) {
    .cn-confirm,
    .cn-confirm__panel {
        transition: none;
    }
}
