:root {
  --bg: #ffffff;
  --bg-soft: #f8fafc;
  --bg-muted: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --red: #d1001f;
  --red-dark: #b10019;
  --line: #e2e8f0;
  --slot: #f8fafc;
  --court1: #2d9e44;
  --court2: #6e3bc1;
  --danger: #b70000;
  --ring: rgba(209, 0, 31, 0.2);
  --shadow-sm: 0 8px 20px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 16px 34px rgba(15, 23, 42, 0.1);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(circle at 12% -10%, #ffe7eb 0%, rgba(255, 231, 235, 0) 42%),
    radial-gradient(circle at 88% 0%, #e8efff 0%, rgba(232, 239, 255, 0) 36%),
    linear-gradient(180deg, #f8fbff 0%, #f5f8ff 100%);
  color: var(--text);
}

body.login-screen {
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(255, 242, 242, 0.8) 100%),
    url("/static/court.jpg");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  background-attachment: fixed;
}

html.drawing-selection,
html.drawing-selection * {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
}

body.drawing-scroll-lock {
  overflow: hidden;
}

main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 18px 16px 28px;
}

.card {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.hidden {
  display: none !important;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

h1,
h2,
h3 {
  margin: 0 0 12px;
  line-height: 1.2;
}

h1 {
  font-size: 1.78rem;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.34rem;
  letter-spacing: -0.015em;
}

h3 {
  font-size: 1.08rem;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 10px;
}

.field {
  margin-bottom: 12px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

input,
select,
button,
textarea {
  width: 100%;
  font-size: 0.98rem;
  border-radius: 12px;
  border: 1px solid #cfd8e6;
  min-height: 44px;
  padding: 10px 12px;
  background: #fff;
}

input,
select,
textarea {
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

input:focus,
select:focus,
textarea:focus {
  outline: 0;
  border-color: #d1001f;
  box-shadow: 0 0 0 4px var(--ring);
}

select[multiple] {
  min-height: 180px;
  padding: 6px;
}

button {
  background: linear-gradient(180deg, #dd1d37 0%, #c5001d 100%);
  color: #fff;
  border: 0;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 22px rgba(209, 0, 31, 0.26);
  transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

button:hover {
  background: linear-gradient(180deg, #c5001d 0%, #ab0019 100%);
  transform: translateY(-1px);
  box-shadow: 0 14px 24px rgba(209, 0, 31, 0.28);
}

button.secondary {
  background: #fff;
  color: var(--red);
  border: 1px solid #d1d9e8;
  box-shadow: none;
}

button.secondary:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 10px 20px rgba(209, 0, 31, 0.24);
}

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

a {
  color: var(--red);
  text-decoration: none;
}

.inline-row {
  display: flex;
  gap: 8px;
}

.inline-row > * {
  flex: 1;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  max-width: 1120px;
  margin: 0 auto;
}

.brand-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand-title {
  display: none;
  align-items: center;
  min-width: 0;
}

.brand-title strong {
  font-size: 1rem;
  line-height: 1.05;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-btn {
  width: auto;
  min-height: 38px;
  padding: 8px 16px;
}

.logo-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.logo-button:hover {
  background: transparent;
  box-shadow: none;
  transform: none;
}

#go-dashboard-logo.logo-button,
#go-dashboard-logo.logo-button:hover,
#go-dashboard-logo.logo-button:focus,
#go-dashboard-logo.logo-button:active {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  padding: 0 !important;
  min-height: 0 !important;
  width: auto !important;
  transform: none !important;
  outline: none;
}

#go-dashboard,
#logout {
  width: auto;
  min-height: 38px;
  padding: 8px 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.topbar-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.mobile-menu-shell {
  display: none;
  position: relative;
}

.mobile-menu-toggle {
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 14px;
  border: 1px solid rgba(209, 0, 31, 0.18);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.mobile-menu-toggle:hover {
  background: rgba(255, 255, 255, 0.98);
}

.mobile-menu-toggle span {
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
  margin: 0 auto;
}

.mobile-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 210px;
  padding: 8px;
  border: 1px solid rgba(226, 232, 240, 0.94);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 34px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(12px);
}

.mobile-menu-item {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  text-align: left;
  font-weight: 650;
}

.mobile-menu-item:hover {
  background: #f8fafc;
  color: var(--red);
  transform: none;
  box-shadow: none;
}

.login-logo {
  display: block;
  width: 120px;
  max-width: 40%;
  height: auto;
  margin: 0 auto 3px;
}

#login-card h1 {
  margin-bottom: 16px;
}

.msg {
  padding: 10px 12px;
  border-radius: 12px;
  margin-bottom: 14px;
  font-weight: 600;
  border: 1px solid transparent;
}

.msg.ok {
  background: #eefaf0;
  color: #176a2d;
  border-color: #b8e3c0;
}

.msg.error {
  background: #fff1f2;
  color: #9f1239;
  border-color: #f7c4ce;
}

.dashboard-grid {
  display: grid;
  gap: 14px;
}

.status-courts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.status-box {
  border-radius: 14px;
  border: 1px solid var(--line);
  padding: 12px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.status-box h4 {
  margin: 0 0 8px;
}

#dashboard-screen {
  background: rgba(255, 255, 255, 0.9);
}

#calendar-screen {
  background: rgba(255, 255, 255, 0.92);
}

#dashboard-screen .card,
#calendar-screen .week-nav,
#calendar-screen .calendar-wrap {
  animation: riseIn 240ms ease both;
}

#auth-screen .card,
#pending-screen .card {
  box-shadow: var(--shadow-md);
}

#auth-screen .card h1,
#auth-screen .card h2 {
  text-wrap: balance;
}

#whoami {
  font-weight: 600;
}

.main-actions {
  display: grid;
  gap: 10px;
}

.main-actions button {
  min-height: 54px;
  font-size: 1.02rem;
  border-radius: 14px;
}

.stats-pie-wrap {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 16px;
  margin: 10px 0 10px;
}

.stats-pie {
  width: 140px;
  height: 140px;
  border-radius: 999px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 0.82rem;
  color: var(--muted);
  text-align: center;
  padding: 6px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.stats-pie-legend {
  display: grid;
  gap: 6px;
  align-content: center;
  font-size: 0.86rem;
}

.stats-pie-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.stats-pie-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex: 0 0 10px;
}

.list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.list li {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
}

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

.rank-medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45em;
  height: 1.45em;
  margin-right: 6px;
  border-radius: 999px;
  font-size: 0.86em;
  font-weight: 800;
  line-height: 1;
  color: #fff;
  vertical-align: middle;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.rank-medal.rank-1 {
  background: linear-gradient(180deg, #f3cb5b 0%, #d8a61d 100%);
}

.rank-medal.rank-2 {
  background: linear-gradient(180deg, #d8dee8 0%, #a6afbd 100%);
}

.rank-medal.rank-3 {
  background: linear-gradient(180deg, #d4a07f 0%, #a9683d 100%);
}

.rank-medal.rank-placeholder {
  background: #fff;
  border-color: #5f5f5f;
  color: #5f5f5f;
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #fff;
}

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

.report-table thead th {
  text-align: left;
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f5f8ff;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
}

.report-table thead th:nth-child(1) {
  width: 220px;
}

.report-table thead th:nth-child(2) {
  width: 98px;
}

.report-table tbody td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.report-table tbody tr:last-child td {
  border-bottom: 0;
}

.report-table tbody tr.next-game-row {
  cursor: pointer;
  transition: background-color 120ms ease;
}

.report-table tbody tr.next-game-row:hover {
  background: #f9fbff;
}

.report-table tbody tr.next-game-row:focus-visible {
  outline: 2px solid #d35d6d;
  outline-offset: -2px;
}

.report-table tbody td.ng-date {
  font-variant-numeric: tabular-nums;
}

.ng-date-day,
.ng-date-time {
  display: block;
}

.ng-date-time {
  color: var(--muted);
  font-size: 0.92em;
}

.report-table tbody td.ng-court {
  white-space: nowrap;
}

.report-table tbody td.ng-player {
  overflow-wrap: anywhere;
}

.report-table tbody tr.empty-row td {
  color: var(--muted);
  font-style: italic;
}

.court-label {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.92em;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.court-label.c1 {
  background: var(--court1);
}

.court-label.c2 {
  background: var(--court2);
}

.week-nav {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
}

.week-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.week-controls button {
  min-height: 0;
  height: auto;
  margin: 0;
  padding: 8px 12px;
  line-height: 1.05;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
}

#calendar-screen,
#calendar-screen * {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.calendar-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow-sm);
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}

.calendar {
  min-width: 910px;
  display: grid;
  grid-template-columns: 72px repeat(7, 1fr);
}

.col-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  font-weight: 700;
  text-align: center;
  backdrop-filter: blur(6px);
}

.calendar > .col-head:first-child {
  left: 0;
  z-index: 4;
}

.time-label {
  display: flex;
  align-items: center;
  justify-content: center;
  position: sticky;
  left: 0;
  z-index: 3;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid #e8edf6;
  padding: 0 4px;
  font-size: 0.78rem;
  line-height: 1;
  color: #475569;
  height: 22px;
  min-height: 22px;
  background: #fff;
  text-align: center;
}

.time-label.hour {
  font-weight: 700;
  border-bottom: 1px dotted #d7dfec;
}

.time-label.half {
  color: transparent;
  border-bottom: 1px solid #e7edf7;
  padding: 0 4px;
}

.slot-cell {
  border-bottom: 1px solid #e8edf6;
  border-right: 1px solid #e8edf6;
  background: var(--slot);
  height: 22px;
  min-height: 22px;
}

.slot-cell.half {
  border-bottom: 1px solid #e3eaf4;
}

.slot-cell.hour-start {
  border-bottom: 1px dotted #d7dfec;
}

.slot-cell.past {
  background: #eef1f6;
}

.day-column {
  position: relative;
  border-right: 1px solid #e5ecf6;
  min-height: 748px;
}

.day-column:last-child {
  border-right: 0;
}

.event {
  position: absolute;
  border-radius: 0;
  color: #fff;
  padding: 6px 7px;
  font-size: 0.76rem;
  line-height: 1.2;
  overflow: hidden;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.event .title {
  font-weight: 700;
  font-size: 0.78rem;
}

.event .meta {
  font-size: 0.72rem;
}

.event.c1 {
  background: var(--court1);
}

.event.c2 {
  background: var(--court2);
}

.event.passive {
  background: #d7dbe3;
  color: #475569;
  box-shadow: inset 0 0 0 1px #c2c8d3;
  cursor: pointer;
  border-color: transparent;
}

.event.own {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.85) inset;
}

.event .handle {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 12px;
  background: transparent;
}

.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.86rem;
  margin: 10px 0;
}

.week-nav .legend {
  margin: 0;
  display: flex;
  justify-content: center;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.admin-list .row {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
}

.admin-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}

.admin-user-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.admin-user-grid .full {
  grid-column: 1 / -1;
}

.admin-user-details {
  border: 0;
}

.admin-user-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 18, 32, 0.44);
  z-index: 20;
  display: grid;
  place-items: end center;
}

.modal .dialog {
  width: 100%;
  max-width: 980px;
  max-height: 92vh;
  overflow: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 16px;
  box-shadow: var(--shadow-md);
}

.small {
  font-size: 0.86rem;
  color: var(--muted);
}

@media (max-width: 879px) {
  body.login-screen {
    position: relative;
    background: #fff;
    overflow-x: hidden;
  }

  body.login-screen::before {
    content: "";
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100vh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
    transform-origin: center;
    background-image: url("/static/court.jpg");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 0;
  }

  body.login-screen::after {
    content: "";
    position: fixed;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.72) 0%, rgba(255, 242, 242, 0.8) 100%);
    z-index: 0;
    pointer-events: none;
  }

  body.login-screen > * {
    position: relative;
    z-index: 1;
  }

  #auth-screen #login-card {
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(2.5px);
  }

  .topbar-logo {
    width: 42px;
    height: 42px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .brand {
    min-height: 52px;
  }

  .brand-left {
    flex: 1;
    gap: 10px;
  }

  .brand-title {
    display: flex;
  }

  .brand-actions,
  #go-dashboard {
    display: none !important;
  }

  #whoami,
  #logout,
  #admin-open,
  .home-btn {
    display: none !important;
  }

  .mobile-menu-shell {
    display: block;
    margin-left: auto;
  }

  main {
    padding: 12px;
  }

  .card {
    border-radius: 16px;
    padding: 14px;
  }

  .week-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 10px;
  }
  .week-controls {
    width: 100%;
    grid-template-columns: 1.05fr 1fr 1fr;
    order: 1;
  }
  .week-controls button {
    min-width: 0;
    padding: 9px 8px;
    font-size: 0.92rem;
  }
  .week-nav .legend {
    order: 2;
    justify-content: center;
    flex-direction: row;
    gap: 8px;
  }
  .week-nav .badge {
    font-size: 0.88rem;
    padding: 4px 8px;
  }
  .calendar {
    min-width: 910px;
  }
  .time-label,
  .slot-cell {
    height: 31px;
    min-height: 31px;
  }
  .time-label {
    font-size: 0.72rem;
    padding: 0 4px;
  }
  .stats-pie-wrap {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    text-align: center;
  }

  .stats-pie {
    margin: 0 auto;
  }

  .stats-pie-legend {
    width: 100%;
    max-width: 320px;
    grid-auto-flow: column;
    grid-template-rows: repeat(3, auto);
    grid-auto-columns: minmax(0, 1fr);
    justify-content: center;
    justify-items: start;
    margin: 0 auto;
  }

  .stats-pie-legend-item {
    min-width: 0;
  }

  .report-table thead th:nth-child(1) {
    width: 118px;
  }

  .report-table thead th:nth-child(2) {
    width: 92px;
  }

  .report-table thead th,
  .report-table tbody td {
    padding-left: 10px;
    padding-right: 10px;
  }

  .report-table tbody td.ng-date {
    white-space: normal;
  }

  .ng-date-day {
    white-space: nowrap;
  }

  .ng-date-time {
    white-space: nowrap;
  }
}

@media (min-width: 880px) {
  .brand-title,
  .mobile-menu-shell {
    display: none;
  }

  .topbar-logo {
    width: 38px;
    height: 38px;
  }
  .calendar-wrap {
    overflow: auto;
  }
  .calendar {
    min-width: 0;
    width: 100%;
  }
  main {
    padding: 20px;
  }
  .dashboard-grid {
    grid-template-columns: 0.9fr 1.4fr;
    align-items: start;
  }
  .dashboard-now-card {
    grid-column: 1;
  }
  .dashboard-next-card {
    grid-column: 2;
    grid-row: 1;
  }
  .modal {
    place-items: center;
  }
  .modal .dialog {
    border-radius: 20px;
    max-width: 720px;
  }
}
