/* CourtFlow app — light brand theme, matched to the marketing site.
   Palette: cream #EAEDE2 / navy #0E2444 / lime #B6CE36. Sora + Plus Jakarta Sans. */
:root {
  --bg: #eaede2;          /* page cream */
  --surface: #fbfbf7;     /* card */
  --surface-2: #f3f4ec;   /* nested tile */
  --navy: #0e2444;        /* primary text / dark court */
  --navy-2: #16294f;
  --line: #dcdfd2;        /* hairline on cream */
  --line-2: #e6e8dc;
  --muted: #5a6b82;       /* secondary text */
  --dim: #8a97a8;         /* tertiary text */
  --lime: #b6ce36;        /* brand accent */
  --lime-2: #c7dc4f;      /* lighter lime */
  --lime-ink: #33400a;    /* text on lime */
  --z-attack: #e2603f;    /* zone: attack (warm) */
  --z-transition: #e8b53d;/* zone: transition (amber) */
  --z-defense: #3b6ea5;   /* zone: defense (cool) */
  --coral: #d9644a;
  --shadow: 0 6px 22px rgba(14, 36, 68, .08);
  --shadow-lg: 0 12px 34px rgba(14, 36, 68, .12);
  --radius: 20px;
  --pill: 999px;
  --head: "Sora", system-ui, sans-serif;
  --body: "Plus Jakarta Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.55 var(--body);
  background: var(--bg);
  color: var(--navy);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#app { max-width: 540px; margin: 0 auto; padding: env(safe-area-inset-top) 16px 56px; }
.loading { padding: 72px 16px; text-align: center; color: var(--muted); font-weight: 500; }

/* clean load-failure fallback */
.error { padding: 64px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.error-mark {
  width: 52px; height: 52px; display: grid; place-items: center; font-size: 24px; margin-bottom: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 50%; color: var(--coral);
}
.error-title { font-family: var(--head); font-weight: 800; font-size: 18px; margin: 0; }
.error-sub { color: var(--muted); font-size: 13.5px; margin: 0 0 8px; }
.retry { display: inline-flex; justify-content: center; }
.retry::before { display: none; }

h1, h2, .brand, .tile-value, .style-badge { font-family: var(--head); }

/* ============================ overview ============================ */
.top { display: flex; align-items: center; justify-content: space-between; padding: 22px 2px 4px; }
.brand { font-weight: 800; letter-spacing: -.2px; font-size: 21px; display: flex; align-items: center; gap: 8px; }
.brand::before {
  content: ""; width: 11px; height: 11px; border-radius: 50%;
  background: var(--lime); box-shadow: 0 0 0 3px rgba(182, 206, 54, .22);
}
.match-meta {
  color: var(--muted); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: var(--surface); border: 1px solid var(--line); padding: 5px 11px; border-radius: var(--pill);
}
.lede { font-size: 17px; font-weight: 600; margin: 14px 2px 18px; letter-spacing: -.2px; }
.hint { color: var(--dim); font-size: 12.5px; text-align: center; margin-top: 16px; }

.court-wrap { display: flex; flex-direction: column; gap: 16px; }

/* top-down court: navy surface, lime net across the middle, four quadrants */
.court {
  position: relative; width: 100%; max-width: 360px; margin: 0 auto;
  aspect-ratio: 5 / 6; background: var(--navy); border-radius: 22px;
  padding: 30px 12px; box-shadow: var(--shadow-lg);
  border: 1.5px solid rgba(234, 237, 226, .18);
}
.court-net {
  position: absolute; left: 10px; right: 10px; top: 50%; height: 3px;
  background: var(--lime); transform: translateY(-50%); border-radius: 2px;
  box-shadow: 0 0 12px rgba(182, 206, 54, .5); z-index: 1;
}
.court-line { position: absolute; left: 10px; right: 10px; height: 1.5px; background: rgba(234, 237, 226, .16); z-index: 1; }
.line-far { top: 33%; }
.line-near { top: 67%; }
.court-side {
  position: absolute; left: 0; right: 0; text-align: center; font-family: var(--head);
  font-weight: 800; font-size: 12px; letter-spacing: 2px; color: rgba(234, 237, 226, .45); z-index: 1;
}
.court-side.far { top: 9px; }
.court-side.near { bottom: 9px; }

.positions {
  position: relative; z-index: 2; height: 100%;
  display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 6px;
}

.pos-card {
  appearance: none; border: 0; background: transparent; cursor: pointer; color: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 6px; border-radius: 16px; font-family: var(--body);
  transition: transform .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.pos-card:hover { transform: translateY(-2px); }
.pos-card:active { transform: scale(.97); }
.pos-card:focus-visible { outline: 2px solid var(--lime); outline-offset: 3px; }

.pos-thumb {
  width: 82px; height: 82px; border-radius: 18px; overflow: hidden; background: var(--surface-2);
  border: 3px solid var(--lime); box-shadow: 0 6px 16px rgba(0, 0, 0, .3);
  display: grid; place-items: center;
}
.side-far .pos-thumb { border-color: #eaede2; }
.thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pos-label {
  font-size: 13.5px; font-weight: 700; color: #eaede2; text-align: center; line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

.pos-card.empty { cursor: default; opacity: .5; }
.pos-card.empty .pos-thumb { border-style: dashed; border-color: rgba(234, 237, 226, .4); background: transparent; }
.empty-mark { color: rgba(234, 237, 226, .5); font-size: 22px; font-weight: 700; }

@media (max-width: 360px) {
  .pos-thumb { width: 70px; height: 70px; }
  .pos-label { font-size: 12.5px; }
}

/* ============================ detail ============================ */
.detail-top {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center;
  gap: 12px; padding: 14px 0 12px; position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 78%, rgba(234, 237, 226, 0));
}
.back {
  appearance: none; background: var(--surface); border: 1px solid var(--line);
  color: var(--navy); border-radius: var(--pill); padding: 9px 14px; font-family: var(--body);
  font-size: 14px; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
}
.back:hover { border-color: var(--lime); }
.detail-title h1 { margin: 0; font-size: 21px; font-weight: 800; letter-spacing: -.4px; }
.detail-title .sub { color: var(--muted); font-size: 12.5px; font-weight: 500; text-transform: capitalize; }
.style-badge {
  justify-self: end; background: var(--lime); color: var(--lime-ink);
  padding: 7px 13px; border-radius: var(--pill); font-size: 12.5px; font-weight: 700;
  white-space: nowrap; box-shadow: 0 3px 10px rgba(182, 206, 54, .35);
}

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin: 13px 0; box-shadow: var(--shadow);
}
.card.quiet { background: transparent; box-shadow: none; border-style: dashed; border-color: var(--dim); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; font-size: 13px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); }
.card-sub { color: var(--dim); font-size: 12px; text-align: right; font-weight: 500; }

.heatmap {
  display: block; width: 100%; max-width: 250px; margin: 2px auto 0; border-radius: 14px;
  border: 1px solid var(--line); background: var(--navy); padding: 8px;
}

/* stat tiles */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 11px; }
.tile { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 15px; padding: 14px; }
.tile-value { font-size: 26px; font-weight: 800; letter-spacing: -.6px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-label { font-size: 13px; font-weight: 700; margin-top: 5px; }
.tile-sub { color: var(--dim); font-size: 11.5px; font-weight: 500; margin-top: 2px; }
.tile-grid.muted .tile { background: transparent; border-style: dashed; }
.tile-grid.muted .tile-value { color: var(--muted); }

/* zone bar */
.zone-bar { display: flex; height: 18px; border-radius: var(--pill); overflow: hidden; border: 1px solid var(--line); }
.zone-seg { min-width: 3px; }
.z-attack { background: var(--z-attack); }
.z-transition { background: var(--z-transition); }
.z-defense { background: var(--z-defense); }
.zone-legend { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 600; }
.swatch { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.legend-name { flex: 1; }
.legend-val { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

/* share this player's page */
.share-me {
  appearance: none; width: 100%; margin: 4px 0 2px; cursor: pointer; font-family: var(--body);
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--lime); color: var(--lime-ink); border: 0; border-radius: var(--pill);
  padding: 13px 16px; font-size: 15px; font-weight: 800;
  box-shadow: 0 4px 14px rgba(182, 206, 54, .38); transition: transform .1s, box-shadow .14s;
}
.share-me:hover { box-shadow: 0 6px 18px rgba(182, 206, 54, .5); }
.share-me:active { transform: translateY(1px); }
.share-ico { width: 16px; height: 16px; }

/* highlight clips */
.clips { display: flex; flex-direction: column; gap: 14px; }
.clip { border-radius: 14px; transition: box-shadow .3s, outline-color .3s; outline: 2px solid transparent; }
.clip.flash { outline-color: var(--lime); box-shadow: 0 0 0 4px rgba(182, 206, 54, .25); }
.clip-video {
  display: block; width: 100%; aspect-ratio: 16 / 9; border-radius: 14px;
  background: var(--navy); border: 1px solid var(--line); object-fit: cover;
}
.clip-missing {
  display: grid; place-items: center; width: 100%; aspect-ratio: 16 / 9; border-radius: 14px;
  background: var(--surface-2); border: 1px dashed var(--dim); color: var(--muted);
  font-size: 13px; font-weight: 600;
}
.clip-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 9px; }
.clip-meta { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.clip-event { font-weight: 700; font-size: 14.5px; }
.clip-event::before { content: "▸ "; color: var(--lime); font-weight: 800; }
.clip-t { color: var(--dim); font-weight: 600; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.clip-share {
  appearance: none; flex: none; cursor: pointer; font-family: var(--body);
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--navy); border: 1px solid var(--line);
  border-radius: var(--pill); padding: 8px 13px; font-size: 13px; font-weight: 700;
}
.clip-share:hover { border-color: var(--lime); }
.clip-share:active { transform: translateY(1px); }
.clip-share .share-ico { width: 14px; height: 14px; color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); z-index: 50;
  background: var(--navy); color: var(--bg); font-weight: 600; font-size: 13.5px;
  padding: 11px 18px; border-radius: var(--pill); box-shadow: var(--shadow-lg);
  max-width: 88vw; text-align: center; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.muted-note { color: var(--muted); font-size: 13px; }

@media (min-width: 480px) {
  .heatmap { max-width: 270px; }
}
