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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: #f1f5f9;
  color: #1e293b;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 2rem 1rem;
}

.container {
  width: 100%;
  max-width: 660px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.75rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
}

.screen {
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f1f5f9;
  padding-bottom: 1rem;
}

.header-titles h1 {
  font-size: 1.65rem;
  font-weight: 700;
  color: #0f172a;
  letter-spacing: -0.025em;
}

.header-titles .tagline {
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 2px;
}

.header-controls {
  display: flex;
  gap: 0.5rem;
}

.room-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: #475569;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  margin-top: 0.25rem;
}

.room-pill strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  color: #0f172a;
}

.btn-icon {
  background: none;
  border: none;
  color: #2563eb;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0 0.2rem;
}

.btn-icon:hover {
  text-decoration: underline;
}

/* Server Status */
.server-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.775rem;
  color: #64748b;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  padding: 0.3rem 0.65rem;
  border-radius: 9999px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: #f59e0b; /* Amber connecting by default */
  transition: background-color 0.2s ease;
}

.status-dot.online {
  background-color: #10b981;
}

.status-dot.offline {
  background-color: #ef4444;
}

/* Lobby View */
.lobby-card {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.lobby-action-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lobby-action-group h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
}

.lobby-desc {
  font-size: 0.85rem;
  color: #64748b;
}

.btn-primary {
  height: 42px;
  background-color: #2563eb;
  color: #ffffff;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.btn-primary:hover:not(:disabled) {
  background-color: #1d4ed8;
}

.btn-secondary {
  height: 40px;
  padding: 0 1.2rem;
  background-color: #0f172a;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease;
}

.btn-secondary:hover:not(:disabled) {
  background-color: #1e293b;
}

.btn-outline {
  background: transparent;
  border: 1px solid #cbd5e1;
  color: #475569;
  font-size: 0.825rem;
  font-weight: 500;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-outline:hover:not(:disabled) {
  background: #f8fafc;
  border-color: #94a3b8;
  color: #1e293b;
}

.lobby-divider {
  display: flex;
  align-items: center;
  text-align: center;
  color: #94a3b8;
  font-size: 0.75rem;
  font-weight: 600;
}

.lobby-divider::before,
.lobby-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #e2e8f0;
}

.lobby-divider span {
  padding: 0 0.75rem;
}

.join-input-row {
  display: flex;
  gap: 0.5rem;
}

.join-input-row input {
  flex: 1;
  height: 40px;
  padding: 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
}

.join-input-row input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.lobby-error {
  font-size: 0.825rem;
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fee2e2;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

/* Lobby Waiting Screen */
.room-code-display {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 1rem;
}

.room-code-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #0f172a;
}

.invite-link {
  flex: 1;
  width: 100%;
  min-width: 0;
  padding: 0.75rem;
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0;
}

.waiting-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.875rem;
  color: #475569;
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background-color: #2563eb;
  animation: pulse 1.5s infinite ease-in-out;
}

@keyframes pulse {
  0% { transform: scale(0.9); opacity: 0.6; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.6; }
}

.cancel-btn {
  align-self: flex-start;
  margin-top: 0.5rem;
}

/* Target to Beat Section */
.target-card {
  text-align: center;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.25rem 1rem;
}

.target-eyebrow {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
  margin-bottom: 0.35rem;
}

.target-value {
  font-size: 1.85rem;
  font-weight: 700;
  color: #0f172a;
  min-height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  word-break: break-word;
}

.target-info {
  font-size: 0.85rem;
  color: #64748b;
  margin-top: 0.35rem;
}

/* Rally & Status */
.status-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
}

.rally-counter {
  color: #475569;
  font-size: 1rem;
  font-weight: 600;
}

.rally-counter strong {
  color: #0f172a;
  font-size: 1.35rem;
  margin-left: 0.25rem;
}

.scoreboard {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.score-card {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
}

.player-label {
  font-size: 0.85rem;
  color: #475569;
  font-weight: 500;
}

.score-value {
  font-size: 1rem;
  font-weight: 700;
  color: #0f172a;
}

.score-divider {
  font-size: 0.8rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
}

.result-text {
  font-size: 0.925rem;
  color: #334155;
  min-height: 1.4rem;
  text-align: center;
  font-weight: 500;
}

/* Players Grid */
.players-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 1rem;
}

.player-card {
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  background: #ffffff;
  transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.player-card.active {
  opacity: 1;
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px #3b82f6;
}

.player-card.disabled {
  opacity: 0.55;
  background-color: #fafbfc;
  border-color: #e2e8f0;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
}

.card-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

.status-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 9999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.player-card.active .status-badge {
  background-color: #eff6ff;
  color: #1d4ed8;
}

.player-card.disabled .status-badge,
.status-badge.badge-neutral {
  background-color: #f1f5f9;
  color: #64748b;
}

/* RPS Picker (Turn 1 Player 1) */
.rps-picker {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.rps-label {
  font-size: 0.8rem;
  color: #64748b;
}

.rps-buttons {
  display: flex;
  gap: 0.4rem;
}

.btn-rps {
  flex: 1;
  padding: 0.55rem 0.2rem;
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.825rem;
  font-weight: 500;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-rps:hover:not(:disabled) {
  background-color: #f1f5f9;
  border-color: #94a3b8;
}

.waiting-box {
  font-size: 0.825rem;
  color: #64748b;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem;
  line-height: 1.4;
}

/* Custom Input Group */
.input-group {
  display: flex;
  gap: 0.5rem;
}

.play-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 0.65rem;
  font-size: 0.875rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  color: #0f172a;
  background: #ffffff;
  outline: none;
  transition: border-color 0.15s ease;
}

.play-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.play-input:disabled {
  background-color: #f8fafc;
  color: #94a3b8;
  cursor: not-allowed;
}

.play-btn {
  height: 38px;
  padding: 0 0.9rem;
  background-color: #2563eb;
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  white-space: nowrap;
}

.play-btn:hover:not(:disabled) {
  background-color: #1d4ed8;
}

.play-btn:disabled {
  background-color: #cbd5e1;
  cursor: not-allowed;
}

/* Opponent Panel */
.opponent-panel {
  background-color: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.opponent-showcase {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem;
  text-align: center;
}

.opp-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  font-weight: 600;
  display: block;
  margin-bottom: 0.25rem;
}

.opp-last-move {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0f172a;
  min-height: 1.5rem;
}

.opponent-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.stat-item {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.stat-name {
  font-size: 0.725rem;
  color: #64748b;
  font-weight: 500;
}

.stat-val {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
}

.stat-online {
  color: #10b981;
}

/* History Panel */
.history-panel {
  border-top: 1px solid #f1f5f9;
  padding-top: 1.25rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.65rem;
}

.history-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #334155;
}

.history-sub {
  font-size: 0.75rem;
  color: #94a3b8;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.history-item {
  font-size: 0.85rem;
  color: #334155;
  background-color: #f8fafc;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
}

.history-empty {
  font-size: 0.825rem;
  color: #94a3b8;
  font-style: italic;
  padding: 0.35rem 0;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Header Right & Navigation */
.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.profile-nav-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.65rem;
  font-size: 0.775rem;
}

.avatar-icon-sm {
  font-size: 0.95rem;
  line-height: 1;
}

/* App Loading & Error States */
.app-loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 4rem 1rem;
  color: #64748b;
  font-size: 0.9rem;
}

.page-error-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
  padding: 2.5rem 1.5rem;
  background-color: #fef2f2;
  border: 1px solid #fee2e2;
  border-radius: 8px;
  color: #991b1b;
}

.page-error-card h2 {
  font-size: 1.15rem;
}

.page-error-card .error-tip {
  font-size: 0.8rem;
  color: #64748b;
  max-width: 480px;
}

/* Profile Screen Styling */
.profile-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.25rem;
}

.profile-identity {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.avatar-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.profile-avatar {
  font-size: 3rem;
  line-height: 1;
  background: #ffffff;
  border: 2px solid #e2e8f0;
  border-radius: 50%;
  width: 72px;
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.avatar-picker-row {
  display: flex;
  gap: 0.25rem;
}

.btn-avatar {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 0.95rem;
  padding: 0.25rem;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1;
}

.btn-avatar:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

.btn-avatar.active {
  border-color: #2563eb;
  background: #eff6ff;
  box-shadow: 0 0 0 1px #2563eb;
}

.profile-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.profile-name-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.profile-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.name-edit-group {
  display: flex;
  gap: 0.4rem;
}

.player-name-input {
  flex: 1;
  height: 36px;
  padding: 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  outline: none;
  background: #ffffff;
}

.player-name-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

#lobby-screen > .player-name-input {
  display: block;
  width: min(100% - 2rem, 420px);
  height: 48px;
  margin: 0 auto 1.25rem;
  padding: 0 1rem;
  border-radius: 10px;
  box-shadow: 0 2px 5px rgba(15, 23, 42, 0.06);
}

#lobby-screen > .player-name-input::placeholder {
  color: #94a3b8;
}

.btn-sm {
  height: 36px;
  padding: 0 0.85rem;
  font-size: 0.8rem;
}

.save-indicator {
  font-size: 0.75rem;
  color: #10b981;
  font-weight: 500;
}

.rank-badge {
  align-self: flex-start;
  font-size: 0.75rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  border: 1px solid #dbeafe;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  letter-spacing: 0.02em;
}

/* Profile Sections & Statistics Grid */
.profile-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.65rem;
}

.stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.stat-title {
  font-size: 0.725rem;
  font-weight: 500;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-number {
  font-size: 1.35rem;
  font-weight: 700;
  color: #0f172a;
}

.stat-number.stat-highlight {
  color: #2563eb;
}

/* Preferences & Toggle Switches */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.setting-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.setting-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
}

.setting-desc {
  font-size: 0.775rem;
  color: #64748b;
}

/* Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #cbd5e1;
  transition: 0.2s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.2s;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

input:checked + .slider {
  background-color: #2563eb;
}

input:checked + .slider:before {
  transform: translateX(20px);
}

/* Profile Footer Actions */
.profile-footer-actions {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid #f1f5f9;
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.btn-danger {
  color: #dc2626;
  border-color: #fecaca;
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
  border-color: #f87171;
  color: #b91c1c;
}

@media (max-width: 540px) {
  .players-grid {
    grid-template-columns: 1fr;
  }
  .stats-overview-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .profile-identity {
    flex-direction: column;
    align-items: flex-start;
  }
}
