* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: Arial, sans-serif; background: #fff; margin: 0; }
.header { background: #003366; color: white; padding: 0; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.header-top { padding: 10px 20px; }
.nav-bar { background: #0066cc; border-top: 1px solid #004499; }
.nav-menu { display: flex; margin: 0; padding: 0; list-style: none; flex-wrap: wrap; }
.nav-item { position: relative; }
.nav-link { display: block; padding: 12px 20px; color: white; text-decoration: none; border-right: 1px solid #004499; cursor: pointer; transition: background 0.2s; }
.nav-link:hover { background: #0052a3; }
.nav-link.active { background: #004080; font-weight: bold; }
.dropdown { position: absolute; top: 100%; left: 0; background: white; border: 1px solid #ccc; box-shadow: 0 4px 8px rgba(0,0,0,0.1); min-width: 200px; display: none; z-index: 1000; }
.dropdown.show { display: block; }
.dropdown-item { display: block; padding: 8px 16px; color: #333; text-decoration: none; border-bottom: 1px solid #eee; }
.dropdown-item:hover { background: #f5f5f5; }
.user-badge { display: flex; align-items: center; gap: 8px; margin-right: 10px; }
.user-badge-icon { width: 28px; height: 28px; border-radius: 50%; background: #1976d2; color: white; font-size: 13px; font-weight: bold; display: flex; align-items: center; justify-content: center; flex-shrink: 0; text-transform: uppercase; }
.user-badge-email { color: white; font-size: 13px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-dropdown { position: relative; display: inline-block; }
.admin-dropdown-btn { background: #2c3e50; color: white; border: none; padding: 8px 12px; border-radius: 4px; cursor: pointer; font-size: 14px; margin-left: 10px; display: flex; flex-direction: column; justify-content: center; align-items: center; width: 40px; height: 32px; }
.admin-dropdown-btn:hover { background: #34495e; }
.hamburger-line { width: 18px; height: 2px; background: white; margin: 2px 0; transition: 0.3s; }
.admin-dropdown-content { position: absolute; right: 0; top: 100%; background: white; min-width: 200px; box-shadow: 0 8px 16px rgba(0,0,0,0.2); border-radius: 4px; z-index: 1000; display: none; }
.admin-dropdown-content.show { display: block; }
.admin-dropdown-item { display: block; padding: 12px 16px; color: #333; text-decoration: none; cursor: pointer; }
.admin-dropdown-item:hover { background: #f1f1f1; }
.admin-dropdown-item:first-child { border-radius: 4px 4px 0 0; }
.admin-dropdown-item:last-child { border-radius: 0 0 4px 4px; }
.main-content { padding: 20px; max-width: 1200px; margin: 0 auto; }

/* Tournament Management list rows — fixed-width columns (Owner/Namelist/QM Active/Questions/
   Rounds/Actions) add up to more than a phone screen's width, which on mobile left nothing
   for the Tournament name column (flex:1 with no min-width shrinks to near-zero and its
   nowrap text gets clipped to almost nothing — looks like it's "covered up" by the columns
   after it, which still claim their full fixed widths). Letting the row wrap, and giving the
   name column a guaranteed floor, fixes that at every width; the mobile breakpoint below
   additionally lets the badge columns size to content and gives the action buttons their own
   full-width line instead of a cramped 140px-wide corner.
   */
.tm-row { flex-wrap: wrap; row-gap: 6px; }
.tm-col-name { min-width: 110px; }
@media (max-width: 600px) {
    .tm-col-owner, .tm-col-badge { width: auto !important; flex: 0 0 auto !important; margin-right: 10px; }
    .tm-col-actions { width: 100% !important; justify-content: flex-start !important; text-align: left !important; margin-top: 4px; }
}

.rd-spinner { width: 32px; height: 32px; margin: 0 auto; border: 4px solid #e0e0e0; border-top-color: #3498db; border-radius: 50%; animation: rd-spin 0.8s linear infinite; }
@keyframes rd-spin { to { transform: rotate(360deg); } }

/* Scoreboard (round detail "Scoreboard" tab) — a big-screen display by default (large fonts,
   teams side by side), reflowed for phones below. Each team's score box and its quizzer list
   are one unit (.sb-team) specifically so they can stack as a whole on narrow screens instead
   of staying in cramped side-by-side columns. */
.sb-wrap { background: #000; color: #fff; font-family: Arial, sans-serif; padding: 20px; min-height: 600px; }
.sb-top { display: flex; gap: 10px; margin-bottom: 20px; min-height: 120px; }
.sb-top-box { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; }
.sb-top-label { background: #0066cc; color: white; padding: 10px; font-size: 18px; font-weight: bold; }
.sb-top-value { font-size: 48px; font-weight: bold; margin-top: 10px; }
.sb-title { flex: 2; min-width: 0; text-align: center; padding: 20px; }
.sb-title-name { font-size: 24px; font-weight: bold; margin-bottom: 10px; overflow-wrap: break-word; }
.sb-title-sub { font-size: 18px; overflow-wrap: break-word; }
.sb-teams { display: flex; gap: 10px; }
.sb-team { flex: 1; min-width: 0; }
.sb-team-box { color: white; text-align: center; padding: 20px; margin-bottom: 10px; border-radius: 8px; }
.sb-team-name { font-size: 20px; font-weight: bold; margin-bottom: 10px; overflow-wrap: break-word; }
.sb-team-score { font-size: 36px; font-weight: bold; }
.sb-quizzer-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 8px 20px; font-size: 16px; }
.sb-quizzer-row.sb-unslotted { opacity: 0.7; }
.sb-quizzer-name { min-width: 0; overflow-wrap: break-word; }
.sb-quizzer-count { flex-shrink: 0; white-space: nowrap; }
.sb-quizzer-blank { padding: 8px 20px; font-size: 16px; }

.video-sb-strip { display: flex; align-items: flex-start; gap: 10px; background: #000; color: #fff; padding: 10px 14px; margin-bottom: 8px; border-radius: 4px; flex-wrap: wrap; }
.video-sb-question { font-weight: bold; font-size: 16px; flex-shrink: 0; padding-top: 2px; }
.video-sb-team { display: flex; flex-direction: column; gap: 3px; padding: 6px 12px; border-radius: 4px; color: #fff; flex: 1; min-width: 160px; }
.video-sb-team-top { display: flex; align-items: baseline; gap: 8px; justify-content: space-between; }
.video-sb-team-name { font-weight: bold; font-size: 14px; overflow-wrap: break-word; }
.video-sb-team-score { font-weight: bold; font-size: 20px; flex-shrink: 0; }
.video-sb-quizzers { font-size: 11px; line-height: 1.4; opacity: 0.9; overflow-wrap: break-word; }
.video-sb-q-count { font-weight: bold; }

/* Base rule deliberately placed before the mobile media query below it, so the media
   query's narrower override (width:100%, no horizontal margin) actually wins at that width
   instead of being overridden back by a same-specificity rule appearing later in the file —
   margin here used to live as an inline style on the <select> itself in index.html, which
   beat the media query unconditionally regardless of source order and caused this exact
   control to overflow the viewport by its own horizontal margins on narrow screens. */
.tournament-selector { padding: 8px 12px; margin: 8px 10px; border: 1px solid #ccc; font-size: 14px; }

/* Mobile responsiveness */
@media (max-width: 768px) {
    .header-top { padding: 8px 12px; }
    .header-top h1 { font-size: 18px; }
    .nav-menu { flex-direction: column; }
    .nav-link { padding: 10px 15px; border-right: none; border-bottom: 1px solid #004499; }
    .main-content { padding: 10px; }
    .tournament-selector { width: 100%; margin: 5px 0; }
    .quizzer-controls > div:first-child { flex-direction: column; align-items: stretch; }
    .quizzer-controls input[type="text"] { margin-bottom: 10px; }
    .user-badge-email { display: none; }
    .user-badge { margin-right: 4px; }
}

/* Phones in portrait — the scoreboard's big-screen layout (large fonts, 3 teams side by
   side) is what actually breaks here: team names and quizzer rows get squeezed hard enough
   to overlap/clip. Shrink everything and stack each team's box + quizzer list full-width
   instead of 3-across. */
@media (max-width: 600px) {
    .sb-wrap { padding: 10px; min-height: 0; }
    .sb-top { gap: 6px; margin-bottom: 10px; min-height: 0; }
    .sb-top-label { font-size: 11px; padding: 5px; }
    .sb-top-value { font-size: 24px; margin-top: 4px; }
    .sb-title { padding: 0 4px; }
    .sb-title-name { font-size: 14px; margin-bottom: 4px; }
    .sb-title-sub { font-size: 11px; }
    .sb-teams { flex-direction: column; gap: 8px; }
    .sb-team-box { padding: 10px; margin-bottom: 6px; }
    .sb-team-name { font-size: 16px; margin-bottom: 6px; }
    .sb-team-score { font-size: 28px; }
    .sb-quizzer-row, .sb-quizzer-blank { font-size: 13px; padding: 5px 12px; }
}
.tab-container { background: white; border-radius: 4px; overflow: hidden; }
.tabs { display: flex; background: #f8f9fa; border-bottom: 1px solid #dee2e6; }
.tab { padding: 12px 20px; cursor: pointer; border-right: 1px solid #dee2e6; transition: background 0.2s; }
.tab:hover { background: #e9ecef; }
.tab.active { background: white; border-bottom: 1px solid white; margin-bottom: -1px; }
.tab-content { padding: 0; }

/* Tournament admin left nav (tm-detail-panel) — a dedicated sidebar rather than reusing
   .tabs/.tab, since this panel outgrew a horizontal strip (10 sections and still growing)
   while round-details and other tab bars elsewhere are still fine as plain horizontal tabs
   and shouldn't be affected by this. Collapses to a horizontal scrollable strip on narrow
   screens (media query below) rather than a permanent column, so it never eats into content
   width on a phone. */
.tm-layout { background: white; border-radius: 4px; overflow: hidden; display: flex; align-items: stretch; }
.tm-sidebar { width: 190px; flex-shrink: 0; background: #f8f9fa; border-right: 1px solid #dee2e6; padding: 0.75rem 0; }
.tm-sidebar-group { margin-bottom: 0.9rem; }
.tm-sidebar-group-label { font-size: 10.5px; font-weight: bold; color: #888; text-transform: uppercase; letter-spacing: 0.04em; padding: 0 1rem; margin-bottom: 0.3rem; }
.tm-sidebar-link { padding: 8px 1rem; cursor: pointer; font-size: 14px; color: #333; border-left: 3px solid transparent; transition: background 0.15s; }
.tm-sidebar-link:hover { background: #e9ecef; }
.tm-sidebar-link.active { background: #fff; border-left-color: #1976d2; font-weight: 600; color: #1976d2; }
.tm-main { flex: 1; min-width: 0; }
@media (max-width: 760px) {
    .tm-layout { flex-direction: column; }
    /* min-width: 0 overrides a flex item's default min-width: auto, which would otherwise
       let this strip's full content width (well over 1000px) inflate .tm-layout — and with
       it the whole page body — instead of staying contained within its OWN overflow-x:auto.
       Without this, the page itself scrolls sideways on a phone, not just this strip. */
    .tm-sidebar { width: 100%; min-width: 0; display: flex; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; border-right: none; border-bottom: 1px solid #dee2e6; padding: 0.4rem 0.4rem; }
    .tm-sidebar-group { display: flex; align-items: center; gap: 2px; margin-bottom: 0; flex-shrink: 0; padding-right: 0.5rem; border-right: 1px solid #ddd; margin-right: 0.5rem; }
    .tm-sidebar-group:last-child { border-right: none; margin-right: 0; padding-right: 0; }
    .tm-sidebar-group-label { display: none; }
    /* Taller than the desktop padding (8px) — close to Apple's 44px touch-target minimum,
       since this becomes finger-tappable nav on a phone instead of mouse-hoverable on desktop. */
    .tm-sidebar-link { white-space: nowrap; padding: 12px 14px; border-left: none; border-bottom: 3px solid transparent; flex-shrink: 0; border-radius: 4px 4px 0 0; }
    .tm-sidebar-link.active { border-left-color: transparent; border-bottom-color: #1976d2; }
}
.card { background: white; border-radius: 8px; padding: 1.5rem; margin-bottom: 1rem; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.tournament-select { margin-bottom: 2rem; }
select { padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.teams-list { display: flex; flex-direction: column; gap: 0.5rem; }
.team-item { padding: 4px 8px; background: white; border: 1px solid #ddd; border-radius: 3px; cursor: pointer; transition: background 0.2s; display: flex; justify-content: space-between; align-items: center; }
.team-item:hover { background: #f8f9fa; }
.team-name { font-weight: 500; font-size: 0.95rem; }
.team-info { font-size: 0.8rem; color: #666; }
.team-card, .quizzer-card { cursor: pointer; transition: transform 0.2s; }
.team-card:hover, .quizzer-card:hover { transform: translateY(-2px); }
.hidden { display: none; }
.back-btn { background: #95a5a6; color: white; border: none; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; margin-bottom: 1rem; }
#breadcrumbs { margin-top: 0.5rem; font-size: 0.9rem; color: #7f8c8d; }
#breadcrumbs span { color: #7f8c8d; }
.breadcrumb-link { color: #3498db !important; cursor: pointer; }
.breadcrumb-link:hover { text-decoration: underline; }

/* Modal styles */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-content { background: white; padding: 2rem; border-radius: 8px; width: 90%; max-width: 400px; }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: bold; }
.form-group input { width: 100%; padding: 0.5rem; border: 1px solid #ddd; border-radius: 4px; font-size: 1rem; }
.btn { padding: 0.5rem 1rem; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem; }
.btn-primary { background: #3498db; color: white; }
.btn-secondary { background: #95a5a6; color: white; margin-left: 0.5rem; }
.btn:hover { opacity: 0.9; }
.user-list { max-height: 300px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px; }
.user-item { padding: 0.5rem; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }
.user-item:last-child { border-bottom: none; }

/* Scoreboard styles */
.scoreboard-container { background: #000; color: #0f0; font-family: 'Courier New', monospace; padding: 20px; border-radius: 8px; margin: 20px 0; }
.scoreboard-header { text-align: center; font-size: 24px; font-weight: bold; margin-bottom: 10px; }
.scoreboard-info { text-align: center; font-size: 18px; margin-bottom: 20px; }
.scoreboard-question { position: absolute; top: 20px; left: 20px; font-size: 36px; font-weight: bold; }
.scoreboard-teams { display: flex; justify-content: space-around; margin: 20px 0; }
.scoreboard-team { text-align: center; flex: 1; margin: 0 10px; }
.scoreboard-team-name { font-size: 20px; font-weight: bold; margin-bottom: 10px; }
.scoreboard-team-score { font-size: 32px; font-weight: bold; margin-bottom: 15px; }
.scoreboard-quizzer { font-size: 14px; margin: 5px 0; }
.scoreboard-quizzer-name { display: inline-block; width: 120px; text-align: left; }
.scoreboard-quizzer-stats { display: inline-block; width: 40px; text-align: right; }
.scoresheet-container { max-width: 100%; margin: 0 auto; background: white; padding: 1rem; position: relative; overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.scoresheet-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 2rem 0; min-width: 800px; }
.scoresheet-table th, .scoresheet-table td { border: 1px solid #000; padding: 0.25rem; text-align: center; }
.scoresheet-label-cell { font-weight: bold; background: #eee; }
.scoresheet-score-cell { user-select: none; width: 30px; min-width: 30px; max-width: 30px; }
.scoresheet-score-cell.correct { background: #c8e6c9; }
.scoresheet-score-cell.incorrect { background: #ffcdd2; }
.scoresheet-score-cell.bonus { background: #bbdefb; }
.scoresheet-score-cell.bonus-correct { background: #82b1ff; }
.scoresheet-score-cell.bonus-incorrect { background: #e3f2fd; }
.scoresheet-score-cell.unanswered { background: #ffeb3b; }
.scoresheet-question-header { background: #f5f5f5; position: relative; padding: 2px; width: 30px; min-width: 30px; max-width: 30px; }
.scoresheet-question-header.unanswered { background: #ffcccb; font-weight: bold; color: #cc0000; }
/* Small badge marking a question with an appeal or challenge — absolutely positioned so it
   doesn't widen the (already narrow, 30px) question-number header cell. Click/tap it (or the
   cell) to see what happened, via the same reveal dialog as bonus/penalty reasons. */
.scoresheet-dispute-flag { position: absolute; top: -2px; right: 0; font-size: 9px; line-height: 1; color: #c0392b; }
.scoresheet-team-name-header { background: #f0f0f0; padding: 0.5rem; font-size: 1.2em; font-weight: bold; text-align: center; }
.scoresheet-name-cell { width: 160px; min-width: 160px; }
.scoresheet-captain-cell { width: 35px; min-width: 35px; max-width: 35px; }
.scoresheet-total-points, .scoresheet-total-errors { font-weight: bold; }

/* Schedule Maker: modern form fields */
.sm-field-card {
    background: #f8f9fa; border: 1px solid #e2e6ea; border-radius: 10px;
    padding: 1.25rem 1.5rem; margin-top: 1.25rem; margin-bottom: 1.5rem;
}
.sm-field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1.1rem 1.25rem; }
.sm-field { display: flex; flex-direction: column; gap: 0.35rem; min-width: 0; }
.sm-field-wide { grid-column: span 2; }
.sm-field label { font-size: 0.78rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: #5f6b7a; }
.sm-field input, .sm-field select {
    width: 100%; padding: 0.6rem 0.75rem; font-size: 0.95rem; color: #1a1a1a;
    background: #fff; border: 1.5px solid #dde1e6; border-radius: 8px; box-sizing: border-box;
    font-family: inherit; transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.sm-field input:hover, .sm-field select:hover { border-color: #b7c0cc; }
.sm-field input:focus, .sm-field select:focus {
    outline: none; border-color: #1976d2; box-shadow: 0 0 0 3px rgba(25, 118, 210, 0.15);
}
@media (max-width: 600px) {
    .sm-field-wide { grid-column: span 1; }
}

/* Mobile table responsiveness */
@media (max-width: 768px) {
    .scoresheet-table { font-size: 10px; }
    .scoresheet-name-cell { width: 120px; min-width: 120px; }
    .scoresheet-score-cell { width: 25px; min-width: 25px; max-width: 25px; }
    .scoresheet-question-header { width: 25px; min-width: 25px; max-width: 25px; }
    .scoresheet-dispute-flag { font-size: 7px; }
    table { width: 100%; }
    th, td { padding: 4px 2px; font-size: 12px; }
    .summary-grid { grid-template-columns: 1fr !important; }
    .card table { min-width: 600px; overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; display: block; white-space: nowrap; }
}