* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  margin: 0;
  color: #111;
  background: #f6f7f9;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

h1 {
  margin: 16px 0;
  font-size: 28px;
}

h2 {
  margin: 8px 0 12px;
  font-size: 20px;
}

h3 {
  margin: 0 0 10px;
  font-size: 16px;
}

.small {
  font-size: 12px;
  color: #555;
}

header .controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-link {
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 8px;
  background: #0b5fff;
  color: #fff;
}

.admin-link.danger {
  background: #e11d48;
}

.table-wrap {
  overflow-x: auto;
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #eee;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #fafafa;
}

td.nowrap {
  white-space: nowrap;
}

tr:hover {
  background: #fafcff;
}

.ranking-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 18px;
}

.controls-top .ranking-nav {
  margin: 0;
}

.ranking-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  background: #fff;
  color: inherit;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.ranking-nav a.active {
  border-color: #0b5fff;
  background: #0b5fff;
  color: #fff;
}

.ranking-section {
  margin: 0 0 28px;
}

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
}

.section-heading h2 {
  margin: 0;
}

.section-heading span {
  color: #6b7280;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.ranking-table-wrap {
  border-radius: 8px;
}

.ranking-table .rank-col {
  width: 54px;
  text-align: right;
  font-weight: 800;
}

.ranking-table .time-col {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}

.category-block {
  min-width: 0;
}

.category-block h3 {
  padding: 0 2px;
}

.card {
  background: white;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
input[type="date"],
select {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
}

button,
.btn-secondary,
.btn-small {
  display: inline-block;
  padding: 10px 14px;
  border-radius: 8px;
  border: none;
  background: #0b5fff;
  color: white;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
}

.btn-secondary {
  background: #6b7280;
}

.btn-small {
  padding: 6px 10px;
  font-size: 12px;
}

.btn-small.danger {
  background: #e11d48;
}

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

.import-form {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  align-items: end;
  gap: 12px;
}

.competition-layout {
  display: grid;
  gap: 14px;
}

.competition-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.competition-new-form {
  grid-template-columns: minmax(120px, 0.7fr) minmax(220px, 1.3fr) minmax(150px, 0.8fr) auto auto;
}

.competition-card .small {
  margin: 10px 0 0;
}

.import-card .small {
  margin: 10px 0 0;
}

.inline-check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  padding-bottom: 11px;
  white-space: nowrap;
}

.alert {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.alert.success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.alert.error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

/* auth */
body.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #f0f4ff 0%, #f6f7f9 100%);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: white;
  padding: 20px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.auth-card h1 {
  text-align: center;
}

.note {
  color: #555;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.open {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.modal-card {
  position: relative;
  width: min(900px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

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

.modal-header h3 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
}

.modal-body {
  padding: 16px 20px 20px;
}

.modal-actions {
  justify-content: flex-end;
}

@media (max-width: 600px) {
  .modal-card {
    width: 96vw;
  }

  .import-form {
    grid-template-columns: 1fr;
  }

  .competition-form,
  .competition-new-form {
    grid-template-columns: 1fr;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }
}
