/* cerbnet – Startseite: Gruppen, Kachelraster, Live Tiles, Animationen */

:root {
    --unit: 70px;
    --gap: 10px;
    --rows: 6;
    --edge: 120px;
}

@media (max-height: 739px) {
    :root { --rows: 4; }
}
@media (max-height: 579px) {
    :root { --rows: 2; }
}
@media (min-height: 900px) {
    :root { --rows: 8; }
}
@media (min-width: 1600px) and (min-height: 1050px) {
    :root { --unit: 84px; --gap: 12px; }
}
@media (max-width: 1100px) {
    :root { --edge: 48px; }
}

.start {
    height: 100vh;
    height: 100dvh;
    display: grid;
    grid-template-rows: auto 1fr auto;
}

.start-header {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 4px 24px;
    padding: 40px var(--edge) 0;
}

.start-title {
    display: flex;
    /* Grundlinie kommt vom Text, nicht vom Logo – sonst sitzt der Konto-Link daneben zu tief */
    align-items: baseline;
    gap: 0.3em;
    margin: 0;
    font-size: clamp(2.25rem, 4vw, 3.5rem);
    font-weight: 300;
    line-height: 1.2;
    letter-spacing: 0.01em;
}

/* Titel und Konto-Link stehen ohne Abstand auf einer Grundlinie: „cerbnet.anmelden“ */
.start-brand {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
}

.start-title-dot {
    color: var(--brand);
}

.start-account {
    font-size: clamp(1.25rem, 2.2vw, 1.875rem);
    font-weight: 300;
    color: var(--text-muted);
    text-decoration: none;
}

.start-account[hidden],
.account-menu[hidden] {
    display: none;
}

.start-account:hover {
    color: var(--text);
}

/* Benutzername mit Menü (Profil, Verwaltung, Abmelden) */
.account-menu {
    position: relative;
}

.account-menu-button {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 0;
    border: 0;
    background: none;
    font-family: inherit;
    line-height: inherit;
    cursor: pointer;
}

.account-menu-button .icon {
    width: 0.6em;
    height: 0.6em;
    stroke-width: 2;
    transition: transform 150ms var(--ease-out);
}

.account-menu-button[aria-expanded="true"] {
    color: var(--text);
}

.account-menu-button[aria-expanded="true"] .icon {
    transform: rotate(180deg);
}

.account-menu-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    z-index: 50;
    min-width: 180px;
    margin: 0;
    padding: 6px 0;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgb(0 0 0 / 0.25);
}

.account-menu-list[hidden] {
    display: none;
}

.account-menu-list a,
.account-menu-list button {
    display: block;
    width: 100%;
    padding: 10px 16px;
    border: 0;
    background: none;
    color: var(--text);
    font: inherit;
    font-size: 0.9375rem;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.account-menu-list a:hover,
.account-menu-list button:hover,
.account-menu-list a:focus-visible,
.account-menu-list button:focus-visible {
    background: var(--surface-2);
    outline-offset: -2px;
}

/* Wolfskopf in der Markenfarbe aus dem alten Auftritt */
.start-logo {
    align-self: center;
    flex-shrink: 0;
    width: 0.88em;
    height: 1em;
    fill: var(--brand);
}

/* Uhr und Datum oben rechts */
.start-clock {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.start-clock[hidden] {
    display: none;
}

.start-clock-time {
    font-size: clamp(1.75rem, 3vw, 2.75rem);
    font-weight: 300;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.start-clock-date {
    font-size: 0.9375rem;
    color: var(--text-muted);
}

.groups {
    display: flex;
    align-items: flex-start;
    gap: 80px;
    padding: 32px var(--edge) 24px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

/* Abstand am Ende, damit die letzte Gruppe nicht am Rand klebt */
.groups::after {
    content: "";
    flex: 0 0 calc(var(--edge) - 80px);
}

.group {
    flex: 0 0 auto;
}

.group-title {
    margin: 0 0 16px;
    font-size: 1.25rem;
    font-weight: 350;
    line-height: 1.5;
}

/* Spaltenzahl je Gruppe setzt metro.js so, dass die Gruppe in --rows Zeilen passt */
.group-grid {
    display: grid;
    grid-auto-flow: row dense;
    grid-template-columns: repeat(var(--cols, 4), var(--unit));
    grid-auto-rows: var(--unit);
    gap: var(--gap);
    margin: 0;
    padding: 0;
    list-style: none;
}

.tile {
    grid-row: span 1;
    grid-column: span 1;
}
.tile--medium { grid-row: span 2; grid-column: span 2; }
.tile--wide { grid-row: span 2; grid-column: span 4; }
.tile--large { grid-row: span 4; grid-column: span 4; }

.tile-link {
    position: relative;
    display: block;
    width: 100%;
    height: 100%;
    color: #fff;
    text-decoration: none;
    perspective: 800px;
    transform: perspective(500px) rotateX(calc(var(--rx, 0) * 1deg)) rotateY(calc(var(--ry, 0) * 1deg)) scale(var(--s, 1));
    transition: transform 140ms var(--ease-out);
    outline-offset: 3px;
    -webkit-tap-highlight-color: transparent;
}

.tile-flipper {
    position: absolute;
    inset: 0;
    transform-style: preserve-3d;
    transition: transform 700ms var(--ease-out);
}

.tile.is-flipped .tile-flipper {
    transform: rotateX(-180deg);
}

.tile-face {
    position: absolute;
    inset: 0;
    background: var(--accent);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    overflow: hidden;
}

.tile-front {
    display: grid;
    place-items: center;
}

.tile-back {
    transform: rotateX(180deg);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 10px 12px 30px;
}

.tile-link:hover .tile-face {
    background: color-mix(in srgb, var(--accent) 88%, #fff);
}

.tile-icon {
    width: 48px;
    height: 48px;
    stroke-width: 1.1;
}
.tile--large .tile-icon { width: 96px; height: 96px; stroke-width: 0.9; }

/* Bookmarks zeigen den Anfangsbuchstaben statt eines Icons */
.tile-letter {
    font-size: 3rem;
    font-weight: 300;
    line-height: 1;
}

.tile-title {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 6px;
    font-size: 0.875rem;
    font-weight: 400;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Inhalte der Rückseite */
.live-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.live-label {
    font-size: 0.75rem;
    font-weight: 400;
    opacity: 0.85;
    margin-bottom: 2px;
}

.live-text {
    font-size: 0.875rem;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tile--medium .live-text { -webkit-line-clamp: 5; font-size: 0.8125rem; }

/* Listen auf der Rückseite (Notizen, Aufgaben) */
.live-list {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 4px;
}

.live-row {
    font-size: 0.875rem;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.live-row-main {
    font-weight: 600;
}

.live-row-extra {
    opacity: 0.85;
}

/* Einblenden beim Laden / Zurückkehren */
.group.is-entering .group-title,
.group.is-entering .tile {
    animation: tile-enter 520ms var(--ease-out) both;
    animation-delay: var(--delay, 0ms);
}

@keyframes tile-enter {
    from {
        opacity: 0;
        transform: translateX(80px);
    }
}

/* Vollbild-Öffnen: farbige Fläche wächst aus der Kachel */
.launch-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: #fff;
    transform-origin: 0 0;
    pointer-events: none;
}

.launch-overlay .icon {
    width: 96px;
    height: 96px;
    stroke-width: 0.9;
}

.start-footer {
    padding: 0 var(--edge) 18px;
}

.noscript-note {
    padding: 0 var(--edge);
    color: var(--text-muted);
}

/* Mobil: Gruppen untereinander, Kacheln füllen die Breite in vier Spalten */
@media (max-width: 700px) {
    :root { --edge: 16px; --gap: 8px; }

    .start {
        height: auto;
        min-height: 100vh;
    }

    /* Mobil steht die Uhr linksbündig unter dem Titel */
    .start-header {
        flex-direction: column;
        align-items: flex-start;
        padding-top: 28px;
    }

    .start-clock {
        align-items: flex-start;
        text-align: left;
    }

    .start-clock-time {
        font-size: 1.75rem;
    }

    .start-clock-date {
        font-size: 0.8125rem;
    }

    .groups {
        flex-direction: column;
        align-items: stretch;
        gap: 36px;
        overflow: visible;
        padding-top: 20px;
    }

    .groups::after { display: none; }

    .group {
        container-type: inline-size;
    }

    .group-grid {
        --unit: calc((100cqi - 3 * var(--gap)) / 4);
        grid-template-columns: repeat(4, 1fr);
        grid-auto-rows: var(--unit);
    }

    .start-footer {
        padding-top: 32px;
        padding-bottom: 24px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tile-link { transform: none; }
    .tile-flipper { transition: none; transform-style: flat; }
    .tile-back { transform: none; visibility: hidden; }
    .tile.is-flipped .tile-flipper { transform: none; }
    .tile.is-flipped .tile-back { visibility: visible; }
    .tile.is-flipped .tile-front { visibility: hidden; }
}
