/* ============================================================
   Fencing Pool Manager — Styles
   Mobile-first responsive design
   ============================================================ */

/* --- Reset & Variables --- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #f0f2f5;
  --card-bg: #ffffff;
  --border: #d1d5db;
  --border-light: #e5e7eb;
  --text: #1a1a1a;
  --text-secondary: #4a4a4a;
  --text-muted: #888888;
  --accent: #1a1a1a;
  --accent-hover: #333333;
  --accent-light: #fff8d6;
  --brand-yellow: #ffe84f;
  --brand-black: #1a1a1a;
  --victory-bg: #dcfce7;
  --victory-text: #166534;
  --defeat-bg: #fee2e2;
  --defeat-text: #991b1b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --diagonal-bg: #e5e7eb;
  --highlight-bg: #fff8d6;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.12);
}

/* --- Base & Typography --- */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* --- Header --- */
header {
  background: var(--brand-black);
  color: var(--brand-yellow);
  padding: 0.5rem 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.header-logo {
  height: 2.2rem;
  width: auto;
  filter: brightness(0) invert(1);
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--brand-yellow);
  white-space: nowrap;
}

.header-utils {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-header {
  padding: 0.3rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid rgba(255, 232, 79, 0.3);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--brand-yellow);
  cursor: pointer;
  min-height: 32px;
  white-space: nowrap;
  transition: background 0.15s;
}

.btn-header:hover {
  background: rgba(255, 232, 79, 0.15);
}

.btn-header-danger {
  color: #ff6b6b;
  border-color: rgba(255, 107, 107, 0.3);
}

.btn-header-danger:hover {
  background: rgba(255, 107, 107, 0.15);
}

.btn-menu {
  background: none;
  border: none;
  color: var(--brand-yellow);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0.2rem;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile: hide nav, show hamburger */
@media (max-width: 599px) {
  .header-utils {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--brand-black);
    padding: 0.5rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
    box-shadow: var(--shadow-lg);
  }

  .header-utils.menu-open {
    display: flex;
  }

  .btn-header {
    flex: 1;
    min-width: 60px;
    text-align: center;
    justify-content: center;
  }
}

/* Desktop: always show nav, hide hamburger */
@media (min-width: 600px) {
  .btn-menu {
    display: none !important;
  }

  .header-utils {
    display: flex !important;
  }
}

/* --- Main Layout --- */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--brand-black);
  border-bottom: 2px solid var(--brand-yellow);
  padding-bottom: 0.4rem;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-header h2 {
  margin-bottom: 0;
  border-bottom: none;
  padding-bottom: 0;
}

.hidden {
  display: none !important;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  min-height: 44px;
  min-width: 44px;
  touch-action: manipulation;
}

.btn:active {
  opacity: 0.85;
}

.btn-primary {
  background: var(--brand-yellow);
  color: var(--brand-black);
  font-weight: 700;
}

.btn-primary:hover {
  background: #fde030;
  color: var(--brand-black);
}

.btn-secondary {
  background: var(--border-light);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-small {
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  min-height: 32px;
  min-width: auto;
  background: var(--border-light);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.btn-small:hover {
  background: var(--border);
}

/* --- Setup Section --- */
.setup-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.setup-row label {
  font-weight: 600;
  font-size: 0.9rem;
}

.setup-row #pool-size,
.setup-row #max-points {
  width: 4.5rem;
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: 44px;
}

#fencer-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.fencer-input-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.fencer-input-row .fencer-seed {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-secondary);
  min-width: 1.8rem;
  text-align: center;
}

.fencer-input-row input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 40px;
}

.fencer-input-row input:focus {
  outline: 2px solid var(--brand-yellow);
  outline-offset: -1px;
  border-color: var(--brand-black);
}

.fencer-input-row .fencer-name-input {
  flex: 2;
}

.fencer-input-row .fencer-club-input {
  flex: 1;
}

.fencer-input-row .fencer-club-input::placeholder {
  color: var(--text-muted);
}

#generate-btn {
  width: 100%;
}

/* --- Progress Text --- */
.progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  font-weight: 500;
}

/* --- Tables (shared) --- */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th,
td {
  padding: 0.35rem 0.5rem;
  text-align: center;
  border: 1px solid var(--border-light);
  white-space: nowrap;
}

th {
  background: #f9fafb;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* --- Standings Table --- */
.standings-table th {
  position: sticky;
  top: 0;
  z-index: 1;
}

.standings-table td:first-child,
.standings-table th:first-child {
  font-weight: 700;
  color: var(--brand-black);
}

.standings-table td.name-cell {
  text-align: left;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.standings-table td.club-cell {
  text-align: left;
  color: var(--text-secondary);
  font-size: 0.8rem;
  max-width: 80px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- Pool Grid Table --- */
.pool-table {
  min-width: auto;
}

.pool-table th:first-child,
.pool-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 2;
  background: #f9fafb;
  text-align: left;
  font-weight: 600;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pool-table th:first-child {
  z-index: 3;
}

.pool-table .cell-header {
  font-weight: 700;
  min-width: 2.5rem;
}

.pool-cell {
  cursor: pointer;
  min-width: 2.8rem;
  min-height: 2.5rem;
  transition: background 0.1s;
  font-weight: 600;
  user-select: none;
}

.pool-cell:hover {
  outline: 2px solid var(--brand-yellow);
  outline-offset: -2px;
}

.pool-cell.diagonal {
  background: var(--diagonal-bg);
  cursor: default;
  color: var(--text-muted);
}

.pool-cell.diagonal:hover {
  outline: none;
}

.pool-cell.victory {
  background: var(--victory-bg);
  color: var(--victory-text);
}

.pool-cell.defeat {
  background: var(--defeat-bg);
  color: var(--defeat-text);
}

.pool-cell.incomplete {
  background: #fff;
  color: var(--text-muted);
}

/* --- Bout List --- */
#bout-list-controls {
  margin-bottom: 0.5rem;
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-secondary);
}

.toggle-label input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--brand-yellow);
}

.bout-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.bout-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.bout-item:last-child {
  border-bottom: none;
}

.bout-item.next-bout {
  background: var(--highlight-bg);
  border-left: 3px solid var(--brand-yellow);
  padding-left: calc(0.4rem - 3px);
}

.bout-num {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 2rem;
  text-align: center;
  flex-shrink: 0;
}

.bout-content {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.bout-fencer-group {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  min-width: 0;
}

.bout-fencer-group-a {
  justify-content: flex-end;
}

.bout-fencer-group-b {
  justify-content: flex-start;
}

.bout-fencer {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
}

.bout-fencer-a {
  text-align: right;
}

.bout-fencer-b {
  text-align: left;
}

.bout-fencer.winner {
  font-weight: 700;
  color: var(--victory-text);
}

.bout-fencer .fencer-club {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 0.15rem;
}

.bout-fencer-b .fencer-club {
  margin-left: 0.15rem;
  margin-right: 0;
}

.bout-scores {
  display: flex;
  align-items: center;
  gap: 0.2rem;
  flex-shrink: 0;
}

.bout-score {
  width: 2.8rem;
  padding: 0.3rem 0.2rem;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 36px;
  appearance: textfield;
  -moz-appearance: textfield;
}

.bout-score::-webkit-inner-spin-button,
.bout-score::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.bout-score:focus {
  outline: 2px solid var(--brand-yellow);
  outline-offset: -1px;
  border-color: var(--brand-black);
}

.bout-separator {
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.bout-status {
  font-size: 0.8rem;
  min-width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.bout-status.complete {
  color: var(--victory-text);
}

.bout-clear-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  touch-action: manipulation;
}

.bout-clear-btn:hover {
  background: var(--defeat-bg);
  color: var(--defeat-text);
}

/* Victory (V) toggle in bout list */
.victory-toggle {
  width: 1.8rem;
  height: 1.8rem;
  min-width: 1.8rem;
  font-size: 0.8rem;
  font-weight: 700;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  touch-action: manipulation;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.victory-toggle:hover {
  border-color: var(--victory-text);
  color: var(--victory-text);
}

.victory-toggle.active {
  background: var(--victory-bg);
  border-color: var(--victory-text);
  color: var(--victory-text);
}

.victory-toggle.hidden {
  display: none;
}

/* Victory checkbox in modal */
.modal-victory-container.hidden {
  display: none;
}

.modal-victory-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  justify-content: center;
}

.modal-victory-label input[type="checkbox"] {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--victory-text);
  cursor: pointer;
}

.modal-victory-label.hidden {
  display: none;
}

/* Winner picker (equal scores) in modal */
.modal-victory-picker {
  margin-top: 0.75rem;
  text-align: center;
}

.modal-victory-picker.hidden {
  display: none;
}

.modal-victory-picker-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.modal-victory-btns {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.btn-victory-pick {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-victory-pick:hover {
  border-color: var(--victory-text);
}

.btn-victory-pick.active {
  background: var(--victory-bg);
  border-color: var(--victory-text);
  color: var(--victory-text);
}

/* Victory pick in bout list */
.victory-pick {
  font-size: 0.7rem;
  width: auto;
  min-width: 1.6rem;
  padding: 0 0.2rem;
}

.bout-warning {
  font-size: 0.7rem;
  color: var(--warning-text);
  background: var(--warning-bg);
  padding: 0.1rem 0.3rem;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  flex-basis: 100%;
  order: 10;
}

/* --- Modal (dialog) --- */
dialog {
  border: none;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 1.25rem;
  max-width: 340px;
  width: calc(100% - 2rem);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

dialog h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  text-align: center;
}

.modal-body {
  margin-bottom: 1rem;
}

.modal-score-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.modal-score-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}

.modal-fencer-label {
  font-size: 0.85rem;
  font-weight: 600;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.modal-vs {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 1.4rem;
}

dialog input[type='number'] {
  width: 4rem;
  padding: 0.6rem;
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 48px;
  appearance: textfield;
  -moz-appearance: textfield;
}

dialog input[type='number']::-webkit-inner-spin-button,
dialog input[type='number']::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

dialog input[type='number']:focus {
  outline: none;
  border-color: var(--brand-yellow);
}

.warning-text {
  color: var(--warning-text);
  background: var(--warning-bg);
  font-size: 0.8rem;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius-sm);
  text-align: center;
  margin-top: 0.75rem;
}

.warning-text:empty {
  display: none;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
}

.modal-actions .btn {
  flex: 1;
}

/* --- Responsive: Tablet+ --- */
@media (min-width: 600px) {
  header h1 {
    font-size: 1.4rem;
  }

  main {
    padding: 1rem;
    gap: 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  table {
    font-size: 0.9rem;
  }

  .bout-fencer {
    font-size: 0.9rem;
  }

  .bout-score {
    width: 3.2rem;
  }

  #generate-btn {
    width: auto;
    min-width: 200px;
  }
}

/* --- Responsive: Desktop --- */
@media (min-width: 960px) {
  .card h2 {
    font-size: 1.2rem;
  }

  .pool-cell {
    min-width: 3.2rem;
  }
}

/* --- Print --- */
@media print {
  header {
    position: static;
    background: none;
    color: var(--text);
    box-shadow: none;
    border-bottom: 2px solid var(--text);
  }

  #setup-section,
  .header-utils,
  .btn-menu,
  #bout-list-controls,
  .bout-scores input,
  .bout-clear-btn,
  .btn,
  dialog {
    display: none !important;
  }

  .card {
    box-shadow: none;
    border: 1px solid var(--border);
    break-inside: avoid;
  }

  .hidden {
    display: none !important;
  }

  .bout-scores {
    font-weight: 600;
  }

  body {
    background: #fff;
  }
}
