:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #dde4ef;
  --green: #15803d;
  --green-soft: #dcfce7;
  --blue: #2563eb;
  --red: #dc2626;
  --amber: #f59e0b;
  --amber-soft: #fff7ed;
  --shadow: 0 14px 36px rgba(23, 32, 51, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 0.68rem 0.9rem;
  color: #ffffff;
  background: var(--blue);
  cursor: pointer;
  min-height: 42px;
}

button:hover {
  filter: brightness(0.94);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.7rem 0.78rem;
  color: var(--text);
  background: #ffffff;
  min-height: 42px;
}

label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.app-shell {
  width: min(100vw - 14px, 1180px);
  margin: 0 auto;
  padding: 7px 0 18px;
}

.topbar,
.account-section,
.group-section,
.setup-row,
.round-entry,
.current-game-section,
.stats-section,
.table-section,
.history-section,
.summary-band {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  margin-bottom: 10px;
  overflow: hidden;
}

.topbar,
.account-section,
.group-section,
.setup-row,
.round-entry,
.current-game-section,
.stats-section,
.table-section,
.history-section {
  padding: 16px;
}

.group-section,
.account-section,
.setup-row {
  box-shadow: none;
}

.account-section,
.group-section {
  padding: 12px;
  background: #fbfcff;
}

.setup-row {
  padding: 10px 12px;
  background: #fbfcff;
}

.group-section .section-title {
  margin-bottom: 8px;
}

.account-section .section-title {
  margin-bottom: 10px;
}

.group-section h2 {
  font-size: 0.96rem;
}

.account-grid,
.account-form {
  display: grid;
  gap: 10px;
}

.account-grid {
  margin-top: 10px;
}

.account-form {
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.topbar {
  display: grid;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 0.15rem;
  color: var(--green);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  font-size: 0.78rem;
}

.sheet-status {
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 2.15rem;
  line-height: 1;
}

h2 {
  font-size: 1.08rem;
}

h3 {
  font-size: 1rem;
}

.actions,
.player-form,
.group-form,
.setup-row,
.section-title {
  display: flex;
  gap: 10px;
}

.actions {
  align-items: center;
  flex-wrap: wrap;
}

.icon-button {
  width: 42px;
  padding: 0;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  background: #334155;
}

.danger {
  background: var(--red);
}

.logout-link {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
}

.setup-row,
.player-form,
.group-form,
.group-controls {
  align-items: stretch;
  flex-direction: column;
}

.setup-row {
  gap: 8px;
}

.group-controls {
  display: flex;
  gap: 8px;
}

.group-form {
  display: flex;
  gap: 8px;
}

.group-controls label,
.group-form label,
.player-form label {
  font-size: 0.76rem;
}

.group-controls input,
.group-controls select,
.group-controls button,
.player-form input,
.player-form button {
  min-height: 38px;
  padding: 0.54rem 0.68rem;
}

.lock-note {
  display: none;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.lock-note:not(:empty) {
  display: block;
}

.player-form.is-locked {
  opacity: 0.64;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
}

.toggle input {
  width: 20px;
  height: 20px;
  min-height: 20px;
  accent-color: var(--green);
}

.section-title {
  justify-content: space-between;
  align-items: start;
  margin-bottom: 14px;
}

.section-title span {
  color: var(--muted);
  font-size: 0.86rem;
  text-align: right;
}

.round-grid,
.current-game-grid,
.stats-grid {
  display: grid;
  gap: 12px;
}

.current-score-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
  display: grid;
  gap: 10px;
}

.current-score-card.over-limit {
  border-color: #fbbf24;
  background: #fffbeb;
}

.current-score-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.current-score-head span {
  color: var(--muted);
  font-weight: 800;
}

.current-score-head strong {
  font-size: 2rem;
  line-height: 1;
}

.progress-track {
  height: 10px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.progress-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.over-limit .progress-track span {
  background: var(--amber);
}

.current-score-card small {
  color: var(--muted);
  font-weight: 700;
}

.score-input {
  display: grid;
  gap: 6px;
}

.score-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 6px;
}

.score-field input {
  text-align: center;
  font-weight: 800;
}

.sign-toggle {
  min-height: 42px;
  padding: 0;
  background: #334155;
  font-size: 0.82rem;
  font-weight: 800;
}

.round-submit {
  background: var(--green);
}

.secondary-button {
  background: #475569;
}

.summary-band {
  display: grid;
}

.summary-band article {
  padding: 15px 16px;
  border-bottom: 1px solid var(--line);
}

.summary-band article:last-child {
  border-bottom: 0;
}

.summary-band span,
.stat-card dt {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.32rem;
}

.summary-band strong {
  font-size: 1.25rem;
}

.stat-card,
.history-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.stat-card {
  padding: 14px;
}

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

.stat-card-head strong {
  font-size: 1.35rem;
}

.stat-card dl {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0;
}

.stat-card dd {
  margin: 0;
  font-weight: 800;
}

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

.chart-panel {
  margin-top: 16px;
}

.compact-title {
  margin-bottom: 8px;
}

.score-chart {
  display: grid;
  gap: 10px;
}

.chart-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chart-wrap svg {
  display: block;
  width: 100%;
  min-width: 520px;
  height: auto;
}

.chart-grid-line {
  stroke: #e5eaf3;
  stroke-width: 1;
}

.chart-axis {
  stroke: #9aa7b8;
  stroke-width: 1.4;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.chart-line {
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.32rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
}

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

th {
  background: #eef4ff;
  color: #0f172a;
  font-size: 0.8rem;
}

td:nth-child(2),
th:nth-child(2) {
  position: sticky;
  left: 0;
  z-index: 1;
  text-align: left;
  background: #ffffff;
}

th:nth-child(2) {
  background: #eef4ff;
}

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

.rank {
  font-weight: 800;
}

.best {
  color: var(--green);
  background: var(--green-soft);
}

.remove-player {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  margin-left: 8px;
  border-radius: 50%;
  background: #e2e8f0;
  color: var(--text);
}

.history-list {
  display: grid;
  gap: 14px;
}

.history-game {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  overflow: hidden;
}

.history-game-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 13px;
  background: #eaf2ff;
  border-bottom: 1px solid var(--line);
}

.history-game-head div {
  display: grid;
  gap: 2px;
}

.history-game-head strong {
  font-size: 1rem;
}

.history-game-head span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.history-game-rounds {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.history-card {
  padding: 13px;
  display: grid;
  gap: 8px;
  box-shadow: none;
}

.history-card > div:first-child,
.history-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.history-card-head > div {
  display: grid;
  gap: 3px;
}

.edit-round-btn {
  min-height: 34px;
  padding: 0.42rem 0.6rem;
  background: #334155;
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.history-card span {
  color: var(--muted);
  font-size: 0.84rem;
}

.history-card p {
  margin: 0;
  font-weight: 800;
}

.history-card.won {
  border-left: 5px solid var(--green);
}

.history-card.lost {
  border-left: 5px solid var(--amber);
  background: var(--amber-soft);
}

.score-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.score-line span {
  padding: 0.28rem 0.45rem;
  border-radius: 8px;
  background: #eef2f7;
  color: var(--text);
  font-weight: 700;
}

.score-line .closer-score {
  background: #dbeafe;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin-bottom: 22px;
}

.login-form {
  display: grid;
  gap: 10px;
}

.reset-request-form {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.form-link {
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.form-error {
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.form-success {
  margin: 0;
  color: var(--green);
  font-weight: 700;
}

.back-top {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 10;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  border-radius: 50%;
  background: #172033;
  box-shadow: 0 12px 28px rgba(23, 32, 51, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.back-top.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

@media (min-width: 700px) {
  .app-shell {
    width: min(1180px, calc(100vw - 32px));
    padding: 24px 0;
  }

  .topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .account-grid {
    grid-template-columns: minmax(220px, 0.8fr) minmax(280px, 1.2fr);
    align-items: start;
  }

  .actions {
    justify-content: end;
  }

  .setup-row,
  .player-form,
  .group-form,
  .group-controls {
    align-items: end;
    flex-direction: row;
  }

  .player-form,
  .group-form {
    flex: 1 1 520px;
  }

  .player-form label,
  .group-form label {
    min-width: 52px;
  }

  .player-form input,
  .group-form input {
    max-width: 340px;
  }

  .summary-band {
    grid-template-columns: repeat(3, 1fr);
  }

  .summary-band article {
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }

  .summary-band article:last-child {
    border-right: 0;
  }

  .round-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .current-game-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
