/* Pis Boys. Layout: fixed shell (top bar, map or page, bottom tabs); sheets slide up over the map.
   Tokens: yellow = the brand, black = ink, everything else quiet greys. Single theme on purpose. */
:root {
  --yellow: #FFD60A;
  --yellow-dark: #E6BE00;
  --ink: #111111;
  --ink-2: #2b2b2b;
  --paper: #ffffff;
  --paper-2: #f4f3ee;
  --line: #e2e0d8;
  --muted: #6d6a60;
  --free: #9e9e9e;
  --danger: #d32f2f;
  --ok: #2e7d32;
  --t1: #7cb342;
  --t2: #1e88e5;
  --t3: #8e24aa;
  --font: "Helvetica Neue", Arial, system-ui, -apple-system, "Segoe UI", sans-serif;
  --top-h: 52px;
  --tabs-h: 58px;
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }   /* no pull-to-refresh mid-claim on Android */
body {
  font: 16px/1.4 var(--font);
  color: var(--ink);
  background: var(--paper-2);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  touch-action: manipulation;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; display: block; }
h1 { font-size: 26px; line-height: 1.1; margin: 0 0 6px; letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-size: 18px; margin: 18px 0 8px; letter-spacing: -0.01em; }
h3 { font-size: 16px; margin: 14px 0 6px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* top bar */
.top {
  position: fixed; inset: 0 0 auto 0; z-index: 30;
  height: calc(var(--top-h) + var(--sa-t));
  padding: var(--sa-t) max(12px, env(safe-area-inset-right, 0px)) 0 max(12px, env(safe-area-inset-left, 0px));
  display: flex; align-items: center; gap: 8px;
  background: var(--ink); color: var(--paper);
}
.brand { font-weight: 900; font-size: 22px; letter-spacing: 0.04em; text-decoration: none; color: var(--yellow); white-space: nowrap; }
.brand span { color: var(--paper); margin-left: 4px; }
.chip {
  border: 0; border-radius: 999px; padding: 7px 12px; font-weight: 700; font-size: 13px;
  background: var(--ink-2); color: var(--paper); white-space: nowrap; max-width: 46vw; overflow: hidden; text-overflow: ellipsis;
}
.chip-season { margin-left: auto; font-variant-numeric: tabular-nums; }
.chip-me { background: var(--yellow); color: var(--ink); }

/* views */
.view { position: fixed; left: 0; right: 0; top: calc(var(--top-h) + var(--sa-t)); bottom: calc(var(--tabs-h) + var(--sa-b)); }
.view-map { overflow: hidden; }
.view-page { overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--paper-2); overscroll-behavior: contain; }
.page {
  max-width: 640px; margin: 0 auto;
  padding-block: 18px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
#map { position: absolute; inset: 0; background: #e8e6df; }
.leaflet-container { font: 12px/1.3 var(--font); }
.leaflet-control-attribution { font-size: 10px; background: rgba(255,255,255,0.75); }

.map-tools {
  position: absolute; right: max(12px, env(safe-area-inset-right, 0px)); bottom: 14px; z-index: 20;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
.round {
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--paper); color: var(--ink);
  font-size: 22px; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}
.pill {
  border: 0; border-radius: 999px; padding: 11px 16px; background: var(--ink); color: var(--yellow);
  font-weight: 800; box-shadow: 0 2px 8px rgba(0,0,0,0.3); min-height: 44px;
}
.legend {
  position: absolute; left: max(12px, env(safe-area-inset-left, 0px)); bottom: 14px; z-index: 20;
  display: flex; gap: 10px; flex-wrap: wrap; font-size: 11px; font-weight: 700;
  background: rgba(255,255,255,0.9); padding: 6px 10px; border-radius: 10px; max-width: 48vw;
}
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,0.25); }
.dot.free { background: var(--free); }
.dot.t1 { background: var(--t1); width: 8px; height: 8px; }
.dot.t2 { background: var(--t2); }
.dot.t3 { background: var(--t3); width: 13px; height: 13px; }

/* tabs */
.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 30; height: calc(var(--tabs-h) + var(--sa-b));
  padding: 0 max(0px, env(safe-area-inset-left, 0px)) var(--sa-b) max(0px, env(safe-area-inset-right, 0px));
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--ink); color: var(--paper);
}
.tabs button {
  border: 0; background: transparent; color: #bdbdbd; font-weight: 700; font-size: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 44px;
}
.tabs button .ico { font-size: 20px; line-height: 1; }
.tabs button.active { color: var(--yellow); }

/* sheet */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0.35); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  max-height: calc(100dvh - var(--top-h) - 8px);
  background: var(--paper); border-radius: 18px 18px 0 0; box-shadow: 0 -6px 30px rgba(0,0,0,0.3);
  display: flex; flex-direction: column;
  padding-bottom: var(--sa-b);
  animation: rise 0.22s ease-out;
}
@keyframes rise { from { transform: translateY(40px); } to { transform: none; } }   /* no fade: nothing bleeds through */
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }
.sheet-handle { width: 42px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 4px; flex: 0 0 auto; }
.sheet-body {
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) 18px max(16px, env(safe-area-inset-left, 0px));
  min-width: 0;
}
.sheet h1 { font-size: 22px; }
.sheet-close { position: absolute; right: 10px; top: 10px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--paper-2); font-size: 18px; }

/* components */
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 800; color: #fff; background: var(--ink); vertical-align: middle; }
.badge.t1 { background: var(--t1); } .badge.t2 { background: var(--t2); } .badge.t3 { background: var(--t3); }
.badge.member { background: var(--yellow); color: var(--ink); }
.owner { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.owner .dot { width: 14px; height: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 0; font-weight: 800; font-size: 16px;
  background: var(--ink); color: var(--paper); width: 100%; text-decoration: none;
}
.btn.primary { background: var(--yellow); color: var(--ink); }
.btn.ghost { background: var(--paper-2); color: var(--ink); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin: 10px 0; }
.card-yellow { background: var(--yellow); border-color: var(--yellow-dark); }
.card-dark { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.card:empty { display: none; }
.rules { background: var(--paper-2); border-radius: 12px; padding: 10px 12px 10px 14px; margin: 10px 0; }
.rules ul { margin: 6px 0 0; padding-left: 18px; }
.rules li { margin: 3px 0; }
.photo-preview { border-radius: 12px; width: 100%; max-height: 46dvh; object-fit: contain; background: var(--ink); }
.thumb { width: 100%; max-height: 220px; object-fit: cover; border-radius: 12px; background: var(--paper-2); }
.thumb-sm { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; flex: 0 0 auto; background: var(--paper-2); }
.thumb-ph { width: 64px; height: 64px; border-radius: 10px; background: var(--paper-2); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); flex: 0 0 auto; text-align: center; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--paper);
  border: 1px solid var(--line); text-align: left; width: 100%; min-width: 0;
}
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.me { border-color: var(--yellow-dark); background: #fff8d6; }
.rank { width: 30px; font-weight: 900; font-variant-numeric: tabular-nums; text-align: right; color: var(--muted); }
.pts { font-weight: 900; font-variant-numeric: tabular-nums; }
.me-row { margin-top: 12px; }
.status { padding: 12px; border-radius: 12px; background: var(--paper-2); margin: 10px 0; }
.status.err { background: #fdecea; color: #7f1d1d; }
.status.ok { background: #e8f5e9; color: #1b5e20; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: middle; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.won { text-align: center; padding: 18px 0 8px; }
.won .big { font-size: 40px; font-weight: 900; letter-spacing: -0.03em; color: var(--ink); line-height: 1; }
.won .pts { font-size: 24px; color: var(--ok); }

/* forms */
label.f { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin: 10px 0 4px; }
input.f, select.f, textarea.f {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper);
}
input.f:focus, select.f:focus, textarea.f:focus, .btn:focus-visible, .item:focus-visible, .chip:focus-visible, .tabs button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 1px; }
.tabs-auth { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--paper-2); padding: 4px; border-radius: 12px; margin-bottom: 8px; }
.tabs-auth button { border: 0; border-radius: 9px; padding: 9px; background: transparent; font-weight: 800; color: var(--muted); min-height: 40px; }
.tabs-auth button.active { background: var(--ink); color: var(--yellow); }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; }
.swatch.active { border-color: var(--ink); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; align-items: center; flex: 1; min-width: 70px; }
.stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.stats { display: flex; gap: 6px; margin: 10px 0; }
details { margin: 8px 0; }
summary { font-weight: 800; cursor: pointer; padding: 8px 0; }
.err-line { color: var(--danger); font-size: 14px; min-height: 18px; margin-top: 6px; }

/* toast and banner */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--top-h) + var(--sa-t) + 10px); z-index: 60;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  max-width: 92vw; text-align: center; box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }
.banner {
  position: fixed; left: 0; right: 0; top: calc(var(--top-h) + var(--sa-t)); z-index: 35; padding: 8px 16px;
  background: var(--danger); color: #fff; font-weight: 700; text-align: center; font-size: 14px;
}
.banner.info { background: var(--yellow); color: var(--ink); }

@media (min-width: 700px) {
  .legend { max-width: none; }
  .sheet { left: 50%; right: auto; width: 520px; transform: translateX(-50%); border-radius: 18px 18px 0 0; }
  @keyframes rise { from { transform: translate(-50%, 40px); opacity: 0.6; } to { transform: translate(-50%, 0); opacity: 1; } }
}
