:root {
    color-scheme: light dark;
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #1a1d23;
    --text-muted: #5a6270;
    --border: #dde1e7;
    --primary: #1d6fd6;
    --primary-text: #ffffff;
    --danger: #c0392b;
    --success: #1f8a4c;
    --home-color: #1d6fd6;
    --away-color: #d6551d;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { color: var(--primary); }

/* ---------- App shell (login/dashboard/sports/admin) ---------- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.app-header .brand {
    font-weight: 700;
    font-size: 1.1rem;
    text-decoration: none;
    color: var(--text);
}

.app-header nav a {
    margin-left: 1rem;
    text-decoration: none;
    color: var(--text-muted);
}

.app-header nav a:hover { color: var(--primary); }

.app-main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

h1 { margin-top: 0; }

.error {
    background: #fdecea;
    color: var(--danger);
    padding: 0.6rem 1rem;
    border-radius: 6px;
    border: 1px solid #f5c6c0;
}

.success {
    background: #e9f7ef;
    color: var(--success);
    padding: 0.6rem 1rem;
    border-radius: 6px;
    border: 1px solid #bfe8cf;
}

.auth-box {
    max-width: 360px;
    margin: 2rem auto;
    background: var(--surface);
    padding: 1.5rem;
    border-radius: 10px;
    border: 1px solid var(--border);
}

form.stacked-form, .auth-box form {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
    max-width: 420px;
}

form label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.single-entry-col {
    /* -1rem accounts for this item's share of .panel-columns' 2rem gap —
       without it, 40%+60% exactly fills the row with no room for the
       gap, which forces an unwanted wrap onto two full-width lines. */
    flex: 1 1 calc(40% - 1rem);
    min-width: 280px;
}

.bulk-entry-col {
    flex: 1 1 calc(60% - 1rem);
    min-width: 280px;
}

.bulk-import-form {
    max-width: none;
}

.bulk-import-form textarea {
    width: 100%;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.85rem;
    resize: vertical;
}

.team-field-row {
    display: flex;
    align-items: flex-end;
    gap: 0.8rem;
}

.team-field-row label.grow {
    flex: 1;
    min-width: 0;
}

.team-field-row label.color-field {
    flex: 0 0 auto;
}

.team-field-row input[type=color] {
    width: 3.4rem;
    height: 2.3rem;
    padding: 2px;
}

input, select, button {
    font: inherit;
}

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    padding: 0.5rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

button {
    cursor: pointer;
    border: none;
    border-radius: 6px;
    padding: 0.55rem 1rem;
    background: var(--primary);
    color: var(--primary-text);
}

button:hover { filter: brightness(1.05); }

.link-button {
    background: none;
    color: var(--danger);
    padding: 0;
    text-decoration: underline;
}

.inline-form { display: inline; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.data-table th, .data-table td {
    text-align: left;
    padding: 0.6rem 0.8rem;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: #eef1f5;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.status-ended {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: #eef1f5;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ---------- Admin control panel ---------- */

.public-link-row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.public-link-row .public-link {
    flex: 1 1 320px;
}

.public-link input {
    width: min(420px, 60vw);
}

.qr-code-block {
    margin-bottom: 1rem;
    flex: 0 0 auto;
}

.panel-columns {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 2rem;
}

.panel-columns > section {
    flex: 1 1 320px;
    min-width: 280px;
}

.team-names-form,
.schedule-form,
.penalties-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
}

.label-filter-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.label-filter {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.label-filter label {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.label-filter-row .inline-form {
    display: inline;
}

.qr-code-block #qr-code-container {
    width: 160px;
}

.qr-code-block #qr-code-container svg {
    width: 100%;
    height: auto;
    display: block;
    background: #ffffff;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.hint,
.qr-code-block .hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

.display-controls-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.sides-toggle {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
}

.display-size-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    margin-top: 1rem;
}

.size-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.size-control button {
    min-width: 2.2rem;
}

.size-control strong {
    min-width: 3.2rem;
    text-align: center;
}

.live-state {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 1.5rem;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin: 1.5rem 0;
}

/* Default left-to-right order: home, clock, away. When "Seiten tauschen"
   is active, mirrors the same left/right swap the public scoreboard
   uses, so the control panel matches what's actually shown on screen. */
.live-state .score-block[data-team="home"] { order: 1; }
.live-state .clock-block { order: 2; }
.live-state .score-block[data-team="away"] { order: 3; }

.live-state[data-swapped="true"] .score-block[data-team="home"] { order: 3; }
.live-state[data-swapped="true"] .score-block[data-team="away"] { order: 1; }

/* Keep the +/- buttons on the outer edge (away from the clock) no matter
   which side a team currently sits on — otherwise a swap leaves them
   pointing inward instead of following the block to the other side. */
.live-state[data-swapped="true"] .score-block[data-team="home"] { flex-direction: row-reverse; }
.live-state[data-swapped="true"] .score-block[data-team="away"] { flex-direction: row; }

.score-block {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.score-block[data-team="away"] {
    flex-direction: row-reverse;
}

.score-info {
    text-align: center;
}

.score-block .team-name {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.3rem;
}

.score-block .score {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.6rem;
}

.score-buttons {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
}

.score-buttons button {
    font-size: 1.2rem;
    width: 3rem;
}

.clock-block { text-align: center; }

.clock-block .clock {
    font-size: 2.5rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.clock-block .period {
    color: var(--text-muted);
    margin-bottom: 0.8rem;
}

.clock-controls, .period-controls {
    display: flex;
    gap: 0.4rem;
    justify-content: center;
    margin-top: 0.5rem;
    flex-wrap: wrap;
}

.primary-action {
    font-size: 1.05rem;
    font-weight: 700;
    padding: 0.6rem 1.2rem;
}

.clock-set {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.7rem;
}

.clock-set label {
    flex-direction: row;
    align-items: center;
    gap: 0.3rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.clock-set input[type=number] {
    width: 3.5rem;
    text-align: center;
}

.clock-block .hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
}

button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.penalty-add-table {
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.penalty-add-table th, .penalty-add-table td {
    padding: 0.4rem 0.9rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.penalty-add-table thead th {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
}

.penalty-add-table tbody th {
    text-align: left;
    color: var(--text);
    font-weight: 700;
    white-space: nowrap;
}

.penalty-add-table button {
    min-width: 2.6rem;
}

.penalty-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.penalty-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
}

.penalty-list li.empty {
    color: var(--text-muted);
    justify-content: flex-start;
}

/* --team-accent is set inline per item (assets/admin.js) from the game's
   configured home_color/away_color. */
.penalty-list li.penalty-item { border-left: 4px solid var(--team-accent, var(--home-color)); }

.penalty-list li button {
    background: var(--danger);
    padding: 0.3rem 0.6rem;
    font-size: 0.85rem;
}

/* ---------- Public scoreboard display ---------- */

.scoreboard-body {
    background: #0b0e14;
    color: #f5f7fa;
    height: 100vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.scoreboard {
    width: 100%;
    max-width: 1800px;
}

.teams-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: clamp(1rem, 4vw, 3rem);
}

.team {
    text-align: center;
}

/* Scoped to .teams-row (public scoreboard only): admin.php reuses the
   .team-name class for its own, differently-themed score-block heading,
   which must NOT get this dark badge look — that previously leaked
   through and produced barely-readable white-on-white text there. */
.teams-row .team-name {
    display: inline-flex;
    align-items: center;
    gap: 0.35em;
    font-size: clamp(1.1rem, 2.4vw, 2.2rem);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.6rem;
    max-width: 100%;
    word-break: break-word;
    /* Same badge look as the penalty badges: a dark, translucent fill so
       the text (always white) stays readable no matter how light or dark
       the team's chosen color is — only the border carries that color,
       set inline as --team-accent per game (assets/scoreboard.js). */
    color: #f5f7fa;
    background: rgba(255, 255, 255, 0.08);
    border: 3px solid var(--team-accent, rgba(255, 255, 255, 0.35));
    border-radius: 999px;
    padding: 0.35em 1.1em;
}

.home-icon {
    flex: 0 0 auto;
    width: 0.85em;
    height: 0.85em;
}

.team-score {
    /* --score-scale is set on <body> per game (assets/scoreboard.js), from
       score_size_percent chosen in the admin panel (default 1 = 100%). */
    font-size: calc(clamp(5rem, min(32vw, 52vh), 34rem) * var(--score-scale, 1));
    font-weight: 800;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.team-score.goal-pop {
    animation: sb-goal-pop 0.9s cubic-bezier(.36, 1.8, .4, 1);
}

@keyframes sb-goal-pop {
    0% { transform: scale(1); }
    35% { transform: scale(1.3); }
    65% { transform: scale(0.95); }
    100% { transform: scale(1); }
}

.center-info {
    text-align: center;
}

.pause-icon {
    display: block;
    margin: 0.3rem auto;
    width: 1.6rem;
    height: 1.6rem;
    color: #aab2c0;
}

.center-info .clock {
    /* --clock-scale is set on <body> per game (assets/scoreboard.js), from
       clock_size_percent chosen in the admin panel (default 1 = 100%). */
    font-size: calc(clamp(4.2rem, 15.6vw, 10.2rem) * var(--clock-scale, 1));
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.center-info .period {
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: #aab2c0;
    margin-top: 0.3rem;
}

.center-info .scheduled-start {
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    color: #aab2c0;
    margin-top: 0.5rem;
}

.center-info .next-game-link {
    margin-top: 0.5rem;
}

.center-info .next-game-link a {
    font-size: clamp(0.85rem, 2vw, 1.1rem);
    color: #aab2c0;
    text-decoration: underline;
}

.center-info .next-game-link a:hover {
    color: #fff;
}

/* "Endstand" is text, not a handful of digits — always sized on its own
   terms so it can't overflow, regardless of how large --clock-scale
   (Uhr-Grösse in the admin panel) has been set for the running clock. */
.center-info .clock.game-ended {
    font-size: clamp(1.8rem, 6vw, 4.5rem);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.penalties-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: clamp(1.5rem, 4vw, 3rem);
}

.penalties {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.penalties.home { justify-content: flex-start; }
.penalties.away { justify-content: flex-end; }

.penalty-badge {
    background: rgba(255, 255, 255, 0.08);
    /* --team-accent is set inline per badge (assets/scoreboard.js) from the
       game's home_color/away_color; .penalty-ending below still overrides
       it with a literal color since it's not referencing the variable. */
    border: 2px solid var(--team-accent, rgba(255, 255, 255, 0.2));
    border-radius: 999px;
    padding: 0.3rem 0.9rem;
    font-size: clamp(0.9rem, 1.8vw, 1.3rem);
    font-variant-numeric: tabular-nums;
}

/* Solid red, not blinking: the badge is rebuilt from scratch on every
   500ms poll, which kept restarting a CSS blink animation from frame
   zero — so it never actually appeared to blink. */
.penalty-badge.penalty-ending {
    background: rgba(224, 82, 82, 0.55);
    border-color: #e05252;
    color: #ffffff;
}

.penalty-list li.penalty-ending {
    background: #fbdada;
    border-color: #e05252;
}

.goal-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    /* fully opaque on purpose: while shown, it must completely hide the
       score/clock behind it, not just dim them */
    background: radial-gradient(circle at 50% 45%, #1c2436 0%, #05070a 75%);
    opacity: 0;
    pointer-events: none;
    z-index: 50;
    text-align: center;
    overflow: hidden;
}

.goal-overlay.show {
    animation: sb-goal-overlay 2.3s ease-out forwards;
}

.goal-overlay .goal-text {
    font-size: clamp(3.5rem, 14vw, 10rem);
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #ffffff;
}

.goal-overlay .goal-team {
    display: inline-flex;
    font-size: clamp(1.3rem, 4vw, 2.5rem);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    /* Same readable badge as the team names: always-white text, the
       scoring team's color (--team-accent, set inline in scoreboard.js)
       only used for the border. */
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
    border: 3px solid var(--team-accent, rgba(255, 255, 255, 0.35));
    border-radius: 999px;
    padding: 0.25em 0.9em;
}

@keyframes sb-goal-overlay {
    0% { opacity: 0; transform: scale(0.92); }
    12% { opacity: 1; transform: scale(1); }
    78% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(1); }
}

.confetti-layer {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.confetti-piece {
    position: absolute;
    top: -20px;
    width: 9px;
    height: 15px;
    opacity: 0.95;
    animation-name: sb-confetti-fall;
    animation-timing-function: cubic-bezier(.25, .46, .45, .94);
    animation-fill-mode: forwards;
}

@keyframes sb-confetti-fall {
    0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
    100% { transform: translate(var(--drift, 0px), 110vh) rotate(var(--spin, 360deg)); opacity: 0.85; }
}

@media (max-width: 640px) {
    .teams-row { grid-template-columns: 1fr; gap: 1rem; }
    .penalties-row { grid-template-columns: 1fr; }
    .penalties.home, .penalties.away { justify-content: center; }
}

/* On a beamer/TV the content always fits exactly one screen, so the body
   is fixed-height with no scrolling. On a phone, many active penalties can
   push the content taller than the viewport — switch to a normal
   top-aligned, scrollable page so nothing gets cut off. Keyed off both
   width (portrait phones) and height (landscape phones, which are wide but
   short) so it applies in either orientation. */
@media (max-width: 640px), (max-height: 500px) and (orientation: landscape) {
    .scoreboard-body {
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        align-items: flex-start;
        padding-top: 2rem;
        padding-bottom: 2rem;
    }
}
