:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #bfbfbf;
  --border: #e5e7eb;
  --accent: #464646;
  --accent-soft: #eaeaea;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.15s ease;
}

a:hover {
  background: var(--accent-soft);
  text-decoration: none;
}

abbr {
  text-decoration: none;
}

.container {
  max-width: 720px;
  margin: 16px auto;
  padding: 0 12px 24px;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 20px rgba(17, 24, 39, 0.05);
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.nav a {
  font-weight: 600;
}

.nav a.active {
  text-decoration: underline;
}

.season-filter {
  display: flex;
  align-items: center;
}

.season-filter select {
  width: 100px;
  max-width: 100px;
  padding: 2px 4px;
  font-size: 16px;
  line-height: 1.2;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 10px 28px rgba(17, 24, 39, 0.07);
}

h1 {
  margin-top: 0;
  margin-bottom: 12px;
}

h2.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  margin-top: 24px;
  margin-bottom: 12px;
}

.table {
  border-collapse: collapse;
  width: 100%;
}

.table th,
.table td {
  border: none;
  padding: 10px;
  text-align: left;
}

.table .rank,
.table .name {
  padding-right: 8px;
}

.table .num {
  text-align: center;
  padding-left: 8px;
  padding-right: 8px;
  width: 7%;
  white-space: nowrap;
}

.table .num + .num {
  padding-left: 6px;
}

.table .rank {
  width: 1%;
  white-space: nowrap;
}

.table th {
  background: transparent;
  font-weight: 700;
  color: var(--muted);
}

.table th.sortable {
  cursor: pointer;
  user-select: none;
}

.table th.sortable:hover {
  color: var(--accent);
}

.table tbody tr:nth-child(even) {
  background: transparent;
}

.nowrap {
  white-space: nowrap;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stack > p {
  margin: 0;
}

.stack > div > p {
  margin: 0 0 8px 0;
}

.stack > button {
  margin-top: 8px;
}

.stack > .actions {
  margin-top: 14px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.actions button {
  flex: 1;
  min-width: 120px;
}

.actions button.ghost {
  order: -1;
}

button {
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 15px;
}

button:hover {
  opacity: 0.85;
}

button.ghost {
  background: var(--accent-soft);
  color: var(--accent);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
  padding: 10px 12px;
  border: 1px solid var(--border);
  font-size: 16px;
  border-radius: 6px;
}

input[type="number"] {
  width: 100px;
}

.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
}

.inline-form input[type="text"] {
  flex: 1;
  min-width: 120px;
}

.list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

.list-item {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

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

.h2h-selects,
.score-selects {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.h2h-results {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 1.5rem;
  margin: 1rem 0 2rem;
}

.h2h-player {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

.h2h-name {
  margin: 0;
  white-space: nowrap;
  min-width: 0;
}

.h2h-name-link {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
}

.h2h-name--right .h2h-name-link {
  justify-content: flex-end;
}

.h2h-name--right {
  text-align: right;
}

.h2h-name--left .h2h-name-link {
  justify-content: flex-start;
}

.h2h-name--left {
  text-align: left;
}

.h2h-emoji {
  flex-shrink: 0;
  font-size: 1.1em;
}

.h2h-name-text {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.h2h-stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  text-align: center;
  gap: 1rem;
}

.h2h-divider {
  width: 3px;
  background-color: rgba(0, 0, 0, 0.3);
  align-self: stretch;
}

.error {
  color: #b00020;
  margin: 0;
}

.success {
  color: #2e7d32;
  margin: 0;
  font-weight: 600;
}

.notice {
  padding: 12px;
  border: 1px solid var(--border);
  background: #f3f4f6;
  border-radius: 8px;
}

.season-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.season-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.4fr) repeat(2, minmax(140px, 1fr));
  gap: 12px;
  align-items: end;
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  padding: 16px;
  color: var(--muted);
  font-size: 14px;
}

.footer a {
  color: var(--muted);
  padding: 0;
}

.footer a:hover {
  color: var(--accent);
  background: transparent;
}

.footer-sep {
  color: var(--muted);
}

.player-stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.player-stats .stat {
  align-items: center;
  text-align: center;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.responsive-label .label-short {
  display: none;
}

@media (max-width: 720px) {
  .hide-small {
    display: none;
  }

  .player-stats {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
  }

  .responsive-label .label-full {
    display: none;
  }

  .responsive-label .label-short {
    display: inline;
  }

  .season-filter {
    display: none;
  }

  .season-row {
    grid-template-columns: 1fr;
  }
}

canvas {
  max-height: 300px;
}

/* Easter egg: Page roll animation */
@keyframes pageRoll {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

body.page-roll {
  animation: pageRoll 2s ease-in-out;
}
