:root {
  --bg: #f6f7f3;
  --ink: #172019;
  --muted: #617067;
  --line: #cfd8cf;
  --panel: #ffffff;
  --court: #e9f3ea;
  --court-hover: #dbeada;
  --accent: #1f7a4d;
  --accent-ink: #ffffff;
  --warn: #9f2f2f;
  --magnet-waiting: #9fd3ff;
  --magnet-complete: #1f4f8f;
  --magnet-ink: #ffffff;
  --magnet-waiting-ink: #12304d;
  --shadow: 0 8px 24px rgba(23, 32, 25, .08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0 14px;
  cursor: pointer;
}

button.secondary {
  background: #e5ebe5;
  color: var(--ink);
}

button.danger {
  background: var(--warn);
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #e8f3ee, #eef4fb);
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-card {
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card p {
  color: var(--muted);
}

.login-card label {
  font-weight: 700;
}

.login-card button {
  margin-top: 8px;
}

.login-error {
  padding: 10px 12px;
  border: 1px solid #e3a1a1;
  border-radius: 8px;
  color: #8d1f1f;
  background: #fff1f1;
}

.logout-link {
  color: var(--accent-ink);
  font-weight: 700;
  text-decoration: none;
}

.topbar {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  font-weight: 600;
}

h2 {
  font-size: 16px;
  font-weight: 600;
}

.topbar p,
.rules,
.selected,
label {
  color: var(--muted);
}

.data-status {
  margin-top: 4px;
  font-weight: 600;
}

.data-status[data-mode="remote"] {
  color: var(--accent);
}

.date-box {
  display: grid;
  gap: 6px;
  min-width: 170px;
}

.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 18px;
  padding: 18px;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
}

.add-player {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.block-form {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.player-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.player {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf7;
  padding: 6px 8px;
  cursor: grab;
}

.player.is-selected {
  border-color: var(--accent);
  outline: 2px solid rgba(31, 122, 77, .2);
}

.remove-player {
  min-height: 28px;
  padding: 0 8px;
}

.selected {
  margin: 10px 0;
  min-height: 24px;
}

.rules {
  margin: 10px 0 0;
  padding-left: 20px;
}

.stats {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.board-wrap {
  min-width: 0;
}

.message {
  min-height: 28px;
  color: var(--warn);
  font-weight: 600;
}

.board {
  width: 100%;
  min-width: 820px;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.board-wrap {
  overflow-x: auto;
}

.board th,
.board td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  text-align: center;
}

.board th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f1f5f1;
  font-weight: 600;
  height: 42px;
}

.board th:first-child,
.time-cell {
  width: 78px;
}

.time-cell {
  background: #f8faf8;
  color: var(--muted);
  font-weight: 600;
}

.slot {
  height: 44px;
  min-width: 104px;
  background: var(--court);
  cursor: pointer;
}

.slot:hover,
.slot.drag-over,
.booking-cell.drag-over {
  background: var(--court-hover);
}

.booking-cell {
  padding: 5px;
  background: var(--court);
  cursor: grab;
}

.booking-cell.block-cell {
  padding: 0;
}

.booking-cell.block-training {
  background: #ffd98f;
}

.booking-cell.block-team {
  background: #d7c7ff;
}

.booking-cell.block-closed {
  background: #d6d8da;
}

.magnet {
  position: relative;
  display: grid;
  align-content: center;
  gap: 4px;
  min-height: 80px;
  border-radius: 8px;
  padding: 8px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
  height: 100%;
}

.magnet.is-waiting {
  background: var(--magnet-waiting);
  color: var(--magnet-waiting-ink);
}

.magnet.is-complete {
  background: var(--magnet-complete);
  color: var(--magnet-ink);
}

.magnet.block {
  color: #172019;
  min-height: 100%;
  border-radius: 0;
  padding: 12px 8px 18px;
}

.magnet.block.training {
  background: #ffd98f;
}

.magnet.block.team {
  background: #d7c7ff;
}

.magnet.block.closed {
  background: #d6d8da;
}

.magnet-names {
  display: grid;
  grid-template-rows: 20px 20px;
  gap: 2px;
  align-items: center;
  min-height: 42px;
}

.magnet strong {
  overflow-wrap: anywhere;
}

.magnet .empty-name {
  visibility: hidden;
}

.magnet small {
  opacity: .9;
}

.magnet .magnet-close {
  position: absolute;
  top: 5px;
  right: 5px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  min-height: 24px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  color: inherit;
  padding: 0;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.resize-handle {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 5px;
  height: 9px;
  border-radius: 999px;
  background: rgba(23, 32, 25, .28);
  cursor: ns-resize;
}

.resize-handle::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 28px;
  height: 3px;
  border-top: 1px solid rgba(255,255,255,.6);
  border-bottom: 1px solid rgba(255,255,255,.6);
  transform: translate(-50%, -50%);
}

@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px;
  }

  h1 {
    font-size: 22px;
  }

  .date-box {
    min-width: 0;
  }

  .layout {
    display: grid;
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .sidebar {
    display: contents;
  }

  .player-panel {
    order: 1;
  }

  .selection-panel {
    order: 2;
  }

  .board-wrap {
    order: 3;
  }

  .guest-panel {
    order: 4;
  }

  .block-panel {
    order: 5;
  }

  .stats-panel {
    order: 6;
  }

  .rules-panel {
    order: 7;
  }

  .panel {
    padding: 12px;
  }

  .player-list {
    grid-template-columns: repeat(auto-fit, minmax(138px, 1fr));
  }

  .player {
    min-height: 42px;
  }

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

  .block-form input,
  .block-form button {
    grid-column: 1 / -1;
  }

  .board-wrap {
    margin: 0 -12px;
    padding: 0 12px 12px;
    -webkit-overflow-scrolling: touch;
  }

  .message {
    position: sticky;
    left: 12px;
    min-height: 24px;
  }

  .board {
    min-width: 720px;
  }

  .board th,
  .board td {
    font-size: 13px;
  }

  .board th {
    height: 38px;
  }

  .board th:first-child,
  .time-cell {
    position: sticky;
    left: 0;
    z-index: 3;
    width: 64px;
  }

  .time-cell {
    font-size: 12px;
  }

  .slot {
    height: 40px;
    min-width: 88px;
  }

  .booking-cell {
    padding: 4px;
  }

  .magnet {
    min-height: 72px;
    padding: 7px 6px;
    border-radius: 6px;
  }

  .magnet.block {
    padding: 10px 6px 17px;
  }

  .magnet-names {
    grid-template-rows: 18px 18px;
    min-height: 38px;
  }

  .magnet .magnet-close {
    width: 22px;
    height: 22px;
    min-height: 22px;
  }
}

@media (max-width: 520px) {
  button,
  input,
  select {
    min-height: 44px;
  }

  .topbar p {
    font-size: 14px;
  }

  .layout {
    padding: 10px;
  }

  .board-wrap {
    margin: 0 -10px;
    padding: 0 10px 12px;
  }

  .add-player {
    grid-template-columns: 1fr auto;
  }

  .add-player input {
    min-width: 0;
  }

  .add-player button {
    padding: 0 10px;
  }

  .player-list {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .player {
    flex: 0 0 164px;
  }

  .rules {
    font-size: 14px;
  }

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

  .stats p {
    padding: 8px;
    border-radius: 8px;
    background: #f7faf7;
  }

  .board {
    min-width: 680px;
  }

  .board th:first-child,
  .time-cell {
    width: 58px;
  }

  .slot {
    min-width: 82px;
  }

  .magnet small {
    font-size: 11px;
  }
}
