/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.5;
}

/* === Navbar === */
.navbar {
    background: #6a1b9a;
    padding: 0 24px;
}
.nav-inner {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    padding: 8px 0;
}
.nav-brand {
    color: #fff;
    font-size: 1.25rem;
    font-weight: 700;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 10px;
}
.nav-logo {
    height: 36px;
    width: auto;
    border-radius: 4px;
}
.nav-links { margin-left: auto; display: flex; gap: 16px; }
.nav-link {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 4px 12px;
    border-radius: 4px;
}
.nav-link:hover { background: rgba(255,255,255,0.15); color: #fff; }

/* === Container === */
.container { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* === Cards === */
.card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.card h2 { margin-bottom: 12px; font-size: 1.2rem; }

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: none;
    color: #333;
    text-align: center;
}
.btn:hover { background: #f5f5f5; }
.btn-primary { background: #f57c00; color: #fff; border-color: #f57c00; }
.btn-primary:hover { background: #e65100; }
.btn-danger { background: #c0392b; color: #fff; border-color: #c0392b; }
.btn-danger:hover { background: #e74c3c; }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

/* === Forms === */
.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.inline-form input, .inline-form select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.875rem;
}

/* === Game rows === */
.game-row {
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    display: flex;
    gap: 16px;
    align-items: center;
}
.game-row:hover { background: #f0f7ff; }
.game-row.selected { background: #fff3e0; border-left: 3px solid #f57c00; }
.game-date { font-weight: 600; min-width: 100px; }
.game-name { flex: 1; }
.game-players { color: #666; font-size: 0.875rem; }
.game-detail-header { display: flex; justify-content: space-between; align-items: center; }

/* === Players Table === */
.players-table { width: 100%; border-collapse: collapse; margin-top: 12px; }
.players-table th, .players-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}
.players-table th { background: #f8f9fa; font-weight: 600; }
.muted { color: #888; font-style: italic; }

/* === Tracker Page === */
.tracker-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f57c00;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}
.header-info { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.header-info span { font-size: 0.95rem; }
.header-actions { display: flex; gap: 8px; }
.header-actions .btn { color: #fff; border-color: rgba(255,255,255,0.5); background: rgba(0,0,0,0.15); }
.header-actions .btn:hover { background: rgba(0,0,0,0.25); }
.bats-badge {
    background: #e74c3c;
    padding: 2px 10px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.9rem;
}

/* === Legend Bar === */
.legend-bar {
    display: flex;
    gap: 24px;
    background: #fff;
    padding: 8px 16px;
    border-radius: 6px;
    margin-bottom: 12px;
    font-size: 0.8rem;
    flex-wrap: wrap;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.legend-group { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.legend-s { color: #e74c3c; }
.legend-f { color: #f39c12; }
.legend-c { color: #9b59b6; }
.legend-b { color: #3498db; }
.legend-o { color: #27ae60; }

/* === Game Grid (table: rows=batting order, cols=at-bats) === */
.game-grid-wrapper { overflow-x: auto; }
.game-grid {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.game-grid th, .game-grid td {
    border: 1px solid #ddd;
    text-align: center;
    vertical-align: middle;
}
.game-grid thead th {
    background: #222;
    color: #fff;
    padding: 8px 6px;
    font-size: 0.85rem;
    font-weight: 600;
}
.game-grid .row-header { width: auto; white-space: nowrap; }
.row-num {
    font-weight: 700;
    font-size: 1rem;
    color: #222;
    padding: 4px 8px;
    background: #f8f9fa;
    width: 36px;
}
.row-player {
    text-align: left !important;
    padding: 4px 10px;
    font-size: 0.85rem;
    min-width: 140px;
    background: #f8f9fa;
    white-space: nowrap;
}
.bats-badge-sm {
    background: #e74c3c;
    color: #fff;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: 4px;
}
.clickable-player { cursor: pointer; }
.clickable-player:hover { background: #e8f0fe !important; }
.inline-player-select {
    padding: 4px 8px;
    border: 2px solid #f57c00;
    border-radius: 4px;
    font-size: 0.85rem;
    width: 100%;
}
/* === At-Bat Cell (paper-style) === */
.ab-cell {
    padding: 2px;
    cursor: pointer;
    min-width: 120px;
    min-height: 150px;
    transition: background 0.15s;
    vertical-align: top;
    font-family: 'Courier New', Courier, monospace;
}
.ab-cell:hover { background: #f0f7ff; }
.ab-cell.has-data { background: #fcfcfc; display: flex; flex-direction: column; }

/* B/S/V grid at top of cell */
.bsv-grid {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2px;
}
.bsv-grid td {
    border: 1px solid #999;
    text-align: center;
    font-family: 'Courier New', monospace;
    font-size: 0.6rem;
    padding: 0 1px;
    height: 13px;
    min-width: 13px;
}
.bsv-grid .bsv-label {
    font-weight: 700;
    background: #f0f0f0;
    color: #222;
    width: 14px;
    min-width: 14px;
}

/* Bottom area: field bottom-left, result center, zone right */
.ab-bottom {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    flex: 1;
}
.ab-mini-field {
    flex-shrink: 0;
    display: block;
}
.ab-mini-zone {
    flex-shrink: 0;
    display: block;
}
.ab-box-result {
    font-weight: 700;
    font-size: 0.85rem;
    color: #222;
    text-align: center;
    align-self: center;
    padding: 0 2px;
    word-break: break-word;
    max-width: 40px;
}

/* === Modal === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.modal {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}
.modal-header h3 { font-size: 1.1rem; }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
}
.modal-body { padding: 20px; }
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

/* === Pitch Entry Layout === */
.pitch-entry {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.zone-section { text-align: center; }
.zone-section h4 { margin-bottom: 8px; font-size: 0.9rem; }
.zone-hint { font-size: 0.75rem; color: #888; margin-top: 4px; }
.strike-zone-wrapper {
    display: inline-block;
    border: 2px solid #333;
    border-radius: 4px;
    padding: 2px;
    background: #fafafa;
}

/* === Pitch Controls === */
.pitch-controls { flex: 1; min-width: 300px; }
.control-group { margin-bottom: 12px; }
.control-group label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }

.pitch-type-buttons, .result-buttons, .hit-type-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.pt-btn, .res-btn, .ht-btn {
    padding: 6px 10px;
    border: 2px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
    transition: all 0.15s;
}
.pt-btn:hover, .res-btn:hover, .ht-btn:hover { background: #f0f0f0; }
.pt-btn.active { border-color: #f57c00; background: #fff3e0; color: #e65100; }
.res-btn.active.res-s { border-color: #e74c3c; background: #fde8e8; color: #e74c3c; }
.res-btn.active.res-f { border-color: #f39c12; background: #fef5e7; color: #f39c12; }
.res-btn.active.res-b { border-color: #3498db; background: #eaf2f8; color: #3498db; }
.res-btn.active.res-o { border-color: #27ae60; background: #e8f8f0; color: #27ae60; }
.ht-btn.active { border-color: #8e44ad; background: #f4ecf7; color: #8e44ad; }

#pitch-velocity {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 120px;
    font-size: 0.9rem;
}

/* === Ball In Play Section === */
.bip-section {
    margin-top: 16px;
    padding: 16px;
    background: #f0fdf4;
    border-radius: 8px;
    border: 1px solid #bbf7d0;
}
.bip-section h4 { margin-bottom: 12px; }
.bip-controls { display: flex; gap: 16px; flex-wrap: wrap; }
.field-map-section { text-align: center; }
.field-map-section label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 4px; }
#play-result {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.875rem;
    width: 100%;
}

/* === Pitch Sequence List === */
.pitch-sequence { margin-top: 16px; }
.pitch-sequence h4 { margin-bottom: 8px; font-size: 0.9rem; }
#pitch-list { max-height: 200px; overflow-y: auto; }
.pitch-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    margin-bottom: 4px;
    font-size: 0.8rem;
}
.pitch-item .pitch-num { font-weight: 700; color: #222; min-width: 20px; }
.pitch-item .pitch-info { flex: 1; }
.pitch-item .pitch-vel { color: #666; }
.pitch-item .pitch-res-s { color: #e74c3c; font-weight: 600; }
.pitch-item .pitch-res-f { color: #f39c12; font-weight: 600; }
.pitch-item .pitch-res-b { color: #3498db; font-weight: 600; }
.pitch-item .pitch-res-o { color: #27ae60; font-weight: 600; }
.pitch-item .delete-pitch {
    background: none;
    border: none;
    color: #c0392b;
    cursor: pointer;
    font-size: 1rem;
    padding: 0 4px;
}

/* === At-Bat Result === */
.at-bat-result { margin-top: 16px; }
#at-bat-final-result {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
    width: 200px;
}

/* === Player select in modal === */
#modal-player-select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9rem;
    width: 100%;
    max-width: 350px;
    margin-bottom: 8px;
}

/* === Responsive === */
@media (max-width: 768px) {
    .pitch-entry { flex-direction: column; }
    .tracker-header { flex-direction: column; text-align: center; }
    .header-info { justify-content: center; }
}
