/* TerrierGrid — inspiré Pokégrille, palette Terrierdle, mobile first */

.tg-page {
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
}

.tg-panel {
    margin-top: 1rem;
    padding: 1.25rem 1rem;
    border-radius: 18px;
    background: rgba(15, 23, 44, 0.92);
    border: 2px solid rgba(119, 208, 255, 0.35);
    text-align: center;
}

.tg-panel--loading .tg-spinner {
    width: 2.5rem;
    height: 2.5rem;
    margin: 0 auto 1rem;
    border: 3px solid rgba(119, 208, 255, 0.25);
    border-top-color: #77d0ff;
    border-radius: 50%;
    animation: tg-spin 0.75s linear infinite;
}

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

.tg-panel--error #tg-error-text {
    margin: 0 0 1rem;
    color: #ffb4b4;
    font-weight: 600;
}

.tg-lead {
    margin: 0 0 0.85rem;
    padding: 0;
    width: 100%;
    max-width: none;
    box-sizing: border-box;
    line-height: 1.38;
    color: #b7cbff;
    font-size: clamp(0.88rem, 1.35vw + 0.55rem, 1.06rem);
    text-align: center;
}

@media (max-width: 640px) {
    .tg-lead {
        font-size: 0.82rem;
        line-height: 1.34;
        margin-bottom: 0.75rem;
    }
}

@media (max-width: 400px) {
    .tg-lead {
        font-size: 0.76rem;
        line-height: 1.3;
    }
}

.tg-victory-chip {
    margin: 0 auto 1rem;
    padding: 0.55rem 1rem;
    max-width: 22rem;
    text-align: center;
    font-weight: 700;
    font-size: 0.88rem;
    color: #0d3d26;
    background: linear-gradient(90deg, #a7f3d0, #6ee7b7);
    border: 1px solid #34d399;
    border-radius: 999px;
    box-shadow: 0 4px 16px rgba(52, 211, 153, 0.25);
}

.tg-shell {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    margin-top: 0.5rem;
}

@media (min-width: 900px) {
    .tg-shell {
        flex-direction: row;
        align-items: flex-start;
        justify-content: center;
        gap: 1.5rem;
    }
}

.tg-card {
    width: 100%;
    max-width: min(520px, 100%);
    background: linear-gradient(
        165deg,
        rgba(51, 65, 85, 0.88) 0%,
        rgba(30, 41, 59, 0.94) 45%,
        rgba(15, 23, 42, 0.96) 100%
    );
    border-radius: 18px;
    padding: 0.65rem 0.5rem 0.85rem;
    border: 1px solid rgba(148, 163, 184, 0.28);
    box-shadow:
        0 22px 50px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

@media (min-width: 640px) {
    .tg-card {
        padding: 0.85rem 0.75rem 1rem;
    }
}

/* Grille 3×3 — cases carrées adaptatives, pas de scroll horizontal */
.tg-board {
    display: grid;
    grid-template-columns: minmax(4.5rem, 0.92fr) repeat(3, minmax(0, 1fr));
    grid-template-rows: auto repeat(3, minmax(0, 1fr));
    gap: clamp(0.35rem, 2vw, 0.55rem);
    aspect-ratio: 1 / 1.05;
    max-height: min(72vh, 520px);
    margin: 0 auto;
    width: 100%;
}

@media (min-width: 400px) {
    .tg-board {
        grid-template-columns: minmax(5.25rem, 1fr) repeat(3, minmax(0, 1fr));
    }
}

.tg-board__corner {
    grid-column: 1;
    grid-row: 1;
}

.tg-board__col-headers {
    grid-column: 2 / -1;
    grid-row: 1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: inherit;
    min-height: 0;
}

.tg-board__row-headers {
    grid-column: 1;
    grid-row: 2 / -1;
    display: grid;
    grid-template-rows: repeat(3, 1fr);
    gap: inherit;
    min-height: 0;
}

.tg-board__cells {
    grid-column: 2 / -1;
    grid-row: 2 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: inherit;
    min-height: 0;
}

.tg-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 2.75rem;
    padding: 0.35rem 0.3rem;
    font-size: clamp(0.58rem, 2.4vw, 0.74rem);
    font-weight: 800;
    line-height: 1.2;
    color: #f1f5f9;
    border-radius: 12px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.22);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        0 4px 12px rgba(0, 0, 0, 0.2);
    transition:
        box-shadow 0.2s ease,
        transform 0.2s ease;
}

.tg-badge--row {
    background: linear-gradient(145deg, #f59e0b, #b45309);
    border-color: #fcd34d;
}

.tg-badge--col {
    background: linear-gradient(145deg, #6366f1, #4338ca);
    border-color: #a5b4fc;
}

.tg-badge--lit {
    box-shadow:
        0 0 0 2px rgba(157, 225, 255, 0.55),
        0 6px 18px rgba(99, 102, 241, 0.35);
    transform: scale(1.02);
}

.tg-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: clamp(0.25rem, 1.5vw, 0.45rem);
    min-height: 0;
    min-width: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, #e2e8f0 100%);
    border-radius: 12px;
    border: 2px solid #cbd5e1;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition:
        border-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.15s ease,
        background 0.2s ease;
}

.tg-cell:active:not(:disabled) {
    transform: scale(0.97);
}

@media (hover: hover) {
    .tg-cell:hover:not(:disabled):not(.tg-cell--success) {
        border-color: #818cf8;
        background: linear-gradient(180deg, #eef2ff 0%, #e0e7ff 100%);
        box-shadow: 0 6px 20px rgba(99, 102, 241, 0.2);
    }
}

.tg-cell:focus-visible {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.35);
}

.tg-cell--success {
    cursor: default;
    color: #fff;
    background: linear-gradient(160deg, #22c55e, #15803d);
    border-color: #4ade80;
    box-shadow: 0 0 20px rgba(74, 222, 128, 0.35);
}

.tg-cell:disabled {
    cursor: default;
}

.tg-cell__inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    width: 100%;
    height: 100%;
    min-height: 0;
}

.tg-cell__avatar {
    width: min(52px, 14vw);
    height: min(52px, 14vw);
    border-radius: 12px;
    object-fit: cover;
    display: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.tg-cell--success .tg-cell__avatar {
    display: block;
}

.tg-cell__name {
    display: none;
    font-size: clamp(0.55rem, 2.8vw, 0.72rem);
    font-weight: 800;
    text-align: center;
    line-height: 1.15;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    word-break: break-word;
    max-width: 100%;
    padding: 0 0.1rem;
}

.tg-cell--success .tg-cell__name {
    display: block;
}

.tg-cell__hint {
    font-size: clamp(0.5rem, 2.2vw, 0.62rem);
    font-weight: 600;
    color: #64748b;
    text-align: center;
    line-height: 1.2;
    padding: 0 0.15rem;
}

.tg-cell--success .tg-cell__hint {
    display: none;
}

/* Indice : nombre de personnes (ligne ∩ colonne) */
.tg-cell__count-hint {
    font-size: clamp(0.48rem, 2.2vw, 0.65rem);
    font-weight: 800;
    text-align: center;
    line-height: 1.2;
    padding: 0.18rem 0.4rem;
    margin-top: 0.08rem;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.18);
    color: #312e81;
    border: 1px solid rgba(79, 70, 229, 0.4);
    max-width: 100%;
}

.tg-cell__count-hint[hidden] {
    display: none !important;
}

.tg-cell--success .tg-cell__count-hint {
    background: rgba(255, 255, 255, 0.2);
    color: #ecfdf5;
    border-color: rgba(255, 255, 255, 0.35);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}

.tg-cell__check {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 1.35rem;
    height: 1.35rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #15803d;
    background: #fff;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.9);
    font-size: 0.75rem;
    font-weight: 900;
}

.tg-cell__check[hidden] {
    display: none !important;
}

.tg-cell--shake {
    animation: tg-shake 0.42s ease;
}

.tg-cell--pop {
    animation: tg-pop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tg-shake {
    0%,
    100% {
        transform: translateX(0);
    }
    25% {
        transform: translateX(-4px);
    }
    75% {
        transform: translateX(4px);
    }
}

@keyframes tg-pop {
    from {
        transform: scale(0.92);
    }
    to {
        transform: scale(1);
    }
}

.tg-aside {
    width: 100%;
    max-width: 320px;
    flex-shrink: 0;
}

.tg-aside-card {
    padding: 1rem 1.1rem;
    border-radius: 16px;
    background: rgba(15, 23, 44, 0.9);
    border: 2px solid rgba(119, 208, 255, 0.3);
    text-align: center;
}

.tg-aside-card__label {
    margin: 0;
    font-size: 0.82rem;
    color: #94a3b8;
    font-weight: 600;
}

.tg-aside-card__count {
    margin: 0.35rem 0;
    font-size: 2rem;
    font-weight: 800;
    color: #9de1ff;
    font-variant-numeric: tabular-nums;
}

.tg-aside-card__sub {
    margin: 0;
    font-size: 0.85rem;
    color: #b7cbff;
}

.tg-feedback {
    margin: 0.85rem 0 0;
    padding: 0.55rem 0.65rem;
    border-radius: 12px;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: center;
}

.tg-feedback--ok {
    background: rgba(34, 197, 94, 0.2);
    border: 1px solid rgba(74, 222, 128, 0.45);
    color: #bbf7d0;
}

.tg-feedback--err {
    background: rgba(239, 68, 68, 0.18);
    border: 1px solid rgba(248, 113, 113, 0.45);
    color: #fecaca;
}

.tg-actions {
    margin-top: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    padding: 0.65rem 1.25rem;
    border-radius: 14px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition:
        transform 0.15s ease,
        box-shadow 0.2s ease,
        filter 0.2s ease;
}

.tg-btn:active {
    transform: scale(0.98);
}

.tg-btn--primary {
    background: linear-gradient(135deg, #4cb8ff, #2d53ff);
    color: #eef6ff;
    box-shadow: 0 6px 20px rgba(45, 83, 255, 0.35);
}

.tg-btn--secondary {
    background: rgba(119, 208, 255, 0.15);
    color: #9de1ff;
    border: 2px solid rgba(119, 208, 255, 0.4);
}

.tg-btn--ghost {
    background: transparent;
    color: #9de1ff;
    border: 2px solid rgba(119, 208, 255, 0.35);
}

/* Dialog */
.tg-dialog {
    border: none;
    padding: 0;
    margin: auto;
    max-width: calc(100vw - 1.25rem);
    width: min(420px, 100%);
    background: transparent;
}

.tg-dialog::backdrop {
    background: rgba(2, 6, 23, 0.72);
    backdrop-filter: blur(4px);
}

.tg-modal {
    padding: 1.15rem 1rem 1.25rem;
    border-radius: 18px;
    background: linear-gradient(
        165deg,
        rgba(51, 65, 85, 0.97) 0%,
        rgba(30, 41, 59, 0.98) 100%
    );
    border: 1px solid rgba(148, 163, 184, 0.35);
    color: #e8f2ff;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.tg-modal__title {
    margin: 0 0 0.5rem;
    font-size: 1.2rem;
    color: #fff;
}

.tg-modal__lead {
    margin: 0 0 0.75rem;
    font-size: 0.9rem;
    color: #cbd5e1;
}

.tg-modal__badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-bottom: 1rem;
}

.tg-modal__badge-slot .tg-badge {
    min-height: 2.5rem;
    font-size: clamp(0.55rem, 2.2vw, 0.68rem);
}

.tg-modal__join {
    font-weight: 800;
    color: #94a3b8;
    padding: 0 0.15rem;
}

.tg-modal__label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
    font-size: 0.88rem;
}

.tg-modal__input {
    width: 100%;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    border: 2px solid rgba(119, 208, 255, 0.4);
    background: rgba(9, 13, 28, 0.92);
    color: inherit;
    font-size: 1rem;
    font-family: inherit;
}

.tg-modal__input:focus {
    outline: none;
    border-color: #77d0ff;
    box-shadow: 0 0 0 3px rgba(119, 208, 255, 0.25);
}

.tg-suggest-list {
    margin-top: 0.5rem;
    max-height: min(40vh, 220px);
    overflow-y: auto;
    border-radius: 14px;
    border: 2px solid rgba(119, 208, 255, 0.35);
    background: rgba(7, 10, 22, 0.95);
    -webkit-overflow-scrolling: touch;
}

.tg-suggest-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 0.85rem;
    min-height: 48px;
    cursor: pointer;
    border-bottom: 1px solid rgba(119, 208, 255, 0.12);
    font-weight: 600;
}

.tg-suggest-item:last-child {
    border-bottom: none;
}

.tg-suggest-item:active {
    background: rgba(119, 208, 255, 0.15);
}

.tg-suggest-item img {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.tg-modal__error {
    margin-top: 0.65rem;
    padding: 0.5rem 0.65rem;
    border-radius: 10px;
    background: rgba(127, 29, 29, 0.45);
    border: 1px solid rgba(248, 113, 113, 0.45);
    color: #fecaca;
    font-weight: 600;
    font-size: 0.86rem;
    line-height: 1.45;
    white-space: pre-line;
    max-height: min(40vh, 220px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tg-modal__actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

@media (min-width: 400px) {
    .tg-modal__actions {
        flex-direction: row;
    }

    .tg-modal__actions .tg-btn {
        flex: 1;
    }
}

/* Victoire */
.tg-victory {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: grid;
    place-items: center;
    padding: 1rem;
}

/* `hidden` impose display:none dans le UA ; notre display:grid le battait en cascade. */
.tg-victory[hidden] {
    display: none !important;
}

.tg-victory__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
    backdrop-filter: blur(5px);
}

.tg-victory__card {
    position: relative;
    z-index: 1;
    width: min(400px, 100%);
    padding: 1.75rem 1.25rem;
    border-radius: 20px;
    text-align: center;
    background: linear-gradient(165deg, #1e293b, #0f172a);
    border: 1px solid rgba(148, 163, 184, 0.35);
    box-shadow: 0 28px 70px rgba(0, 0, 0, 0.55);
    color: #e8f2ff;
}

.tg-victory__title {
    margin: 0 0 0.5rem;
    font-size: 1.45rem;
    color: #86efac;
}

.tg-victory__sub {
    margin: 0 0 1.25rem;
    color: #cbd5e1;
}

.tg-victory__confetti span {
    position: absolute;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    opacity: 0;
    animation: tg-confetti 1.2s ease-out forwards;
}

.tg-victory__confetti span:nth-child(odd) {
    background: #fbbf24;
    left: 15%;
    top: 20%;
    animation-delay: 0.05s;
}

.tg-victory__confetti span:nth-child(even) {
    background: #60a5fa;
    right: 18%;
    top: 25%;
    animation-delay: 0.12s;
}

@keyframes tg-confetti {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0);
    }
    100% {
        opacity: 0;
        transform: translateY(40px) rotate(180deg);
    }
}

.tg-victory__btn {
    width: 100%;
}

/*
 * Cette feuille ne s’applique qu’à grid.php (chargée après style.css).
 * Renfort du menu : si style.css était servi depuis le cache avec un vieux ?v=
 * (avant correction dans grid.php), les liens restent lisibles ici grâce à une
 * spécificité plus forte (.app-header …).
 */
.app-header .app-nav a {
    color: #f0f9ff;
    text-decoration: none;
    border: 1px solid rgba(125, 211, 252, 0.5);
    background: rgba(14, 116, 144, 0.35);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.app-header .app-nav a:hover,
.app-header .app-nav a:focus-visible {
    color: #ffffff;
    background: rgba(56, 189, 248, 0.35);
    border-color: rgba(186, 230, 253, 0.85);
    box-shadow:
        0 0 0 2px rgba(56, 189, 248, 0.25),
        0 2px 8px rgba(0, 0, 0, 0.25);
    outline: none;
}

.app-header .app-nav-pokemon a {
    color: #faf5ff;
    border-color: rgba(196, 181, 253, 0.55);
    background: rgba(91, 33, 182, 0.35);
    box-shadow:
        0 1px 3px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.app-header .app-nav-pokemon a:hover,
.app-header .app-nav-pokemon a:focus-visible {
    color: #ffffff;
    background: rgba(124, 58, 237, 0.45);
    border-color: rgba(221, 214, 254, 0.9);
    box-shadow:
        0 0 0 2px rgba(167, 139, 250, 0.3),
        0 2px 8px rgba(0, 0, 0, 0.25);
    outline: none;
}

@media (max-width: 760px) {
    .app-header .app-nav {
        background: rgba(2, 6, 23, 0.55);
        border: 1px solid rgba(148, 163, 184, 0.4);
        border-radius: 14px;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    }

    .app-header .app-nav-pokemon {
        background: rgba(15, 23, 42, 0.65);
        border: 1px solid rgba(167, 139, 250, 0.35);
        border-radius: 14px;
        padding: 0.55rem 0.5rem;
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
    }

    .app-header .app-nav a,
    .app-header .app-nav-pokemon a {
        font-weight: 700;
    }
}
