/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --text: #1D1D1F;
  --text-secondary: #6E6E73;
  --text-tertiary: #AEAEB2;
  --border: #E5E5EA;
  --divider: #F2F2F7;

  --orange: #F47321;
  --orange-light: rgba(244, 115, 33, 0.08);
  --orange-mid: rgba(244, 115, 33, 0.15);
  --green: #005030;
  --green-light: rgba(0, 80, 48, 0.06);
  --green-text: #00843D;

  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow: 0 2px 16px rgba(0,0,0,0.04), 0 1px 4px rgba(0,0,0,0.03);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);

  --font: 'Satoshi', -apple-system, BlinkMacSystemFont, 'SF Pro Display', system-ui, sans-serif;
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100dvh;
  padding-bottom: calc(72px + var(--safe-bottom));
  overflow-x: hidden;
}

/* ── Header ──────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(245, 245, 247, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: calc(8px + var(--safe-top)) 20px 8px;
}

.header-inner {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logos {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-logo-img {
  height: 28px;
  width: auto;
  object-fit: contain;
}

.header-logo-ncvf {
  height: 24px;
}

.header-title {
  display: block;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-subtitle {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.header-meta {
  text-align: right;
}

.header-update {
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* ── Tab Bar ─────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(245, 245, 247, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 0;
  padding: 6px 0 calc(6px + var(--safe-bottom));
}

.tab {
  flex: 1;
  max-width: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.2s var(--ease);
  border-radius: var(--radius-xs);
  -webkit-tap-highlight-color: transparent;
}

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-tertiary);
  transition: color 0.2s var(--ease);
}

.tab.active .tab-label {
  color: var(--orange);
}

.tab.active {
  position: relative;
}

.tab.active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--orange);
  border-radius: 0 0 3px 3px;
}

/* ── Content ─────────────────────────────────────────────── */
.content {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.25s ease;
}

.tab-panel.active {
  display: block;
}

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

/* ── Section headers ─────────────────────────────────────── */
.section-label {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 24px 0 10px;
  padding-left: 4px;
}

.section-label:first-child {
  margin-top: 0;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 10px;
  transition: box-shadow 0.2s var(--ease);
}

.card:active {
  box-shadow: var(--shadow-lg);
}

/* Schedule cards */
.card-play {
  background: linear-gradient(135deg, rgba(0, 132, 61, 0.03) 0%, var(--card) 100%);
  border-left: 3px solid var(--green-text);
}

.card-work {
  background: linear-gradient(135deg, rgba(244, 115, 33, 0.04) 0%, var(--card) 100%);
  border-left: 3px solid var(--orange);
}

.card-past-win {
  border-left: 3px solid var(--green-text);
}

.card-past-loss {
  border-left: 3px solid #D32F2F;
}

/* Card internals */
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}

.card-time {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.card-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 20px;
}

.badge-play {
  background: var(--green-light);
  color: var(--green-text);
}

.badge-work {
  background: var(--orange-light);
  color: var(--orange);
}

.card-detail {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.card-detail-icon {
  width: 16px;
  text-align: center;
  font-size: 12px;
  flex-shrink: 0;
}

.card-opponent {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  margin-top: 6px;
}

/* Countdown */
.countdown {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 6px 12px;
  background: var(--green-light);
  border-radius: var(--radius-xs);
}

.countdown-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green-text);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.countdown-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--green-text);
  font-variant-numeric: tabular-nums;
}

/* ── Direct Link Button ──────────────────────────────────── */
.btn-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  background: var(--orange);
  color: #fff;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: 24px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s var(--ease);
  margin-top: 8px;
  -webkit-tap-highlight-color: transparent;
}

.btn-link:hover {
  background: #E06218;
  box-shadow: 0 4px 16px rgba(244, 115, 33, 0.3);
}

.btn-link:active {
  transform: scale(0.97);
}

.btn-link svg {
  width: 14px;
  height: 14px;
}

/* ── Pool standings ──────────────────────────────────────── */
.pool-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-top: 8px;
}

.pool-table th {
  text-align: left;
  font-weight: 600;
  color: var(--text-secondary);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}

.pool-table th:not(:first-child) {
  text-align: center;
}

.pool-table td {
  padding: 10px 6px;
  border-bottom: 1px solid var(--divider);
  font-variant-numeric: tabular-nums;
}

.pool-table td:not(:first-child) {
  text-align: center;
}

.pool-table tr.row-us td {
  font-weight: 600;
  color: var(--green);
}

.pool-table tr.row-us td:first-child {
  position: relative;
}

.pool-table tr.row-us td:first-child::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 60%;
  background: var(--orange);
  border-radius: 2px;
}

/* ── Past results ────────────────────────────────────────── */
.result-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.result-outcome {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  width: 28px;
  text-align: center;
}

.result-win { color: var(--green-text); }
.result-loss { color: #D32F2F; }

.result-info {
  flex: 1;
}

.result-opponent {
  font-size: 15px;
  font-weight: 600;
}

.result-scores {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.result-meta {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: right;
}

/* ── Record badge ────────────────────────────────────────── */
.record-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--divider);
  border-radius: 20px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-bottom: 10px;
}

/* ── Future paths ────────────────────────────────────────── */
.path-card {
  padding: 14px;
}

.path-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.path-rank {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 20px;
}

.path-win {
  background: var(--green-light);
  color: var(--green-text);
}

.path-loss {
  background: var(--orange-light);
  color: var(--orange);
}

.path-detail {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

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

/* ── Info tab ────────────────────────────────────────────── */
.info-card {
  padding: 0;
  overflow: hidden;
}

.info-card-header {
  padding: 16px 16px 12px;
}

.info-card-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.info-card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.info-img-wrap {
  position: relative;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.info-img-wrap img {
  width: 100%;
  display: block;
  border-radius: 0 0 var(--radius) var(--radius);
}

.info-img-tap {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  backdrop-filter: blur(8px);
  pointer-events: none;
}

/* Event info card */
.event-detail-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--divider);
}

.event-detail-row:last-child {
  border-bottom: none;
}

.event-detail-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
  padding-top: 1px;
}

.event-detail-label {
  font-size: 12px;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

.event-detail-value {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-top: 1px;
}

/* ── Lightbox ────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s var(--ease);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.lightbox.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-close {
  position: absolute;
  top: calc(16px + var(--safe-top));
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  -webkit-tap-highlight-color: transparent;
}

.lightbox-content {
  max-width: 95vw;
  max-height: 90vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.lightbox-content img {
  max-width: 100%;
  max-height: 85vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 32px 20px;
  color: var(--text-tertiary);
}

.empty-state-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.empty-state-text {
  font-size: 14px;
  font-weight: 500;
}

/* ── Loading ─────────────────────────────────────────────── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 14px;
  color: var(--text-tertiary);
  font-weight: 500;
}

/* ── Divider line ────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--divider);
  margin: 20px 0;
}

/* ── Team header card ────────────────────────────────────── */
.team-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  margin-bottom: 16px;
}

.team-name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.team-division {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 2px;
}

.team-pool-badge {
  font-size: 13px;
  font-weight: 700;
  color: var(--orange);
  background: var(--orange-light);
  padding: 6px 14px;
  border-radius: 20px;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (min-width: 768px) {
  .content {
    padding: 24px 20px 48px;
  }
  
  .tab-bar {
    position: sticky;
    top: 57px;
    bottom: auto;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding: 0;
    max-width: 600px;
    margin: 0 auto;
    justify-content: flex-start;
    gap: 0;
  }
  
  .tab {
    flex-direction: row;
    gap: 6px;
    padding: 14px 24px;
    max-width: none;
  }
  
  .tab-label {
    font-size: 13px;
  }
  
  .tab.active::after {
    top: auto;
    bottom: -1px;
    left: 0;
    right: 0;
    transform: none;
    width: 100%;
    height: 2px;
    border-radius: 2px 2px 0 0;
  }
  
  body {
    padding-bottom: 32px;
  }
}
