:root {
  --brand: #1f6b3a;
  --court-green: #1f6b3a;
  --court-green-dark: #14512b;
  --ball: #c8dc28;
  --ink: #1a2420;
  --muted: #6b7a72;
  --card-bg: #ffffff;
  --page-bg: #f2f6f1;
  --border: #e1e8e0;
  --playing: #1f8a3b;
  --playing-bg: #e6f6ea;
  --resting: #b9631a;
  --resting-bg: #fbeee0;
  --neutral: #55606b;
  --neutral-bg: #eceff1;
  --check-green: #16a34a;
  --cross-red: #dc2626;
  --ov-grid-line: #d7dfda;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--page-bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  background: var(--brand);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.topbar-row { display: flex; align-items: center; gap: 10px; }
.topbar-logo { width: 28px; height: 28px; border-radius: 50%; }
.topbar-title { font-weight: 700; font-size: 1.1rem; letter-spacing: 0.2px; }

.player-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.16);
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 11px;
  border-radius: 999px;
  cursor: pointer;
}
.player-chip:active { background: rgba(255,255,255,0.28); }
.player-chip svg { opacity: 0.85; flex-shrink: 0; }

.view { padding: 18px 16px 28px; max-width: 640px; margin: 0 auto; }

.today-card {
  background: var(--card-bg);
  border-radius: 18px;
  padding: 28px 22px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 8px 24px rgba(20,60,30,0.06);
  margin-top: 8px;
}

.week-label { font-size: 1rem; color: var(--muted); margin: 0; font-weight: 600; }
.date-label { font-size: 1.05rem; color: var(--ink); margin: 2px 0 20px; }

.status-banner {
  border-radius: 14px;
  padding: 22px 16px;
  margin-bottom: 16px;
}
.status-banner.playing { background: var(--playing-bg); }
.status-banner.resting { background: var(--resting-bg); }
.status-banner.neutral { background: var(--neutral-bg); }

.status-text {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.25;
}
.status-banner.playing .status-text { color: var(--playing); }
.status-banner.resting .status-text { color: var(--resting); }
.status-banner.neutral .status-text { color: var(--neutral); }

.status-detail { color: var(--muted); font-size: 0.98rem; margin: 0 0 18px; line-height: 1.45; }

.training-meta {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  color: var(--ink);
  font-size: 0.95rem;
}
.training-meta p { margin: 2px 0; }
.training-meta p:last-child { color: var(--muted); }

.schedule-section h2, .teams-section h2, .overview-section h2 {
  font-size: 1.1rem;
  margin: 8px 0 4px;
}
.schedule-title { text-align: center; }
.schedule-hint { color: var(--muted); font-size: 0.9rem; margin: 0 0 14px; }

.table-scroll { overflow-x: auto; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.schedule-table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  background: var(--card-bg);
  font-size: 0.92rem;
}
.schedule-table th, .schedule-table td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.schedule-table th:first-child, .schedule-table td:first-child { padding-left: 10px; }
.schedule-table th { color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.3px; }
.schedule-table th:nth-child(1), .schedule-table td:nth-child(1) { width: 15%; }
.schedule-table th:nth-child(2), .schedule-table td:nth-child(2) { width: 22%; }
.schedule-table th:nth-child(3), .schedule-table td:nth-child(3) { width: 24%; }
.schedule-table th:nth-child(4), .schedule-table td:nth-child(4) { width: 39%; }
.schedule-table tr.current-week { background: #f2fbf3; }
.schedule-table tr.current-week td:first-child { font-weight: 700; color: var(--playing); }

.rest-names { line-height: 1.4; padding-top: 8px; padding-bottom: 8px; }
.rest-names div { font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rest-names div.rest-you { font-weight: 800; color: var(--resting); white-space: normal; }
.holiday-note { color: var(--neutral); font-weight: 700; font-size: 0.82rem; }

.tag {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.tag-playing { background: var(--playing-bg); color: var(--playing); }
.tag-resting { background: var(--resting-bg); color: var(--resting); }
.tag-neutral { background: var(--neutral-bg); color: var(--neutral); }

.teams-section { margin-top: 26px; }
.teams-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.team-card { background: var(--card-bg); border-radius: 12px; padding: 14px 16px; box-shadow: 0 1px 3px rgba(0,0,0,0.06); }
.team-card h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--court-green-dark); }
.team-card ul { list-style: none; margin: 0; padding: 0; }
.team-card li { padding: 4px 0; font-size: 0.92rem; border-bottom: 1px dashed var(--border); }
.team-card li:last-child { border-bottom: none; }
.team-card li.you { font-weight: 700; }
.team-card li strong { color: var(--court-green-dark); }
.badge { font-size: 0.7rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--neutral-bg); color: var(--neutral); margin-left: 4px; }
.badge-you { background: var(--ball); color: #14512b; }

/* ---------- Identitetsval ---------- */
.identity-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 20, 14, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
.identity-overlay[hidden] { display: none; }
.identity-card {
  background: var(--card-bg);
  width: 100%;
  max-width: 640px;
  max-height: 82vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(24px + env(safe-area-inset-bottom));
}
.identity-card h2 { margin: 0 0 6px; font-size: 1.2rem; }
.identity-card > p { margin: 0 0 16px; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.identity-group h3 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  margin: 14px 0 6px;
}
.identity-group:first-of-type h3 { margin-top: 0; }
.identity-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--neutral-bg);
  border: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 0.98rem;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: pointer;
}
.identity-btn:active { background: var(--playing-bg); }

/* ---------- Översikt ---------- */
.overview-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.overview-legend span { display: flex; align-items: center; gap: 5px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw-rest { background: var(--resting-bg); box-shadow: inset 0 0 0 1px var(--resting); }
.sw-you { background: transparent; border: 2px solid var(--court-green); }
.sw-week { background: transparent; border-top: 2px solid var(--playing); border-bottom: 2px solid var(--playing); }
.sw-check, .sw-cross {
  width: 14px; height: 14px; border-radius: 3px;
  font-size: 10px; font-weight: 900; line-height: 14px; text-align: center; color: #fff;
}
.sw-check { background: var(--check-green); }
.sw-cross { background: var(--cross-red); }

.overview-grid {
  display: grid;
  gap: 2px;
  background: var(--ov-grid-line);
  border: 1px solid var(--ov-grid-line);
  border-radius: 10px;
  overflow: hidden;
  padding: 2px;
}
.ov-corner, .ov-week, .ov-name, .ov-cell, .ov-banner {
  background: var(--card-bg);
}
.ov-name {
  height: 116px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  white-space: nowrap;
  font-size: 9.5px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 4px 0 2px;
  overflow: hidden;
}
.ov-week {
  font-size: 9.5px;
  font-weight: 700;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ov-cell {
  aspect-ratio: 1 / 1;
  min-height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ov-cell-resting { background: var(--resting-bg); box-shadow: inset 0 0 0 1px var(--resting); }
.ov-col-you { box-shadow: inset 0 0 0 2px var(--court-green); }
.ov-cell.ov-row-you { box-shadow: inset 0 2px 0 var(--playing), inset 0 -2px 0 var(--playing); }
.ov-cell.ov-row-you.ov-col-you { box-shadow: inset 0 0 0 2px var(--court-green), inset 0 2px 0 var(--playing), inset 0 -2px 0 var(--playing); }
.ov-week.ov-row-you { background: var(--playing-bg); color: var(--playing); font-weight: 800; }
.ov-name.ov-col-you { color: var(--court-green-dark); font-weight: 800; }

.ov-you-today {
  font-size: 12px;
  font-weight: 900;
  color: #fff;
  border-radius: 4px;
}
.ov-you-today.is-playing { background: var(--check-green); }
.ov-you-today.is-resting { background: var(--cross-red); }

.ov-banner {
  grid-column: 2 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--neutral-bg);
  color: var(--neutral);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 3px 0;
}
.ov-banner.ov-row-you { box-shadow: inset 0 2px 0 var(--playing), inset 0 -2px 0 var(--playing); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 7px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.68rem;
  font-family: inherit;
  white-space: nowrap;
  cursor: pointer;
}
.tab-btn.active { color: var(--court-green); }

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #eef2ef;
    --muted: #9db0a4;
    --card-bg: #16211a;
    --page-bg: #0e1512;
    --border: #263229;
    --playing: #3ddc84;
    --playing-bg: #133a1f;
    --resting: #ffab5e;
    --resting-bg: #6b3a12;
    --neutral-bg: #2c3a42;
    --court-green: #3ddc84;
    --court-green-dark: #86e6a5;
    --check-green: #22c55e;
    --cross-red: #f04747;
    --ov-grid-line: #3a4a41;
  }
  .tabbar { background: #16211a; }
  .schedule-table tr.current-week { background: #12261a; }
}
