/* ===== Variables ===== */
:root {
    --paper: #FFFFFF;
    --ink: #16202C;
    --muted: #5B6470;
    --line: #E6E3DC;
    --green: #01573C;
    --red: #C8102E;
    --blue: #003F8C;
    --tram-bilbao: #4EB848;
    --tram-vitoria: #60AE27;
    --renfe: #74349A;
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html { background: var(--paper); }
body {
    margin: 0;
    min-height: 100vh;
    background: var(--paper);
    color: var(--ink);
    font-family: 'Hanken Grotesk', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    padding: calc(20px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

/* ===== Estructura de la página ===== */
main {
    max-width: 920px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 22px;
}
    header {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        gap: 10px 16px;
        padding: 6px 4px 0;
    }
        header h1 { margin: 0; line-height: 0; }
        header .wordmark { height: 44px; width: auto; display: block; }
        header p {
            order: 3;
            flex-basis: 100%;
            margin: 0;
            color: var(--muted);
            font-size: 0.95rem;
            line-height: 1.25;
        }
    h2 {
        margin: 0 0 10px 4px;
        font-family: 'Bricolage Grotesque', system-ui, sans-serif;
        font-size: 0.98rem;
        font-weight: 700;
        color: var(--muted);
        letter-spacing: -0.005em;
    }
    footer {
        color: var(--muted);
        font-size: 0.82rem;
        padding: 6px 4px 0;
        max-width: 60ch;
    }

/* ===== Colores por app ===== */
.tile--bus { --c: var(--green); }
.tile--metro { --c: var(--red); }
.tile--euskotren { --c: var(--blue); }
.tile--tranvia-bilbao { --c: var(--tram-bilbao); }
.tile--tranvia-vitoria { --c: var(--tram-vitoria); }
.tile--renfe { --c: var(--renfe); }

/* ===== Fichas de las apps ===== */
.tiles {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
    .tiles li { display: flex; }

.tile {
    position: relative;
    flex: 1;
    min-height: 168px;
    padding: 16px;
    border-radius: 24px;
    background: var(--c);
    color: #fff;
    text-decoration: none;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    overflow: hidden;
    isolation: isolate;
    transition: transform .12s ease;
}
    .tile::before {
        content: '';
        position: absolute;
        inset: 0;
        z-index: -1;
        background: var(--wipe, rgba(255, 255, 255, .22));
        transform: scaleX(0);
        transform-origin: left center;
        pointer-events: none;
    }
    .tile.is-launching::before {
        transform: scaleX(1);
        transition: transform .38s cubic-bezier(.4, 0, .2, 1);
    }
    .tile.is-launching::after {
        content: '';
        position: absolute;
        inset: 0;
        z-index: -1;
        background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, .35) 50%, transparent 100%);
        transform: translateX(-100%);
        animation: launch-shine .9s ease-in-out .4s infinite;
        pointer-events: none;
    }
@keyframes launch-shine {
    to { transform: translateX(100%); }
}
    a.tile:active { transform: scale(.98); }
    a.tile:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
    .tile .glyph { width: 46px; height: 46px; display: block; }
    .tile .appicon {
        display: block;
        width: 56px;
        height: 56px;
        border-radius: 16px;
        object-fit: cover;
    }
    .tile .mark {
        position: absolute;
        right: -26px;
        bottom: -30px;
        width: 150px;
        height: 150px;
        object-fit: contain;
        opacity: .25;
        -webkit-mask-image: radial-gradient(closest-side, #000 62%, transparent 100%);
        mask-image: radial-gradient(closest-side, #000 62%, transparent 100%);
        z-index: -1;
        pointer-events: none;
    }
    .tile .go {
        position: absolute;
        top: 16px;
        right: 16px;
        width: 22px;
        height: 22px;
        opacity: .85;
    }
    .tile .txt { display: block; }
        .tile strong {
            display: block;
            font-family: 'Bricolage Grotesque', system-ui, sans-serif;
            font-size: 1.4rem;
            font-weight: 800;
            letter-spacing: -0.02em;
            line-height: 1.1;
        }
        .tile .txt span {
            display: block;
            margin-top: 4px;
            font-size: 0.86rem;
            line-height: 1.3;
            opacity: .88;
        }
        .tile strong .tile-mark {
            display: inline;
            margin-top: 0;
            font-size: 1em;
            line-height: 1.1;
            color: inherit;
            font-weight: inherit;
            opacity: 1;
        }
        /* Como el nombre de un elemento en la tabla periódica: pequeño,
           justo bajo "Tranvía+". En ficha (fondo de color) va en blanco
           translúcido; en lista (fondo blanco) se recolorea más abajo,
           con más especificidad que la regla genérica de "[data-view=list]
           .tile .txt span" para poder ganarle. */
        .tile .txt .tile-city {
            margin-top: -2px;
            font-size: .8rem;
            line-height: 1.2;
            font-weight: 700;
            letter-spacing: 1.5px;
            text-transform: uppercase;
            text-align: left;
            color: rgba(255, 255, 255, .85);
            opacity: 1;
        }

/* ===== Ficha "próximamente" ===== */
.tile.soon {
    background: transparent;
    color: var(--muted);
    border: 2px dashed #CFCBC0;
}
    .tile.soon strong { color: var(--ink); }
    .tile.soon .glyph {
        width: 46px;
        height: 46px;
        border-radius: 14px;
        background: #F2A900;
        color: var(--ink);
        display: grid;
        place-items: center;
        font-family: 'Bricolage Grotesque', system-ui, sans-serif;
        font-weight: 800;
        font-size: 1.5rem;
    }
    .tile.soon svg.glyph { padding: 9px; }

/* ===== Selector de vista ===== */
.view-toggle {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}
.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}
.lang-toggle {
    height: 44px;
    min-width: 80px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    color: var(--ink);
    font-family: 'Hanken Grotesk', system-ui, sans-serif;
    font-weight: 700;
    font-size: 0.86rem;
    text-align: center;
    cursor: pointer;
}
    .lang-toggle:hover { background: #FAF9F6; }
    .lang-toggle:focus-visible { outline: 3px solid var(--green); outline-offset: -3px; }

    .view-toggle button {
        width: 44px;
        height: 44px;
        border: 0;
        background: var(--paper);
        color: var(--muted);
        display: grid;
        place-items: center;
        cursor: pointer;
    }
        .view-toggle button svg { width: 22px; height: 22px; }
        .view-toggle button[aria-pressed="true"] { background: var(--ink); color: #fff; }
        .view-toggle button:focus-visible { outline: 3px solid var(--green); outline-offset: -3px; }

/* ===== Vista en lista (accesible, iconos pequeños) ===== */
.tile .chev, .tile .txt .last { display: none; }

[data-view="list"] main { max-width: 640px; }
[data-view="list"] .tile { --wipe: var(--c); }
    [data-view="list"] .tile.is-launching .txt strong,
    [data-view="list"] .tile.is-launching .txt span,
    [data-view="list"] .tile.is-launching .chev { color: #fff; transition: color .18s ease .12s; }
    [data-view="list"] .tiles,
    [data-view="list"] #tr .tiles { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    [data-view="list"] .tile {
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 14px;
        min-height: 0;
        padding: 12px 14px 12px 12px;
        border: 1px solid var(--line);
        border-radius: 16px;
        background: var(--paper);
        color: var(--ink);
    }
        [data-view="list"] a.tile:hover { border-color: #C9C5BB; background: #FAF9F6; }
        [data-view="list"] .tile:not(.soon) .glyph,
        [data-view="list"] .tile .mark,
        [data-view="list"] .tile .go { display: none; }
        [data-view="list"] .tile .appicon {
            flex: none;
            border-radius: 14px;
        }
        [data-view="list"] .tile .txt { flex: 1; min-width: 0; order: 1; }
            [data-view="list"] .tile .txt span { color: var(--muted); opacity: 1; font-size: 0.92rem; }
            [data-view="list"] .tile .txt .tile-mark { color: inherit; font-size: 1em; opacity: 1; }
            [data-view="list"] .tile .txt .tile-city { color: var(--c); opacity: .8; font-size: .8rem; text-align: left; }
            [data-view="list"] .tile.is-last .txt .last {
                display: block;
                margin-top: 4px;
                color: var(--green);
                font-size: 0.78rem;
                font-weight: 600;
            }
            [data-view="list"] .tile.is-launching.is-last .txt .last { color: #fff; }
        [data-view="list"] .tile .chev {
            display: block;
            order: 2;
            flex: none;
            width: 20px;
            height: 20px;
            color: #8C8A82;
        }
        [data-view="list"] .tile.soon {
            border: 1px dashed #CFCBC0;
            background: #FAF9F6;
        }
            [data-view="list"] .tile.soon .glyph { flex: none; width: 56px; height: 56px; }

/* ===== Página 404 ===== */
.notfound {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
    padding: 28px 4px;
}
    .notfound h1 {
        margin: 0;
        font-family: 'Bricolage Grotesque', system-ui, sans-serif;
        font-size: clamp(2rem, 7vw, 3.2rem);
        font-weight: 800;
        letter-spacing: -0.025em;
        line-height: 1.05;
    }
    .notfound p { margin: 0; color: var(--muted); max-width: 44ch; }
    .notfound .back {
        margin-top: 6px;
        padding: 12px 22px;
        border-radius: 999px;
        background: var(--green);
        color: #fff;
        font-weight: 600;
        text-decoration: none;
    }
        .notfound .back:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
    .notfound ul {
        list-style: none;
        margin: 8px 0 0;
        padding: 0;
        display: flex;
        flex-wrap: wrap;
        gap: 8px 18px;
    }
        .notfound ul a { color: var(--ink); font-weight: 600; }

/* ===== Escritorio ===== */
@media (min-width: 720px) {
    body { padding-top: 48px; }
    main { gap: 30px; }
        header .wordmark { height: 56px; }
        #tr .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .tile { min-height: 200px; }
}

/* ===== Animación al cambiar de vista ===== */
main { transition: opacity .12s ease; }
    main.is-switching { opacity: 0; }

::view-transition-old(root),
::view-transition-new(root) {
    animation-duration: .2s;
    animation-timing-function: ease;
}

/* ===== Movimiento reducido ===== */
@media (prefers-reduced-motion: reduce) {
    .tile { transition: none; }
    main { transition: none; }
    .tile.is-launching::before { transition: none; }
    .tile.is-launching::after { animation: none; }
    ::view-transition-group(*),
    ::view-transition-old(*),
    ::view-transition-new(*) { animation: none; }
}
