/* ==========================================================================
   Spielplan - oeffentliches Frontend (Mobile First)
   Bewusst handgeschrieben und klein, damit die PWA offline schnell laedt.
   ========================================================================== */

/*
 * Farben des Radebeuler Handballvereins, abgenommen von radebeuler-hv.de:
 *   #af1e1b  Vereinsrot (Flächen, Ränder, Links)
 *   #212934  Anthrazit (Überschriften, Auswärts-Kennzeichnung)
 *   #4a4e57  Fließtext
 *   #e0e0e0  Trennlinien und helle Flächen
 */
:root {
    --accent:        #af1e1b;
    --accent-soft:   #fbeceb;
    --accent-ink:    #ffffff;
    --highlight:     #af1e1b;
    --highlight-soft:#fbeceb;
    --away:          #212934;
    --away-soft:     #eceef1;

    /* Die Kopfzeile bleibt in beiden Modi im Vereinsrot. */
    --header-bg:     #af1e1b;
    --header-ink:    #ffffff;

    --bg:            #f4f5f7;
    --surface:       #ffffff;
    --surface-2:     #f7f8f9;
    --border:        #e0e0e0;
    --ink:           #212934;
    --ink-soft:      #4a4e57;
    --ink-faint:     #8b8f98;

    --ok:            #15803d;
    --warn:          #b45309;
    --danger:        #af1e1b;

    --radius:        14px;
    --radius-sm:     9px;
    --shadow:        0 1px 2px rgba(16, 20, 30, .06), 0 4px 14px rgba(16, 20, 30, .06);
    --tap:           44px;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Das Vereinsrot aufgehellt, damit es auf dunklem Grund lesbar bleibt. */
        --accent:        #e8635f;
        --accent-soft:   #3a1917;
        --accent-ink:    #ffffff;
        --highlight:     #e8635f;
        --highlight-soft:#3a1917;
        --away:          #c3cad6;
        --away-soft:     #262d38;

        --bg:            #14171c;
        --surface:       #1c2027;
        --surface-2:     #222730;
        --border:        #333944;
        --ink:           #e7eaf0;
        --ink-soft:      #aeb4c0;
        --ink-faint:     #848b97;

        --danger:        #e8635f;
        --shadow:        0 1px 2px rgba(0, 0, 0, .4);
    }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.45;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.2; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 1em; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* --- Grundgeruest ------------------------------------------------------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: .7rem;
    min-height: 56px;
    padding: .5rem 1rem;
    padding-top: calc(.5rem + env(safe-area-inset-top));
    background: var(--header-bg);
    color: var(--header-ink);
    box-shadow: var(--shadow);
}
.app-header a { color: inherit; }

/* Vereinslogo links, auf hellem Grund damit dunkle Wappen sichtbar bleiben. */
.app-header__logo {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; height: 40px;
    padding: 3px;
    border-radius: 8px;
    background: #fff;
}
.app-header__logo img { width: 100%; height: 100%; object-fit: contain; }

/* Der Textblock darf schrumpfen, damit lange Namen den Kopf nicht sprengen. */
.app-header__text  { min-width: 0; }
.app-header__title {
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.15;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-header__sub   { font-size: .78rem; opacity: .85; }
.app-header__spacer{ margin-left: auto; }

.app-header__back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    margin-left: -.35rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, .14);
}

.app-main {
    /* Die Mannschaftsseite setzt --breite hoch und nutzt zwei Spalten. */
    max-width: var(--breite, 760px);
    margin: 0 auto;
    padding: 1rem 1rem 3rem;
    padding-bottom: calc(3rem + env(safe-area-inset-bottom));
}

.app-footer {
    max-width: var(--breite, 760px);
    margin: 0 auto;
    padding: 0 1rem 2rem;
    color: var(--ink-faint);
    font-size: .8rem;
    text-align: center;
}

/* --- Kacheln der Mannschaften ------------------------------------------ */

.team-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .75rem;
}
@media (min-width: 560px) {
    .team-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

.team-tile {
    position: relative;
    min-height: 150px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.team-tile:hover { border-color: var(--accent); }

/* Der Link fuellt die Kachel, das Herz liegt darueber. */
.team-tile__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
    height: 100%;
    padding: 1rem .7rem .9rem;
    color: inherit;
    text-align: center;
}
.team-tile__link:hover { text-decoration: none; }
.team-tile__link::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
}

.team-tile__logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--surface-2);
    overflow: hidden;
}
/* Wappen sind fuer hellen Grund gezeichnet - sonst verschwinden dunkle
   Umrisse im Dunkelmodus. Die Ersatz-Initialen brauchen das nicht. */
.team-tile__logo--bild { background: #fff; padding: 6px; }
.team-tile__logo img { width: 100%; height: 100%; object-fit: contain; }
.team-tile__logo span { font-size: 1.25rem; font-weight: 700; color: var(--ink-soft); }

.team-tile__name { font-weight: 600; font-size: .95rem; }
.team-tile__meta { font-size: .78rem; color: var(--ink-soft); }

/* --- Favoriten-Herz ----------------------------------------------------- */

.fav {
    position: absolute;
    z-index: 1;
    top: .1rem; right: .1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap); height: var(--tap);
    padding: 0;
    border: 0;
    background: none;
    color: var(--ink-faint);
    cursor: pointer;
}
.fav svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
.fav[aria-pressed="true"] { color: var(--highlight); }
.fav[aria-pressed="true"] svg { fill: currentColor; }

/* --- Karten und Listen -------------------------------------------------- */

.card {
    padding: 1rem;
    margin-bottom: .75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}
.card--accent { border-left: 4px solid var(--highlight); }

.section-title {
    margin: 1.6rem 0 .6rem;
    font-size: .8rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.empty {
    padding: 2.5rem 1rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    color: var(--ink-soft);
    text-align: center;
}

/* --- Buttons ------------------------------------------------------------ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    min-height: var(--tap);
    padding: .55rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--block   { width: 100%; }
.btn--ghost   { background: transparent; }

/* --- Formulare (Login, Setup) ------------------------------------------ */

.form-card {
    max-width: 420px;
    margin: 2.5rem auto;
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.field { margin-bottom: 1rem; }
.field > label {
    display: block;
    margin-bottom: .3rem;
    font-size: .85rem;
    font-weight: 600;
    color: var(--ink-soft);
}
.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: var(--tap);
    padding: .55rem .7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
    font: inherit;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}
.field__hint { margin-top: .3rem; font-size: .78rem; color: var(--ink-faint); }

/* --- Toasts ------------------------------------------------------------- */

.toasts {
    position: fixed;
    left: 50%;
    bottom: calc(1rem + env(safe-area-inset-bottom));
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    width: min(420px, calc(100vw - 2rem));
    transform: translateX(-50%);
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .7rem .9rem;
    border-radius: var(--radius-sm);
    background: #1f2937;
    color: #fff;
    font-size: .9rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
    animation: toast-in .18s ease-out;
}
.toast--success { background: var(--ok); }
.toast--error   { background: var(--danger); }
.toast--info    { background: #1f2937; }
.toast button {
    margin-left: auto;
    border: 0;
    background: none;
    color: inherit;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    opacity: .8;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- Kleinkram ---------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: .12rem .5rem;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .02em;
}
.badge--highlight { background: var(--away-soft); color: var(--away); }

.muted { color: var(--ink-soft); }
.text-center { text-align: center; }
.stack > * + * { margin-top: .75rem; }
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* --- Spielzeile ---------------------------------------------------------- */

.game {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    padding: .7rem 0;
    border-bottom: 1px solid var(--border);
}
.game:last-child { border-bottom: 0; }
.game--off { opacity: .55; }

.game__date {
    flex: 0 0 3.4rem;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.2;
}
.game__day  { font-weight: 700; font-size: .9rem; }
.game__time { font-size: .8rem; color: var(--ink-soft); }

.game__main { flex: 1 1 auto; min-width: 0; }

.game__opponent {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-weight: 600;
    font-size: .95rem;
}
.game__logo { width: 22px; height: 22px; object-fit: contain; flex: 0 0 auto; }

.game__meta { font-size: .8rem; color: var(--ink-soft); }
.game__meta--warn { color: var(--danger); font-weight: 600; }

.game__score {
    flex: 0 0 auto;
    align-self: center;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* --- Nächstes Spiel ------------------------------------------------------- */

.next { display: flex; align-items: center; gap: .9rem; margin-bottom: .8rem; }
.next__logo { width: 54px; height: 54px; object-fit: contain; }
.next__opponent { font-size: 1.15rem; font-weight: 700; line-height: 1.25; }
.next__when { font-size: .88rem; color: var(--ink-soft); }

.facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .3rem .9rem;
    margin: 0;
    font-size: .88rem;
}
.facts dt { color: var(--ink-faint); }
.facts dd { margin: 0; }

details > summary { list-style: revert; }

/* --- Kachel: naechstes Spiel --------------------------------------------- */

.team-tile__meta {
    margin-top: -.15rem;
    font-size: .75rem;
    line-height: 1.3;
    color: var(--ink-soft);
}
.team-tile__opponent {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    color: var(--ink-faint);
}

/* --- Hinweis zum Installieren --------------------------------------------- */

.install-hint {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .7rem .9rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-left: 4px solid var(--highlight);
    border-radius: var(--radius-sm);
    background: var(--surface);
    font-size: .85rem;
    color: var(--ink-soft);
    box-shadow: var(--shadow);
}
.install-hint__action {
    flex: 0 0 auto;
    padding: .35rem .7rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-ink);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.install-hint__close {
    flex: 0 0 auto;
    margin-left: auto;
    padding: 0 .2rem;
    border: 0;
    background: none;
    color: var(--ink-faint);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
}

/* --- Mannschaftsseite: zwei Spalten auf dem Rechner ---------------------- */

.seiten-raster { display: grid; gap: 1rem; }

/* Auf dem Handy zuerst das nächste Spiel, dann der Plan, dann die Knöpfe. */
.seiten-raster__naechstes { order: 1; }
.seiten-raster__plan      { order: 2; }
.seiten-raster__aktionen  { order: 3; }
/* Der erste Block der Seitenleiste braucht keinen eigenen Abstand nach oben. */
.seiten-raster__aktionen > .stack:first-child { margin-top: 0; }

@media (min-width: 900px) {
    .seiten-raster {
        grid-template-columns: minmax(0, 7fr) minmax(0, 3fr);
        grid-template-areas:
            "plan naechstes"
            "plan aktionen";
        /* Die erste Zeile ist genau so hoch wie das Panel. Sonst verteilt sich
           die Hoehe des langen Spielplans auf beide Zeilen und schiebt die
           Knoepfe weit nach unten. */
        grid-template-rows: min-content 1fr;
        align-items: start;
        /* Waagerecht Luft zwischen den Spalten, senkrecht nur wenig - die
           Knoepfe sollen direkt unter dem Panel sitzen. Der Spielplan links
           ueberspannt beide Zeilen und merkt davon nichts. */
        column-gap: 1.25rem;
        row-gap: .75rem;
    }
    .seiten-raster__plan      { grid-area: plan; }
    .seiten-raster__naechstes { grid-area: naechstes; }
    .seiten-raster__aktionen  { grid-area: aktionen; }
}

/* --- Dialog vor dem Drucken ---------------------------------------------- */

dialog.druck-dialog {
    width: min(440px, calc(100vw - 2rem));
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
dialog.druck-dialog::backdrop { background: rgba(15, 23, 42, .45); }

.druck-dialog__kopf {
    display: flex;
    align-items: center;
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--border);
}
.druck-dialog__zu {
    margin-left: auto;
    width: 2rem; height: 2rem;
    border: 0;
    background: none;
    color: var(--ink-faint);
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}
.druck-dialog__inhalt { padding: 1rem; }
.druck-dialog__haken {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .45rem 0;
    font-size: .9rem;
}
.druck-dialog__fuss {
    display: flex;
    gap: .5rem;
    justify-content: flex-end;
    padding: .9rem 1rem;
    border-top: 1px solid var(--border);
}
