* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

@media (min-width: 1600px) {
    .container { max-width: 1400px; }
}

@media (min-width: 2000px) {
    .container { max-width: 1700px; }
}

@media (min-width: 2800px) {
    .container { max-width: 2200px; }
}

.top-nav {
    padding: 12px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 16px;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

.top-nav a {
    color: #2563eb;
    text-decoration: none;
    font-size: 0.95rem;
}

.top-nav a:hover {
    text-decoration: underline;
}

.top-nav a.active {
    font-weight: 700;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 2px solid #2563eb;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.5rem;
    color: #1e40af;
}

nav a {
    margin-left: 16px;
    color: #2563eb;
    text-decoration: none;
}

nav a:hover {
    text-decoration: underline;
}

.memo {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

/* Forms */
.login-form {
    max-width: 400px;
    margin: 60px auto;
    background: white;
    padding: 32px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.login-form h2 {
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.2s;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #6b7280;
    color: white;
}

.btn-secondary:hover {
    background: #4b5563;
}

.btn-success {
    background: #16a34a;
    color: white;
}

.btn-success:hover {
    background: #15803d;
}

.btn-danger {
    background: #dc2626;
    color: white;
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-small {
    padding: 6px 12px;
    font-size: 0.85rem;
}

.btn-disabled {
    background: #e5e7eb;
    color: #9ca3af;
    cursor: not-allowed;
}

.btn-icon {
    padding: 4px 10px;
    font-size: 1.1rem;
    line-height: 1;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-success {
    background: #dcfce7;
    color: #166534;
}

.badge-warning {
    background: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background: #fee2e2;
    color: #991b1b;
}

.badge-default {
    background: #f3f4f6;
    color: #6b7280;
}

/* Brain ring checkbox */
.brain-ring-section {
    background: white;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.brain-ring-section label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-size: 0.95rem;
}

.brain-ring-section input[type="checkbox"] {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
    cursor: pointer;
}

/* Games list */
.games-list {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.games-list h3 {
    margin-bottom: 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

tbody tr:nth-child(even) {
    background: #f9fafb;
}

tbody tr.my-team,
tbody tr.my-team:nth-child(even) {
    background: #fef3c7;
}

th, td {
    text-align: left;
    padding: 12px;
    border-bottom: 1px solid #e5e7eb;
}

th {
    font-weight: 600;
    color: #6b7280;
    font-size: 0.85rem;
    text-transform: uppercase;
}

/* Team info */
.team-info-section {
    background: white;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.team-info-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.team-info-form .form-group {
    margin-bottom: 0;
}

.team-info-form input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
}

.team-info-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.team-info-form input:disabled {
    background: #f3f4f6;
    color: #6b7280;
}

/* Lineup editor */
.lineup-page h2 {
    margin-bottom: 8px;
}

.hint {
    color: #6b7280;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.editor-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.panel {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.panel h3 {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e5e7eb;
}

.lineup-panel h3 {
    border-bottom-color: #2563eb;
}

.candidates-panel h3 {
    border-bottom-color: #16a34a;
}

.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    margin-bottom: 4px;
    background: #f9fafb;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.player-card:hover {
    background: #f3f4f6;
}

.player-info {
    font-size: 0.9rem;
}

.empty {
    color: #9ca3af;
    font-style: italic;
    padding: 20px 0;
    text-align: center;
}

.add-by-id {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

.add-by-id h4 {
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: #6b7280;
}

.add-by-id input {
    width: 100%;
    margin-bottom: 4px;
}

/* Search results */
#search-results {
    margin-top: 4px;
}

.search-result {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    margin-bottom: 2px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
}

.search-result:hover {
    background: #dcfce7;
}

/* Town autocomplete */
.autocomplete-wrap {
    position: relative;
}

#town-results {
    position: absolute;
    z-index: 10;
    background: white;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    width: 100%;
    margin-top: 2px;
}

.town-result {
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid #f3f4f6;
}

.town-result:last-child {
    border-bottom: none;
}

.search-empty {
    color: #9ca3af;
    font-size: 0.85rem;
    font-style: italic;
    padding: 4px 0;
}

.input-small {
    padding: 6px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    width: 120px;
}

.input-small:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Lineup actions */
.lineup-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.submitted-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* Error */
.error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

/* HTMX loading indicator — dim buttons of the form that issued the
   in-flight request. Deliberately NOT the bare descendant selector
   `.htmx-request .btn`: background polling containers (#si-standings,
   #results-data) also get the htmx-request class every refresh tick,
   and dimming every button on the page each poll reads as blinking. */
form.htmx-request .btn,
.btn.htmx-request {
    opacity: 0.6;
    pointer-events: none;
}

/* Request form */
.request-page {
    max-width: 600px;
    margin: 0 auto;
}

.request-page h2 {
    margin-bottom: 16px;
}

.request-form {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.request-form .form-group {
    margin-bottom: 16px;
}

.request-form select,
.request-form input[type="number"],
.request-form input[type="text"],
.request-form textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

.request-form select:focus,
.request-form input:focus,
.request-form textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.request-form textarea {
    resize: vertical;
}

.request-form .btn {
    margin-right: 8px;
}

.success-message,
.warning-message {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.warning-message {
    background: #fffbeb;
    color: #92400e;
    border-color: #fcd34d;
}

/* Registration form */
.register-page {
    max-width: 640px;
    margin: 0 auto;
}

.register-form {
    background: white;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.reg-section {
    margin-bottom: 24px;
}

.reg-section h3 {
    margin-bottom: 12px;
    color: #1e40af;
    font-size: 1.05rem;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 6px;
}

.register-form .form-group {
    margin-bottom: 14px;
}

.register-form input[type="text"],
.register-form input[type="number"],
.register-form input[type="email"] {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
}

.register-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.register-form small {
    color: #6b7280;
    font-size: 0.85rem;
    display: block;
    margin-top: 4px;
}

.reg-field {
    position: relative;
}

.reg-autocomplete {
    position: absolute;
    z-index: 10;
    background: white;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    width: 100%;
    margin-top: 2px;
    max-height: 260px;
    overflow-y: auto;
}

.reg-autocomplete:empty {
    display: none;
}

.reg-option {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    display: flex;
    flex-direction: column;
}

.reg-option:last-child {
    border-bottom: none;
}

.reg-option:hover {
    background: #eff6ff;
}

.reg-option-main {
    font-size: 0.95rem;
}

.reg-option-sub {
    font-size: 0.8rem;
    color: #6b7280;
}

/* Teams list / stats */
.teams-page {
    margin: 0 auto;
}

.teams-total {
    text-align: center;
    font-size: 1.1rem;
    margin: 0 0 20px;
}

.teams-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.stats-card {
    background: white;
    border-radius: 12px;
    padding: 16px 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    margin-bottom: 16px;
}

.stats-card h3 {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #2563eb;
    color: #1e40af;
    font-size: 1.05rem;
}

.stats-card table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.stats-card th,
.stats-card td {
    padding: 6px 8px;
    border-bottom: 1px solid #f3f4f6;
    text-align: left;
}

.stats-card th.num,
.stats-card td.num {
    text-align: right;
}

.stats-card tr:last-child td {
    border-bottom: none;
}

@media (max-width: 640px) {
    .teams-stats { grid-template-columns: 1fr; }
}

.admin-regs {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.admin-regs th,
.admin-regs td {
    padding: 6px 8px;
    border-bottom: 1px solid #f3f4f6;
    text-align: left;
    vertical-align: top;
}

.admin-regs tr:hover td {
    background: #f9fafb;
}

.nowrap {
    white-space: nowrap;
}

.invite-box {
    display: flex;
    gap: 8px;
    align-items: stretch;
    margin-top: 8px;
}

.invite-box input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-family: monospace;
    font-size: 0.9rem;
    background: #f9fafb;
}

.invite-box input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

/* Generic card layout (used by /me and registration success) */
.card {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.card h3 {
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e5e7eb;
}

.me-page .card form .form-group {
    margin-bottom: 12px;
}

.me-page .card input[type="password"],
.me-page .card input[type="number"],
.me-page .card input[type="text"],
.me-page .card input[type="email"] {
    width: 100%;
    max-width: 360px;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
}

.kv {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 4px 16px;
    font-size: 0.95rem;
}

.kv dt {
    color: #6b7280;
}

.invites-table {
    width: 100%;
    font-size: 0.9rem;
}

.invites-table code {
    font-size: 0.8rem;
    background: #f3f4f6;
    padding: 2px 4px;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 768px) {
    .editor-panels {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 12px;
    }

    .top-nav {
        padding: 8px 12px;
        gap: 10px;
        font-size: 0.85rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    header h1 {
        font-size: 1.2rem;
    }

    /* Generic stacked schedule rows (already mobile-friendly) */
    .schedule-row {
        flex-direction: column;
        gap: 2px;
    }
    .schedule-row .time {
        min-width: unset;
    }

    /* Cards pull their padding in */
    .card,
    .stats-card,
    .games-list,
    .brain-ring-section,
    .team-info-section,
    .register-form,
    .login-form {
        padding: 14px 16px;
    }

    h2 {
        font-size: 1.25rem;
    }

    /* Tables: wrap onto two rows per cell, shrink fonts and padding */
    table {
        font-size: 0.85rem;
    }
    th, td {
        padding: 6px 6px;
    }
    .admin-regs,
    .stats-card table {
        font-size: 0.8rem;
    }
    .admin-regs th,
    .admin-regs td,
    .stats-card th,
    .stats-card td {
        padding: 4px 5px;
    }

    /* Teams stats grid already stacks; let venue text breathe */
    .venue {
        padding: 12px;
        font-size: 0.95rem;
    }

    /* Hero (festival landing) stacks image + title vertically */
    .hero-title {
        flex-direction: column;
        gap: 10px;
    }
    .hero h1 {
        font-size: 1.5rem;
    }
    .logo {
        width: 60px;
        height: 60px;
    }

    /* Registration success: long invite URL shouldn't stretch the card */
    .invite-box {
        flex-direction: column;
    }
    .invite-box input {
        font-size: 0.75rem;
    }

    /* Buttons sized for thumbs */
    .btn {
        padding: 8px 14px;
        font-size: 0.9rem;
    }
    .btn-small {
        padding: 5px 10px;
        font-size: 0.8rem;
    }
}

/* --- Festival landing page (ported from static/umlaut2026/index.html) --- */

.festival-main .hero {
    text-align: center;
    padding: 40px 0 20px;
}

.festival-main .hero-title {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.festival-main .logo {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
}

.festival-main .hero h1 {
    font-size: 2.2rem;
    color: #1e40af;
    margin-bottom: 8px;
}

.festival-main .hero .subtitle {
    font-size: 1.1rem;
    color: #6b7280;
}

.festival-main .venue {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 24px;
    text-align: center;
    font-size: 1rem;
}

.festival-main .venue strong { color: #1e40af; }

.festival-main .calendar-link {
    display: inline-block;
    margin-top: 8px;
    color: #2563eb;
    text-decoration: none;
    font-size: 0.95rem;
}

.festival-main .calendar-link:hover { text-decoration: underline; }

.festival-main .links-section {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.festival-main .links-section h2 {
    font-size: 1.2rem;
    color: #1e40af;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #2563eb;
}

.festival-main .links-section a {
    display: block;
    padding: 8px 0;
    color: #2563eb;
    text-decoration: none;
    border-bottom: 1px solid #f3f4f6;
}

.festival-main .links-section a:last-child { border-bottom: none; }
.festival-main .links-section a:hover { text-decoration: underline; }

.festival-main .roster-cta {
    display: block;
    text-align: center;
    background: #2563eb;
    color: white !important;
    padding: 14px 24px;
    border-radius: 8px;
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 12px;
    text-decoration: none !important;
}

.festival-main .roster-cta:hover {
    background: #1d4ed8;
}

.festival-main .schedule-card,
.festival-main .day {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.festival-main .schedule-card h2,
.festival-main .day h2 {
    font-size: 1.2rem;
    color: #1e40af;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #2563eb;
}

.festival-main .schedule-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    gap: 16px;
}

.festival-main .schedule-row:last-child { border-bottom: none; }

.festival-main .schedule-row .time {
    font-weight: 600;
    color: #2563eb;
    min-width: 120px;
    flex-shrink: 0;
}

.festival-main .schedule-row .event { flex: 1; }

@media (max-width: 600px) {
    .festival-main .schedule-row { flex-direction: column; gap: 2px; }
    .festival-main .schedule-row .time { min-width: unset; }
}

.festival-main .schedule-card table.google-sheet {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.festival-main .schedule-card table.google-sheet th,
.festival-main .schedule-card table.google-sheet td {
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    text-align: left;
    vertical-align: top;
}

.festival-main .schedule-card table.google-sheet tr:last-child td {
    border-bottom: none;
}

/* First column (time) — match the old `.time` style. */
.festival-main .schedule-card table.google-sheet td:first-child {
    font-weight: 600;
    color: #2563eb;
    min-width: 120px;
    width: 140px;
    padding-right: 16px;
}

/* Single-cell "section" rows (day separators like "Пятница, 21.08.2026"). */
.festival-main .schedule-card tr.sheet-section td {
    color: #1e40af;
    font-weight: 600;
    font-size: 1.05rem;
    padding-top: 16px;
    padding-bottom: 8px;
    border-bottom: 2px solid #2563eb;
}

.festival-main .schedule-card table.google-sheet th {
    color: #1e40af;
    font-weight: 600;
}

@media (max-width: 600px) {
    .festival-main .schedule-card table.google-sheet td:first-child {
        width: auto;
        min-width: 0;
        display: block;
        padding-bottom: 0;
        border-bottom: none;
    }
    .festival-main .schedule-card table.google-sheet td {
        display: block;
    }
}

.festival-main .doc-content {
    margin-top: 8px;
}

.festival-main .festival-switcher {
    text-align: center;
    margin-bottom: 16px;
    color: #6b7280;
    font-size: 0.95rem;
}

.festival-main .festival-switcher a,
.festival-main .festival-switcher strong {
    margin: 0 6px;
    color: #2563eb;
    text-decoration: none;
}

.festival-main .festival-switcher strong { color: #1e40af; }
.festival-main .festival-switcher a:hover { text-decoration: underline; }

@media (max-width: 600px) {
    .festival-main .hero-title { flex-direction: column; gap: 10px; }
}

/* --- Event / KVRM page --- */

.festival-main .event-standings {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
    table-layout: fixed;
}

.festival-main .event-standings th,
.festival-main .event-standings td {
    padding: 6px 10px;
    border-bottom: 1px solid #f3f4f6;
    text-align: left;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.festival-main .event-standings td.event-mark,
.festival-main .event-standings th.event-mark {
    padding: 4px 2px;
    text-align: center;
    vertical-align: middle;
}

.festival-main .event-standings th {
    color: #1e40af;
    font-weight: 600;
    border-bottom-width: 2px;
    border-bottom-color: #2563eb;
}

.festival-main .event-standings td.num,
.festival-main .event-standings th.num {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Team/player name columns keep a readable minimum width — numeric and
   question columns can't crush them; the wrapper scrolls instead.
   NOTE: `min-width` alone does nothing under `table-layout: fixed`
   (column sizing only reads `width` from the col / first-row cell), so
   `width` does the real work there; `min-width` covers auto-layout
   tables (brain matrix). Extra space on wide screens still flows
   mostly to this column. */
.festival-main .event-standings th.name-col,
.festival-main .event-standings td.name-col,
.br-group-matrix th.br-team,
.br-group-matrix td.br-team {
    width: 180px;
    min-width: 180px;
}

.festival-main .event-stage-header {
    cursor: pointer;
    user-select: none;
    color: #1e40af;
}

.festival-main .event-stage-header:hover {
    background: #eff6ff;
}

.festival-main .event-stage-header .event-stage-caret {
    color: #6b7280;
    transition: transform 0.15s ease;
    display: inline-block;
}

.festival-main .event-stage-header.open .event-stage-caret {
    transform: rotate(180deg);
}

.festival-main .event-stage-q {
    font-weight: 400;
}

.festival-main .event-mark-box {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    margin: 0 auto;
}

.festival-main .event-mark-ok {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: #bbf7d0;
    color: #14532d;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.85rem;
    line-height: 1;
}

.festival-main .event-mark-wrong {
    width: 7px;
    height: 7px;
    background: #fca5a5;
    border-radius: 50%;
}

.festival-main .event-mark-struck {
    width: 7px;
    height: 22px;
    background: #fca5a5;
    border-radius: 2px;
}

.event-standings .team-flag {
    margin-left: 4px;
    font-size: 0.95em;
    line-height: 1;
}

/* --- Mobile: standings table ---------------------------------------------
   The desktop layout uses `table-layout: fixed` with a colgroup that sums
   to ~700 px, which on a phone viewport (~360 px) starves the auto-sized
   team column to 0 width and the names disappear. Below 720 px we let the
   browser size columns by content, drop padding + font a notch, and let
   the wrapper scroll sideways. Nothing is hidden: every column (points,
   rating, city, actions) stays reachable by scrolling. */
@media (max-width: 720px) {
    .festival-main .event-standings {
        table-layout: auto;
        font-size: 0.85rem;
    }
    .festival-main .event-standings th,
    .festival-main .event-standings td {
        padding: 4px 6px;
    }
    .festival-main .event-standings col {
        width: auto !important;
    }
}

@media (max-width: 480px) {
    .festival-main .event-standings {
        font-size: 0.78rem;
    }
    .festival-main .event-standings th,
    .festival-main .event-standings td {
        padding: 3px 4px;
    }
    .festival-main .event-standings td.event-mark,
    .festival-main .event-standings th.event-mark {
        padding: 2px 1px;
    }
}

/* --- Mobile: container + header + nav -----------------------------------
   Pull viewport padding down so the standings table gets as much width as
   possible. Top-nav links wrap on a phone today; force compact spacing
   so the wrap costs less vertical real estate. */
@media (max-width: 720px) {
    .container {
        padding: 12px;
    }
    header {
        padding: 8px 0 12px;
    }
    header h1 {
        font-size: 1.4rem;
    }
    .top-nav {
        padding: 8px 12px;
        gap: 8px 12px;
        font-size: 0.9rem;
    }
    .schedule-card {
        padding: 12px;
    }
    .festival-main h2 {
        font-size: 1.1rem;
        margin: 0 0 8px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 8px;
    }
    .top-nav {
        padding: 4px 8px;
        gap: 4px 10px;
        font-size: 0.85rem;
    }
    header h1 {
        font-size: 1.2rem;
    }
    .schedule-card {
        padding: 10px;
    }
}

/* Three-stripe German flag rendered in pure CSS — emoji flags don't
   render on Chrome/Windows so we draw it ourselves. 3:5 ratio. */
.team-flag-de {
    display: inline-block;
    width: 18px;
    height: 11px;
    margin-left: 6px;
    vertical-align: -1px;
    background: linear-gradient(
        to bottom,
        #000 0,
        #000 33.33%,
        #d00 33.33%,
        #d00 66.67%,
        #fc0 66.67%,
        #fc0 100%
    );
    border: 1px solid rgba(0, 0, 0, 0.18);
    border-radius: 1px;
}

.festival-main .festival-number-input {
    width: 110px;
    text-align: right;
}

.festival-main .festival-number-input.conflict,
.festival-main td.festival-number-conflict {
    background: #fef2f2;
    color: #b91c1c;
}

.festival-main .festival-number-input.conflict {
    border-color: #ef4444;
}

.festival-main .event-roster-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.festival-main .event-roster-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid #f3f4f6;
}

.festival-main .event-roster-list li:last-child {
    border-bottom: none;
}

/* Rows with name + meta + actions: the list owns four shared columns
   and each row is a subgrid, so names, meta and buttons line up across
   rows (the flex default spaces each row on its own, so they drift). */
.festival-main .event-roster-list.roster-cols {
    display: grid;
    grid-template-columns: minmax(0, max-content) minmax(0, 1fr) auto auto;
    column-gap: 12px;
}
.festival-main .event-roster-list.roster-cols li {
    display: grid;
    grid-template-columns: subgrid;
    grid-column: 1 / -1;
}
@media (max-width: 600px) {
    /* Narrow: meta goes under the name; buttons span both rows. */
    .festival-main .event-roster-list.roster-cols {
        grid-template-columns: minmax(0, 1fr) auto auto;
    }
    .festival-main .event-roster-list.roster-cols li {
        row-gap: 2px;
    }
    .festival-main .event-roster-list.roster-cols li > :first-child {
        grid-column: 1;
        grid-row: 1;
    }
    .festival-main .event-roster-list.roster-cols li > small {
        grid-column: 1;
        grid-row: 2;
    }
    .festival-main .event-roster-list.roster-cols li > .btn,
    .festival-main .event-roster-list.roster-cols li > form {
        grid-row: 1 / span 2;
    }
}

.festival-main .host-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.festival-main .host-arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #eff6ff;
    color: #1e40af;
    text-decoration: none;
    font-size: 1.4rem;
    border: 1px solid #bfdbfe;
}

.festival-main .host-arrow:hover {
    background: #dbeafe;
}

.festival-main .host-arrow.disabled {
    background: #f3f4f6;
    color: #d1d5db;
    border-color: #e5e7eb;
    cursor: not-allowed;
}

.festival-main .host-q-form input {
    font-size: 1.4rem;
    font-weight: 600;
    width: 80px;
    text-align: center;
    padding: 6px 8px;
}

.festival-main .host-correct-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.festival-main .host-correct-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.festival-main .host-correct-item .btn-x {
    background: transparent;
    border: none;
    color: #b91c1c;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

.festival-main .host-correct-item .btn-x:hover {
    color: #7f1d1d;
}

.festival-main .host-team-number {
    display: inline-block;
    min-width: 40px;
    padding: 2px 8px;
    background: #eff6ff;
    color: #1e40af;
    border-radius: 4px;
    text-align: center;
    font-weight: 600;
}

.festival-main .host-team-name {
    flex: 1;
}

.event-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin: 0 0 20px;
    border-bottom: 1px solid #e5e7eb;
}

.event-tabs .event-tab {
    padding: 10px 18px;
    color: #4b5563;
    text-decoration: none;
    font-weight: 500;
    border: 2px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    margin-bottom: -1px;
}

.event-tabs .event-tab:hover {
    color: #1f2937;
    background: #f9fafb;
}

.event-tabs .event-tab.active {
    color: #1e40af;
    border-color: #2563eb;
    background: #eff6ff;
    font-weight: 700;
}

.correction-card {
    border: 1px solid #fde68a;
    background: #fffbeb;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 10px;
}

.correction-card .corr-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.correction-card .corr-q {
    display: inline-block;
    min-width: 28px;
    padding: 2px 8px;
    background: #fde68a;
    color: #78350f;
    border-radius: 4px;
    font-weight: 700;
    text-align: center;
}

.correction-card .corr-state {
    color: #6b7280;
    font-size: 0.9rem;
}

.correction-card .corr-comment {
    color: #1f2937;
    margin: 6px 0 10px;
    white-space: pre-wrap;
}

.correction-card .corr-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.badge-pending { background: #fef3c7; color: #78350f; }
.badge-correct { background: #bbf7d0; color: #14532d; }
.badge-incorrect { background: #fecaca; color: #7f1d1d; }
.badge-dismissed { background: #e5e7eb; color: #374151; }

.verdict-popup {
    position: absolute;
    z-index: 100;
    background: white;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    max-width: 360px;
    min-width: 220px;
}

.verdict-popup-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 6px 6px 12px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
    border-radius: 8px 8px 0 0;
    font-weight: 600;
    font-size: 0.85rem;
    color: #374151;
}

.verdict-popup-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    color: #6b7280;
    padding: 2px 8px;
}

.verdict-popup-close:hover {
    color: #1f2937;
}

.verdict-popup-body {
    padding: 10px 12px;
    white-space: pre-wrap;
    color: #1f2937;
    font-size: 0.92rem;
    max-height: 320px;
    overflow-y: auto;
}

/* --- Shared collapsible sections (promoted from event_si_standings) --- */

.ui-section {
    background: white;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.ui-section > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.ui-section > summary::-webkit-details-marker { display: none; }
.ui-section > summary::before {
    content: '▸';
    display: inline-block;
    width: 1em;
    color: #6b7280;
    transition: transform 0.15s;
}
.ui-section[open] > summary::before { transform: rotate(90deg); }

.ui-subsection {
    margin-top: 12px;
    border-top: 1px solid #f3f4f6;
    padding-top: 8px;
}
.ui-subsection > summary {
    cursor: pointer;
    list-style: none;
    user-select: none;
    color: #1e40af;
}
.ui-subsection > summary::-webkit-details-marker { display: none; }
.ui-subsection > summary::before {
    content: '▸';
    display: inline-block;
    width: 1em;
    color: #6b7280;
    transition: transform 0.15s;
}
.ui-subsection[open] > summary::before { transform: rotate(90deg); }

/* --- Shared autocomplete picker (promoted from КСИ/квиз templates) --- */

.team-picker-dropdown { display: none; }
.team-picker-dropdown.open { display: block; }
.team-picker-group-label {
    padding: 6px 10px 2px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    background: #f9fafb;
}

/* Host entry tables share the public tables' name-column guarantee. */
.stats-table th.name-col,
.stats-table td.name-col {
    width: 180px;
    min-width: 180px;
}

/* Horizontal-scroll wrapper for wide tables on narrow viewports —
   keeps the page body from scrolling sideways. */
.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Inline per-field save (room names, round times): ui.js marks each
   form.inline-save .is-clean or .is-dirty against the server-rendered
   value. The ✓ keeps its box while clean — visibility, not display —
   so its appearance never shifts the neighbours. Only border-color
   changes on the dirty input: a different border width would move
   the ✓ by the difference. */
form.inline-save.is-clean button[type="submit"] { visibility: hidden; }
form.inline-save.is-dirty button[type="submit"] { background: #2563eb; }
form.inline-save.is-dirty button[type="submit"]:hover { background: #1d4ed8; }
form.inline-save.save-failed button[type="submit"] { background: #dc2626; }
form.inline-save.is-dirty input[type="text"] {
    border-color: #f59e0b;
    background: #fffbeb;
}

/* --- Seating plan: a hall sketch is a CSS grid of the sheet's cells;
   tables and labels sit at their sheet coordinates and span merged
   ranges. Cells are squares and both axes are fr tracks, so the hall
   keeps its proportions (--w × --h units) at any size: at most 56px a
   unit on wide screens, at least 50px on phones, which then scroll
   the hall sideways instead of squeezing it. --- */
.seating-scroll { overflow-x: auto; }
.seating-hall {
    display: grid;
    gap: 0;
    width: min(100%, calc(var(--w) * 56px));
    min-width: calc(var(--w) * 50px);
    aspect-ratio: var(--w) / var(--h);
    margin: 0 auto;
}
.hall-table {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    margin: 2px;
    padding: 1px 3px;
    border: 2px solid #1e40af;
    border-radius: 6px;
    background: #eff6ff;
}
/* The number never gives way; a name too long for its box is what
   gets clipped (the list below has it in full). */
.hall-num { flex-shrink: 0; font-weight: 700; font-size: 1.05rem; color: #1e40af; line-height: 1.1; }
.hall-team {
    min-height: 0;
    overflow: hidden;
    font-size: 0.62rem;
    line-height: 1.15;
    text-align: center;
    color: #374151;
    overflow-wrap: break-word;
    hyphens: auto;
}
.hall-label {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    margin: 2px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #6b7280;
    border: 1px dashed #9ca3af;
    border-radius: 6px;
    text-align: center;
}
.seating-teams, .print-teams { width: 100%; border-collapse: collapse; }
.seating-teams th, .seating-teams td, .print-teams th, .print-teams td {
    padding: 6px 10px;
    border-bottom: 1px solid #e5e7eb;
    text-align: left;
}
.seating-teams td.num, .print-teams td.num { text-align: right; white-space: nowrap; }
.print-list h1 { font-size: 1.3rem; }

@media print {
    .top-nav, .no-print { display: none !important; }
    .container { max-width: none; padding: 0; }
    .schedule-card, .seating-hall-card { box-shadow: none; break-inside: avoid; }
    .seating-scroll { overflow: visible; }
    .seating-hall { min-width: 0; width: 100%; }
    .hall-table { background: none; }
    .print-teams th, .print-teams td { border-bottom: 1px solid #9ca3af; font-size: 11pt; }
}

/* --- Standings: presentation mode (festival_event_present.html) ---
   One table on a hall screen: bigger type, the header row pinned while
   the page glides through the rows, nothing else on the page. --- */
.table-scroll-x { overflow-x: auto; }
h2.with-present-link { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.present-link { font-size: 0.85rem; font-weight: 500; white-space: nowrap; }
html.present { font-size: 22px; }
html.present body { background: #fff; }
.present .present-main { max-width: none; padding: 0 16px 24px; }
.present .table-scroll-x { overflow: visible; }
.present .event-standings { table-layout: auto; }
.present .event-standings thead th {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    box-shadow: 0 2px 0 #2563eb;
}
.present .event-standings th.event-stage-header { cursor: default; }
.present .event-standings th.event-stage-header:hover { background: #fff; }
.present .present-empty { padding: 48px 0; text-align: center; color: #6b7280; }

/* --- Table filter / sort tools (ui.js, data-table-tools) --- */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable::after { content: " ↕"; color: #9ca3af; font-size: 0.8em; }
th.sortable.sort-asc::after { content: " ▲"; color: #1e40af; }
th.sortable.sort-desc::after { content: " ▼"; color: #1e40af; }
tr.table-filters th { padding: 4px 6px; font-weight: 400; }
tr.table-filters input, tr.table-filters select { width: 100%; min-width: 70px; padding: 3px 6px; font-size: 0.85rem; }
