:root {
  --bg: #f4f7f8;
  --card: #ffffff;
  --ink: #112027;
  --subtle: #5d6e76;
  --brand: #0f766e;
  --brand-strong: #0b5d57;
  --line: #d6e0e4;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  background: radial-gradient(circle at 100% 0%, #cdebe8 0%, var(--bg) 45%);
  color: var(--ink);
}

.app {
  width: min(720px, 100%);
  margin: 0 auto;
  padding: 12px;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

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

h1 {
  margin: 0;
  font-size: 1.15rem;
}

h2 {
  margin: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 8px 20px rgba(17, 32, 39, 0.08);
}

.hidden {
  display: none;
}

.hint {
  margin-top: 6px;
  color: var(--subtle);
  font-size: 0.92rem;
}

.add-player-row {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 1rem;
}

button {
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 0 14px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 0.95rem;
}

button:disabled {
  opacity: 0.45;
}

button.ghost {
  background: #e6eff1;
  color: var(--ink);
}

button.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f4ccc9;
}

.players-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.players-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.players-list li:last-child {
  border-bottom: 0;
}

.player-item-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.remove-player-btn {
  min-height: 34px;
  min-width: 34px;
  border-radius: 8px;
  background: var(--danger-bg);
  border: 1px solid #f4ccc9;
  color: var(--danger);
  padding: 0;
}

.setup-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.lane-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.lane-header button:last-child {
  justify-self: end;
}

.label {
  margin: 0;
  font-size: 0.78rem;
  color: var(--subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.score-rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
}

.player-name {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.player-total {
  margin: 3px 0 0;
  color: var(--subtle);
  font-size: 0.88rem;
}

.counter {
  display: grid;
  grid-template-columns: 48px 48px 48px;
  align-items: center;
  gap: 6px;
}

.counter button {
  min-height: 48px;
  font-size: 1.2rem;
  padding: 0;
}

.score-value {
  width: 48px;
  min-height: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #edf1f3;
  color: #51626a;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1.12rem;
  font-weight: 700;
  cursor: pointer;
}

.score-value.score-edited {
  background: #38a169;
  border-color: #2f855a;
  color: #fff;
}

.row-actions {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.report {
  margin-top: 12px;
}

.report-only-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.report-only-bar.hidden {
  display: none;
}

.report-only-mode #laneHeader,
.report-only-mode #scoreRows,
.report-only-mode #rowActions {
  display: none;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px;
  text-align: center;
  white-space: nowrap;
}

/* Keep Rank, Player, Total visible while lane columns scroll horizontally. */
th:nth-child(1),
td:nth-child(1),
th:nth-child(2),
td:nth-child(2),
th:nth-child(3),
td:nth-child(3) {
  position: sticky;
  background: #f9fcfd;
}

th:nth-child(1),
td:nth-child(1) {
  left: 0;
  min-width: 40px;
  width: 40px;
  z-index: 4;
}

th:nth-child(2),
td:nth-child(2) {
  left: 40px;
  min-width: 80px;
  max-width: 80px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 3;
}

th:nth-child(3),
td:nth-child(3) {
  left: 120px;
  min-width: 52px;
  width: 52px;
  font-weight: 800;
  z-index: 2;
}

.total-cell {
  font-weight: 800;
}

.lane-score-cell {
  font-weight: 700;
}

.lane-header-cell {
  padding: 2px 4px;
}

.lane-col-header {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 2px;
}

.delete-lane-btn {
  min-height: 20px;
  min-width: 20px;
  font-size: 0.7rem;
  padding: 0;
  border-radius: 6px;
  background: var(--danger-bg);
  border: 1px solid #f4ccc9;
  color: var(--danger);
}

#gameView:not(.report-only-mode) #reportSection table {
  font-size: 0.82rem;
}

#gameView:not(.report-only-mode) #reportSection th,
#gameView:not(.report-only-mode) #reportSection td {
  padding: 5px 4px;
}

tr:last-child td {
  border-bottom: 0;
}

@media (min-width: 700px) {
  .app {
    padding: 20px;
  }

  h1 {
    font-size: 1.3rem;
  }
}

@media (max-width: 520px) {
  .top-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1;
  }
}
