/* ============================================================
   AI INSTRUCTIONS — READ BEFORE MAKING ANY CHANGES
   ============================================================

   MOBILE FIRST: This is a fast-paced sports tracking app used
   primarily on mobile devices. DO NOT rely on :hover states for
   vital UI feedback, as they stick awkwardly on iOS/Android.
   Use :active states instead.

   TOUCH TARGETS: Ensure all new buttons or clickable elements
   have a minimum height of 44px for easy thumb tapping.

   NO DRAG & DROP: Do not suggest native HTML5 drag-and-drop,
   as it conflicts with mobile scrolling.

   ============================================================ */

/* General App Styling */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #121212;
    color: #ffffff;
    margin: 0;
    padding: 15px;
    position: relative;
}

/* Fixed top bar */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 54px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    background-color: #121212;
    z-index: 100;
    border-bottom: 1px solid #222;
}

.top-bar-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: 700;
    white-space: nowrap;
}

.top-bar-actions {
    display: flex;
    gap: 8px;
}

/* Auth Button */
.auth-btn {
    background-color: #1565c0;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 1rem;
    cursor: pointer;
    white-space: nowrap;
}

.auth-btn:active {
    background-color: #0d47a1;
}

/* Help Button */
.help-btn {
    background-color: #333;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 1rem;
    cursor: pointer;
}

.help-btn:active {
    background-color: #555;
}

/* Options Button */
.options-btn {
    background-color: #333;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 1rem;
    cursor: pointer;
}

.options-btn:active {
    background-color: #555;
}

/* Modal Styling */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #1e1e1e;
    border-radius: 8px;
    max-width: 480px;
    width: 95%;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    max-height: 88vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #333;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.3rem;
}

.close-btn {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
}

.close-btn:active {
    background-color: transparent;
}

.modal-body {
    padding: 20px;
    flex-grow: 1;
}

/* Legend Styling */
.legend {
    background-color: #2a2a2a;
    padding: 15px;
    border-radius: 6px;
    border-left: 3px solid #4caf50;
    margin-bottom: 20px;
}

.legend h3 {
    margin: 0 0 12px 0;
    font-size: 1rem;
    color: #4caf50;
}

.legend-item {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.legend-item label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    flex: 1;
    min-width: 0;
}

.legend-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
}

.custom-action-input {
    margin-left: auto;
    width: 110px;
    padding: 6px 8px;
    background-color: #3a3a3a;
    border: 1px solid #555;
    border-radius: 4px;
    color: #fff;
    font-size: 0.85rem;
}

.custom-action-input:focus {
    outline: none;
    border-color: #4caf50;
}

.legend-item:last-child {
    margin-bottom: 0;
}

.legend-icon {
    font-size: 1.3rem;
    margin-right: 12px;
    min-width: 30px;
}

.legend-text {
    color: #ffffff;
}

.names-title {
    margin-top: 20px;
    margin-bottom: 15px;
}

.player-input-group {
    margin-bottom: 15px;
}

.player-input-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
    font-size: 0.9rem;
}

.player-input-group input {
    width: 100%;
    padding: 10px;
    background-color: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

.player-input-group input:focus {
    outline: none;
    border-color: #4caf50;
}

.opponent-input {
    background-color: #333;
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
    border-left: 3px solid #ff9800;
}

.modal-footer {
    display: flex;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid #333;
    justify-content: flex-end;
}

.btn-save {
    background-color: #4caf50;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-save:active {
    background-color: #45a049;
}

.btn-cancel {
    background-color: #f44336;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-cancel:active {
    background-color: #da190b;
}

/* Clear Stats Button */
.clear-stats-btn {
    width: 100%;
    background-color: #f44336;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 1rem;
    cursor: pointer;
}

.clear-stats-btn:active {
    background-color: #da190b;
}

/* Button Row */
.button-row {
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.button-row button {
    flex: 1;
}

/* Save to Cloud Button */
.save-cloud-btn {
    background-color: #7b1fa2;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 1rem;
    cursor: pointer;
}

.save-cloud-btn:active {
    background-color: #6a1b9a;
}

/* Share / Export Button */
.share-export-btn {
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 1rem;
    cursor: pointer;
}

.share-export-btn:active {
    background-color: #0b7dda;
}

/* Share / Export Bottom Sheet */
.share-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background-color: rgba(0, 0, 0, 0.6);
    align-items: flex-end;
}

.share-modal.show {
    display: flex;
}

.share-sheet {
    width: 100%;
    background-color: #1e1e1e;
    border-radius: 16px 16px 0 0;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

.share-sheet-handle {
    width: 36px;
    height: 4px;
    background-color: #444;
    border-radius: 2px;
    margin: 12px auto 16px;
}

.share-sheet-title {
    margin: 0 0 4px 0;
    padding: 0 20px 12px;
    font-size: 0.85rem;
    color: #888;
    font-weight: 400;
}

/* Match name input inside the share sheet */
.share-name-section {
    padding: 12px 20px 16px;
    border-bottom: 1px solid #2a2a2a;
}

.share-name-label {
    display: block;
    font-size: 0.75rem;
    color: #888;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.share-match-name-input {
    width: 100%;
    box-sizing: border-box;
    background-color: #2a2a2a;
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    color: #ffffff;
    font-size: 1rem;
    font-family: inherit;
    padding: 10px 14px;
    outline: none;
    min-height: 44px;
}

.share-match-name-input:focus {
    border-color: #4caf50;
}

.share-option-btn {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    background: none;
    border: none;
    border-bottom: 1px solid #2a2a2a;
    color: white;
    padding: 14px 20px;
    font-size: 1rem;
    text-align: left;
    cursor: pointer;
    min-height: 64px;
    border-radius: 0;
}

.share-option-btn:active {
    background-color: #2a2a2a;
}

.share-option-icon {
    font-size: 1.6rem;
    flex-shrink: 0;
    width: 36px;
    text-align: center;
}

.share-option-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.share-option-label {
    font-size: 1rem;
    font-weight: 600;
}

.share-option-desc {
    font-size: 0.8rem;
    color: #888;
}

.share-sheet-cancel-btn {
    display: block;
    width: calc(100% - 40px);
    margin: 12px 20px 4px;
    background-color: #2a2a2a;
    color: white;
    border: none;
    border-radius: 10px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 52px;
}

.share-sheet-cancel-btn:active {
    background-color: #3a3a3a;
}

/* Toast notification */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background-color: #323232;
    color: white;
    padding: 12px 22px;
    border-radius: 24px;
    font-size: 0.9rem;
    z-index: 2000;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
    pointer-events: none;
}

.toast.toast-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.container {
    max-width: 500px; /* Keeps it phone-sized even on desktop */
    margin: 0 auto;
    padding-top: 66px;
    padding-bottom: 20px;
}

.button-row + .button-row {
    margin-top: 10px;
}

.secondary-btn-row {
    margin-top: 10px;
}

h2 { 
    margin-top: 0; 
    border-bottom: 1px solid #333; 
    padding-bottom: 10px;
}

/* --- THE FLEXBOX MAGIC --- */
.player-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #1e1e1e;
    padding: 10px 15px;
    margin-bottom: 8px;
    border-radius: 8px;
}

.player-row.opponent-row {
    background-color: #2a2a2a;
    border-left: 3px solid #ff9800;
}

.player-name {
    flex: 0 0 120px;
    font-weight: bold;
    font-size: 1.1rem;
    padding-right: 10px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.player-name-text {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-edit-player {
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 2px 3px;
    font-size: 0.8rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.4;
    border-radius: 3px;
    touch-action: manipulation;
}

.btn-edit-player:active {
    opacity: 1;
    background-color: #444;
}

.player-name-input {
    flex: 1;
    min-width: 0;
    background-color: #2a2a2a;
    color: white;
    border: 1px solid #4caf50;
    border-radius: 4px;
    font-size: 0.9rem;
    font-weight: bold;
    font-family: inherit;
    padding: 2px 5px;
    outline: none;
}

.actions-scroll {
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.button-group {
    display: flex;
    gap: 8px;
    min-width: max-content;
}

/* Button Styling */
button {
    background-color: #333;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 1.2rem;
    cursor: pointer;
    touch-action: manipulation; /* Prevents double-tap zooming on mobile */
}

button:active { 
    background-color: #555; 
}

.btn-kill { border-bottom: 3px solid #ff9800; }
.btn-ace { border-bottom: 3px solid #4caf50; }
.btn-err { border-bottom: 3px solid #f44336; }
.btn-serve-err { border-bottom: 3px solid #e53935; }
.btn-block { border-bottom: 3px solid #03a9f4; }
.btn-defend { border-bottom: 3px solid #ab47bc; }
.btn-custom-1 { border-bottom: 3px solid #ffd54f; }
.btn-custom-2 { border-bottom: 3px solid #ab47bc; }
.btn-custom-3 { border-bottom: 3px solid #26a69a; }
.btn-custom-4 { border-bottom: 3px solid #ef5350; }
.btn-custom { border-bottom: 3px solid #ffd54f; }

/* Action button layout — flex column: icon on top, count below */
.button-group button {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 58px;
    padding: 8px 14px;
    font-size: inherit;
}

.btn-icon {
    font-size: 1.3rem;
    line-height: 1;
    display: block;
}

.btn-count {
    font-size: 0.85rem;
    font-weight: 700;
    line-height: 1;
    color: rgba(255, 255, 255, 0.95);
}

/* Click flash animations */
@keyframes flash-add {
    0%   { transform: scale(1);    background-color: rgba(76, 175, 80, 0.5); }
    35%  { transform: scale(1.12); background-color: rgba(76, 175, 80, 0.4); }
    70%  { transform: scale(0.96); background-color: rgba(76, 175, 80, 0.15); }
    100% { transform: scale(1);    background-color: transparent; }
}

@keyframes flash-undo {
    0%   { transform: scale(1);    background-color: rgba(244, 67, 54, 0.5); }
    35%  { transform: scale(1.12); background-color: rgba(244, 67, 54, 0.4); }
    70%  { transform: scale(0.96); background-color: rgba(244, 67, 54, 0.15); }
    100% { transform: scale(1);    background-color: transparent; }
}

.action-stat-btn.btn-flash-add {
    animation: flash-add 0.4s ease-out;
}

.action-stat-btn.btn-flash-undo {
    animation: flash-undo 0.4s ease-out;
}

/* Undo Button */
.undo-btn {
    background-color: #5c6bc0;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 15px;
    font-size: 1rem;
    cursor: pointer;
}

.undo-btn:active {
    background-color: #3949ab;
}

.undo-btn:disabled {
    background-color: #2a2a2a;
    color: #555;
    cursor: default;
}

/* Add / Delete custom action buttons */
.btn-add-custom {
    margin-top: 12px;
    width: 100%;
    background-color: #2e7d32;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: center;
}

.btn-add-custom:disabled {
    background-color: #444;
    color: #888;
    cursor: default;
}

.btn-add-custom:not(:disabled):active {
    background-color: #1b5e20;
}

.btn-delete-custom {
    margin-left: 8px;
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: #f44336;
    padding: 6px 10px;
    border-radius: 4px;
    flex-shrink: 0;
}

.btn-delete-custom:active {
    background-color: #3a1a1a;
}

.sort-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 1rem;
    line-height: 1;
    padding: 4px 5px;
    cursor: pointer;
    border-radius: 4px;
    touch-action: manipulation;
    opacity: 0.7;
}

.sort-btn:active {
    background-color: #444;
    opacity: 1;
}

.sort-btn:disabled {
    opacity: 0.2;
    cursor: default;
}

/* Auth modal form */
.auth-field {
    margin-bottom: 16px;
}

.auth-field label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: #ccc;
}

.auth-field input {
    width: 100%;
    padding: 10px;
    background-color: #333;
    color: white;
    border: 1px solid #555;
    border-radius: 4px;
    font-size: 1rem;
    box-sizing: border-box;
}

.auth-field input:focus {
    outline: none;
    border-color: #1565c0;
}

.auth-error {
    background-color: #3a1a1a;
    color: #ff6b6b;
    border: 1px solid #f44336;
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.btn-login {
    background-color: #1565c0;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-login:active {
    background-color: #0d47a1;
}

.btn-login:disabled {
    background-color: #2a2a2a;
    color: #555;
    cursor: default;
}

.btn-signup {
    background-color: #2e7d32;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-signup:active {
    background-color: #1b5e20;
}

.btn-signup:disabled {
    background-color: #2a2a2a;
    color: #555;
    cursor: default;
}

/* History Button */
.history-btn {
    background-color: #333;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 1rem;
    cursor: pointer;
    white-space: nowrap;
}

.history-btn:active {
    background-color: #555;
}

/* Match History List */
.history-status {
    font-size: 0.9rem;
    color: #aaa;
    margin: 0 0 10px 0;
}

.history-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.history-list li {
    background-color: #2a2a2a;
    padding: 12px 14px;
    border-radius: 6px;
    margin-bottom: 10px;
}

.history-list li:last-child {
    margin-bottom: 0;
}

.history-match-title {
    font-weight: bold;
    font-size: 1rem;
    display: block;
    margin-bottom: 4px;
}

.history-match-date {
    font-size: 0.8rem;
    color: #aaa;
}

/* History action buttons */
.hist-action-bar {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.hist-view-btn,
.hist-dl-btn,
.hist-restore-btn,
.hist-delete-btn {
    flex: 1;
    background-color: #3a3a3a;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 4px;
    font-size: 0.78rem;
    cursor: pointer;
    min-height: 36px;
    touch-action: manipulation;
}

.hist-view-btn:active,
.hist-dl-btn:active,
.hist-restore-btn:active {
    background-color: #555;
}

.hist-delete-btn {
    color: #ff6b6b;
    border: 1px solid #7a2020;
}

.hist-delete-btn:active {
    background-color: #3a1a1a;
}

/* Box score table inside view-match-modal */
.box-score-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.box-score-table th,
.box-score-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #333;
    text-align: center;
}

.box-score-table th:first-child,
.box-score-table td:first-child {
    text-align: left;
}

.box-score-table thead tr {
    background-color: #1a1a1a;
    color: #4caf50;
}

/* Lucide icon sizing */
button svg {
    width: 1em;
    height: 1em;
    vertical-align: middle;
    flex-shrink: 0;
}

.legend-icon svg {
    width: 1.3rem;
    height: 1.3rem;
    vertical-align: middle;
}

/* ── Action Table ─────────────────────────────────────────── */

/* Horizontal scroll container so the grey background tracks the grid columns
   on narrow screens (e.g. iPhone SE) instead of clipping at the container edge.
   NOTE: overflow-x:auto implicitly computes overflow-y:auto per CSS spec, which
   makes #action-grid a vertical scroll container and breaks position:sticky
   inside it. The sticky header is therefore removed to avoid the header being
   pushed down 54px and hiding the first data row. */
#action-grid {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.action-table-header,
.action-table-row {
    /* Expand the element box to match its grid content width, so the
       background colour covers every column even when columns overflow. */
    min-width: max-content;
}

.action-table-header {
    display: grid;
    background-color: #1a1a1a;
    border-radius: 8px 8px 0 0;
}

.action-header-cell {
    padding: 10px 4px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    font-size: 0.68rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.2;
    overflow: hidden;
}

.action-header-cell svg {
    width: 1.1rem;
    height: 1.1rem;
    flex-shrink: 0;
}

.action-header-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Column accent colours — header only */
.action-header-cell.btn-kill      { border-bottom: 3px solid #ff9800; color: #ff9800; }
.action-header-cell.btn-ace       { border-bottom: 3px solid #4caf50; color: #4caf50; }
.action-header-cell.btn-err       { border-bottom: 3px solid #f44336; color: #f44336; }
.action-header-cell.btn-serve-err { border-bottom: 3px solid #e53935; color: #e53935; }
.action-header-cell.btn-block     { border-bottom: 3px solid #03a9f4; color: #03a9f4; }
.action-header-cell.btn-defend    { border-bottom: 3px solid #ab47bc; color: #ab47bc; }
.action-header-cell.btn-custom    { border-bottom: 3px solid #ffd54f; color: #ffd54f; }

.action-header-player {
    align-items: flex-start;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #4caf50;
    letter-spacing: 0;
    text-transform: none;
    padding-left: 12px;
    border-bottom: none;
}

.action-table-row {
    display: grid;
    background-color: #1e1e1e;
    border-bottom: 1px solid #252525;
}

.action-table-row:last-child {
    border-radius: 0 0 8px 8px;
    border-bottom: none;
}

.action-table-row.opponent-row {
    background-color: #252525;
    border-left: 3px solid #ff9800;
}

.action-player-cell {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px 0 10px;
    font-weight: 600;
    font-size: 0.9rem;
    min-height: 56px;
    min-width: 0;
}

.action-player-cell .player-name-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.action-stat-btn {
    background: none;
    border: none;
    border-left: 1px solid #252525;
    border-bottom: none;
    border-radius: 0;
    padding: 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.4rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    width: 100%;
}

.action-stat-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ── Share / Export Bottom Sheet ──────────────────────────── */
.share-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    align-items: flex-end;
}

.share-modal.show {
    display: flex;
}

.share-sheet {
    width: 100%;
    background-color: #1e1e1e;
    border-radius: 16px 16px 0 0;
    padding: 12px 20px 36px;
    box-sizing: border-box;
}

.share-sheet-handle {
    width: 36px;
    height: 4px;
    background-color: #555;
    border-radius: 2px;
    margin: 0 auto 16px;
}

.share-sheet-title {
    text-align: center;
    font-size: 0.8rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 20px;
    font-weight: 600;
}

.share-name-section {
    margin-bottom: 16px;
}

.share-name-label {
    display: block;
    font-size: 0.75rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
}

.share-match-name-input {
    width: 100%;
    background-color: #2a2a2a;
    color: white;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 1rem;
    box-sizing: border-box;
    font-family: inherit;
}

.share-match-name-input:focus {
    outline: none;
    border-color: #2196F3;
}

.share-option-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 16px;
    background-color: transparent;
    border: none;
    border-bottom: 1px solid #2a2a2a;
    border-radius: 0;
    padding: 16px 4px;
    color: white;
    cursor: pointer;
    text-align: left;
    font-size: inherit;
    min-height: 60px;
}

.share-option-btn:active {
    background-color: #2a2a2a;
}

.share-option-icon {
    font-size: 1.8rem;
    width: 44px;
    text-align: center;
    flex-shrink: 0;
}

.share-option-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.share-option-label {
    font-size: 1rem;
    font-weight: 600;
    color: white;
}

.share-option-desc {
    font-size: 0.8rem;
    color: #888;
}

.share-sheet-cancel-btn {
    width: 100%;
    background-color: #2a2a2a;
    color: white;
    border: none;
    border-radius: 10px;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 12px;
    text-align: center;
}

.share-sheet-cancel-btn:active {
    background-color: #3a3a3a;
}

/* Scoreboard Table */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

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

/* ── History Search ───────────────────────────────────────── */
.history-search-row {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.history-search-input {
    flex: 1;
    padding: 10px 12px;
    background-color: #2a2a2a;
    color: white;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    min-width: 0;
}

.history-search-input:focus {
    outline: none;
    border-color: #2196F3;
}

.history-search-btn {
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    min-height: 44px;
}

.history-search-btn:active {
    background-color: #0b7dda;
}

/* History share button */
.hist-share-btn {
    flex: 1;
    background-color: #3a3a3a;
    color: white;
    border: none;
    border-radius: 4px;
    padding: 6px 4px;
    font-size: 0.78rem;
    cursor: pointer;
    min-height: 36px;
    touch-action: manipulation;
}

.hist-share-btn:active {
    background-color: #555;
}

/* ── Save Result Modal ────────────────────────────────────── */
.save-result-id-row {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: #2a2a2a;
    border-radius: 6px;
    padding: 12px 14px;
    margin: 12px 0;
}

.save-result-id-label {
    font-size: 0.8rem;
    color: #aaa;
    white-space: nowrap;
    flex-shrink: 0;
}

.save-result-id-value {
    flex: 1;
    font-family: monospace;
    font-size: 0.85rem;
    color: #4caf50;
    word-break: break-all;
    min-width: 0;
}

.btn-copy-id {
    background: none;
    border: none;
    color: #aaa;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    min-height: 36px;
}

.btn-copy-id:active {
    background-color: #3a3a3a;
    color: #fff;
}

.save-result-hint {
    font-size: 0.85rem;
    color: #aaa;
    margin: 0;
}

.btn-share-link {
    background-color: #2196F3;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
}

.btn-share-link:active {
    background-color: #0b7dda;
}

/* ── Roster Player Row ────────────────────────────────────── */
.player-roster-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.95rem;
}

/* ── Onboarding / Mode Select Modal ──────────────────────── */
.mode-cards {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mode-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    background-color: #2a2a2a;
    border: 2px solid #3a3a3a;
    border-radius: 10px;
    padding: 16px;
    cursor: pointer;
    text-align: left;
    min-height: 80px;
    width: 100%;
    box-sizing: border-box;
    color: white;
    font-family: inherit;
}

.mode-card:active {
    background-color: #333;
}

.mode-card-easy   { border-color: #ff9800; }
.mode-card-medium { border-color: #4caf50; }
.mode-card-advanced { border-color: #2196F3; }

.mode-card-icon {
    font-size: 1.5rem;
}

.mode-card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
}

.mode-card-desc {
    font-size: 0.85rem;
    color: #aaa;
    line-height: 1.4;
    font-weight: 400;
}

/* ── Change Mode Button (in Actions modal footer) ─────────── */
.btn-change-mode {
    background-color: #333;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    margin-bottom: 12px;
}

.btn-change-mode:active {
    background-color: #555;
}

.btn-hard-reset {
    background-color: #b71c1c;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-hard-reset:active {
    background-color: #7f0000;
}

/* ── Advanced Mode: Player Card Grid ─────────────────────── */
.player-card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 4px 0;
}

.player-card {
    background-color: #1e1e1e;
    border-radius: 10px;
    padding: 14px 12px;
    min-height: 80px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border: 1px solid #2a2a2a;
    touch-action: manipulation;
}

.player-card:active {
    background-color: #2a2a2a;
}

.player-card-opponent {
    border-color: #ff9800;
}

.player-card-name {
    font-weight: 700;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.player-card-summary {
    font-size: 0.75rem;
    color: #aaa;
    line-height: 1.4;
}

/* ── Advanced Mode: Drilldown Layout ─────────────────────── */
.drilldown-back-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0 12px;
    border-bottom: 1px solid #2a2a2a;
    margin-bottom: 8px;
}

.drilldown-back-btn {
    background-color: #2a2a2a;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    flex-shrink: 0;
    touch-action: manipulation;
}

.drilldown-back-btn:active {
    background-color: #3a3a3a;
}

.drilldown-player-title {
    font-size: 1.1rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.drilldown-header {
    display: grid;
    background-color: #1a1a1a;
    border-radius: 8px 8px 0 0;
    position: sticky;
    top: 54px;
    z-index: 10;
}

.drilldown-header-cell {
    padding: 10px 6px 8px;
    text-align: center;
    font-size: 0.72rem;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    line-height: 1.2;
    font-weight: 600;
}

.drilldown-header-cell:first-child {
    text-align: left;
    padding-left: 12px;
    color: #4caf50;
    text-transform: none;
    font-size: 0.78rem;
}

.drilldown-pct-header {
    color: #ff9800;
}

.drilldown-row {
    display: grid;
    background-color: #1e1e1e;
    border-bottom: 1px solid #252525;
}

.drilldown-row:last-child {
    border-radius: 0 0 8px 8px;
    border-bottom: none;
}

.drilldown-action-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 3px;
    padding: 10px 6px 10px 12px;
    font-size: 0.8rem;
    color: #ccc;
    min-height: 56px;
}

.drilldown-action-cell svg {
    width: 1rem;
    height: 1rem;
    flex-shrink: 0;
    opacity: 0.7;
}

.drilldown-action-cell span {
    font-size: 0.75rem;
    line-height: 1;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    max-width: 80px;
}

.drilldown-stat-btn {
    background: none;
    border: none;
    border-left: 1px solid #2a2a2a;
    border-radius: 0;
    padding: 0;
    color: rgba(255, 255, 255, 0.9);
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    width: 100%;
}

.drilldown-stat-btn:active {
    background-color: rgba(255, 255, 255, 0.1);
}

.drilldown-empty-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    color: #444;
    font-size: 0.9rem;
    border-left: 1px solid #2a2a2a;
}

.drilldown-pct-cell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #ff9800;
    border-left: 1px solid #2a2a2a;
}

/* ── Advanced Mode: Sub-stat Config in Actions Modal ─────── */
.substat-config-section {
    margin: 6px 0 10px 28px;
    padding: 8px 10px;
    background-color: #222;
    border-radius: 6px;
    border-left: 2px solid #2196F3;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.substat-config-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.substat-label-input {
    flex: 1;
    padding: 6px 8px;
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    color: #fff;
    font-size: 0.85rem;
    font-family: inherit;
    min-height: 36px;
}

.substat-label-input:focus {
    outline: none;
    border-color: #2196F3;
}

.btn-add-substat {
    width: 100%;
    background-color: #1a3a5c;
    color: #64b5f6;
    border: 1px dashed #2196F3;
    border-radius: 4px;
    padding: 6px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    text-align: center;
    min-height: 36px;
}

.btn-add-substat:disabled {
    opacity: 0.4;
    cursor: default;
}

.btn-add-substat:not(:disabled):active {
    background-color: #1e4d80;
}
/* ── Scoreboard ─────────────────────────────────────────── */

.scoreboard {
    background: #1a1a2e;
    border: 1px solid #2a2a4a;
    border-radius: 12px;
    padding: 10px 10px 8px;
    margin-bottom: 12px;
    box-sizing: border-box; /* prevents horizontal overflow */
    width: 100%;
}

.scoreboard.hidden {
    display: none;
}

/* Set history badges */
.score-history-badges {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 8px;
    margin-bottom: 4px;
    scrollbar-width: none;
}

.score-history-badges::-webkit-scrollbar {
    display: none;
}

.score-history-badge {
    flex-shrink: 0;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
    letter-spacing: 0.02em;
}

.badge-win {
    background: #1b3a2a;
    color: #4caf50;
    border: 1px solid #2e6b3e;
}

.badge-loss {
    background: #3a1b1b;
    color: #ef5350;
    border: 1px solid #6b2e2e;
}

/* Main score row */
.score-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.score-team-block {
    flex: 1;
    min-width: 0; /* allows flex shrinking */
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.score-team-name {
    font-size: 0.65rem;
    font-weight: 600;
    color: #aaa;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    text-align: center;
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.score-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

.score-display {
    font-size: clamp(2rem, 8vw, 2.4rem);
    font-weight: 800;
    color: #ffffff;
    width: 2.5ch;
    text-align: center;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    flex-shrink: 1;
}

.score-adj {
    width: 38px;
    height: 44px;
    border-radius: 8px;
    border: 2px solid #444;
    background: #2a2a2a;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    line-height: 1;
    padding: 0;
    touch-action: manipulation;
}

.score-adj:active {
    background: #3a3a3a;
    border-color: #666;
    transform: scale(0.92);
}

.score-set-label {
    font-size: 0.62rem;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-align: center;
    min-width: 34px;
    flex-shrink: 0;
    white-space: nowrap;
}

/* End Set button */
.end-set-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    margin-top: 8px;
    padding: 7px 12px;
    background: #1a2a3a;
    color: #90caf9;
    border: 1px solid #2a4a6a;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    touch-action: manipulation;
    min-height: 44px;
    box-sizing: border-box;
}

.end-set-btn:active {
    background: #243850;
    border-color: #4a7aaa;
}

/* ── AI Coach Share Buttons ─────────────────────────────────── */

.ai-share-btns {
    display: flex;
    gap: 8px;
    flex: 1;
}

.btn-ai-share {
    display: flex;
    align-items: center;
    gap: 6px;
    background-color: #2a2a2a;
    color: #b0bec5;
    border: 1px solid #444;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 0.9rem;
    cursor: pointer;
    white-space: nowrap;
}

.btn-ai-share:active {
    background-color: #383838;
    color: #ffffff;
}

.btn-ai-share svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

/* ── AI Coach Buttons ───────────────────────────────────────── */

.ai-btn-row {
}

.ai-timeout-btn {
    background-color: #00796b;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 1rem;
    cursor: pointer;
}

.ai-timeout-btn:active {
    background-color: #00574b;
}

.ai-timeout-btn:disabled {
    background-color: #2a2a2a;
    color: #555;
    cursor: default;
}

.ai-summary-btn {
    background-color: #303f9f;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 12px 16px;
    font-size: 1rem;
    cursor: pointer;
}

.ai-summary-btn:active {
    background-color: #1a237e;
}

.ai-summary-btn:disabled {
    background-color: #2a2a2a;
    color: #555;
    cursor: default;
}

/* ── AI Coach Modal Response ────────────────────────────────── */

.ai-coach-response {
    line-height: 1.75;
    color: #e0e0e0;
    max-height: 60vh;
    overflow-y: auto;
    font-size: 0.95rem;
}

.ai-coach-response p {
    margin: 0 0 10px 0;
}

.ai-coach-response h1,
.ai-coach-response h2,
.ai-coach-response h3 {
    margin: 16px 0 6px 0;
    color: #ffffff;
    line-height: 1.3;
}

.ai-coach-response h1 { font-size: 1.15rem; }
.ai-coach-response h2 { font-size: 1.05rem; }
.ai-coach-response h3 { font-size: 0.95rem; color: #b0bec5; }

.ai-coach-response ul,
.ai-coach-response ol {
    padding-left: 20px;
    margin: 6px 0 10px 0;
}

.ai-coach-response li {
    margin-bottom: 6px;
}

.ai-coach-response strong {
    color: #ffffff;
}

.ai-coach-response code {
    background-color: #2a2a2a;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 0.88rem;
}

.ai-loading {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 32px 0;
    color: #b0bec5;
    font-size: 0.95rem;
}

.ai-loading-spinner {
    display: inline-block;
    width: 22px;
    height: 22px;
    border: 3px solid #444;
    border-top-color: #ffffff;
    border-radius: 50%;
    flex-shrink: 0;
    animation: ai-spin 0.8s linear infinite;
}

@keyframes ai-spin {
    to { transform: rotate(360deg); }
}

/* SEO description block */
.seo-description {
    margin-top: 40px;
    padding: 0 20px;
    text-align: center;
    color: #666;
}
.seo-description h3 {
    font-size: 0.95rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 8px;
}
.seo-description p {
    font-size: 0.8rem;
    line-height: 1.6;
    max-width: 600px;
    margin: 0 auto;
}

/* Site footer */
.site-footer {
    margin-top: 16px;
    text-align: center;
    font-size: 0.8rem;
    color: #444;
    padding-bottom: 24px;
}
.site-footer a {
    color: #555;
    text-decoration: none;
}
.site-footer a:active {
    color: #999;
}
.footer-sep {
    margin: 0 8px;
    color: #333;
}
