/* Botões, campo do nome e a grelha dos níveis.
 *
 * O topo desta folha (botões, campo do nome, chip da conta) é o mesmo do Maze
 * Run e do Pixel Racing: os jogos partilham a linguagem, não o ficheiro. */

button,
input {
    font-family: inherit;
    color: inherit;
}

button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* ---------- Botões ---------- */

.btn {
    width: 100%;
    padding: 15px 28px;
    font-family: var(--font-display);
    font-size: clamp(15px, 4vw, 17px);
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--on-accent);
    border: none;
    border-radius: var(--radius-pill);
    background: linear-gradient(100deg, var(--accent), var(--accent-2));
    box-shadow: 0 16px 34px -16px var(--glow), inset 0 1px 0 rgba(255, 255, 255, 0.45);
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}

.btn:hover { filter: brightness(1.06); box-shadow: 0 20px 40px -16px var(--glow), inset 0 1px 0 rgba(255, 255, 255, 0.45); }
.btn:active { transform: translateY(1px) scale(0.995); }

.btnOutline {
    width: 100%;
    padding: 13px 24px;
    font-family: var(--font-display);
    font-size: clamp(13px, 3.4vw, 15px);
    font-weight: 600;
    border: 1px solid var(--glass-border-strong);
    border-radius: var(--radius-pill);
    background: var(--glass-bg-soft);
    transition: background 0.2s ease, border-color 0.2s ease;
}

.btnOutline:hover { background: var(--glass-bg-hover); border-color: var(--accent); }

.iconBtn {
    display: grid;
    place-items: center;
    flex: none;
    width: 40px;
    height: 40px;
    font-size: 18px;
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    background: var(--glass-bg-soft);
    transition: background 0.2s ease, transform 0.15s ease;
}

.iconBtn:hover { background: var(--glass-bg-hover); }
.iconBtn:active { transform: scale(0.94); }

/* ---------- Nome do jogador / conta ---------- */

/*
 * O nome só aparece a quem não tem sessão iniciada, e isso só se sabe depois da
 * resposta de /api/account/me. Até lá o espaço fica reservado e o conteúdo
 * invisível (`is-pending`), para não haver salto de layout nem piscar do campo
 * a quem afinal já está autenticado.
 */
.nameSlot {
    width: 100%;
    min-height: 74px;
    display: grid;
    place-items: center;
}

.nameSlot > * {
    grid-area: 1 / 1;
    width: 100%;
    transition: opacity 0.25s ease;
}

.nameSlot.is-pending > * { opacity: 0; }

.field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    width: 100%;
    text-align: left;
}

.fieldLabel {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--faint);
}

.nameInput {
    width: 100%;
    padding: 13px 16px;
    font-size: 15px;
    font-weight: 600;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.07);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.nameInput::placeholder { color: var(--faint); font-weight: 400; }

.nameInput:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--ring);
}

.playerChip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px 9px 9px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-pill);
    background: var(--glass-bg-soft);
    text-align: left;
}

.chipAvatar {
    display: grid;
    place-items: center;
    flex: none;
    width: 30px;
    height: 30px;
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 700;
    color: var(--on-accent);
    border-radius: 50%;
    background: linear-gradient(140deg, var(--accent), var(--accent-2));
}

.chipText { font-size: 13px; color: var(--muted); }
.chipText b { color: var(--text); font-weight: 700; }

/* ---------- Cartões dos níveis ---------- */

/*
 * Os níveis vão num carrossel (css/carousel.css), como no Maze Run, e os
 * cartões têm a mesma anatomia dos de lá: uma caixa em cima com o desenho do
 * nível — aqui, o tabuleiro em miniatura, com as cartas viradas na grelha em
 * que vão aparecer ao alto — e cinco linhas por baixo, sempre as mesmas e
 * sempre presentes: número, nome, cartas, estado e estrelas. É isso que lhes
 * dá a todos a mesma altura.
 */
.levelCard {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    height: 100%;
    gap: 8px;
    padding: 12px;
    text-align: left;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    background: var(--glass-bg-soft);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.levelCard:hover { background: var(--glass-bg-hover); transform: translateY(-2px); }

/* Cada cartão tem a cor do seu nível (`--card-accent`, escrita pelo js/menu.js). */
.levelCard.active {
    border-color: var(--card-accent, var(--accent));
    background: linear-gradient(150deg, color-mix(in srgb, var(--card-accent, var(--accent)) 24%, transparent), rgba(255, 255, 255, 0.03));
}

/*
 * Um nível fechado continua a ser um botão: clicar nele abana o cartão, e o
 * cartão diz o que falta fazer. Um `disabled` calado deixava quem joga sem
 * saber porquê.
 */
.levelCard.is-locked { cursor: not-allowed; }
.levelCard.is-locked:hover { background: var(--glass-bg-soft); transform: none; }
.levelCard.is-locked .levelName,
.levelCard.is-locked .levelNumber,
.levelCard.is-locked .levelCards { color: var(--faint); }

.levelCard.shake { animation: cardShake 0.36s ease; }

@keyframes cardShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

@media (prefers-reduced-motion: reduce) {
    .levelCard.shake { animation: none; }
}

/* A caixa do tabuleiro tem proporção fixa, seja qual for a grelha lá dentro:
   senão um tabuleiro largo e um alto davam cartões de alturas diferentes. */
.levelShape {
    position: relative;
    display: block;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius-sm);
    background: rgba(6, 16, 14, 0.45);
    overflow: hidden;
}

.boardShape {
    display: block;
    width: 100%;
    height: 100%;
}

/*
 * As cartas da miniatura: as costas na cor do nível, com a patinha branca,
 * como no jogo. A patinha é o símbolo #paw do index.html.
 */
.boardShape .tile {
    fill: var(--card-accent, var(--accent));
    stroke: rgba(255, 255, 255, 0.8);
    stroke-width: 0.6;
}

.boardShape .paw { fill: rgba(255, 255, 255, 0.85); }

/* Nível concluído: a moldura dourada dos pares encontrados. */
.levelCard.is-done .boardShape .tile { stroke: var(--card-matched); stroke-width: 0.9; }

.boardShape.is-locked .tile {
    fill: rgba(241, 247, 238, 0.14);
    stroke: rgba(241, 247, 238, 0.22);
}

.boardShape.is-locked .paw { fill: rgba(241, 247, 238, 0.18); }

.levelLock {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 22px;
    background: rgba(6, 16, 14, 0.35);
}

.levelInfo {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.levelNumber {
    min-height: 1em;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--faint);
}

/* O nome nunca quebra: são de uma palavra (ver js/levels.js), e isto é a rede. */
.levelName {
    min-height: 1.15em;
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.levelCards {
    min-height: 1.2em;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--muted);
}

.levelState {
    min-height: 1.25em;
    font-size: 11px;
    letter-spacing: 0.02em;
    white-space: nowrap;
    color: var(--muted);
}

/* As estrelas que faltam ficam lá, apagadas: vê-se de quantas é a escala. */
.levelStars {
    display: flex;
    align-items: center;
    min-height: 13px;
    gap: 2px;
    font-size: 11px;
    line-height: 1;
    color: var(--gold);
}

.levelStars i { font-style: normal; }
.levelStars i.off { color: rgba(241, 247, 238, 0.22); }

/* Deitado, é a altura que falta: a caixa do tabuleiro achata. */
@media (orientation: landscape) and (max-height: 600px) {
    .levelShape { aspect-ratio: 16 / 9; }
}

/* Telemóvel: os cartões encolhem para caberem quatro por página ao alto (ou
   uma fila de três ao comprido) sem o painel ter de rolar. */
@media (max-width: 560px), (orientation: landscape) and (max-height: 600px) {
    .levelCard { gap: 6px; padding: 9px; }
    .levelNumber { font-size: 9px; letter-spacing: 0.1em; }
    .levelName { font-size: 12.5px; }
    .levelCards, .levelState { font-size: 10px; }
    .levelStars { min-height: 12px; font-size: 10px; }
    .levelLock { font-size: 18px; }
}
