*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface2: #334155;
  --text: #f1f5f9;
  --text2: #94a3b8;
  --accent: #22c55e;
  --accent2: #16a34a;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* PIN Screen */
.pin-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem;
  gap: 2rem;
}
.pin-screen h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.pin-screen .subtitle {
  color: var(--text2);
  font-size: 0.9rem;
  margin-top: -1rem;
}
.pin-dots {
  display: flex;
  gap: 16px;
}
.pin-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--text2);
  transition: all 0.15s;
}
.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}
.pin-dot.error {
  border-color: var(--danger);
  background: var(--danger);
}
.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 80px);
  gap: 12px;
}
.pin-key {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text);
  font-size: 1.75rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-user-select: none;
  user-select: none;
  transition: background 0.1s;
}
.pin-key:active {
  background: var(--surface2);
}
.pin-key.empty {
  visibility: hidden;
}
.pin-key.delete {
  font-size: 1.25rem;
  background: transparent;
}

/* Setup Screen */
.setup-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem;
  gap: 1.5rem;
  max-width: 400px;
  margin: 0 auto;
}
.setup-screen h1 { font-size: 1.5rem; font-weight: 700; }
.setup-screen p { color: var(--text2); font-size: 0.85rem; text-align: center; line-height: 1.5; }
.setup-screen input {
  width: 100%;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--surface2);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  outline: none;
}
.setup-screen input:focus {
  border-color: var(--accent);
}
.setup-screen label {
  width: 100%;
  font-size: 0.85rem;
  color: var(--text2);
  font-weight: 500;
}

/* Buttons */
.btn {
  padding: 14px 24px;
  border-radius: var(--radius);
  border: none;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.8; }
.btn-primary {
  background: var(--accent);
  color: #000;
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
}

/* App Shell */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--surface2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 {
  font-size: 1.1rem;
  font-weight: 700;
}
.header-back {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1rem;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
}
.header-action {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
}

/* Content */
.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(70px + var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tab Bar */
.tab-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
  padding-bottom: var(--safe-bottom);
  z-index: 100;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 4px;
  border: none;
  background: none;
  color: var(--text2);
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s;
}
.tab.active {
  color: var(--accent);
}
.tab-icon {
  font-size: 1.25rem;
}

/* Team List */
.team-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.team-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
}
.team-card:active {
  background: var(--surface2);
}
.team-avatar {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  color: #000;
  flex-shrink: 0;
}
.team-info h3 {
  font-size: 0.95rem;
  font-weight: 600;
}
.team-info p {
  font-size: 0.8rem;
  color: var(--text2);
  margin-top: 2px;
}

/* Schedule Filters */
.schedule-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.filter-pill {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--surface2);
  background: transparent;
  color: var(--text2);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-pill.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

/* Next Up Card */
.next-game-card {
  padding: 20px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  border-left: 4px solid var(--accent);
  background: var(--surface);
}
.next-game-card.game {
  border-left-color: var(--warn);
}
.next-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text2);
  margin-bottom: 6px;
}
.next-title {
  font-size: 1.15rem;
  font-weight: 700;
}
.next-datetime {
  font-size: 0.85rem;
  color: var(--text2);
  margin-top: 4px;
}
.next-location {
  font-size: 0.8rem;
  color: var(--text2);
  margin-top: 2px;
}

/* Game badge */
.game-badge {
  font-size: 0.6rem;
  font-weight: 700;
  background: var(--warn);
  color: #000;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}
.game-card {
  border-left: 3px solid var(--warn);
}

/* Event Cards */
.event-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.event-card {
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
  cursor: pointer;
}
.event-card:active {
  background: var(--surface2);
}
.event-date {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.event-title {
  font-size: 1rem;
  font-weight: 600;
  margin-top: 4px;
}
.event-meta {
  display: flex;
  gap: 16px;
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text2);
}
.event-rsvp {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.rsvp-btn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--surface2);
  background: transparent;
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.rsvp-btn.yes { border-color: var(--accent); color: var(--accent); }
.rsvp-btn.yes.active { background: var(--accent); color: #000; }
.rsvp-btn.maybe { border-color: var(--warn); color: var(--warn); }
.rsvp-btn.maybe.active { background: var(--warn); color: #000; }
.rsvp-btn.no { border-color: var(--danger); color: var(--danger); }
.rsvp-btn.no.active { background: var(--danger); color: #fff; }

/* Availability summary */
.avail-summary {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  font-size: 0.8rem;
}
.avail-count {
  display: flex;
  align-items: center;
  gap: 4px;
}
.avail-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.avail-dot.yes { background: var(--accent); }
.avail-dot.maybe { background: var(--warn); }
.avail-dot.no { background: var(--danger); }

/* Roster */
.roster-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.roster-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  cursor: pointer;
}
.roster-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.roster-item:last-child { border-radius: 0 0 var(--radius) var(--radius); }
.roster-item:only-child { border-radius: var(--radius); }
.roster-initial {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}
.roster-name {
  font-size: 0.9rem;
  font-weight: 500;
}
.roster-role {
  font-size: 0.75rem;
  color: var(--text2);
}
.roster-contact {
  margin-left: auto;
  display: flex;
  gap: 12px;
}
.roster-contact a {
  color: var(--accent);
  text-decoration: none;
  font-size: 1.1rem;
}

/* Messages */
.message-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.message-card {
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius);
}
.message-from {
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 600;
}
.message-subject {
  font-size: 0.95rem;
  font-weight: 600;
  margin-top: 4px;
}
.message-preview {
  font-size: 0.85rem;
  color: var(--text2);
  margin-top: 6px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.message-date {
  font-size: 0.75rem;
  color: var(--text2);
  margin-top: 8px;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--text2);
}
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--surface2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Empty state */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text2);
}
.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

/* Section headers */
.section-header {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 8px 0;
  margin-top: 8px;
}
.section-header:first-child { margin-top: 0; }

/* Team switcher in header */
.team-select {
  background: var(--surface2);
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  max-width: 200px;
  text-overflow: ellipsis;
  cursor: pointer;
}

/* Chat */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 130px - var(--safe-bottom));
  margin: -16px;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.chat-date-divider {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text2);
  padding: 12px 0 4px;
  font-weight: 600;
}
.chat-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.chat-bubble.theirs {
  background: var(--surface);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.chat-bubble.mine {
  background: var(--accent2);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.chat-sender {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
}
.chat-text {}
.chat-time {
  font-size: 0.65rem;
  color: var(--text2);
  margin-top: 4px;
  text-align: right;
}
.chat-bubble.mine .chat-time {
  color: rgba(255,255,255,0.6);
}
.chat-image {
  max-width: 100%;
  border-radius: 8px;
  margin: 4px 0;
}
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--surface2);
}
.chat-input-bar input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--surface2);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}
.chat-input-bar input:focus {
  border-color: var(--accent);
}
.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #000;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-send-btn:active {
  background: var(--accent2);
}
.chat-send-btn:disabled {
  opacity: 0.5;
}

/* Utility */
.hidden { display: none !important; }
.text-center { text-align: center; }
