* {
    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: 960px;
    margin: 0 auto;
    padding: 20px;
}

.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;
}

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-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-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;
}

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 */
.htmx-request .btn {
    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 {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

/* 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 {
    max-width: 900px;
    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;
    }
}
