:root {
  --paper: #ebe8e1;
  --card: #fffdf8;
  --ink: #14161a;
  --muted: #5d6068;
  --orange: #ff5b1f;
  --green: #0d6b4f;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
}

.sr {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }

/* ---------- Header ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem clamp(1rem, 4vw, 2.5rem);
  border-bottom: 3px solid var(--ink);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 500;
}
.logo {
  font-size: 1.7rem;
  font-weight: 900;
  font-stretch: 125%;
  letter-spacing: -.02em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
}

.btn-ghost, .btn-main {
  padding: .6rem 1.1rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-weight: 700;
  background: var(--card);
  transition: transform .1s, box-shadow .1s;
}
.btn-main { background: var(--orange); box-shadow: 3px 3px 0 var(--ink); }
.btn-ghost:hover, .btn-main:hover { transform: translate(-1px, -1px); }
.btn-main:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
.btn-ghost.small { padding: .4rem .9rem; font-size: .9rem; }
.count {
  display: inline-block;
  min-width: 1.5em;
  margin-left: .3em;
  padding: 0 .4em;
  border-radius: 999px;
  background: var(--ink);
  color: var(--card);
  font-size: .85em;
  text-align: center;
}

/* ---------- Intro ---------- */
.intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  padding: clamp(1.5rem, 5vw, 3rem) clamp(1rem, 4vw, 2.5rem) 1rem;
}
.intro h1 {
  margin: 0 0 .6rem;
  font-size: clamp(2.4rem, 8vw, 5rem);
  font-weight: 900;
  font-stretch: 125%;
  line-height: .95;
  letter-spacing: -.03em;
  text-transform: uppercase;
}
.intro p { margin: 0; font-size: 1.15rem; color: var(--muted); }
.halfcourt {
  width: clamp(110px, 18vw, 190px);
  color: var(--orange);
  flex-shrink: 0;
}

/* ---------- Finder layout ---------- */
.finder {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  padding: 1rem clamp(1rem, 4vw, 2.5rem) 2rem;
}
.mapwrap { order: -1; position: relative; }
#map {
  height: 280px;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 5px 5px 0 var(--ink);
  background: #d9d6cf;
  z-index: 1;
}
.mapfail {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  margin: 0; padding: 1rem; text-align: center; color: var(--muted);
}

@media (min-width: 900px) {
  .finder { grid-template-columns: minmax(380px, 460px) 1fr; align-items: start; }
  .mapwrap { order: 0; position: sticky; top: 5.5rem; }
  #map { height: calc(100vh - 8rem); min-height: 420px; }
}

/* ---------- Toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: .75rem; }
.search { flex: 1 1 100%; }
.search input {
  width: 100%;
  padding: .7rem 1rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--card);
}
.chips { display: flex; gap: .4rem; }
.fchip {
  padding: .4rem .9rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  font-size: .9rem;
}
.fchip.on { background: var(--ink); color: var(--card); }
.status { margin: 0 0 .75rem; color: var(--muted); font-size: .95rem; min-height: 1.4em; }

/* ---------- Court cards ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1rem; }
.card {
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  box-shadow: 4px 4px 0 var(--ink);
  transition: box-shadow .15s, transform .15s;
}
.card.on { box-shadow: 6px 6px 0 var(--orange); transform: translate(-2px, -2px); }
.card-head {
  display: block;
  width: 100%;
  padding: 1rem 1rem .5rem;
  border: 0;
  background: none;
  text-align: left;
}
.card h3 { margin: 0; font-size: 1.25rem; font-weight: 800; font-stretch: 110%; letter-spacing: -.01em; }
.area { margin: .15rem 0 .6rem; color: var(--muted); font-size: .95rem; }
.tags { display: flex; flex-wrap: wrap; gap: .35rem; }
.tag {
  padding: .1rem .6rem;
  border: 1.5px solid var(--ink);
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 600;
}
.tag.in { background: var(--green); border-color: var(--green); color: #fff; }
.tag.out { background: #ffe0cf; }
.runs-row { padding: .25rem 1rem 1rem; }
.runs-label { margin: .4rem 0; font-size: .85rem; font-weight: 700; color: var(--muted); }
.slots { display: flex; flex-wrap: wrap; gap: .45rem; }
.slot {
  padding: .45rem .8rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--card);
  text-align: left;
  line-height: 1.2;
}
.slot b { display: block; font-size: 1rem; }
.slot span { font-size: .78rem; color: var(--muted); }
.slot:hover:not(:disabled) { background: var(--orange); }
.slot:hover:not(:disabled) span { color: var(--ink); }
.slot:disabled { opacity: .45; cursor: not-allowed; text-decoration: line-through; }
.slot.mine { background: var(--green); border-color: var(--green); color: #fff; }
.slot.mine span { color: #d6f2e7; }

/* ---------- Map pins ---------- */
.pin {
  width: 30px; height: 30px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background:
    linear-gradient(var(--ink), var(--ink)) center / 100% 2px no-repeat,
    linear-gradient(var(--ink), var(--ink)) center / 2px 100% no-repeat,
    var(--orange);
  box-shadow: 2px 2px 0 rgba(20, 22, 26, .5);
  transition: transform .15s, background-color .15s;
}
.pin.on { transform: scale(1.4); background-color: var(--green); }
.leaflet-container { font-family: inherit; }
.you {
  width: 16px; height: 16px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: #2b6dff;
  box-shadow: 0 0 0 3px rgba(43, 109, 255, .35);
}

/* ---------- Dialogs ---------- */
dialog {
  width: min(92vw, 420px);
  padding: 1.5rem;
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: 6px 6px 0 var(--ink);
}
dialog::backdrop { background: rgba(20, 22, 26, .55); }
dialog h2 { margin: 0 0 .25rem; font-size: 1.5rem; font-weight: 900; font-stretch: 115%; text-transform: uppercase; }
dialog label { display: block; margin: 1rem 0 .3rem; font-weight: 700; font-size: .9rem; }
dialog input, dialog select {
  width: 100%;
  padding: .65rem .8rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: #fff;
}
.meta { margin: 0; color: var(--muted); }
.error { margin: .6rem 0 0; color: #b3261e; font-weight: 600; }
.actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.4rem; }

.runs { list-style: none; margin: 1rem 0 0; padding: 0; display: grid; gap: .7rem; }
.runs li {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .7rem .9rem;
  border: 2px solid var(--ink);
  border-radius: 10px;
}
.runs .t { font-weight: 800; }
.runs .s { color: var(--muted); font-size: .9rem; }
.runs .x { padding: .3rem .7rem; font-size: .85rem; }
.empty { color: var(--muted); padding: .5rem 0; }

/* ---------- Toast & footer ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 1.5rem;
  z-index: 2000;
  max-width: 90vw;
  padding: .8rem 1.3rem;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  transform: translate(-50%, 250%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform .3s cubic-bezier(.2, 1.4, .4, 1), opacity .2s, visibility 0s .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; transition-delay: 0s; }
.foot { padding: 1.5rem; text-align: center; color: var(--muted); font-size: .9rem; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}