:root {
  --bg: #f6f3ee;
  --bg-deep: #f1ede6;
  --card: #ffffff;
  --text: #1d1b18;
  --muted: #6f655a;
  --accent: #d4682b;
  --accent-soft: #f4c9ac;
  --accent-2: #2b7a78;
  --accent-2-soft: #b8d9d4;
  --live: #d72638;
  --favorite: #f7c24b;
  --shadow: 0 20px 40px rgba(29, 27, 24, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(212, 104, 43, 0.15), transparent 55%),
    radial-gradient(circle at 80% 20%, rgba(43, 122, 120, 0.18), transparent 45%),
    linear-gradient(120deg, var(--bg), var(--bg-deep));
  min-height: 100vh;
}

.app-shell {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 24px 24px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 16px 20px;
  background: var(--card);
  border-radius: var(--radius);
  border-top-left-radius: 0;
  border-top-right-radius: 0;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 16px;
  background: conic-gradient(from 30deg, var(--accent), #f2a56f, var(--accent-2));
  box-shadow: 0 10px 20px rgba(212, 104, 43, 0.25);
}

.brand-title {
  font-family: "DM Serif Display", "Times New Roman", serif;
  font-size: 1.6rem;
  letter-spacing: 0.5px;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.9rem;
}

.nav-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.status {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.btn {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
  font-family: inherit;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 10px 20px rgba(212, 104, 43, 0.25);
}

.btn.primary:hover {
  transform: translateY(-1px);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid rgba(29, 27, 24, 0.1);
}

.btn.ghost:hover {
  background: rgba(29, 27, 24, 0.04);
}

.btn.outline {
  background: transparent;
  border: 1px solid rgba(29, 27, 24, 0.2);
}

.layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 24px;
  margin-top: 24px;
}

.filters {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 120px;
  height: fit-content;
}

.filters-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.filters-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.filters-close {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(29, 27, 24, 0.2);
  background: #fff;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.filters-close:hover {
  background: rgba(29, 27, 24, 0.05);
}

.filter-block {
  margin-bottom: 20px;
}

.filter-block h3 {
  font-size: 1rem;
  margin: 0 0 8px;
}

.filter-block select,
.filter-block input[type="search"] {
  width: 100%;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(29, 27, 24, 0.15);
  font-family: inherit;
}

.check {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.95rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.hint strong {
  color: var(--text);
}

.country-list {
  max-height: 160px;
  overflow: auto;
  border: 1px dashed rgba(29, 27, 24, 0.15);
  border-radius: 12px;
  padding: 8px;
  background: #faf8f4;
}

.content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.banner {
  background: #fff4f0;
  border: 1px solid rgba(212, 104, 43, 0.3);
  color: #9b3d12;
  padding: 12px 16px;
  border-radius: 14px;
}

.view {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.view-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 16px;
}

.view-header h2 {
  margin: 0;
  font-size: 1.4rem;
}

.view-count {
  color: var(--muted);
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.now-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
}

.now-divider::before,
.now-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(29, 27, 24, 0.2);
}

.match-card {
  display: grid;
  grid-template-columns: 110px 1fr 160px;
  gap: 16px;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(29, 27, 24, 0.08);
  background: #fff;
  position: relative;
  animation: riseIn 0.3s ease both;
}

.match-card.favorite {
  border-color: rgba(247, 194, 75, 0.8);
  box-shadow: 0 12px 24px rgba(247, 194, 75, 0.15);
}

.match-card.country {
  border-color: rgba(43, 122, 120, 0.5);
}

.card-time {
  display: flex;
  flex-direction: column;
}

.time-label {
  font-weight: 600;
  font-size: 1.1rem;
}

.time-date {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

.card-time.live {
  color: var(--live);
}

.card-time.live .time-date {
  color: var(--live);
}

.card-time.finished {
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 6px;
}

.status-pill.live {
  background: rgba(215, 38, 56, 0.1);
  color: var(--live);
}

.status-pill.finished {
  background: rgba(29, 27, 24, 0.08);
  color: var(--muted);
}

.card-players {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.competitor-row {
  display: grid;
  gap: 12px;
  align-items: start;
}

.competitor-row.has-scores {
  grid-template-columns: 1fr auto;
}

.competitor-players {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.serve-indicator {
  display: inline-flex;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 3px rgba(215, 38, 56, 0.15);
}

.score-grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(18px, auto);
  gap: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  text-align: center;
  align-items: center;
}

.score-cell {
  min-width: 16px;
  text-align: center;
  font-weight: 600;
}

.score-cell.serve-cell {
  min-width: 12px;
}

.score-cell.point-cell {
  color: #1f7a3f;
  font-weight: 700;
}

.score-cell.winner {
  font-weight: 700;
  color: var(--text);
}

.score-value {
  line-height: 1;
}

.score-tiebreak {
  font-size: 0.65em;
  vertical-align: super;
  margin-left: 1px;
}

.star-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: rgba(29, 27, 24, 0.4);
}

.star-btn.active {
  color: var(--favorite);
}

.star-placeholder {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  color: rgba(29, 27, 24, 0.3);
}

.player-name {
  font-weight: 600;
}

.player-line.winner .player-name {
  font-weight: 700;
}

.player-line.loser .player-name {
  font-weight: 500;
  color: var(--muted);
}

.seed-tag {
  font-weight: 400;
  font-size: 0.7em;
}

.rank-badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(29, 27, 24, 0.06);
  font-size: 0.75rem;
  font-weight: 700;
}

.rank-top5 {
  background: rgba(215, 38, 56, 0.15);
  color: #9b1c2c;
}

.rank-top10 {
  background: rgba(212, 104, 43, 0.18);
  color: #a24b18;
}

.rank-top20 {
  background: rgba(43, 122, 120, 0.15);
  color: #1f5a57;
}

.country-tag {
  font-size: 0.75rem;
  color: var(--muted);
}

.selected-countries {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 8px;
}

.country-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(29, 27, 24, 0.2);
  border-radius: 999px;
  padding: 4px 10px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.75rem;
}

.country-chip .chip-close {
  color: var(--muted);
  font-weight: 600;
}

.card-meta {
  text-align: right;
  font-size: 0.9rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding-right: 36px;
}

.card-meta .tour {
  font-weight: 700;
  color: var(--accent-2);
}

.tournament-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.details-toggle {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(29, 27, 24, 0.2);
  background: #fff;
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.details-toggle::before {
  content: "+";
}

.details-toggle[aria-expanded="true"]::before {
  content: "-";
}

.card-details {
  grid-column: 1 / -1;
  margin-top: 12px;
  padding-top: 0;
  border-top: none;
  font-size: 0.9rem;
  color: var(--muted);
}

.details-toggle[aria-expanded="true"] + .card-details {
  border: 1px dashed rgba(29, 27, 24, 0.2);
  border-radius: 12px;
  padding: 12px;
  background: rgba(29, 27, 24, 0.02);
}

.card-details a {
  color: var(--accent);
  text-decoration: none;
}

.favorites-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}

.favorite-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 14px;
  border: 1px solid rgba(29, 27, 24, 0.1);
}

.favorite-card h4 {
  margin: 0 0 6px;
}

.favorite-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(29, 27, 24, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 50;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: min(520px, 100%);
  box-shadow: var(--shadow);
  position: relative;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  border: none;
  background: none;
  font-size: 1.6rem;
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0;
}

.tab {
  border: 1px solid rgba(29, 27, 24, 0.2);
  background: transparent;
  padding: 6px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-weight: 600;
}

.tab.active {
  background: var(--accent-2);
  color: #fff;
  border-color: transparent;
}

.modal-list {
  margin-top: 12px;
  max-height: 320px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(29, 27, 24, 0.1);
}

.hidden {
  display: none;
}

@keyframes riseIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1024px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .filters {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    width: min(360px, 90vw);
    transform: translateX(110%);
    transition: transform 0.25s ease;
    z-index: 30;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .filters-header {
    display: flex;
    position: sticky;
    top: 0;
    background: var(--card);
    padding: 6px 0 10px;
    z-index: 1;
  }

  body.filters-open {
    overflow: hidden;
  }

  body.filters-open .filters {
    transform: translateX(0);
  }
}

@media (max-width: 720px) {
  .match-card {
    grid-template-columns: 1fr;
  }

  .competitor-row {
    grid-template-columns: 1fr;
  }

  .score-grid {
    justify-content: flex-start;
  }

  .card-meta {
    text-align: left;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 10px;
    padding-right: 0;
  }

  .details-toggle {
    position: static;
    margin-top: 8px;
    align-self: flex-end;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .app-shell {
    padding: 0 0 24px;
  }

  .topbar {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 0;
  }

  .brand {
    display: none;
  }

  .status #lastUpdated {
    display: none;
  }

  .nav-actions {
    gap: 6px;
  }

  .view {
    border-radius: 0;
    box-shadow: none;
    padding-left: 0;
    padding-right: 0;
  }

  .match-card .country-tag {
    display: none;
  }
}
