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

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --text: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12);
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
nav { background: #1e293b; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 1.5rem; height: 56px; }
nav .brand { font-weight: 700; font-size: 1.1rem; color: #fff; }
nav .nav-actions { display: flex; gap: .75rem; align-items: center; }
#user-email { font-size: .85rem; color: #94a3b8; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: var(--radius); border: none; cursor: pointer; font-size: .875rem; font-weight: 500; transition: background .15s; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #e5e7eb; color: var(--text); }
.btn-secondary:hover { background: #d1d5db; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Page container */
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem; }

/* Card */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }

/* Badge */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-active { background: #dcfce7; color: #166534; }
.badge-completed { background: #ede9fe; color: #5b21b6; }

/* Form elements */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .875rem; outline: none; transition: border-color .15s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.form-row { display: flex; gap: 1rem; }
.form-row .form-group { flex: 1; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin-bottom: 1.25rem; font-size: 1.1rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .75rem; margin-top: 1.25rem; }
.hidden { display: none !important; }

/* Alert */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .875rem; }
.alert-error { background: #fee2e2; color: #991b1b; }
.alert-success { background: #dcfce7; color: #166534; }

/* Login page */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #1e293b; }
.login-card { background: var(--surface); border-radius: var(--radius); padding: 2.5rem 2rem; width: 100%; max-width: 380px; box-shadow: 0 4px 24px rgba(0,0,0,.2); }
.login-card h1 { font-size: 1.5rem; margin-bottom: .25rem; }
.login-card .subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 1.75rem; }
.divider { display: flex; align-items: center; gap: .65rem; color: var(--text-muted); font-size: .8rem; margin: 1rem 0; white-space: nowrap; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.btn-google { width: 100%; background: #fff; border: 1px solid var(--border); color: var(--text); justify-content: center; padding: .6rem; font-size: .9rem; }
.btn-google:hover { background: var(--bg); }

/* Tournament list */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.page-header h1 { font-size: 1.4rem; }
.tournaments-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.t-card { cursor: pointer; transition: box-shadow .15s; }
.t-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.t-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .5rem; }
.t-card h3 { font-size: 1rem; }
.t-meta { font-size: .8rem; color: var(--text-muted); margin-top: .4rem; }
.t-actions { display: flex; gap: .5rem; margin-top: .75rem; }
.empty-state { text-align: center; padding: 3rem; color: var(--text-muted); }

/* Tournament detail */
.tournament-header { margin-bottom: 1.5rem; display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.tournament-header h1 { font-size: 1.5rem; }
.tournament-meta { display: flex; gap: 1rem; align-items: center; margin-top: .5rem; flex-wrap: wrap; }
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 1.25rem; }
.tab-btn { padding: .6rem 1.1rem; border: none; background: none; cursor: pointer; font-size: .9rem; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color .15s; }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* Participants list */
.participants-list { display: flex; flex-direction: column; gap: .5rem; }
.participant-row { display: flex; align-items: center; justify-content: space-between; padding: .6rem .9rem; background: var(--bg); border-radius: var(--radius); font-size: .875rem; }
.participant-seed { color: var(--text-muted); font-size: .8rem; margin-left: .4rem; }
.add-participant-form { display: flex; gap: .75rem; margin-top: 1rem; align-items: flex-end; }
.add-participant-form .form-group { margin-bottom: 0; flex: 1; }

/* Bracket */
.bracket-wrap { overflow-x: auto; }
.bracket { display: flex; gap: 2rem; align-items: flex-start; padding: 1rem 0; min-width: max-content; }
.bracket-round { display: flex; flex-direction: column; gap: .5rem; }
.round-label { font-size: .75rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .5rem; text-align: center; }
.match-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); width: 200px; overflow: hidden; box-shadow: var(--shadow); }
.match-slot { display: flex; align-items: center; justify-content: space-between; padding: .45rem .7rem; font-size: .85rem; border-bottom: 1px solid var(--border); }
.match-slot:last-child { border-bottom: none; }
.match-slot.winner { background: #f0fdf4; font-weight: 600; }
.match-slot.loser { color: var(--text-muted); }
.slot-score { font-variant-numeric: tabular-nums; min-width: 1.5rem; text-align: right; }
.match-status { font-size: .7rem; color: var(--text-muted); padding: .25rem .7rem; background: #f9fafb; border-top: 1px solid var(--border); }
.match-card.ready { border-color: var(--primary); }
.match-card.completed { border-color: var(--border); }
.phase-label { font-size: .8rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin: 1.25rem 0 .5rem; }

/* Score entry modal */
.score-inputs { display: flex; align-items: center; gap: .75rem; margin: 1rem 0; }
.score-inputs input { width: 70px; text-align: center; font-size: 1.1rem; padding: .5rem; }
.score-vs { color: var(--text-muted); font-weight: 600; }

/* Schedule table */
.schedule-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.schedule-table th { text-align: left; padding: .6rem .75rem; background: var(--bg); font-weight: 600; border-bottom: 2px solid var(--border); }
.schedule-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.schedule-table tr:hover td { background: #f9fafb; }

/* Standings table */
.standings-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.standings-table th { text-align: left; padding: .6rem .75rem; background: var(--bg); font-weight: 600; border-bottom: 2px solid var(--border); }
.standings-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.standings-table tr:hover td { background: #f9fafb; }
.rank-1 td:first-child { color: #ca8a04; font-weight: 700; }
.rank-2 td:first-child { color: #64748b; font-weight: 600; }
.rank-3 td:first-child { color: #b45309; }

/* Spinner */
.spinner { border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; width: 28px; height: 28px; animation: spin .7s linear infinite; margin: 2rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
  .form-row { flex-direction: column; }
  nav { padding: 0 1rem; }
  .container { padding: 1rem; }
  .match-card { width: 160px; }
}

/* Share link section */
.share-section { margin-top: 2rem; padding: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.share-section h3 { font-size: 1rem; margin-bottom: .35rem; }
.share-description { font-size: .825rem; color: var(--text-muted); margin-bottom: .85rem; }
.share-link-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .75rem; flex-wrap: wrap; }
.share-link-input { flex: 1; min-width: 200px; padding: .45rem .65rem; border: 1px solid var(--border); border-radius: var(--radius); font-size: .8rem; background: var(--bg); color: var(--text); }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }

/* View-only page */
.view-only-badge { font-size: .75rem; font-weight: 600; background: #fef9c3; color: #854d0e; padding: .2rem .6rem; border-radius: 999px; border: 1px solid #fde68a; }
.loading-msg { text-align: center; padding: 3rem; color: var(--text-muted); }
.error-banner { background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c; padding: .85rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.eliminated-row td { color: var(--text-muted); text-decoration: line-through; }
.empty-msg { color: var(--text-muted); padding: 1.5rem 0; }
.phase-title { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
.tournament-header-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.5rem; }
.meta-row { display: flex; gap: .5rem; margin-top: .5rem; flex-wrap: wrap; }

/* Modal wide variant */
.modal-lg { max-width: 560px; }

/* Field hints & section labels */
.field-hint { font-size: .8rem; color: var(--text-muted); margin-top: .35rem; line-height: 1.45; }
.section-label { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin: 1.1rem 0 .4rem; }
.section-label-hint { font-weight: 400; text-transform: none; letter-spacing: 0; }

/* Tiebreaker list */
.tiebreaker-list { list-style: none; display: flex; flex-direction: column; gap: .35rem; }
.tiebreaker-list li { display: flex; align-items: center; gap: .6rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: .45rem .7rem; font-size: .85rem; counter-increment: tb-counter; }
.tiebreaker-list li::before { content: counter(tb-counter); counter-increment: none; font-size: .7rem; font-weight: 700; color: var(--text-muted); min-width: 1rem; text-align: center; }
.tiebreaker-list { counter-reset: tb-counter; }
.tb-handle { color: var(--text-muted); font-size: 1rem; cursor: grab; user-select: none; }
.tb-label { flex: 1; }
.tb-desc { color: var(--text-muted); font-size: .78rem; }
.tb-arrows { display: flex; gap: .2rem; }
.tb-arrows button { background: none; border: 1px solid var(--border); border-radius: 4px; width: 22px; height: 22px; cursor: pointer; font-size: .75rem; line-height: 1; display: flex; align-items: center; justify-content: center; }
.tb-arrows button:hover { background: var(--border); }
.tb-arrows button:disabled { opacity: .35; cursor: not-allowed; }

/* Inline checkbox label */
.checkbox-label { display: flex; align-items: center; gap: .45rem; font-size: .875rem; font-weight: 500; cursor: pointer; }
.checkbox-label input[type=checkbox] { width: auto; cursor: pointer; }

/* Logo in nav and login */
.nav-logo { height: 24px; width: auto; vertical-align: middle; margin-right: .4rem; display: inline-block; }
.login-logo { text-align: center; margin-bottom: 1rem; }
.login-logo img { height: 72px; width: auto; }

/* Landing page */
.landing-body { background: #0f172a; min-height: 100vh; }

/* Hero */
.landing-hero { padding: 3.5rem 1.5rem 3rem; display: flex; justify-content: center; }
.landing-hero-inner { width: 100%; max-width: 440px; text-align: center; }
.landing-logo { height: 72px; width: auto; margin-bottom: 1rem; }
.landing-title { font-size: 2.2rem; color: #f1f5f9; margin-bottom: .5rem; }
.landing-tagline { color: #94a3b8; font-size: 1rem; line-height: 1.6; margin-bottom: 2rem; }

/* Sign-in card */
.landing-card { background: #1e293b; border: 1px solid #334155; border-radius: 12px; padding: 2rem; text-align: left; }
.landing-card h2 { font-size: 1.25rem; color: #f1f5f9; margin-bottom: .3rem; }
.landing-card .subtitle { color: #94a3b8; font-size: .85rem; margin-bottom: 1.25rem; }
.landing-card .form-group label { color: #cbd5e1; }
.landing-card .form-group input { background: #0f172a; border-color: #334155; color: #f1f5f9; }
.landing-card .form-group input:focus { border-color: #3b82f6; }
.landing-card .divider { color: #475569; }
.landing-card .divider::before, .landing-card .divider::after { background: #334155; }
.landing-hint { font-size: .8rem; color: #64748b; margin-top: .6rem; text-align: center; }

/* Features section */
.landing-features { padding: 1rem 1.5rem 4rem; }
.landing-features-inner { max-width: 960px; margin: 0 auto; }
.features-heading { text-align: center; color: #94a3b8; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .1em; margin-bottom: 1.5rem; }
.features-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.feature-card { background: #1e293b; border: 1px solid #334155; border-radius: 10px; padding: 1.4rem 1.25rem; }
.feature-card-icon { font-size: 1.6rem; margin-bottom: .65rem; }
.feature-card h3 { font-size: .95rem; color: #f1f5f9; margin-bottom: .4rem; }
.feature-card p { font-size: .825rem; color: #94a3b8; line-height: 1.55; }

@media (max-width: 768px) {
  .features-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .features-grid { grid-template-columns: 1fr; }
  .landing-title { font-size: 1.75rem; }
}
