:root {
  --bg: #0d1b2a;
  --bg-soft: #16263b;
  --card-bg: #ffffff;
  --ink: #1a1a1f;
  --muted: #6b6b74;
  --line: #d9d9e0;
  --accent: #e4c04a;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(160deg, var(--bg), #091422 70%);
  color: #fff;
  font-family: "Roboto", "Helvetica Neue", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* ---- top bar ---- */
/* Scrolls away with the page (not sticky) so the cards get the full height. */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 24px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
  background: rgba(9, 20, 34, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}
.subtitle {
  margin-left: auto;
  color: #9fb0c4;
  font-size: 14px;
  font-weight: 500;
}
/* ---- sort control (nation page, top-right) ---- */
.sort-control {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sort-label {
  color: #9fb0c4;
  font-size: 14px;
  font-weight: 500;
}
.sort-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06)
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' fill='none' stroke='%239fb0c4' stroke-width='1.6'/></svg>")
    no-repeat right 10px center;
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 30px 8px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.sort-select:focus { outline: none; border-color: var(--accent); }
.sort-select option { color: #1a1a1f; }

.back-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 15px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}
.back-btn:active { background: rgba(255, 255, 255, 0.18); }

/* ---- view container ---- */
.view {
  padding: 24px;
  padding-left: max(24px, env(safe-area-inset-left));
  padding-right: max(24px, env(safe-area-inset-right));
}
/* Nation page: tighter padding so the cards get more room. */
body.nation .view {
  padding: 0 14px 14px;
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
}

/* ---- flags grid (start page) ---- */
.flag-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 18px;
}
.flag-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 16px 12px;
  background: var(--bg-soft);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, background 0.12s;
}
.flag-tile:hover { transform: translateY(-3px); border-color: var(--accent); }
.flag-tile:active { transform: translateY(0); background: #1d3045; }
.flag-tile img {
  width: 96px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: var(--shadow);
  background: #fff;
}
.flag-tile .name {
  font-size: 15px;
  font-weight: 500;
  text-align: center;
  line-height: 1.2;
}
.flag-tile .count {
  font-size: 12px;
  color: #8aa0b8;
}

/* ---- player cards grid (one nation) ---- */
/* 7 cards per row; rows size to the card, and the view scrolls when the whole
   squad doesn't fit on screen (photos keep a proper size). */
.cards-grid {
  display: grid;
  /* minmax(0, 1fr) lets the 7 columns shrink to fit the screen width instead
     of being forced wider by card content (long names, photo). */
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
}
.card {
  background: var(--card-bg);
  color: var(--ink);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 7px 7px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0; /* allow the card to shrink below its content's min size */
}
/* Top row: photo on the left, club logo + flag stacked beside it on the right.
   Everything is sized in % of the card, so it scales with the screen. */
.card .top {
  display: flex;
  align-items: stretch;
  gap: 6px;
  width: 100%;
}
.card .photo {
  flex: 1 1 auto;
  aspect-ratio: 1 / 1;
  min-width: 0;
  object-fit: contain;
  background: #eef0f4;
  border-radius: 6px;
}
.card .photo.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  padding: 4px;
}
.card .badges {
  flex: 0 0 26%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8%;
  min-width: 0;
}
.card .badges img {
  width: 100%;
  height: auto;
  max-height: 46%;
  object-fit: contain;
}
.card .pname {
  flex: 0 0 auto;
  margin-top: 7px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  line-height: 1.12;
  /* Two fixed rows: first name on row 1, last name on row 2. */
  min-height: 2.24em;
  max-width: 100%;
  overflow: hidden;
}
.card .pname .fn,
.card .pname .ln {
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .pos {
  flex: 0 0 auto;
  margin-top: 3px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .stats {
  flex: 0 0 auto;
  width: 100%;
  margin-top: 7px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.card .stat {
  display: flex;
  justify-content: space-between;
  gap: 4px;
  font-size: 9px;
  line-height: 1.2;
}
.card .stat .label { color: var(--muted); }
.card .stat .value { font-weight: 600; white-space: nowrap; }

/* ---- states ---- */
.status {
  text-align: center;
  color: #9fb0c4;
  padding: 60px 0;
  font-size: 16px;
}

@media (max-width: 740px) {
  .topbar h1 { font-size: 17px; }
}
